import jalview.datamodel.Annotation;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.FeatureProperties;
+import jalview.datamodel.GraphLine;
import jalview.datamodel.Mapping;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.schemes.ResidueProperties;
+import jalview.util.Comparison;
import jalview.util.MapList;
import jalview.util.ShiftList;
import java.util.ArrayList;
import java.util.Hashtable;
+import java.util.List;
import java.util.Vector;
public class Dna
}
/**
- * translate na alignment annotations onto translated amino acid alignment al
+ * Translate na alignment annotations onto translated amino acid alignment al
* using codon mapping codons
*
* @param annotations
AlignmentAnnotation[] annotations, AlignmentI al,
AlignedCodonFrame codons)
{
- // //////////////////////////////
- // Copy annotations across
- //
// Can only do this for columns with consecutive codons, or where
// annotation is sequence associated.
- int pos, a, aSize;
if (annotations != null)
{
- for (int i = 0; i < annotations.length; i++)
+ for (AlignmentAnnotation annotation : annotations)
{
- // Skip any autogenerated annotation
- if (annotations[i].autoCalculated)
- {
- continue;
- }
-
- // skip hidden sequence annotations
- final SequenceI seqRef = annotations[i].sequenceRef;
- if (seqRef != null && !annotations[i].visible)
+ /*
+ * Skip hidden or autogenerated annotation. Also (for now), RNA
+ * secondary structure annotation. If we want to show this against
+ * protein we need a smarter way to 'translate' without generating
+ * invalid (unbalanced) structure annotation.
+ */
+ if (annotation.autoCalculated || !annotation.visible
+ || annotation.isRNA())
{
continue;
}
- aSize = codons.getaaWidth(); // aa alignment width.
- jalview.datamodel.Annotation[] anots = (annotations[i].annotations == null) ? null
- : new jalview.datamodel.Annotation[aSize];
+ int aSize = codons.getaaWidth(); // aa alignment width.
+ Annotation[] anots = (annotation.annotations == null) ? null
+ : new Annotation[aSize];
if (anots != null)
{
- for (a = 0; a < aSize; a++)
+ for (int a = 0; a < aSize; a++)
{
// process through codon map.
if (a < codons.codons.length && codons.codons[a] != null
&& codons.codons[a][0] == (codons.codons[a][2] - 2))
{
anots[a] = getCodonAnnotation(codons.codons[a],
- annotations[i].annotations);
+ annotation.annotations);
}
}
}
- jalview.datamodel.AlignmentAnnotation aa = new jalview.datamodel.AlignmentAnnotation(
- annotations[i].label, annotations[i].description, anots);
- aa.graph = annotations[i].graph;
- aa.graphGroup = annotations[i].graphGroup;
- aa.graphHeight = annotations[i].graphHeight;
- if (annotations[i].getThreshold() != null)
+ AlignmentAnnotation aa = new AlignmentAnnotation(annotation.label,
+ annotation.description, anots);
+ aa.graph = annotation.graph;
+ aa.graphGroup = annotation.graphGroup;
+ aa.graphHeight = annotation.graphHeight;
+ if (annotation.getThreshold() != null)
{
- aa.setThreshold(new jalview.datamodel.GraphLine(annotations[i]
+ aa.setThreshold(new GraphLine(annotation
.getThreshold()));
}
- if (annotations[i].hasScore)
+ if (annotation.hasScore)
{
- aa.setScore(annotations[i].getScore());
+ aa.setScore(annotation.getScore());
}
+
+ final SequenceI seqRef = annotation.sequenceRef;
if (seqRef != null)
{
- SequenceI aaSeq = codons
- .getAaForDnaSeq(seqRef);
+ SequenceI aaSeq = codons.getAaForDnaSeq(seqRef);
if (aaSeq != null)
{
// aa.compactAnnotationArray(); // throw away alignment annotation
// positioning
aa.setSequenceRef(aaSeq);
- aa.createSequenceMapping(aaSeq, aaSeq.getStart(), true); // rebuild
- // mapping
+ // rebuild mapping
+ aa.createSequenceMapping(aaSeq, aaSeq.getStart(), true);
aa.adjustForAlignment();
aaSeq.addAlignmentAnnotation(aa);
}
-
}
al.addAnnotation(aa);
}
String seqstring, int[] viscontigs, AlignedCodonFrame codons,
char gapCharacter, DBRefEntry product, final boolean starForStop)
{
- java.util.List skip = new ArrayList();
+ List<int[]> skip = new ArrayList<int[]>();
int skipint[] = null;
ShiftList vismapping = new ShiftList(); // map from viscontigs to seqstring
// intervals
scontigs[vc + 1] = viscontigs[vc + 1];
}
- StringBuffer protein = new StringBuffer();
+ // allocate a roughly sized buffer for the protein sequence
+ StringBuilder protein = new StringBuilder(seqstring.length() / 2);
String seq = seqstring.replace('U', 'T');
char codon[] = new char[3];
int cdp[] = new int[3], rf = 0, lastnpos = 0, nend;
int resSize = 0;
for (npos = 0, nend = seq.length(); npos < nend; npos++)
{
- if (!jalview.util.Comparison.isGap(seq.charAt(npos)))
+ if (!Comparison.isGap(seq.charAt(npos)))
{
cdp[rf] = npos; // store position
codon[rf++] = seq.charAt(npos); // store base
}
- // filled an RF yet ?
if (rf == 3)
{
+ /*
+ * Filled up a reading frame...
+ */
String aa = ResidueProperties.codonTranslate(new String(codon));
rf = 0;
if (aa == null)