apply version 2.7 copyright
[jalview.git] / src / jalview / ws / DBRefFetcher.java
index 82b411a..d235410 100644 (file)
@@ -1,39 +1,49 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)\r
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle\r
+ * \r
+ * This file is part of Jalview.\r
+ * \r
+ * Jalview is free software: you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License \r
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
+ * \r
+ * Jalview is distributed in the hope that it will be useful, but \r
+ * WITHOUT ANY WARRANTY; without even the implied warranty \r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ * PURPOSE.  See the GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.\r
  */\r
 package jalview.ws;\r
 \r
-import java.io.*;\r
-import java.util.*;\r
-\r
-import org.exolab.castor.mapping.*;\r
-import org.exolab.castor.xml.*;\r
-import jalview.analysis.*;\r
-import jalview.datamodel.*;\r
+import jalview.analysis.AlignSeq;\r
+import jalview.bin.Cache;\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.datamodel.DBRefEntry;\r
+import jalview.datamodel.DBRefSource;\r
 import jalview.datamodel.Mapping;\r
-import jalview.gui.*;\r
-import jalview.ws.dbsources.Uniprot;\r
-import jalview.ws.ebi.EBIFetchClient;\r
+import jalview.datamodel.SequenceFeature;\r
+import jalview.datamodel.SequenceI;\r
+import jalview.gui.AlignFrame;\r
+import jalview.gui.CutAndPasteTransfer;\r
+import jalview.gui.Desktop;\r
+import jalview.gui.IProgressIndicator;\r
+import jalview.gui.OOMWarning;\r
+\r
+import java.lang.reflect.Array;\r
+import java.util.Enumeration;\r
+import java.util.Hashtable;\r
+import java.util.StringTokenizer;\r
+import java.util.Vector;\r
+\r
+import org.biojava.dasobert.dasregistry.DasSource;\r
+\r
+import uk.ac.ebi.picr.model.UPEntry;\r
 \r
 /**\r
- * Implements a runnable for validating a sequence \r
- * against external databases and then propagating \r
- * references and features onto the sequence(s)\r
+ * Implements a runnable for validating a sequence against external databases\r
+ * and then propagating references and features onto the sequence(s)\r
  * \r
  * @author $author$\r
  * @version $Revision$\r
@@ -50,6 +60,11 @@ public class DBRefFetcher implements Runnable
 \r
   boolean running = false;\r
 \r
+  /**\r
+   * picr client instance\r
+   */\r
+  uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperInterface picrClient = null;\r
+\r
   // /This will be a collection of Vectors of sequenceI refs.\r
   // The key will be the seq name or accession id of the seq\r
   Hashtable seqRefs;\r
@@ -58,24 +73,45 @@ public class DBRefFetcher implements Runnable
 \r
   SequenceFetcher sfetcher;\r
 \r
+  private SequenceI[] alseqs;\r
+\r
   public DBRefFetcher()\r
   {\r
   }\r
 \r
   /**\r
-   * Creates a new SequenceFeatureFetcher object.\r
+   * Creates a new SequenceFeatureFetcher object and fetches from the currently\r
+   * selected set of databases.\r
    * \r
    * @param seqs\r
-   *                fetch references for these sequences\r
+   *          fetch references for these sequences\r
    * @param af\r
-   *                the parent alignframe for progress bar monitoring.\r
+   *          the parent alignframe for progress bar monitoring.\r
    */\r
   public DBRefFetcher(SequenceI[] seqs, AlignFrame af)\r
   {\r
+    this(seqs, af, null);\r
+  }\r
+\r
+  /**\r
+   * Creates a new SequenceFeatureFetcher object and fetches from the currently\r
+   * selected set of databases.\r
+   * \r
+   * @param seqs\r
+   *          fetch references for these sequences\r
+   * @param af\r
+   *          the parent alignframe for progress bar monitoring.\r
+   * @param sources\r
+   *          array of database source strings to query references from\r
+   */\r
+  public DBRefFetcher(SequenceI[] seqs, AlignFrame af, String[] sources)\r
+  {\r
     this.af = af;\r
+    alseqs = new SequenceI[seqs.length];\r
     SequenceI[] ds = new SequenceI[seqs.length];\r
     for (int i = 0; i < seqs.length; i++)\r
     {\r
+      alseqs[i] = seqs[i];\r
       if (seqs[i].getDatasetSequence() != null)\r
         ds[i] = seqs[i].getDatasetSequence();\r
       else\r
@@ -83,15 +119,82 @@ public class DBRefFetcher implements Runnable
     }\r
     this.dataset = ds;\r
     // TODO Jalview 2.5 lots of this code should be in the gui package!\r
-    sfetcher = jalview.gui.SequenceFetcher.getSequenceFetcherSingleton(af); \r
-    // select appropriate databases based on alignFrame context.\r
-    if (af.getViewport().getAlignment().isNucleotide())\r
+    sfetcher = jalview.gui.SequenceFetcher.getSequenceFetcherSingleton(af);\r
+    if (sources == null)\r
     {\r
-      dbSources = DBRefSource.DNACODINGDBS;\r
+      // af.featureSettings_actionPerformed(null);\r
+      String[] defdb = null, otherdb = sfetcher\r
+              .getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);\r
+      Vector selsources = new Vector(), dasselsrc = (af.featureSettings != null) ? af.featureSettings\r
+              .getSelectedSources() : new jalview.gui.DasSourceBrowser()\r
+              .getSelectedSources();\r
+      Enumeration en = dasselsrc.elements();\r
+      while (en.hasMoreElements())\r
+      {\r
+        DasSource src = (DasSource) en.nextElement();\r
+        selsources.addElement(src.getNickname());\r
+      }\r
+      int osel = 0;\r
+      for (int o = 0; otherdb != null && o < otherdb.length; o++)\r
+      {\r
+        if (!selsources.contains(otherdb[o]))\r
+        {\r
+          otherdb[o] = null;\r
+        }\r
+        else\r
+        {\r
+          osel++;\r
+        }\r
+      }\r
+      // select appropriate databases based on alignFrame context.\r
+      if (af.getViewport().getAlignment().isNucleotide())\r
+      {\r
+        defdb = DBRefSource.DNACODINGDBS;\r
+      }\r
+      else\r
+      {\r
+        defdb = DBRefSource.PROTEINDBS;\r
+      }\r
+      // append the selected sequence sources to the default dbs\r
+      dbSources = new String[defdb.length + osel];\r
+      System.arraycopy(defdb, 0, dbSources, 0, defdb.length);\r
+      for (int o = 0, op = defdb.length; otherdb != null\r
+              && o < otherdb.length; o++)\r
+      {\r
+        if (otherdb[o] != null)\r
+        {\r
+          dbSources[op++] = otherdb[o];\r
+        }\r
+      }\r
     }\r
     else\r
     {\r
-      dbSources = DBRefSource.PROTEINDBS;\r
+      // we assume the caller knows what they're doing and ensured that all the\r
+      // db source names are valid\r
+      dbSources = sources;\r
+    }\r
+  }\r
+\r
+  /**\r
+   * retrieve all the das sequence sources and add them to the list of db\r
+   * sources to retrieve from\r
+   */\r
+  public void appendAllDasSources()\r
+  {\r
+    if (dbSources == null)\r
+    {\r
+      dbSources = new String[]\r
+      {};\r
+    }\r
+    // append additional sources\r
+    String[] otherdb = sfetcher\r
+            .getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);\r
+    if (otherdb != null && otherdb.length > 0)\r
+    {\r
+      String[] newsrc = new String[dbSources.length + otherdb.length];\r
+      System.arraycopy(dbSources, 0, newsrc, 0, dbSources.length);\r
+      System.arraycopy(otherdb, 0, newsrc, dbSources.length, otherdb.length);\r
+      dbSources = newsrc;\r
     }\r
   }\r
 \r
@@ -99,7 +202,7 @@ public class DBRefFetcher implements Runnable
    * start the fetcher thread\r
    * \r
    * @param waitTillFinished\r
-   *                true to block until the fetcher has finished\r
+   *          true to block until the fetcher has finished\r
    */\r
   public void fetchDBRefs(boolean waitTillFinished)\r
   {\r
@@ -126,9 +229,9 @@ public class DBRefFetcher implements Runnable
    * could be either seq name or dbref id\r
    * \r
    * @param seq\r
-   *                SequenceI\r
+   *          SequenceI\r
    * @param key\r
-   *                String\r
+   *          String\r
    */\r
   void addSeqId(SequenceI seq, String key)\r
   {\r
@@ -168,9 +271,21 @@ public class DBRefFetcher implements Runnable
     {\r
       throw new Error("Implementation error. Must initialise dbSources");\r
     }\r
+    running = true;\r
     long startTime = System.currentTimeMillis();\r
     af.setProgressBar("Fetching db refs", startTime);\r
-    running = true;\r
+    try\r
+    {\r
+      if (Cache.getDefault("DBREFFETCH_USEPICR", false))\r
+      {\r
+        picrClient = new uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperServiceLocator()\r
+                .getAccessionMapperPort();\r
+      }\r
+    } catch (Exception e)\r
+    {\r
+      System.err.println("Couldn't locate PICR service instance.\n");\r
+      e.printStackTrace();\r
+    }\r
     int db = 0;\r
     Vector sdataset = new Vector();\r
     for (int s = 0; s < dataset.length; s++)\r
@@ -194,8 +309,10 @@ public class DBRefFetcher implements Runnable
       {\r
         maxqlen = ((Integer) dbsource.getDbSourceProperties().get(\r
                 DBRefSource.MULTIACC)).intValue();\r
-      } else {\r
-        maxqlen=1;\r
+      }\r
+      else\r
+      {\r
+        maxqlen = 1;\r
       }\r
       // iterate through db for each remaining un-verified sequence\r
       SequenceI[] currSeqs = new SequenceI[sdataset.size()];\r
@@ -212,31 +329,40 @@ public class DBRefFetcher implements Runnable
         {\r
           // Still queries to make for current seqIndex\r
           StringBuffer queryString = new StringBuffer("");\r
-          int nqSize = (maxqlen > queries.size()) ? queries.size()\r
-                  : maxqlen;\r
-          for (int nq = 0, numq = 0; nq < nqSize; nq++)\r
+          int numq = 0, nqSize = (maxqlen > queries.size()) ? queries\r
+                  .size() : maxqlen;\r
+\r
+          while (queries.size() > 0 && numq < nqSize)\r
           {\r
-            String query = (String) queries.elementAt(nq);\r
+            String query = (String) queries.elementAt(0);\r
             if (dbsource.isValidReference(query))\r
             {\r
-              queryString.append((nq == 0) ? "" : dbsource\r
+              queryString.append((numq == 0) ? "" : dbsource\r
                       .getAccessionSeparator());\r
               queryString.append(query);\r
               numq++;\r
             }\r
-          }\r
-          for (int nq = 0; nq < nqSize; nq++)\r
-          {\r
+            // remove the extracted query string\r
             queries.removeElementAt(0);\r
           }\r
           // make the queries and process the response\r
           AlignmentI retrieved = null;\r
           try\r
           {\r
+            if (jalview.bin.Cache.log.isDebugEnabled())\r
+            {\r
+              jalview.bin.Cache.log.debug("Querying "\r
+                      + dbsource.getDbName() + " with : '"\r
+                      + queryString.toString() + "'");\r
+            }\r
             retrieved = dbsource.getSequenceRecords(queryString.toString());\r
           } catch (Exception ex)\r
           {\r
             ex.printStackTrace();\r
+          } catch (OutOfMemoryError err)\r
+          {\r
+            new OOMWarning("retrieving database references ("\r
+                    + queryString.toString() + ")", err);\r
           }\r
           if (retrieved != null)\r
           {\r
@@ -254,14 +380,12 @@ public class DBRefFetcher implements Runnable
                     { dbSources[db] }); // jalview.datamodel.DBRefSource.UNIPROT\r
             // });\r
             // check for existing dbrefs to use\r
-            if (uprefs != null)\r
+            if (uprefs != null && uprefs.length > 0)\r
             {\r
               for (int j = 0; j < uprefs.length; j++)\r
               {\r
                 addSeqId(sequence, uprefs[j].getAccessionId());\r
-                queries\r
-                        .addElement(uprefs[j].getAccessionId()\r
-                                .toUpperCase());\r
+                queries.addElement(uprefs[j].getAccessionId().toUpperCase());\r
               }\r
             }\r
             else\r
@@ -272,8 +396,44 @@ public class DBRefFetcher implements Runnable
               while (st.hasMoreTokens())\r
               {\r
                 String token = st.nextToken();\r
-                addSeqId(sequence, token);\r
-                queries.addElement(token.toUpperCase());\r
+                UPEntry[] presp = null;\r
+                if (picrClient != null)\r
+                {\r
+                  // resolve the string against PICR to recover valid IDs\r
+                  try\r
+                  {\r
+                    presp = picrClient\r
+                            .getUPIForAccession(token, null,\r
+                                    picrClient.getMappedDatabaseNames(),\r
+                                    null, true);\r
+                  } catch (Exception e)\r
+                  {\r
+                    System.err.println("Exception with Picr for '" + token\r
+                            + "'\n");\r
+                    e.printStackTrace();\r
+                  }\r
+                }\r
+                if (presp != null && presp.length > 0)\r
+                {\r
+                  for (int id = 0; id < presp.length; id++)\r
+                  {\r
+                    // construct sequences from response if sequences are\r
+                    // present, and do a transferReferences\r
+                    // otherwise transfer non sequence x-references directly.\r
+                  }\r
+                  System.out\r
+                          .println("Validated ID against PICR... (for what its worth):"\r
+                                  + token);\r
+                  addSeqId(sequence, token);\r
+                  queries.addElement(token.toUpperCase());\r
+                }\r
+                else\r
+                {\r
+                  // if ()\r
+                  // System.out.println("Not querying source with token="+token+"\n");\r
+                  addSeqId(sequence, token);\r
+                  queries.addElement(token.toUpperCase());\r
+                }\r
               }\r
             }\r
           }\r
@@ -284,11 +444,10 @@ public class DBRefFetcher implements Runnable
     } // all databases have been queries.\r
     if (sbuffer.length() > 0)\r
     {\r
-      output\r
-              .setText("Your sequences have been verified against known sequence databases. Some of the ids have been\n"\r
-                      + "altered, most likely the start/end residue will have been updated.\n"\r
-                      + "Save your alignment to maintain the updated id.\n\n"\r
-                      + sbuffer.toString());\r
+      output.setText("Your sequences have been verified against known sequence databases. Some of the ids have been\n"\r
+              + "altered, most likely the start/end residue will have been updated.\n"\r
+              + "Save your alignment to maintain the updated id.\n\n"\r
+              + sbuffer.toString());\r
       Desktop.addInternalFrame(output, "Sequence names updated ", 600, 300);\r
       // The above is the dataset, we must now find out the index\r
       // of the viewed sequence\r
@@ -311,13 +470,15 @@ public class DBRefFetcher implements Runnable
           AlignmentI retrievedAl) // File\r
   // file)\r
   {\r
-\r
     if (retrievedAl == null || retrievedAl.getHeight() == 0)\r
     {\r
       return;\r
     }\r
-    SequenceI[] retrieved = retrievedAl.getSequencesArray();\r
+    SequenceI[] retrieved = recoverDbSequences(retrievedAl\r
+            .getSequencesArray());\r
     SequenceI sequence = null;\r
+    boolean transferred = false;\r
+    StringBuffer messages = new StringBuffer();\r
 \r
     // Vector entries = new Uniprot().getUniprotEntries(file);\r
 \r
@@ -331,9 +492,16 @@ public class DBRefFetcher implements Runnable
       // taking into account all accessionIds and names in the file\r
       Vector sequenceMatches = new Vector();\r
       // look for corresponding accession ids\r
-      DBRefEntry[] entryRefs = jalview.util.DBRefUtils.selectRefs(entry\r
-              .getDBRef(), new String[]\r
-      { dbSource });\r
+      DBRefEntry[] entryRefs = jalview.util.DBRefUtils.selectRefs(\r
+              entry.getDBRef(), new String[]\r
+              { dbSource });\r
+      if (entryRefs == null)\r
+      {\r
+        System.err\r
+                .println("Dud dbSource string ? no entryrefs selected for "\r
+                        + dbSource + " on " + entry.getName());\r
+        continue;\r
+      }\r
       for (int j = 0; j < entryRefs.length; j++)\r
       {\r
         String accessionId = entryRefs[j].getAccessionId(); // .getAccession().elementAt(j).toString();\r
@@ -351,14 +519,15 @@ public class DBRefFetcher implements Runnable
           }\r
         }\r
       }\r
