X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignedCodonFrame.java;h=627f0a6a6ba112e3178ed909e80432ca8a551b10;hb=4d7f98a6dd54d9863ba449ec79dcd95d25ed863d;hp=1f5d827ed54461888f3daf44664c107655ff4cc3;hpb=be32c14cd8e48fe0a207cd7030cb9cd46f894678;p=jalview.git diff --git a/src/jalview/datamodel/AlignedCodonFrame.java b/src/jalview/datamodel/AlignedCodonFrame.java index 1f5d827..627f0a6 100644 --- a/src/jalview/datamodel/AlignedCodonFrame.java +++ b/src/jalview/datamodel/AlignedCodonFrame.java @@ -23,6 +23,9 @@ package jalview.datamodel; 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. @@ -30,12 +33,12 @@ import jalview.util.MappingUtils; 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 @@ -370,7 +373,8 @@ public class AlignedCodonFrame if (dnaSeqs[mi] == targetDs && dnaToProt[mi].to == sourceDs) { int[] codon = dnaToProt[mi].map.locateInFrom(pos, pos); - if (codon != null) { + if (codon != null) + { return codon; } } @@ -419,8 +423,40 @@ public class AlignedCodonFrame * 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], + return new char[] { dnaSeq[codonPos[0] - 1], dnaSeq[codonPos[1] - 1], dnaSeq[codonPos[2] - 1] }; } + + /** + * Returns any mappings found which are to (or from) the given sequence, and + * to distinct sequences. + * + * @param seq + * @return + */ + public List getMappingsForSequence(SequenceI seq) + { + List result = new ArrayList(); + if (dnaSeqs == null) + { + return result; + } + List related = new ArrayList(); + 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; + } }