Skip to content

Instantly share code, notes, and snippets.

@nathandunn
Created October 11, 2016 17:49
Show Gist options
  • Save nathandunn/927c212bc23c89c8104707b2637f5206 to your computer and use it in GitHub Desktop.
Save nathandunn/927c212bc23c89c8104707b2637f5206 to your computer and use it in GitHub Desktop.
old apollo setLongestORF
public void setLongestORF(Transcript transcript, SequenceUtil.TranslationTable translationTable, boolean allowPartialExtension, boolean readThroughStopCodon) {
String mrna = getSession().getResiduesWithAlterationsAndFrameshifts(transcript);
if (mrna == null || mrna.equals("null")) {
return;
}
String longestPeptide = "";
int bestStartIndex = -1;
int bestStopIndex = -1;
boolean partialStop = false;
if (mrna.length() > 3) {
for (String startCodon : translationTable.getStartCodons()) {
int startIndex = mrna.indexOf(startCodon);
while (startIndex >= 0) {
String mrnaSubstring = mrna.substring(startIndex);
String aa = SequenceUtil.translateSequence(mrnaSubstring, translationTable, true, readThroughStopCodon);
if (aa.length() > longestPeptide.length()) {
longestPeptide = aa;
bestStartIndex = startIndex;
bestStopIndex = startIndex + (aa.length() * 3);
if (!longestPeptide.substring(longestPeptide.length() - 1).equals(SequenceUtil.TranslationTable.STOP)) {
partialStop = true;
bestStopIndex += mrnaSubstring.length() % 3;
}
}
startIndex = mrna.indexOf(startCodon, startIndex + 1);
}
}
}
Date date = new Date();
if (transcript.getType().equals("sequence:mRNA")) {
boolean needCdsIndex = transcript.getCDS() == null;
CDS cds = transcript.getCDS();
if (cds == null) {
cds = createCDS(transcript);
transcript.setCDS(cds);
}
if (bestStartIndex >= 0) {
int fmin = getSession().convertModifiedLocalCoordinateToSourceCoordinate(transcript, bestStartIndex);
int fmax = getSession().convertModifiedLocalCoordinateToSourceCoordinate(transcript, bestStopIndex);
if (cds.getStrand().equals(-1)) {
int tmp = fmin;
fmin = fmax + 1;
fmax = tmp + 1;
}
cds.setFmin(fmin);
cds.setFminPartial(false);
cds.setFmax(fmax);
cds.setFmaxPartial(partialStop);
} else {
cds.setFmin(transcript.getFmin());
cds.setFminPartial(true);
String aa = SequenceUtil.translateSequence(mrna, translationTable, true, readThroughStopCodon);
if (aa.substring(aa.length() - 1).equals(SequenceUtil.TranslationTable.STOP)) {
cds.setFmax(getSession().convertModifiedLocalCoordinateToSourceCoordinate(transcript, aa.length() * 3));
cds.setFmaxPartial(false);
} else {
cds.setFmax(transcript.getFmax());
cds.setFmaxPartial(true);
}
}
if (readThroughStopCodon) {
String aa = SequenceUtil.translateSequence(getSession().getResiduesWithAlterationsAndFrameshifts(cds), translationTable, true, true);
int firstStopIndex = aa.indexOf(SequenceUtil.TranslationTable.STOP);
if (firstStopIndex < aa.length() - 1) {
StopCodonReadThrough stopCodonReadThrough = createStopCodonReadThrough(cds);
cds.setStopCodonReadThrough(stopCodonReadThrough);
int offset = transcript.getStrand() == -1 ? -2 : 0;
stopCodonReadThrough.setFmin(getSession().convertModifiedLocalCoordinateToSourceCoordinate(cds, firstStopIndex * 3) + offset);
stopCodonReadThrough.setFmax(getSession().convertModifiedLocalCoordinateToSourceCoordinate(cds, firstStopIndex * 3) + 3 + offset);
}
} else {
cds.deleteStopCodonReadThrough();
}
setManuallySetTranslationStart(cds, false);
setManuallySetTranslationEnd(cds, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment