X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FMappingUtils.java;h=0933b978db6b993dc27940168d21e2411582ba6a;hb=17e77c3f2949a0729322b4a8d907f3f34b6a9914;hp=ece1bacddd95b36c0a98d142440205ed4f6684c7;hpb=7f61a28aad5fe2ef3df8aa4024ea3e7d8fbe1548;p=jalview.git
diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java
index ece1bac..0933b97 100644
--- a/src/jalview/util/MappingUtils.java
+++ b/src/jalview/util/MappingUtils.java
@@ -1,13 +1,25 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.util;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import jalview.analysis.AlignmentSorter;
import jalview.api.AlignViewportI;
import jalview.commands.CommandI;
@@ -25,6 +37,14 @@ import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Helper methods for manipulations involving sequence mappings.
*
@@ -200,8 +220,8 @@ public final class MappingUtils
*/
int mappedEditPos = action == Action.DELETE_GAP ? match[0]
- mappedCount : match[0];
- Edit e = result.new Edit(action, new SequenceI[]
- { targetSeq }, mappedEditPos, mappedCount, gapChar);
+ Edit e = result.new Edit(action, new SequenceI[] { targetSeq },
+ mappedEditPos, mappedCount, gapChar);
result.addEdit(e);
/*
@@ -250,8 +270,23 @@ public final class MappingUtils
public static SearchResults buildSearchResults(SequenceI seq, int index,
Set seqmappings)
{
- SearchResults results;
- results = new SearchResults();
+ SearchResults results = new SearchResults();
+ addSearchResults(results, seq, index, seqmappings);
+ return results;
+ }
+
+ /**
+ * Adds entries to a SearchResults object describing the mapped region
+ * corresponding to the specified sequence position.
+ *
+ * @param results
+ * @param seq
+ * @param index
+ * @param seqmappings
+ */
+ public static void addSearchResults(SearchResults results, SequenceI seq,
+ int index, Set seqmappings)
+ {
if (index >= seq.getStart() && index <= seq.getEnd())
{
for (AlignedCodonFrame acf : seqmappings)
@@ -259,7 +294,6 @@ public final class MappingUtils
acf.markMappedRegion(seq, index, results);
}
}
- return results;
}
/**
@@ -325,7 +359,7 @@ public final class MappingUtils
*/
int startResiduePos = selected.findPosition(firstUngappedPos);
int endResiduePos = selected.findPosition(lastUngappedPos);
-
+
for (AlignedCodonFrame acf : codonFrames)
{
SequenceI mappedSequence = targetIsNucleotide ? acf
@@ -399,18 +433,19 @@ public final class MappingUtils
SequenceI[] sortOrder = command.getSequenceOrder(undo);
List mappedOrder = new ArrayList();
int j = 0;
+
+ /*
+ * Assumption: we are only interested in a cDNA/protein mapping; refactor in
+ * future if we want to support sorting (c)dna as (c)dna or protein as
+ * protein
+ */
+ boolean mappingToNucleotide = mapTo.isNucleotide();
for (SequenceI seq : sortOrder)
{
for (AlignedCodonFrame acf : mappings)
{
- /*
- * Try protein-to-Dna, failing that try dna-to-protein
- */
- SequenceI mappedSeq = acf.getDnaForAaSeq(seq);
- if (mappedSeq == null)
- {
- mappedSeq = acf.getAaForDnaSeq(seq);
- }
+ SequenceI mappedSeq = mappingToNucleotide ? acf.getDnaForAaSeq(seq)
+ : acf.getAaForDnaSeq(seq);
if (mappedSeq != null)
{
for (SequenceI seq2 : mapTo.getSequences())
@@ -480,6 +515,12 @@ public final class MappingUtils
Set codonFrames = protein.getAlignment()
.getCodonFrames();
ColumnSelection mappedColumns = new ColumnSelection();
+
+ if (colsel == null)
+ {
+ return mappedColumns;
+ }
+
char fromGapChar = mapFrom.getAlignment().getGapCharacter();
// FIXME allow for hidden columns
@@ -608,4 +649,30 @@ public final class MappingUtils
}
return result;
}
+
+ /**
+ * Returns a list of any mappings that are from or to the given (aligned or
+ * dataset) sequence.
+ *
+ * @param sequence
+ * @param mappings
+ * @return
+ */
+ public static List findMappingsForSequence(
+ SequenceI sequence, Set mappings)
+ {
+ List result = new ArrayList();
+ if (sequence == null || mappings == null)
+ {
+ return result;
+ }
+ for (AlignedCodonFrame mapping : mappings)
+ {
+ if (mapping.involvesSequence(sequence))
+ {
+ result.add(mapping);
+ }
+ }
+ return result;
+ }
}