From ee5e8d9c81551a581b11dc4b0c609e2b75ab772a Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 3 Feb 2022 14:20:11 +0000 Subject: [PATCH] JAL-3806 use same logic as for mouse over highlighting to work out extent of selected region in complement alignment --- src/jalview/util/MappingUtils.java | 83 +++++++++++++++++------------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 1337cf0..c992243 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -40,6 +40,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; @@ -362,55 +363,49 @@ public final class MappingUtils */ int startResiduePos = selected.findPosition(firstUngappedPos); int endResiduePos = selected.findPosition(lastUngappedPos); - - for (AlignedCodonFrame acf : codonFrames) + for (SequenceI seq : mapTo.getAlignment().getSequences()) { - // TODO: handle multiple mappings - SequenceI mappedSequence = targetIsNucleotide - ? acf.getDnaForAaSeq(selected) - : acf.getAaForDnaSeq(selected); - if (mappedSequence != null) + int mappedStartResidue = 0; + int mappedEndResidue = 0; + + for (AlignedCodonFrame acf : codonFrames) { - for (SequenceI seq : mapTo.getAlignment().getSequences()) + Mapping map = acf.getMappingBetween(seq, selected); + if (map != null) { - int mappedStartResidue = 0; - int mappedEndResidue = 0; - if (seq.getDatasetSequence() == mappedSequence) + /* + * Found a sequence mapping. Locate the start/end mapped residues. + */ + List mapping = Arrays + .asList(new AlignedCodonFrame[] + { acf }); + SearchResultsI sr = buildSearchResults(selected, + startResiduePos, mapping); + for (SearchResultMatchI m : sr.getResults()) { - /* - * Found a sequence mapping. Locate the start/end mapped residues. - */ - List mapping = Arrays - .asList(new AlignedCodonFrame[] - { 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()) - { - 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; + mappedStartResidue = m.getStart(); + mappedEndResidue = m.getEnd(); } + 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; } } } -- 1.7.10.2