X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=blobdiff_plain;f=src%2Fjalview%2Futil%2FMappingUtils.java;h=c8b5190865ab4ad30dc479ed73e1dbba0751b5a7;hp=4e07a08ba6c739402fa7f10389b05a4889ca3a28;hb=27aed96d1aeae689818bd0a0028553186e3c3839;hpb=7312fed439c2a32de989c6f5155203ebc0a7f854 diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 4e07a08..c8b5190 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -29,12 +29,14 @@ import java.util.Map; import jalview.analysis.AlignmentSorter; import jalview.api.AlignViewportI; +import jalview.bin.Cache; import jalview.commands.CommandI; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; import jalview.commands.EditCommand.Edit; import jalview.commands.OrderCommand; import jalview.datamodel.AlignedCodonFrame; +import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.ColumnSelection; @@ -78,7 +80,7 @@ public final class MappingUtils action = action.getUndoAction(); } // TODO write this - System.err.println("MappingUtils.mapCutOrPaste not yet implemented"); + Cache.log.error("MappingUtils.mapCutOrPaste not yet implemented"); } /** @@ -364,52 +366,45 @@ public final class MappingUtils for (AlignedCodonFrame acf : codonFrames) { - SequenceI mappedSequence = targetIsNucleotide - ? acf.getDnaForAaSeq(selected) - : acf.getAaForDnaSeq(selected); - if (mappedSequence != null) + for (SequenceI seq : mapTo.getAlignment().getSequences()) { - for (SequenceI seq : mapTo.getAlignment().getSequences()) + SequenceI peptide = targetIsNucleotide ? selected : seq; + SequenceI cds = targetIsNucleotide ? seq : selected; + SequenceToSequenceMapping s2s = acf.getCoveringMapping(cds, + peptide); + if (s2s == 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()) - { - 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; - } + 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()) + { + 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; } } } @@ -449,20 +444,23 @@ public final class MappingUtils { for (AlignedCodonFrame acf : mappings) { - SequenceI mappedSeq = mappingToNucleotide ? acf.getDnaForAaSeq(seq) - : acf.getAaForDnaSeq(seq); - if (mappedSeq != null) - { for (SequenceI seq2 : mapTo.getSequences()) { - if (seq2.getDatasetSequence() == mappedSeq) + /* + * the corresponding peptide / CDS is the one for which there is + * a complete ('covering') mapping to 'seq' + */ + SequenceI peptide = mappingToNucleotide ? seq2 : seq; + SequenceI cds = mappingToNucleotide ? seq : seq2; + SequenceToSequenceMapping s2s = acf.getCoveringMapping(cds, + peptide); + if (s2s != null) { mappedOrder.add(seq2); j++; break; } } - } } } @@ -524,7 +522,7 @@ public final class MappingUtils if (colsel == null) { - return; // mappedColumns; + return; } char fromGapChar = mapFrom.getAlignment().getGapCharacter(); @@ -548,7 +546,7 @@ public final class MappingUtils mapHiddenColumns(regions.next(), codonFrames, newHidden, fromSequences, toSequences, fromGapChar); } - return; // mappedColumns; + return; } /** @@ -666,7 +664,9 @@ public final class MappingUtils */ for (SequenceI toSeq : toSequences) { - if (toSeq.getDatasetSequence() == mappedSeq) + if (toSeq.getDatasetSequence() == mappedSeq + && mappedStartResidue >= toSeq.getStart() + && mappedEndResidue <= toSeq.getEnd()) { int mappedStartCol = toSeq.findIndex(mappedStartResidue); int mappedEndCol = toSeq.findIndex(mappedEndResidue);