-      if (sequenceMatches.size()==0)\r
+      if (sequenceMatches.size() == 0)\r
       {\r
-        // failed to match directly on accessionId==query so just compare all sequences to entry\r
+        // failed to match directly on accessionId==query so just compare all\r
+        // sequences to entry\r
         Enumeration e = seqRefs.keys();\r
         while (e.hasMoreElements())\r
         {\r
           Vector sqs = (Vector) seqRefs.get(e.nextElement());\r
-          if (sqs!=null && sqs.size()>0)\r
+          if (sqs != null && sqs.size() > 0)\r
           {\r
             Enumeration sqe = sqs.elements();\r
             while (sqe.hasMoreElements())\r
@@ -388,9 +557,12 @@ public class DBRefFetcher implements Runnable
       for (int m = 0; m < sequenceMatches.size(); m++)\r
       {\r
         sequence = (SequenceI) sequenceMatches.elementAt(m);\r
-        // only update start and end positions and shift features if there are no existing references\r
-        // TODO: test for legacy where uniprot or EMBL refs exist but no mappings are made (but content matches retrieved set)\r
-        boolean updateRefFrame = sequence.getDBRef()==null || sequence.getDBRef().length==0;\r
+        // only update start and end positions and shift features if there are\r
+        // no existing references\r
+        // TODO: test for legacy where uniprot or EMBL refs exist but no\r
+        // mappings are made (but content matches retrieved set)\r
+        boolean updateRefFrame = sequence.getDBRef() == null\r
+                || sequence.getDBRef().length == 0;\r
         // verify sequence against the entry sequence\r
 \r
         String nonGapped = AlignSeq.extractGaps("-. ",\r
@@ -406,27 +578,31 @@ public class DBRefFetcher implements Runnable
           absStart = nonGapped.indexOf(entrySeq);\r
           if (absStart == -1)\r
           { // verification failed.\r
-            sbuffer.append(sequence.getName()\r
+            messages.append(sequence.getName()\r
                     + " SEQUENCE NOT %100 MATCH \n");\r
             continue;\r
           }\r
-          \r
+          transferred = true;\r
           sbuffer.append(sequence.getName() + " HAS " + absStart\r
-                + " PREFIXED RESIDUES COMPARED TO " + dbSource+"\n");\r
+                  + " PREFIXED RESIDUES COMPARED TO " + dbSource + "\n");\r
           //\r
-          //      + " - ANY SEQUENCE FEATURES"\r
-          //        + " HAVE BEEN ADJUSTED ACCORDINGLY \n");\r
+          // + " - ANY SEQUENCE FEATURES"\r
+          // + " HAVE BEEN ADJUSTED ACCORDINGLY \n");\r
           // absStart = 0;\r
           // create valid mapping between matching region of local sequence and\r
           // the mapped sequence\r
           mp = new Mapping(null, new int[]\r
-          { sequence.getStart()+absStart, sequence.getStart()+absStart+entrySeq.length()-1 }, new int[]\r
-          { entry.getStart(),\r
-              entry.getStart() + entrySeq.length() - 1 }, 1, 1);\r
-          updateRefFrame=false; // mapping is based on current start/end so don't modify start and end\r
+          { sequence.getStart() + absStart,\r
+              sequence.getStart() + absStart + entrySeq.length() - 1 },\r
+                  new int[]\r
+                  { entry.getStart(),\r
+                      entry.getStart() + entrySeq.length() - 1 }, 1, 1);\r
+          updateRefFrame = false; // mapping is based on current start/end so\r
+          // don't modify start and end\r
         }\r
         else\r
         {\r
+          transferred = true;\r
           // update start and end of local sequence to place it in entry's\r
           // reference frame.\r
           // apply identity map map from whole of local sequence to matching\r
@@ -438,19 +614,24 @@ public class DBRefFetcher implements Runnable
           // absStart+sequence.getStart()+entrySeq.length()-1},\r
           // new int[] { entry.getStart(), entry.getEnd() }, 1, 1);\r
           // relocate local features for updated start\r
-          if (updateRefFrame && sequence.getSequenceFeatures() != null)\r
+          if (updateRefFrame)\r
           {\r
-            SequenceFeature[] sf = sequence.getSequenceFeatures();\r
-            int start = sequence.getStart();\r
-            int end = sequence.getEnd();\r
-            int startShift = 1-absStart-start; // how much the features are to be shifted by\r
-            for (int sfi = 0; sfi < sf.length; sfi++)\r
+            if (sequence.getSequenceFeatures() != null)\r
             {\r
-              if (sf[sfi].getBegin() >= start && sf[sfi].getEnd() <= end)\r
+              SequenceFeature[] sf = sequence.getSequenceFeatures();\r
+              int start = sequence.getStart();\r
+              int end = sequence.getEnd();\r
+              int startShift = 1 - absStart - start; // how much the features\r
+                                                     // are\r
+              // to be shifted by\r
+              for (int sfi = 0; sfi < sf.length; sfi++)\r
               {\r
-                // shift feature along by absstart\r
-                sf[sfi].setBegin(sf[sfi].getBegin() + startShift);\r
-                sf[sfi].setEnd(sf[sfi].getEnd() + startShift);\r
+                if (sf[sfi].getBegin() >= start && sf[sfi].getEnd() <= end)\r
+                {\r
+                  // shift feature along by absstart\r
+                  sf[sfi].setBegin(sf[sfi].getBegin() + startShift);\r
+                  sf[sfi].setEnd(sf[sfi].getEnd() + startShift);\r
+                }\r
               }\r
             }\r
           }\r
@@ -467,11 +648,74 @@ public class DBRefFetcher implements Runnable
           // finally, update local sequence reference frame if we're allowed\r
           sequence.setStart(absStart);\r
           sequence.setEnd(absEnd);\r
+          // search for alignment sequences to update coordinate frame for\r
+          for (int alsq = 0; alsq < alseqs.length; alsq++)\r
+          {\r
+            if (alseqs[alsq].getDatasetSequence() == sequence)\r
+            {\r
+              String ngAlsq = AlignSeq.extractGaps("-. ",\r
+                      alseqs[alsq].getSequenceAsString()).toUpperCase();\r
+              int oldstrt = alseqs[alsq].getStart();\r
+              alseqs[alsq].setStart(sequence.getSequenceAsString()\r
+                      .toUpperCase().indexOf(ngAlsq)\r
+                      + sequence.getStart());\r
+              if (oldstrt != alseqs[alsq].getStart())\r
+              {\r
+                alseqs[alsq].setEnd(ngAlsq.length()\r
+                        + alseqs[alsq].getStart() - 1);\r
+              }\r
+            }\r
+          }\r
+          // TODO: search for all other references to this dataset sequence, and\r
+          // update start/end\r
+          // TODO: update all AlCodonMappings which involve this alignment\r
+          // sequence (e.g. Q30167 cdna translation from exon2 product (vamsas\r
+          // demo)\r
         }\r
         // and remove it from the rest\r
         // TODO: decide if we should remove annotated sequence from set\r
         sdataset.remove(sequence);\r
+        // TODO: should we make a note of sequences that have received new DB\r
+        // ids, so we can query all enabled DAS servers for them ?\r
       }\r
     }\r
+    if (!transferred)\r
+    {\r
+      // report the ID/sequence mismatches\r
+      sbuffer.append(messages);\r
+    }\r
+  }\r
+\r
+  /**\r
+   * loop thru and collect additional sequences in Map.\r
+   * \r
+   * @param sequencesArray\r
+   * @return\r
+   */\r
+  private SequenceI[] recoverDbSequences(SequenceI[] sequencesArray)\r
+  {\r
+    Vector nseq = new Vector();\r
+    for (int i = 0; sequencesArray != null && i < sequencesArray.length; i++)\r
+    {\r
+      nseq.addElement(sequencesArray[i]);\r
+      DBRefEntry dbr[] = sequencesArray[i].getDBRef();\r
+      jalview.datamodel.Mapping map = null;\r
+      for (int r = 0; (dbr != null) && r < dbr.length; r++)\r
+      {\r
+        if ((map = dbr[r].getMap()) != null)\r
+        {\r
+          if (map.getTo() != null && !nseq.contains(map.getTo()))\r
+          {\r
+            nseq.addElement(map.getTo());\r
+          }\r
+        }\r
+      }\r
+    }\r
+    if (nseq.size() > 0)\r
+    {\r
+      sequencesArray = new SequenceI[nseq.size()];\r
+      nseq.toArray(sequencesArray);\r
+    }\r
+    return sequencesArray;\r
   }\r
 }\r