Skip to content

Commit

Permalink
made a protective hook if no longestPeptide set
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandunn committed Jan 25, 2021
1 parent 3eabb02 commit 632cbe7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
14 changes: 13 additions & 1 deletion grails-app/services/org/bbop/apollo/FeatureService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,19 @@ class FeatureService {
CDS cds = transcriptService.getCDS(transcript);
log.info "calculateCDS"
if (cds == null) {
log.debug "CDS is null, so setting longest ORF"
setLongestORF(transcript, readThroughStopCodon);
return;
}
log.debug "CDS found $cds, checking for manual start and end"
boolean manuallySetStart = cdsService.isManuallySetTranslationStart(cds);
boolean manuallySetEnd = cdsService.isManuallySetTranslationEnd(cds);
log.debug "CDS found $cds, manual start $manuallySetStart end $manuallySetEnd"
if (manuallySetStart && manuallySetEnd) {
return;
}
if (!manuallySetStart && !manuallySetEnd) {
log.debug "neither start or end is set manually so calculating ORF"
setLongestORF(transcript, readThroughStopCodon);
} else if (manuallySetStart) {
setTranslationStart(transcript, cds.getFeatureLocation().getStrand().equals(-1) ? cds.getFmax() - 1 : cds.getFmin(), true, readThroughStopCodon);
Expand Down Expand Up @@ -1182,9 +1186,13 @@ public void setTranslationEnd(Transcript transcript, int translationEnd) {
@Timed
@Transactional
void setLongestORF(Transcript transcript, boolean readThroughStopCodon) {
log.debug "Setting longest orf with $transcript and read through stop codon $readThroughStopCodon"
Organism organism = transcript.featureLocation.sequence.organism
log.debug "organism found ${organism}"
TranslationTable translationTable = organismService.getTranslationTable(organism)
log.debug "translation table found ${translationTable.startCodons} , $translationTable.stopCodons"
String mrna = getResiduesWithAlterationsAndFrameshifts(transcript);
log.debug "mrna residues found ${mrna}"
if (!mrna) {
return;
}
Expand All @@ -1197,6 +1205,7 @@ public void setTranslationEnd(Transcript transcript, int translationEnd) {
boolean partialStop = false;

if (mrna.length() > 3) {
log.debug "finding start index"
for (String startCodon : translationTable.getStartCodons()) {
// find the first start codon
startIndex = mrna.indexOf(startCodon)
Expand All @@ -1210,6 +1219,7 @@ public void setTranslationEnd(Transcript transcript, int translationEnd) {
startIndex = mrna.indexOf(startCodon, startIndex + 1)
}
}
log.debug "best start index $bestStartIndex"

// Just in case the 5' end is missing, check to see if a longer
// translation can be obtained without looking for a start codon
Expand All @@ -1224,10 +1234,12 @@ public void setTranslationEnd(Transcript transcript, int translationEnd) {
}
startIndex++
}
log.debug "best start index modified if initial start index <3 $bestStartIndex"
}
log.debug "longest peptide: '$longestPeptide'"

// check for partial stop
if (!longestPeptide.substring(longestPeptide.length() - 1).equals(TranslationTable.STOP)) {
if (longestPeptide && !longestPeptide.substring(longestPeptide.length() - 1).equals(TranslationTable.STOP)) {
partialStop = true
bestStopIndex = -1
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ class SequenceTranslationHandler {
* @throws AnnotationException - If an invalid NCBI translation table code is used
*/
static TranslationTable getTranslationTableForGeneticCode(String code, String rootPath) throws AnnotationException {
println "input code ${code} ${rootPath}"
if (!translationTables.containsKey(code)) {
initTranslationTables(code,rootPath);
}
Expand Down
10 changes: 5 additions & 5 deletions src/groovy/org/bbop/apollo/sequence/TranslationTable.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TranslationTable {
alternateTranslationTable = new HashMap<String, String>();
}

public TranslationTable cloneTable() {
TranslationTable cloneTable() {
TranslationTable clone = null;
try {
clone = getClass().newInstance();
Expand All @@ -50,7 +50,7 @@ class TranslationTable {
* @param codon - Codon to be translated
* @return Amino acid corresponding to the the codon
*/
public String translateCodon(String codon) {
String translateCodon(String codon) {
String aa = translationTable.get(codon);
if (aa == null) {
return "X";
Expand All @@ -62,7 +62,7 @@ class TranslationTable {
*
* @return Collection of Strings representing the start codons
*/
public Collection<String> getStartCodons() {
Collection<String> getStartCodons() {
return startCodons;
}

Expand All @@ -78,11 +78,11 @@ class TranslationTable {
return translateCodon(codon).equals(STOP);
}

public Map<String, String> getTranslationTable() {
Map<String, String> getTranslationTable() {
return translationTable;
}

public Map<String, String> getAlternateTranslationTable() {
Map<String, String> getAlternateTranslationTable() {
return alternateTranslationTable;
}

Expand Down

0 comments on commit 632cbe7

Please sign in to comment.