X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=bin%2Fjalview%2Futil%2FMappingUtils.js;h=487e30d4eaf06d147ac333c67add5a93e3dba1de;hp=e5f76b9eb1ccb15a0f95b8d5dce6e01b3ee2ebfd;hb=7301a2415adab88038b291fc54caeeb3a5a47a44;hpb=6154cb57a6eac3bb1344b8342495f5bb701ee921 diff --git a/bin/jalview/util/MappingUtils.js b/bin/jalview/util/MappingUtils.js index e5f76b9..487e30d 100644 --- a/bin/jalview/util/MappingUtils.js +++ b/bin/jalview/util/MappingUtils.js @@ -1,245 +1,245 @@ -Clazz.declarePackage ("jalview.util"); -Clazz.load (null, "jalview.util.MappingUtils", ["jalview.analysis.AlignmentSorter", "jalview.commands.EditCommand", "$.OrderCommand", "jalview.datamodel.AlignmentOrder", "$.ColumnSelection", "$.SearchResults", "$.Sequence", "$.SequenceGroup", "jalview.util.Comparison", "$.StringUtils", "java.util.ArrayList", "$.Collections", "$.HashMap"], function () { -c$ = Clazz.declareType (jalview.util, "MappingUtils"); -c$.mapCutOrPaste = Clazz.defineMethod (c$, "mapCutOrPaste", -function (edit, undo, targetSeqs, result, mappings) { -var action = edit.getAction (); -if (undo) { -action = action.getUndoAction (); -}System.err.println ("MappingUtils.mapCutOrPaste not yet implemented"); -}, "jalview.commands.EditCommand.Edit,~B,java.util.List,jalview.commands.EditCommand,java.util.Set"); -c$.mapEditCommand = Clazz.defineMethod (c$, "mapEditCommand", -function (command, undo, mapTo, gapChar, mappings) { -if (!mapTo.isNucleotide ()) { -return null; -}var targetCopies = new java.util.HashMap (); -for (var seq, $seq = mapTo.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) { -var ds = seq.getDatasetSequence (); -if (ds != null) { -var copy = new jalview.datamodel.Sequence (seq); -copy.setDatasetSequence (ds); -targetCopies.put (ds, copy); -}} -var originalSequences = command.priorState (undo); -var result = new jalview.commands.EditCommand (); -var edits = command.getEditIterator (!undo); -while (edits.hasNext ()) { -var edit = edits.next (); -if (edit.getAction () === jalview.commands.EditCommand.Action.CUT || edit.getAction () === jalview.commands.EditCommand.Action.PASTE) { -jalview.util.MappingUtils.mapCutOrPaste (edit, undo, mapTo.getSequences (), result, mappings); -} else if (edit.getAction () === jalview.commands.EditCommand.Action.INSERT_GAP || edit.getAction () === jalview.commands.EditCommand.Action.DELETE_GAP) { -jalview.util.MappingUtils.mapInsertOrDelete (edit, undo, originalSequences, mapTo.getSequences (), targetCopies, gapChar, result, mappings); -}} -return result.getSize () > 0 ? result : null; -}, "jalview.commands.EditCommand,~B,jalview.datamodel.AlignmentI,~S,java.util.Set"); -c$.mapInsertOrDelete = Clazz.defineMethod (c$, "mapInsertOrDelete", -function (edit, undo, originalSequences, targetSeqs, targetCopies, gapChar, result, mappings) { -var action = edit.getAction (); -if (undo) { -action = action.getUndoAction (); -}var count = edit.getNumber (); -var editPos = edit.getPosition (); -for (var seq, $seq = 0, $$seq = edit.getSequences (); $seq < $$seq.length && ((seq = $$seq[$seq]) || true); $seq++) { -var ds = seq.getDatasetSequence (); -if (ds == null) { -continue; -}var actedOn = originalSequences.get (ds); -var seqpos = actedOn.findPosition (editPos); -var sr = jalview.util.MappingUtils.buildSearchResults (seq, seqpos, mappings); -if (!sr.isEmpty ()) { -for (var targetSeq, $targetSeq = targetSeqs.iterator (); $targetSeq.hasNext () && ((targetSeq = $targetSeq.next ()) || true);) { -ds = targetSeq.getDatasetSequence (); -if (ds == null) { -continue; -}var copyTarget = targetCopies.get (ds); -var match = sr.getResults (copyTarget, 0, copyTarget.getLength ()); -if (match != null) { -var ratio = 3; -var mappedCount = count * 3; -var mappedEditPos = action === jalview.commands.EditCommand.Action.DELETE_GAP ? match[0] - mappedCount : match[0]; -var e = resultClazz.innerTypeInstance (jalview.commands.EditCommand.Edit, this, null, action, Clazz.newArray (-1, [targetSeq]), mappedEditPos, mappedCount, gapChar); -result.addEdit (e); -if (action === jalview.commands.EditCommand.Action.INSERT_GAP) { -copyTarget.setSequence ( String.instantialize (jalview.util.StringUtils.insertCharAt (copyTarget.getSequence (), mappedEditPos, mappedCount, gapChar))); -} else if (action === jalview.commands.EditCommand.Action.DELETE_GAP) { -copyTarget.setSequence ( String.instantialize (jalview.util.StringUtils.deleteChars (copyTarget.getSequence (), mappedEditPos, mappedEditPos + mappedCount))); -}}} -}if (action === jalview.commands.EditCommand.Action.INSERT_GAP) { -actedOn.setSequence ( String.instantialize (jalview.util.StringUtils.insertCharAt (actedOn.getSequence (), editPos, count, gapChar))); -} else if (action === jalview.commands.EditCommand.Action.DELETE_GAP) { -actedOn.setSequence ( String.instantialize (jalview.util.StringUtils.deleteChars (actedOn.getSequence (), editPos, editPos + count))); -}} -}, "jalview.commands.EditCommand.Edit,~B,java.util.Map,java.util.List,java.util.Map,~S,jalview.commands.EditCommand,java.util.Set"); -c$.buildSearchResults = Clazz.defineMethod (c$, "buildSearchResults", -function (seq, index, seqmappings) { -var results = new jalview.datamodel.SearchResults (); -jalview.util.MappingUtils.addSearchResults (results, seq, index, seqmappings); -return results; -}, "jalview.datamodel.SequenceI,~N,java.util.Set"); -c$.addSearchResults = Clazz.defineMethod (c$, "addSearchResults", -function (results, seq, index, seqmappings) { -if (index >= seq.getStart () && index <= seq.getEnd ()) { -for (var acf, $acf = seqmappings.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) { -acf.markMappedRegion (seq, index, results); -} -}}, "jalview.datamodel.SearchResults,jalview.datamodel.SequenceI,~N,java.util.Set"); -c$.mapSequenceGroup = Clazz.defineMethod (c$, "mapSequenceGroup", -function (sg, mapFrom, mapTo) { -var targetIsNucleotide = mapTo.isNucleotide (); -var protein = targetIsNucleotide ? mapFrom : mapTo; -var codonFrames = protein.getAlignment ().getCodonFrames (); -var mappedGroup = new jalview.datamodel.SequenceGroup (sg); -mappedGroup.cs = mapTo.getGlobalColourScheme (); -mappedGroup.clear (); -var minStartCol = -1; -var maxEndCol = -1; -var selectionStartRes = sg.getStartRes (); -var selectionEndRes = sg.getEndRes (); -for (var selected, $selected = sg.getSequences ().iterator (); $selected.hasNext () && ((selected = $selected.next ()) || true);) { -var firstUngappedPos = selectionStartRes; -while (firstUngappedPos <= selectionEndRes && jalview.util.Comparison.isGap (selected.getCharAt (firstUngappedPos))) { -firstUngappedPos++; -} -if (firstUngappedPos > selectionEndRes) { -continue; -}var lastUngappedPos = selectionEndRes; -while (lastUngappedPos >= selectionStartRes && jalview.util.Comparison.isGap (selected.getCharAt (lastUngappedPos))) { -lastUngappedPos--; -} -var startResiduePos = selected.findPosition (firstUngappedPos); -var endResiduePos = selected.findPosition (lastUngappedPos); -for (var acf, $acf = codonFrames.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) { -var mappedSequence = targetIsNucleotide ? acf.getDnaForAaSeq (selected) : acf.getAaForDnaSeq (selected); -if (mappedSequence != null) { -for (var seq, $seq = mapTo.getAlignment ().getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) { -var mappedStartResidue = 0; -var mappedEndResidue = 0; -if (seq.getDatasetSequence () === mappedSequence) { -var sr = jalview.util.MappingUtils.buildSearchResults (selected, startResiduePos, java.util.Collections.singleton (acf)); -for (var m, $m = sr.getResults ().iterator (); $m.hasNext () && ((m = $m.next ()) || true);) { -mappedStartResidue = m.getStart (); -mappedEndResidue = m.getEnd (); -} -sr = jalview.util.MappingUtils.buildSearchResults (selected, endResiduePos, java.util.Collections.singleton (acf)); -for (var m, $m = sr.getResults ().iterator (); $m.hasNext () && ((m = $m.next ()) || true);) { -mappedStartResidue = Math.min (mappedStartResidue, m.getStart ()); -mappedEndResidue = Math.max (mappedEndResidue, m.getEnd ()); -} -var mappedStartCol = seq.findIndex (mappedStartResidue) - 1; -minStartCol = minStartCol == -1 ? mappedStartCol : Math.min (minStartCol, mappedStartCol); -var mappedEndCol = seq.findIndex (mappedEndResidue) - 1; -maxEndCol = maxEndCol == -1 ? mappedEndCol : Math.max (maxEndCol, mappedEndCol); -mappedGroup.addSequence (seq, false); -break; -}} -}} -} -mappedGroup.setStartRes (minStartCol < 0 ? 0 : minStartCol); -mappedGroup.setEndRes (maxEndCol < 0 ? 0 : maxEndCol); -return mappedGroup; -}, "jalview.datamodel.SequenceGroup,jalview.api.AlignViewportI,jalview.api.AlignViewportI"); -c$.mapOrderCommand = Clazz.defineMethod (c$, "mapOrderCommand", -function (command, undo, mapTo, mappings) { -var sortOrder = command.getSequenceOrder (undo); -var mappedOrder = new java.util.ArrayList (); -var j = 0; -var mappingToNucleotide = mapTo.isNucleotide (); -for (var seq, $seq = 0, $$seq = sortOrder; $seq < $$seq.length && ((seq = $$seq[$seq]) || true); $seq++) { -for (var acf, $acf = mappings.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) { -var mappedSeq = mappingToNucleotide ? acf.getDnaForAaSeq (seq) : acf.getAaForDnaSeq (seq); -if (mappedSeq != null) { -for (var seq2, $seq2 = mapTo.getSequences ().iterator (); $seq2.hasNext () && ((seq2 = $seq2.next ()) || true);) { -if (seq2.getDatasetSequence () === mappedSeq) { -mappedOrder.add (seq2); -j++; -break; -}} -}} -} -if (j == 0) { -return null; -}if (j < mapTo.getHeight ()) { -for (var seq, $seq = mapTo.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) { -if (!mappedOrder.contains (seq)) { -mappedOrder.add (seq); -}} -}var mappedOrderArray = mappedOrder.toArray ( new Array (mappedOrder.size ())); -var oldOrder = mapTo.getSequencesArray (); -jalview.analysis.AlignmentSorter.sortBy (mapTo, new jalview.datamodel.AlignmentOrder (mappedOrderArray)); -var result = new jalview.commands.OrderCommand (command.getDescription (), oldOrder, mapTo); -return result; -}, "jalview.commands.OrderCommand,~B,jalview.datamodel.AlignmentI,java.util.Set"); -c$.mapColumnSelection = Clazz.defineMethod (c$, "mapColumnSelection", -function (colsel, mapFrom, mapTo) { -var targetIsNucleotide = mapTo.isNucleotide (); -var protein = targetIsNucleotide ? mapFrom : mapTo; -var codonFrames = protein.getAlignment ().getCodonFrames (); -var mappedColumns = new jalview.datamodel.ColumnSelection (); -if (colsel == null) { -return mappedColumns; -}var fromGapChar = mapFrom.getAlignment ().getGapCharacter (); -for (var obj, $obj = colsel.getSelected ().iterator (); $obj.hasNext () && ((obj = $obj.next ()) || true);) { -var col = (obj).intValue (); -var mappedToMin = 2147483647; -var mappedToMax = -2147483648; -for (var fromSeq, $fromSeq = mapFrom.getAlignment ().getSequences ().iterator (); $fromSeq.hasNext () && ((fromSeq = $fromSeq.next ()) || true);) { -if (fromSeq.getCharAt (col) == fromGapChar) { -continue; -}var residuePos = fromSeq.findPosition (col); -var sr = jalview.util.MappingUtils.buildSearchResults (fromSeq, residuePos, codonFrames); -for (var m, $m = sr.getResults ().iterator (); $m.hasNext () && ((m = $m.next ()) || true);) { -var mappedStartResidue = m.getStart (); -var mappedEndResidue = m.getEnd (); -var mappedSeq = m.getSequence (); -for (var toSeq, $toSeq = mapTo.getAlignment ().getSequences ().iterator (); $toSeq.hasNext () && ((toSeq = $toSeq.next ()) || true);) { -if (toSeq.getDatasetSequence () === mappedSeq) { -var mappedStartCol = toSeq.findIndex (mappedStartResidue); -var mappedEndCol = toSeq.findIndex (mappedEndResidue); -mappedToMin = Math.min (mappedToMin, mappedStartCol); -mappedToMax = Math.max (mappedToMax, mappedEndCol); -break; -}} -} -} -for (var i = mappedToMin; i <= mappedToMax; i++) { -mappedColumns.addElement (i - 1); -} -} -return mappedColumns; -}, "jalview.datamodel.ColumnSelection,jalview.api.AlignViewportI,jalview.api.AlignViewportI"); -c$.findCodonFor = Clazz.defineMethod (c$, "findCodonFor", -function (seq, col, mappings) { -var dsPos = seq.findPosition (col); -for (var mapping, $mapping = mappings.iterator (); $mapping.hasNext () && ((mapping = $mapping.next ()) || true);) { -if (mapping.involvesSequence (seq)) { -return mapping.getMappedCodon (seq.getDatasetSequence (), dsPos); -}} -return null; -}, "jalview.datamodel.SequenceI,~N,java.util.Set"); -c$.flattenRanges = Clazz.defineMethod (c$, "flattenRanges", -function (ranges) { -var count = 0; -for (var i = 0; i < ranges.length - 1; i += 2) { -count += ranges[i + 1] - ranges[i] + 1; -} -var result = Clazz.newIntArray (count, 0); -var k = 0; -for (var i = 0; i < ranges.length - 1; i += 2) { -for (var j = ranges[i]; j <= ranges[i + 1]; j++) { -result[k++] = j; -} -} -return result; -}, "~A"); -c$.findMappingsForSequence = Clazz.defineMethod (c$, "findMappingsForSequence", -function (sequence, mappings) { -var result = new java.util.ArrayList (); -if (sequence == null || mappings == null) { -return result; -}for (var mapping, $mapping = mappings.iterator (); $mapping.hasNext () && ((mapping = $mapping.next ()) || true);) { -if (mapping.involvesSequence (sequence)) { -result.add (mapping); -}} -return result; -}, "jalview.datamodel.SequenceI,java.util.Set"); -}); +Clazz.declarePackage ("jalview.util"); +Clazz.load (null, "jalview.util.MappingUtils", ["jalview.analysis.AlignmentSorter", "jalview.commands.EditCommand", "$.OrderCommand", "jalview.datamodel.AlignmentOrder", "$.ColumnSelection", "$.SearchResults", "$.Sequence", "$.SequenceGroup", "jalview.util.Comparison", "$.StringUtils", "java.util.ArrayList", "$.Collections", "$.HashMap"], function () { +c$ = Clazz.declareType (jalview.util, "MappingUtils"); +c$.mapCutOrPaste = Clazz.defineMethod (c$, "mapCutOrPaste", +function (edit, undo, targetSeqs, result, mappings) { +var action = edit.getAction (); +if (undo) { +action = action.getUndoAction (); +}System.err.println ("MappingUtils.mapCutOrPaste not yet implemented"); +}, "jalview.commands.EditCommand.Edit,~B,java.util.List,jalview.commands.EditCommand,java.util.Set"); +c$.mapEditCommand = Clazz.defineMethod (c$, "mapEditCommand", +function (command, undo, mapTo, gapChar, mappings) { +if (!mapTo.isNucleotide ()) { +return null; +}var targetCopies = new java.util.HashMap (); +for (var seq, $seq = mapTo.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) { +var ds = seq.getDatasetSequence (); +if (ds != null) { +var copy = new jalview.datamodel.Sequence (seq); +copy.setDatasetSequence (ds); +targetCopies.put (ds, copy); +}} +var originalSequences = command.priorState (undo); +var result = new jalview.commands.EditCommand (); +var edits = command.getEditIterator (!undo); +while (edits.hasNext ()) { +var edit = edits.next (); +if (edit.getAction () === jalview.commands.EditCommand.Action.CUT || edit.getAction () === jalview.commands.EditCommand.Action.PASTE) { +jalview.util.MappingUtils.mapCutOrPaste (edit, undo, mapTo.getSequences (), result, mappings); +} else if (edit.getAction () === jalview.commands.EditCommand.Action.INSERT_GAP || edit.getAction () === jalview.commands.EditCommand.Action.DELETE_GAP) { +jalview.util.MappingUtils.mapInsertOrDelete (edit, undo, originalSequences, mapTo.getSequences (), targetCopies, gapChar, result, mappings); +}} +return result.getSize () > 0 ? result : null; +}, "jalview.commands.EditCommand,~B,jalview.datamodel.AlignmentI,~S,java.util.Set"); +c$.mapInsertOrDelete = Clazz.defineMethod (c$, "mapInsertOrDelete", +function (edit, undo, originalSequences, targetSeqs, targetCopies, gapChar, result, mappings) { +var action = edit.getAction (); +if (undo) { +action = action.getUndoAction (); +}var count = edit.getNumber (); +var editPos = edit.getPosition (); +for (var seq, $seq = 0, $$seq = edit.getSequences (); $seq < $$seq.length && ((seq = $$seq[$seq]) || true); $seq++) { +var ds = seq.getDatasetSequence (); +if (ds == null) { +continue; +}var actedOn = originalSequences.get (ds); +var seqpos = actedOn.findPosition (editPos); +var sr = jalview.util.MappingUtils.buildSearchResults (seq, seqpos, mappings); +if (!sr.isEmpty ()) { +for (var targetSeq, $targetSeq = targetSeqs.iterator (); $targetSeq.hasNext () && ((targetSeq = $targetSeq.next ()) || true);) { +ds = targetSeq.getDatasetSequence (); +if (ds == null) { +continue; +}var copyTarget = targetCopies.get (ds); +var match = sr.getResults (copyTarget, 0, copyTarget.getLength ()); +if (match != null) { +var ratio = 3; +var mappedCount = count * 3; +var mappedEditPos = action === jalview.commands.EditCommand.Action.DELETE_GAP ? match[0] - mappedCount : match[0]; +var e = resultClazz.innerTypeInstance (jalview.commands.EditCommand.Edit, this, null, action, Clazz.newArray (-1, [targetSeq]), mappedEditPos, mappedCount, gapChar); +result.addEdit (e); +if (action === jalview.commands.EditCommand.Action.INSERT_GAP) { +copyTarget.setSequence ( String.instantialize (jalview.util.StringUtils.insertCharAt (copyTarget.getSequence (), mappedEditPos, mappedCount, gapChar))); +} else if (action === jalview.commands.EditCommand.Action.DELETE_GAP) { +copyTarget.setSequence ( String.instantialize (jalview.util.StringUtils.deleteChars (copyTarget.getSequence (), mappedEditPos, mappedEditPos + mappedCount))); +}}} +}if (action === jalview.commands.EditCommand.Action.INSERT_GAP) { +actedOn.setSequence ( String.instantialize (jalview.util.StringUtils.insertCharAt (actedOn.getSequence (), editPos, count, gapChar))); +} else if (action === jalview.commands.EditCommand.Action.DELETE_GAP) { +actedOn.setSequence ( String.instantialize (jalview.util.StringUtils.deleteChars (actedOn.getSequence (), editPos, editPos + count))); +}} +}, "jalview.commands.EditCommand.Edit,~B,java.util.Map,java.util.List,java.util.Map,~S,jalview.commands.EditCommand,java.util.Set"); +c$.buildSearchResults = Clazz.defineMethod (c$, "buildSearchResults", +function (seq, index, seqmappings) { +var results = new jalview.datamodel.SearchResults (); +jalview.util.MappingUtils.addSearchResults (results, seq, index, seqmappings); +return results; +}, "jalview.datamodel.SequenceI,~N,java.util.Set"); +c$.addSearchResults = Clazz.defineMethod (c$, "addSearchResults", +function (results, seq, index, seqmappings) { +if (index >= seq.getStart () && index <= seq.getEnd ()) { +for (var acf, $acf = seqmappings.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) { +acf.markMappedRegion (seq, index, results); +} +}}, "jalview.datamodel.SearchResults,jalview.datamodel.SequenceI,~N,java.util.Set"); +c$.mapSequenceGroup = Clazz.defineMethod (c$, "mapSequenceGroup", +function (sg, mapFrom, mapTo) { +var targetIsNucleotide = mapTo.isNucleotide (); +var protein = targetIsNucleotide ? mapFrom : mapTo; +var codonFrames = protein.getAlignment ().getCodonFrames (); +var mappedGroup = new jalview.datamodel.SequenceGroup (sg); +mappedGroup.cs = mapTo.getGlobalColourScheme (); +mappedGroup.clear (); +var minStartCol = -1; +var maxEndCol = -1; +var selectionStartRes = sg.getStartRes (); +var selectionEndRes = sg.getEndRes (); +for (var selected, $selected = sg.getSequences ().iterator (); $selected.hasNext () && ((selected = $selected.next ()) || true);) { +var firstUngappedPos = selectionStartRes; +while (firstUngappedPos <= selectionEndRes && jalview.util.Comparison.isGap (selected.getCharAt (firstUngappedPos))) { +firstUngappedPos++; +} +if (firstUngappedPos > selectionEndRes) { +continue; +}var lastUngappedPos = selectionEndRes; +while (lastUngappedPos >= selectionStartRes && jalview.util.Comparison.isGap (selected.getCharAt (lastUngappedPos))) { +lastUngappedPos--; +} +var startResiduePos = selected.findPosition (firstUngappedPos); +var endResiduePos = selected.findPosition (lastUngappedPos); +for (var acf, $acf = codonFrames.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) { +var mappedSequence = targetIsNucleotide ? acf.getDnaForAaSeq (selected) : acf.getAaForDnaSeq (selected); +if (mappedSequence != null) { +for (var seq, $seq = mapTo.getAlignment ().getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) { +var mappedStartResidue = 0; +var mappedEndResidue = 0; +if (seq.getDatasetSequence () === mappedSequence) { +var sr = jalview.util.MappingUtils.buildSearchResults (selected, startResiduePos, java.util.Collections.singleton (acf)); +for (var m, $m = sr.getResults ().iterator (); $m.hasNext () && ((m = $m.next ()) || true);) { +mappedStartResidue = m.getStart (); +mappedEndResidue = m.getEnd (); +} +sr = jalview.util.MappingUtils.buildSearchResults (selected, endResiduePos, java.util.Collections.singleton (acf)); +for (var m, $m = sr.getResults ().iterator (); $m.hasNext () && ((m = $m.next ()) || true);) { +mappedStartResidue = Math.min (mappedStartResidue, m.getStart ()); +mappedEndResidue = Math.max (mappedEndResidue, m.getEnd ()); +} +var mappedStartCol = seq.findIndex (mappedStartResidue) - 1; +minStartCol = minStartCol == -1 ? mappedStartCol : Math.min (minStartCol, mappedStartCol); +var mappedEndCol = seq.findIndex (mappedEndResidue) - 1; +maxEndCol = maxEndCol == -1 ? mappedEndCol : Math.max (maxEndCol, mappedEndCol); +mappedGroup.addSequence (seq, false); +break; +}} +}} +} +mappedGroup.setStartRes (minStartCol < 0 ? 0 : minStartCol); +mappedGroup.setEndRes (maxEndCol < 0 ? 0 : maxEndCol); +return mappedGroup; +}, "jalview.datamodel.SequenceGroup,jalview.api.AlignViewportI,jalview.api.AlignViewportI"); +c$.mapOrderCommand = Clazz.defineMethod (c$, "mapOrderCommand", +function (command, undo, mapTo, mappings) { +var sortOrder = command.getSequenceOrder (undo); +var mappedOrder = new java.util.ArrayList (); +var j = 0; +var mappingToNucleotide = mapTo.isNucleotide (); +for (var seq, $seq = 0, $$seq = sortOrder; $seq < $$seq.length && ((seq = $$seq[$seq]) || true); $seq++) { +for (var acf, $acf = mappings.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) { +var mappedSeq = mappingToNucleotide ? acf.getDnaForAaSeq (seq) : acf.getAaForDnaSeq (seq); +if (mappedSeq != null) { +for (var seq2, $seq2 = mapTo.getSequences ().iterator (); $seq2.hasNext () && ((seq2 = $seq2.next ()) || true);) { +if (seq2.getDatasetSequence () === mappedSeq) { +mappedOrder.add (seq2); +j++; +break; +}} +}} +} +if (j == 0) { +return null; +}if (j < mapTo.getHeight ()) { +for (var seq, $seq = mapTo.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) { +if (!mappedOrder.contains (seq)) { +mappedOrder.add (seq); +}} +}var mappedOrderArray = mappedOrder.toArray ( new Array (mappedOrder.size ())); +var oldOrder = mapTo.getSequencesArray (); +jalview.analysis.AlignmentSorter.sortBy (mapTo, new jalview.datamodel.AlignmentOrder (mappedOrderArray)); +var result = new jalview.commands.OrderCommand (command.getDescription (), oldOrder, mapTo); +return result; +}, "jalview.commands.OrderCommand,~B,jalview.datamodel.AlignmentI,java.util.Set"); +c$.mapColumnSelection = Clazz.defineMethod (c$, "mapColumnSelection", +function (colsel, mapFrom, mapTo) { +var targetIsNucleotide = mapTo.isNucleotide (); +var protein = targetIsNucleotide ? mapFrom : mapTo; +var codonFrames = protein.getAlignment ().getCodonFrames (); +var mappedColumns = new jalview.datamodel.ColumnSelection (); +if (colsel == null) { +return mappedColumns; +}var fromGapChar = mapFrom.getAlignment ().getGapCharacter (); +for (var obj, $obj = colsel.getSelected ().iterator (); $obj.hasNext () && ((obj = $obj.next ()) || true);) { +var col = (obj).intValue (); +var mappedToMin = 2147483647; +var mappedToMax = -2147483648; +for (var fromSeq, $fromSeq = mapFrom.getAlignment ().getSequences ().iterator (); $fromSeq.hasNext () && ((fromSeq = $fromSeq.next ()) || true);) { +if (fromSeq.getCharAt (col) == fromGapChar) { +continue; +}var residuePos = fromSeq.findPosition (col); +var sr = jalview.util.MappingUtils.buildSearchResults (fromSeq, residuePos, codonFrames); +for (var m, $m = sr.getResults ().iterator (); $m.hasNext () && ((m = $m.next ()) || true);) { +var mappedStartResidue = m.getStart (); +var mappedEndResidue = m.getEnd (); +var mappedSeq = m.getSequence (); +for (var toSeq, $toSeq = mapTo.getAlignment ().getSequences ().iterator (); $toSeq.hasNext () && ((toSeq = $toSeq.next ()) || true);) { +if (toSeq.getDatasetSequence () === mappedSeq) { +var mappedStartCol = toSeq.findIndex (mappedStartResidue); +var mappedEndCol = toSeq.findIndex (mappedEndResidue); +mappedToMin = Math.min (mappedToMin, mappedStartCol); +mappedToMax = Math.max (mappedToMax, mappedEndCol); +break; +}} +} +} +for (var i = mappedToMin; i <= mappedToMax; i++) { +mappedColumns.addElement (i - 1); +} +} +return mappedColumns; +}, "jalview.datamodel.ColumnSelection,jalview.api.AlignViewportI,jalview.api.AlignViewportI"); +c$.findCodonFor = Clazz.defineMethod (c$, "findCodonFor", +function (seq, col, mappings) { +var dsPos = seq.findPosition (col); +for (var mapping, $mapping = mappings.iterator (); $mapping.hasNext () && ((mapping = $mapping.next ()) || true);) { +if (mapping.involvesSequence (seq)) { +return mapping.getMappedCodon (seq.getDatasetSequence (), dsPos); +}} +return null; +}, "jalview.datamodel.SequenceI,~N,java.util.Set"); +c$.flattenRanges = Clazz.defineMethod (c$, "flattenRanges", +function (ranges) { +var count = 0; +for (var i = 0; i < ranges.length - 1; i += 2) { +count += ranges[i + 1] - ranges[i] + 1; +} +var result = Clazz.newIntArray (count, 0); +var k = 0; +for (var i = 0; i < ranges.length - 1; i += 2) { +for (var j = ranges[i]; j <= ranges[i + 1]; j++) { +result[k++] = j; +} +} +return result; +}, "~A"); +c$.findMappingsForSequence = Clazz.defineMethod (c$, "findMappingsForSequence", +function (sequence, mappings) { +var result = new java.util.ArrayList (); +if (sequence == null || mappings == null) { +return result; +}for (var mapping, $mapping = mappings.iterator (); $mapping.hasNext () && ((mapping = $mapping.next ()) || true);) { +if (mapping.involvesSequence (sequence)) { +result.add (mapping); +}} +return result; +}, "jalview.datamodel.SequenceI,java.util.Set"); +});