/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1)
+ * Copyright (C) 2015 The Jalview Authors
*
* This file is part of Jalview.
*
import jalview.util.MapList;
import jalview.util.MappingUtils;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Stores mapping between the columns of a protein alignment and a DNA alignment
* and a list of individual codon to amino acid mappings between sequences.
public class AlignedCodonFrame
{
- /*
+ /**
* tied array of na Sequence objects.
*/
private SequenceI[] dnaSeqs = null;
- /*
+ /**
* tied array of Mappings to protein sequence Objects and SequenceI[]
* aaSeqs=null; MapLists where each maps from the corresponding dnaSeqs
* element to corresponding aaSeqs element
if (dnaSeqs[mi] == targetDs && dnaToProt[mi].to == sourceDs)
{
int[] codon = dnaToProt[mi].map.locateInFrom(pos, pos);
- if (codon != null) {
+ if (codon != null)
+ {
return codon;
}
}
return null;
}
MapList ml = null;
- char[] dnaSeq = null;
+ SequenceI dnaSeq = null;
for (int i = 0; i < dnaToProt.length; i++)
{
if (dnaToProt[i].to == protein)
{
ml = getdnaToProt()[i];
- dnaSeq = dnaSeqs[i].getSequence();
+ dnaSeq = dnaSeqs[i];
break;
}
}
* Read off the mapped nucleotides (converting to position base 0)
*/
codonPos = MappingUtils.flattenRanges(codonPos);
- return new char[]
- { dnaSeq[codonPos[0] - 1], dnaSeq[codonPos[1] - 1],
- dnaSeq[codonPos[2] - 1] };
+ char[] dna = dnaSeq.getSequence();
+ int start = dnaSeq.getStart();
+ return new char[] { dna[codonPos[0] - start], dna[codonPos[1] - start],
+ dna[codonPos[2] - start] };
+ }
+
+ /**
+ * Returns any mappings found which are to (or from) the given sequence, and
+ * to distinct sequences.
+ *
+ * @param seq
+ * @return
+ */
+ public List<Mapping> getMappingsForSequence(SequenceI seq)
+ {
+ List<Mapping> result = new ArrayList<Mapping>();
+ if (dnaSeqs == null)
+ {
+ return result;
+ }
+ List<SequenceI> related = new ArrayList<SequenceI>();
+ SequenceI seqDs = seq.getDatasetSequence();
+ seqDs = seqDs != null ? seqDs : seq;
+
+ for (int ds = 0; ds < dnaSeqs.length; ds++)
+ {
+ final Mapping mapping = dnaToProt[ds];
+ if (dnaSeqs[ds] == seqDs || mapping.to == seqDs)
+ {
+ if (!related.contains(mapping.to))
+ {
+ result.add(mapping);
+ related.add(mapping.to);
+ }
+ }
+ }
+ return result;
}
}