import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
public class Dna
* 'final' variables describe the inputs to the translation, which should not
* be modified.
*/
- final private List<SequenceI> selection;
+ private final List<SequenceI> selection;
- final private String[] seqstring;
+ private final String[] seqstring;
- final private int[] contigs;
+ private final Iterator<int[]> contigs;
- final private char gapChar;
+ private final char gapChar;
- final private AlignmentAnnotation[] annotations;
+ private final AlignmentAnnotation[] annotations;
- final private int dnaWidth;
+ private final int dnaWidth;
- final private AlignmentI dataset;
+ private final AlignmentI dataset;
+
+ private ShiftList vismapping;
+
+ private int[] startcontigs;
/*
* Working variables for the translation.
* @param viewport
* @param visibleContigs
*/
- public Dna(AlignViewportI viewport, int[] visibleContigs)
+ public Dna(AlignViewportI viewport, Iterator<int[]> visibleContigs)
{
this.selection = Arrays.asList(viewport.getSequenceSelection());
this.seqstring = viewport.getViewAsString(true);
this.annotations = viewport.getAlignment().getAlignmentAnnotation();
this.dnaWidth = viewport.getAlignment().getWidth();
this.dataset = viewport.getAlignment().getDataset();
+ initContigs();
+ }
+
+ /**
+ * Initialise contigs used as starting point for translateCodingRegion
+ */
+ private void initContigs()
+ {
+ vismapping = new ShiftList(); // map from viscontigs to seqstring
+ // intervals
+
+ int npos = 0;
+ int[] lastregion = null;
+ ArrayList<Integer> tempcontigs = new ArrayList<>();
+ while (contigs.hasNext())
+ {
+ int[] region = contigs.next();
+ if (lastregion == null)
+ {
+ vismapping.addShift(npos, region[0]);
+ }
+ else
+ {
+ // hidden region
+ vismapping.addShift(npos, region[0] - lastregion[1] + 1);
+ }
+ lastregion = region;
+ tempcontigs.add(region[0]);
+ tempcontigs.add(region[1]);
+ }
+
+ startcontigs = new int[tempcontigs.size()];
+ int i = 0;
+ for (Integer val : tempcontigs)
+ {
+ startcontigs[i] = val;
+ i++;
+ }
+ tempcontigs = null;
}
/**
}
/**
+ * Translates cDNA using the specified code table
*
* @return
*/
- public AlignmentI translateCdna()
+ public AlignmentI translateCdna(GeneticCodeI codeTable)
{
AlignedCodonFrame acf = new AlignedCodonFrame();
int s;
int sSize = selection.size();
- List<SequenceI> pepseqs = new ArrayList<SequenceI>();
+ List<SequenceI> pepseqs = new ArrayList<>();
for (s = 0; s < sSize; s++)
{
SequenceI newseq = translateCodingRegion(selection.get(s),
- seqstring[s], acf, pepseqs);
+ seqstring[s], acf, pepseqs, codeTable);
if (newseq != null)
{
if (dnarefs != null)
{
// intersect with pep
- List<DBRefEntry> mappedrefs = new ArrayList<DBRefEntry>();
+ List<DBRefEntry> mappedrefs = new ArrayList<>();
DBRefEntry[] refs = dna.getDBRefs();
for (int d = 0; d < refs.length; d++)
{
* @param acf
* Definition of global ORF alignment reference frame
* @param proteinSeqs
+ * @param codeTable
* @return sequence ready to be added to alignment.
*/
protected SequenceI translateCodingRegion(SequenceI selection,
String seqstring, AlignedCodonFrame acf,
- List<SequenceI> proteinSeqs)
+ List<SequenceI> proteinSeqs, GeneticCodeI codeTable)
{
- List<int[]> skip = new ArrayList<int[]>();
- int skipint[] = null;
- ShiftList vismapping = new ShiftList(); // map from viscontigs to seqstring
- // intervals
- int vc;
- int[] scontigs = new int[contigs.length];
+ List<int[]> skip = new ArrayList<>();
+ int[] skipint = null;
+
int npos = 0;
- for (vc = 0; vc < contigs.length; vc += 2)
- {
- if (vc == 0)
- {
- vismapping.addShift(npos, contigs[vc]);
- }
- else
- {
- // hidden region
- vismapping.addShift(npos, contigs[vc] - contigs[vc - 1] + 1);
- }
- scontigs[vc] = contigs[vc];
- scontigs[vc + 1] = contigs[vc + 1];
- }
+ int vc = 0;
+
+ int[] scontigs = new int[startcontigs.length];
+ System.arraycopy(startcontigs, 0, scontigs, 0, startcontigs.length);
// allocate a roughly sized buffer for the protein sequence
StringBuilder protein = new StringBuilder(seqstring.length() / 2);
/*
* Filled up a reading frame...
*/
- AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1],
- cdp[2]);
- String aa = ResidueProperties.codonTranslate(new String(codon));
+ AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1], cdp[2]);
+ String aa = codeTable.translate(new String(codon));
rf = 0;
final String gapString = String.valueOf(gapChar);
if (aa == null)
skip.add(skipint);
skipint = null;
}
- if (aa.equals("STOP"))
+ if (aa.equals(ResidueProperties.STOP))
{
aa = STOP_ASTERIX;
}
public AlignmentI reverseCdna(boolean complement)
{
int sSize = selection.size();
- List<SequenceI> reversed = new ArrayList<SequenceI>();
+ List<SequenceI> reversed = new ArrayList<>();
for (int s = 0; s < sSize; s++)
{
SequenceI newseq = reverseSequence(selection.get(s).getName(),