JAL-2029 further fixes to get correct xrefs and xrefs on xrefs...
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 21 Mar 2016 16:46:10 +0000 (16:46 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 21 Mar 2016 16:46:10 +0000 (16:46 +0000)
src/jalview/analysis/CrossRef.java
src/jalview/datamodel/xdb/embl/EmblEntry.java

index d48c14a..0f7a754 100644 (file)
@@ -385,6 +385,15 @@ public class CrossRef
                                 .findIdMatch(map.getTo());
                         if (matched != null)
                         {
+                          /*
+                           * already got an xref to this sequence; update this
+                           * map to point to the same sequence, and add
+                           * any new dbrefs to it
+                           */
+                          for (DBRefEntry ref : map.getTo().getDBRefs())
+                          {
+                            matched.addDBRef(ref);
+                          }
                           map.setTo(matched);
                         }
                         else
index 7da6d6c..d830130 100644 (file)
@@ -502,47 +502,50 @@ public class EmblEntry
         dna.addSequenceFeature(sf);
       }
     }
-    // add dbRefs to sequence
+
+    /*
+     * add dbRefs to sequence, and mappings for Uniprot xrefs
+     */
     if (feature.dbRefs != null)
     {
-      boolean productMapped = false;
+      boolean mappingUsed = false;
       for (DBRefEntry ref : feature.dbRefs)
       {
         ref.setSource(DBRefUtils.getCanonicalName(ref.getSource()));
-        // Hard code the kind of protein product accessions that EMBL cite
         if (ref.getSource().equals(DBRefSource.UNIPROT))
         {
-          String refSeqName = DBRefSource.UNIPROT + "|"
+          String proteinSeqName = DBRefSource.UNIPROT + "|"
                   + ref.getAccessionId();
-          ref.setMap(map);
           if (map != null && map.getTo() != null)
           {
-            // if (!productMapped)
-            // {
-            // map.getTo().setName(refSeqName);
-            // map.getTo().addDBRef(
-            // new DBRefEntry(ref.getSource(), ref.getVersion(), ref
-            // .getAccessionId())); // don't copy map over.
-            // // if (map.getTo().getName().startsWith(prid))
-            // productMapped = true;
-            // }
-            // else
-            // {
+            if (mappingUsed)
+            {
               /*
-               * an alternate UNIPROT product for CDS - same mapping
-               * but to a sequence with a different name
+               * two or more Uniprot xrefs for the same CDS - 
+               * each needs a distinct Mapping (as to a different sequence)
                */
-              SequenceI newSeq = matcher.findIdMatch(refSeqName);
-              if (newSeq == null)
-              {
-                newSeq = new Sequence(refSeqName, map.getTo()
+              map = new Mapping(map);
+            }
+            mappingUsed = true;
+
+            /*
+             * try to locate the protein mapped to (possibly by a 
+             * previous CDS feature)
+             */
+            SequenceI proteinSeq = matcher.findIdMatch(proteinSeqName);
+            if (proteinSeq == null)
+            {
+              proteinSeq = new Sequence(proteinSeqName,
+                      product
                       .getSequenceAsString());
-                matcher.add(newSeq);
-                peptides.add(newSeq);
-              }
-              Mapping newMap = new Mapping(newSeq, map.getMap());
-              ref.setMap(newMap);
-            // }
+              matcher.add(proteinSeq);
+              peptides.add(proteinSeq);
+            }
+            map.setTo(proteinSeq);
+            map.getTo().addDBRef(
+                    new DBRefEntry(ref.getSource(), ref.getVersion(), ref
+                            .getAccessionId()));
+            ref.setMap(map);
           }
           noProteinDbref = false;
         }