X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=blobdiff_plain;f=src%2Fjalview%2Futil%2FMappingUtils.java;h=86b7a6da8733ec04f3a3d7b61ae1f0ec21dca020;hp=590e1c538278342b8c4a25af6c6933a0d70e48af;hb=4d71acba1cc4999e8e4061ec3e9ae55e1b37084e;hpb=105b70cd101cddf62d694776852bdbf0eeca3261 diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 590e1c5..86b7a6d 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -41,6 +41,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; +import jalview.datamodel.Mapping; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; @@ -363,49 +364,55 @@ public final class MappingUtils */ int startResiduePos = selected.findPosition(firstUngappedPos); int endResiduePos = selected.findPosition(lastUngappedPos); - - for (AlignedCodonFrame acf : codonFrames) + for (SequenceI seq : mapTo.getAlignment().getSequences()) { - for (SequenceI seq : mapTo.getAlignment().getSequences()) + int mappedStartResidue = 0; + int mappedEndResidue = 0; + for (AlignedCodonFrame acf : codonFrames) { - SequenceI peptide = targetIsNucleotide ? selected : seq; - SequenceI cds = targetIsNucleotide ? seq : selected; - SequenceToSequenceMapping s2s = acf.getCoveringMapping(cds, - peptide); - if (s2s == null) + // rather than use acf.getCoveringMapping() we iterate through all + // mappings to make sure all CDS are selected for a protein + for (SequenceToSequenceMapping map: acf.getMappings()) { - continue; - } - int mappedStartResidue = 0; - int mappedEndResidue = 0; - List mapping = Arrays.asList(acf); - SearchResultsI sr = buildSearchResults(selected, startResiduePos, - mapping); - for (SearchResultMatchI m : sr.getResults()) - { - mappedStartResidue = m.getStart(); - mappedEndResidue = m.getEnd(); - } - sr = buildSearchResults(selected, endResiduePos, mapping); - for (SearchResultMatchI m : sr.getResults()) + if (map.covers(selected) && map.covers(seq)) { - mappedStartResidue = Math.min(mappedStartResidue, m.getStart()); - mappedEndResidue = Math.max(mappedEndResidue, m.getEnd()); - } + /* + * Found a sequence mapping. Locate the start/end mapped residues. + */ + List mapping = Arrays + .asList(new AlignedCodonFrame[] + { acf }); + // locate start + SearchResultsI sr = buildSearchResults(selected, + startResiduePos, mapping); + for (SearchResultMatchI m : sr.getResults()) + { + mappedStartResidue = m.getStart(); + mappedEndResidue = m.getEnd(); + } + // locate end - allowing for adjustment of start range + sr = buildSearchResults(selected, endResiduePos, mapping); + for (SearchResultMatchI m : sr.getResults()) + { + mappedStartResidue = Math.min(mappedStartResidue, + m.getStart()); + mappedEndResidue = Math.max(mappedEndResidue, m.getEnd()); + } - /* - * Find the mapped aligned columns, save the range. Note findIndex - * returns a base 1 position, SequenceGroup uses base 0 - */ - int mappedStartCol = seq.findIndex(mappedStartResidue) - 1; - minStartCol = minStartCol == -1 ? mappedStartCol - : Math.min(minStartCol, mappedStartCol); - int mappedEndCol = seq.findIndex(mappedEndResidue) - 1; - maxEndCol = maxEndCol == -1 ? mappedEndCol - : Math.max(maxEndCol, mappedEndCol); - mappedGroup.addSequence(seq, false); - break; - } + /* + * Find the mapped aligned columns, save the range. Note findIndex + * returns a base 1 position, SequenceGroup uses base 0 + */ + int mappedStartCol = seq.findIndex(mappedStartResidue) - 1; + minStartCol = minStartCol == -1 ? mappedStartCol + : Math.min(minStartCol, mappedStartCol); + int mappedEndCol = seq.findIndex(mappedEndResidue) - 1; + maxEndCol = maxEndCol == -1 ? mappedEndCol + : Math.max(maxEndCol, mappedEndCol); + mappedGroup.addSequence(seq, false); + break; + } + }} } } mappedGroup.setStartRes(minStartCol < 0 ? 0 : minStartCol);