JAL-2110 bug fixing and tidying for get cross-refs
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 1 Jul 2016 15:54:01 +0000 (16:54 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 1 Jul 2016 15:54:01 +0000 (16:54 +0100)
src/jalview/analysis/AlignmentUtils.java
src/jalview/analysis/CrossRef.java
src/jalview/datamodel/AlignedCodonFrame.java
src/jalview/gui/AlignFrame.java
src/jalview/util/DBRefUtils.java
src/jalview/ws/jws2/MsaWSThread.java

index f94d393..9150d62 100644 (file)
@@ -2347,13 +2347,13 @@ public class AlignmentUtils
   {
     /*
      * Map will hold, for each aligned column position, a map of
-     * {unalignedSequence, sequenceCharacter} at that position.
+     * {unalignedSequence, characterPerSequence} at that position.
      * TreeMap keeps the entries in ascending column order. 
      */
     Map<Integer, Map<SequenceI, Character>> map = new TreeMap<Integer, Map<SequenceI, Character>>();
 
     /*
-     * r any sequences that have no mapping so can't be realigned
+     * record any sequences that have no mapping so can't be realigned
      */
     unmapped.addAll(unaligned.getSequences());
 
@@ -2402,6 +2402,15 @@ public class AlignmentUtils
       return false;
     }
 
+    /*
+     * invert mapping if it is from unaligned to aligned sequence
+     */
+    if (seqMap.getTo() == fromSeq.getDatasetSequence())
+    {
+      seqMap = new Mapping(seq.getDatasetSequence(), seqMap.getMap()
+              .getInverse());
+    }
+
     char[] fromChars = fromSeq.getSequence();
     int toStart = seq.getStart();
     char[] toChars = seq.getSequence();
@@ -2435,7 +2444,8 @@ public class AlignmentUtils
          * of the next character of the mapped-to sequence; stop when all
          * the characters of the range have been counted
          */
-        while (mappedCharPos <= range[1])
+        while (mappedCharPos <= range[1] && fromCol <= fromChars.length
+                && fromCol >= 0)
         {
           if (!Comparison.isGap(fromChars[fromCol - 1]))
           {
index 0011e39..e73912d 100644 (file)
@@ -357,7 +357,8 @@ public class CrossRef
   {
     ASequenceFetcher sftch = SequenceFetcherFactory.getSequenceFetcher();
     SequenceI[] retrieved = null;
-    SequenceI dss = null;
+    SequenceI dss = seq.getDatasetSequence() == null ? seq : seq
+            .getDatasetSequence();
     try
     {
       retrieved = sftch.getSequences(sourceRefs, !fromDna);
index a4b99bf..18aaecf 100644 (file)
@@ -702,7 +702,7 @@ public class AlignedCodonFrame
   }
 
   /**
-   * Returns the first mapping found that is from 'fromSeq' to 'toSeq', or null
+   * Returns the first mapping found that is between 'fromSeq' and 'toSeq', or null
    * if none found
    * 
    * @param fromSeq
@@ -713,12 +713,17 @@ public class AlignedCodonFrame
    */
   public Mapping getMappingBetween(SequenceI fromSeq, SequenceI toSeq)
   {
+    SequenceI dssFrom = fromSeq.getDatasetSequence() == null ? fromSeq
+            : fromSeq.getDatasetSequence();
+    SequenceI dssTo = toSeq.getDatasetSequence() == null ? toSeq : toSeq
+            .getDatasetSequence();
+
     for (SequenceToSequenceMapping mapping : mappings)
     {
       SequenceI from = mapping.fromSeq;
       SequenceI to = mapping.mapping.to;
-      if ((from == fromSeq || from == fromSeq.getDatasetSequence())
-              && (to == toSeq || to == toSeq.getDatasetSequence()))
+      if ((from == dssFrom && to == dssTo)
+              || (from == dssTo && to == dssFrom))
       {
         return mapping.mapping;
       }
index 64bdf44..b310ab9 100644 (file)
@@ -4763,7 +4763,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           AlignmentI copyAlignment = null;
           final SequenceI[] sequenceSelection = AlignFrame.this.viewport
                   .getSequenceSelection();
-          // List<AlignedCodonFrame> cf = xrefs.getCodonFrames();
           boolean copyAlignmentIsAligned = false;
           if (dna)
           {
index ed6d860..d5d0cf5 100755 (executable)
@@ -546,7 +546,7 @@ public class DBRefUtils
 
   /**
    * Returns the (possibly empty) list of those supplied dbrefs which have the
-   * specified source databse
+   * specified source database, with a case-insensitive match of source name
    * 
    * @param dbRefs
    * @param source
@@ -560,7 +560,7 @@ public class DBRefUtils
     {
       for (DBRefEntry dbref : dbRefs)
       {
-        if (source.equals(dbref.getSource()))
+        if (source.equalsIgnoreCase(dbref.getSource()))
         {
           matches.add(dbref);
         }
index bfae384..e425624 100644 (file)
@@ -1032,6 +1032,10 @@ class MsaWSThread extends AWS2Thread implements WSClientI
       // becomes null if the alignment window was closed before the alignment
       // job finished.
       AlignmentI copyComplement = new Alignment(complement);
+      // todo should this be done by copy constructor?
+      copyComplement.setGapCharacter(complement.getGapCharacter());
+      // share the same dataset (and the mappings it holds)
+      copyComplement.setDataset(complement.getDataset());
       copyComplement.alignAs(al);
       if (copyComplement.getHeight() > 0)
       {