JAL-2110 field 'cf' moved to stack
[jalview.git] / src / jalview / analysis / CrossRef.java
index 2b5a0e2..288d60e 100644 (file)
@@ -68,11 +68,6 @@ public class CrossRef
   List<SequenceI> rseqs;
 
   /**
-   * mappings constructed
-   */
-  AlignedCodonFrame cf;
-
-  /**
    * Constructor
    * 
    * @param seqs
@@ -213,7 +208,7 @@ public class CrossRef
   {
 
     rseqs = new ArrayList<SequenceI>();
-    cf = new AlignedCodonFrame();
+    AlignedCodonFrame cf = new AlignedCodonFrame();
     matcher = new SequenceIdMatcher(
             dataset.getSequences());
 
@@ -295,12 +290,14 @@ public class CrossRef
               if (fromDna)
               {
                 // map is from dna seq to a protein product
-                cf.addMap(dss, rsq, xref.getMap().getMap());
+                cf.addMap(dss, rsq, xref.getMap().getMap(), xref.getMap()
+                        .getMappedFromId());
               }
               else
               {
                 // map should be from protein seq to its coding dna
-                cf.addMap(rsq, dss, xref.getMap().getMap().getInverse());
+                cf.addMap(rsq, dss, xref.getMap().getMap().getInverse(),
+                        xref.getMap().getMappedFromId());
               }
             }
           }
@@ -336,7 +333,7 @@ public class CrossRef
        */
       if (!sourceRefs.isEmpty())
       {
-        retrieveCrossRef(sourceRefs, seq, xrfs, fromDna);
+        retrieveCrossRef(sourceRefs, seq, xrfs, fromDna, cf);
       }
     }
 
@@ -353,7 +350,7 @@ public class CrossRef
   }
 
   private void retrieveCrossRef(List<DBRefEntry> sourceRefs, SequenceI seq,
-          DBRefEntry[] xrfs, boolean fromDna)
+          DBRefEntry[] xrfs, boolean fromDna, AlignedCodonFrame cf)
   {
     ASequenceFetcher sftch = SequenceFetcherFactory.getSequenceFetcher();
     SequenceI[] retrieved = null;
@@ -621,14 +618,14 @@ public class CrossRef
   void updateDbrefMappings(SequenceI mapFrom, DBRefEntry[] xrefs,
           SequenceI[] retrieved, AlignedCodonFrame acf, boolean fromDna)
   {
-    SequenceIdMatcher matcher = new SequenceIdMatcher(retrieved);
+    SequenceIdMatcher idMatcher = new SequenceIdMatcher(retrieved);
     for (DBRefEntry xref : xrefs)
     {
       if (!xref.hasMap())
       {
         String targetSeqName = xref.getSource() + "|"
                 + xref.getAccessionId();
-        SequenceI[] matches = matcher.findAllIdMatches(targetSeqName);
+        SequenceI[] matches = idMatcher.findAllIdMatches(targetSeqName);
         if (matches == null)
         {
           return;
@@ -705,6 +702,20 @@ public class CrossRef
       return false;
     }
     xref.setMap(new Mapping(mapTo, mapping));
+
+    /*
+     * and add a reverse DbRef with the inverse mapping
+     */
+    if (mapFrom.getDatasetSequence() != null
+            && mapFrom.getDatasetSequence().getSourceDBRef() != null)
+    {
+      DBRefEntry dbref = new DBRefEntry(mapFrom.getDatasetSequence()
+              .getSourceDBRef());
+      dbref.setMap(new Mapping(mapFrom.getDatasetSequence(), mapping
+              .getInverse()));
+      mapTo.addDBRef(dbref);
+    }
+
     if (fromDna)
     {
       AlignmentUtils.computeProteinFeatures(mapFrom, mapTo, mapping);