merge from 2_4_Release branch
[jalview.git] / src / jalview / ws / DasSequenceFeatureFetcher.java
index e3f7478..f252b67 100644 (file)
@@ -1,17 +1,17 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)\r
+ * Copyright (C) 2008 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
+ * \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
+ * \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
@@ -34,7 +34,7 @@ import jalview.gui.*;
 \r
 /**\r
  * DOCUMENT ME!\r
- *\r
+ * \r
  * @author $author$\r
  * @version $Revision$\r
  */\r
@@ -51,43 +51,51 @@ public class DasSequenceFeatureFetcher
   Vector selectedSources;\r
 \r
   boolean cancelled = false;\r
+\r
   private void debug(String mesg)\r
   {\r
     debug(mesg, null);\r
   }\r
+\r
   private void debug(String mesg, Exception e)\r
   {\r
-    if (Cache.log!=null)\r
+    if (Cache.log != null)\r
     {\r
       Cache.log.debug(mesg, e);\r
-    } else {\r
+    }\r
+    else\r
+    {\r
       System.err.println(mesg);\r
-      if (e!=null)\r
-      { \r
-        e.printStackTrace(); \r
+      if (e != null)\r
+      {\r
+        e.printStackTrace();\r
       }\r
     }\r
   }\r
+\r
   long startTime;\r
 \r
   /**\r
-   * Creates a new SequenceFeatureFetcher object.\r
-   * Uses default\r
-   *\r
-   * @param align DOCUMENT ME!\r
-   * @param ap DOCUMENT ME!\r
+   * Creates a new SequenceFeatureFetcher object. Uses default\r
+   * \r
+   * @param align\r
+   *                DOCUMENT ME!\r
+   * @param ap\r
+   *                DOCUMENT ME!\r
    */\r
   public DasSequenceFeatureFetcher(SequenceI[] sequences,\r
           FeatureSettings fsettings, Vector selectedSources)\r
   {\r
     this(sequences, fsettings, selectedSources, true, true);\r
   }\r
+\r
   public DasSequenceFeatureFetcher(SequenceI[] sequences,\r
-          FeatureSettings fsettings, Vector selectedSources, boolean checkDbrefs, boolean promptFetchDbrefs)\r
+          FeatureSettings fsettings, Vector selectedSources,\r
+          boolean checkDbrefs, boolean promptFetchDbrefs)\r
   {\r
     this.selectedSources = selectedSources;\r
     this.sequences = sequences;\r
-    if (fsettings!=null)\r
+    if (fsettings != null)\r
     {\r
       this.fsettings = fsettings;\r
       this.af = fsettings.af;\r
@@ -100,7 +108,8 @@ public class DasSequenceFeatureFetcher
       DasCoordinateSystem[] coords = source.getCoordinateSystem();\r
       for (int c = 0; c < coords.length; c++)\r
       {\r
-        // TODO: match UniProt coord system canonically (?) - does UniProt==uniprot==UNIPROT ? \r
+        // TODO: match UniProt coord system canonically (?) - does\r
+        // UniProt==uniprot==UNIPROT ?\r
         if (coords[c].getName().indexOf("UniProt") > -1)\r
         {\r
           uniprotCount++;\r
@@ -133,13 +142,15 @@ public class DasSequenceFeatureFetcher
       int reply = JOptionPane.YES_OPTION;\r
       if (promptFetchDbrefs)\r
       {\r
-        reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
-             "Do you want Jalview to find\n"\r
-                      + "Uniprot Accession ids for given sequence names?",\r
-              "Find Uniprot Accession Ids", JOptionPane.YES_NO_OPTION,\r
-              JOptionPane.QUESTION_MESSAGE);\r
+        reply = JOptionPane\r
+                .showInternalConfirmDialog(\r
+                        Desktop.desktop,\r
+                        "Do you want Jalview to find\n"\r
+                                + "Uniprot Accession ids for given sequence names?",\r
+                        "Find Uniprot Accession Ids",\r
+                        JOptionPane.YES_NO_OPTION,\r
+                        JOptionPane.QUESTION_MESSAGE);\r
       }\r
-              \r
 \r
       if (reply == JOptionPane.YES_OPTION)\r
       {\r
@@ -168,13 +179,14 @@ public class DasSequenceFeatureFetcher
   }\r
 \r
   /**\r
-   * Spawns a number of dasobert Fetcher threads to add features to sequences in the dataset\r
+   * Spawns a number of dasobert Fetcher threads to add features to sequences in\r
+   * the dataset\r
    */\r
   void startFetching()\r
   {\r
     cancelled = false;\r
     startTime = System.currentTimeMillis();\r
-    if (af!=null)\r
+    if (af != null)\r
     {\r
       af.setProgressBar("Fetching DAS Sequence Features", startTime);\r
     }\r
@@ -211,7 +223,7 @@ public class DasSequenceFeatureFetcher
     }\r
 \r
     sourcesRemaining = selectedSources.size();\r
-    //Now sending requests one at a time to each server\r
+    // Now sending requests one at a time to each server\r
     for (int sourceIndex = 0; sourceIndex < selectedSources.size()\r
             && !cancelled; sourceIndex++)\r
     {\r
@@ -225,18 +237,20 @@ public class DasSequenceFeatureFetcher
   private void setGuiNoDassourceActive()\r
   {\r
 \r
-    if (af!=null)\r
+    if (af != null)\r
     {\r
       af.setProgressBar("No DAS Sources Active", startTime);\r
     }\r
-    if (getFeatSettings()!=null)\r
+    if (getFeatSettings() != null)\r
     {\r
       fsettings.noDasSourceActive();\r
-     }\r
+    }\r
   }\r
 \r
   /**\r
-   * Update our fsettings dialog reference if we didn't have one when we were first initialised.\r
+   * Update our fsettings dialog reference if we didn't have one when we were\r
+   * first initialised.\r
+   * \r
    * @return fsettings\r
    */\r
   private FeatureSettings getFeatSettings()\r
@@ -253,7 +267,7 @@ public class DasSequenceFeatureFetcher
 \r
   public void cancel()\r
   {\r
-    if (af!=null)\r
+    if (af != null)\r
     {\r
       af.setProgressBar("DAS Feature Fetching Cancelled", startTime);\r
     }\r
@@ -307,7 +321,7 @@ public class DasSequenceFeatureFetcher
 \r
   void featuresAdded(SequenceI seq)\r
   {\r
-    if (af==null)\r
+    if (af == null)\r
     {\r
       // no gui to update with features.\r
       return;\r
@@ -335,11 +349,13 @@ public class DasSequenceFeatureFetcher
     DBRefEntry[] uprefs = jalview.util.DBRefUtils.selectRefs(\r
             seq.getDBRef(), new String[]\r
             {\r
-            //  jalview.datamodel.DBRefSource.PDB,\r
+            // jalview.datamodel.DBRefSource.PDB,\r
             jalview.datamodel.DBRefSource.UNIPROT,\r
-            //  jalview.datamodel.DBRefSource.EMBL - not tested on any EMBL coord sys sources\r
+            // jalview.datamodel.DBRefSource.EMBL - not tested on any EMBL coord\r
+            // sys sources\r
             });\r
-    // TODO: minimal list of DAS queries to make by querying with untyped ID if distinct from any typed IDs\r
+    // TODO: minimal list of DAS queries to make by querying with untyped ID if\r
+    // distinct from any typed IDs\r
 \r
     boolean dasCoordSysFound = false;\r
 \r
@@ -358,8 +374,9 @@ public class DasSequenceFeatureFetcher
           {\r
             debug("Launched fetcher for coordinate system "\r
                     + cs[0].getName());\r
-            //  Will have to pass any mapping information to the fetcher\r
-            //- the start/end for the DBRefEntry may not be the same as the sequence's start/end\r
+            // Will have to pass any mapping information to the fetcher\r
+            // - the start/end for the DBRefEntry may not be the same as the\r
+            // sequence's start/end\r
 \r
             System.out.println(seq.getName() + " "\r
                     + (seq.getDatasetSequence() == null) + " "\r
@@ -381,13 +398,14 @@ public class DasSequenceFeatureFetcher
       if (seq.getName().indexOf("|") > -1)\r
       {\r
         id = seq.getName().substring(seq.getName().lastIndexOf("|") + 1);\r
-        if (id.trim().length()<4)\r
+        if (id.trim().length() < 4)\r
         {\r
-          // hack - we regard a significant ID as being at least 4 non-whitespace characters\r
+          // hack - we regard a significant ID as being at least 4\r
+          // non-whitespace characters\r
           id = seq.getName().substring(0, seq.getName().lastIndexOf("|"));\r
-          if (id.indexOf("|")>-1)\r
+          if (id.indexOf("|") > -1)\r
           {\r
-            id = id.substring(id.lastIndexOf("|")+1);\r
+            id = id.substring(id.lastIndexOf("|") + 1);\r
           }\r
         }\r
       }\r
@@ -406,8 +424,10 @@ public class DasSequenceFeatureFetcher
   }\r
 \r
   /**\r
-   * fetch and add das features to a sequence using the given source URL and compatible DbRef id.\r
-   * new features are mapped using the DbRef mapping to the local coordinate system.\r
+   * fetch and add das features to a sequence using the given source URL and\r
+   * compatible DbRef id. new features are mapped using the DbRef mapping to the\r
+   * local coordinate system.\r
+   * \r
    * @param seq\r
    * @param SourceUrl\r
    * @param dbref\r
@@ -416,8 +436,8 @@ public class DasSequenceFeatureFetcher
           final DasSource dasSource, final DBRefEntry dbref)\r
   {\r
 \r
-    //////////////\r
-    /// fetch DAS features\r
+    // ////////////\r
+    // / fetch DAS features\r
     final Das1Source source = new Das1Source();\r
     source.setUrl(dasSource.getUrl());\r
     source.setNickname(dasSource.getNickname());\r
@@ -427,11 +447,10 @@ public class DasSequenceFeatureFetcher
       responseComplete(dasSource, seq); // reduce thread count anyhow\r
       return;\r
     }\r
-    debug("new Das Feature Fetcher for " + dbref.getSource()\r
-            + ":" + dbref.getAccessionId() + " querying "\r
-            + dasSource.getUrl());\r
+    debug("new Das Feature Fetcher for " + dbref.getSource() + ":"\r
+            + dbref.getAccessionId() + " querying " + dasSource.getUrl());\r
     FeatureThread fetcher = new FeatureThread(dbref.getAccessionId()\r
-    //  +  ":" + start + "," + end,\r
+    // + ":" + start + "," + end,\r
             , source);\r
 \r
     fetcher.addFeatureListener(new FeatureListener()\r
@@ -451,8 +470,8 @@ public class DasSequenceFeatureFetcher
 \r
         Map[] features = e.getFeatures();\r
         // add features to sequence\r
-        debug("das source " + ds.getUrl() + " returned "\r
-                + features.length + " features");\r
+        debug("das source " + ds.getUrl() + " returned " + features.length\r
+                + " features");\r
 \r
         if (features.length > 0)\r
         {\r
@@ -463,8 +482,7 @@ public class DasSequenceFeatureFetcher
             if (dbref.getMap() != null && f.getBegin() > 0\r
                     && f.getEnd() > 0)\r
             {\r
-              debug("mapping from " + f.getBegin() + " - "\r
-                      + f.getEnd());\r
+              debug("mapping from " + f.getBegin() + " - " + f.getEnd());\r
               SequenceFeature vf[] = null;\r
 \r
               try\r
@@ -486,8 +504,8 @@ public class DasSequenceFeatureFetcher
               {\r
                 for (int v = 0; v < vf.length; v++)\r
                 {\r
-                  debug("mapping to " + v + ": "\r
-                          + vf[v].getBegin() + " - " + vf[v].getEnd());\r
+                  debug("mapping to " + v + ": " + vf[v].getBegin() + " - "\r
+                          + vf[v].getEnd());\r
                   seq.addSequenceFeature(vf[v]);\r
                 }\r
               }\r
@@ -502,8 +520,8 @@ public class DasSequenceFeatureFetcher
         }\r
         else\r
         {\r
-          //  System.out.println("No features found for " + seq.getName()\r
-          //                     + " from: " + e.getDasSource().getNickname());\r
+          // System.out.println("No features found for " + seq.getName()\r
+          // + " from: " + e.getDasSource().getNickname());\r
         }\r
         responseComplete(dasSource, seq);\r
 \r
@@ -518,13 +536,13 @@ public class DasSequenceFeatureFetcher
   protected void createFeatureFetcher(final SequenceI seq,\r
           final DasSource dasSource, String id)\r
   {\r
-    //////////////\r
-    /// fetch DAS features\r
+    // ////////////\r
+    // / fetch DAS features\r
     final Das1Source source = new Das1Source();\r
     source.setUrl(dasSource.getUrl());\r
     source.setNickname(dasSource.getNickname());\r
-    \r
-    if (id!=null)\r
+\r
+    if (id != null)\r
     {\r
       id = id.trim();\r
     }\r
@@ -533,7 +551,7 @@ public class DasSequenceFeatureFetcher
       debug("new Das Feature Fetcher for " + id + " querying "\r
               + dasSource.getUrl());\r
       FeatureThread fetcher = new FeatureThread(id\r
-      //  +  ":" + start + "," + end,\r
+      // + ":" + start + "," + end,\r
               , source);\r
 \r
       fetcher.addFeatureListener(new FeatureListener()\r
@@ -570,8 +588,8 @@ public class DasSequenceFeatureFetcher
           }\r
           else\r
           {\r
-            //  System.out.println("No features found for " + seq.getName()\r
-            //                     + " from: " + e.getDasSource().getNickname());\r
+            // System.out.println("No features found for " + seq.getName()\r
+            // + " from: " + e.getDasSource().getNickname());\r
           }\r
           responseComplete(dasSource, seq);\r
 \r
@@ -581,16 +599,18 @@ public class DasSequenceFeatureFetcher
       );\r
 \r
       fetcher.start();\r
-    } else {\r
+    }\r
+    else\r
+    {\r
       // invalid fetch - indicate it is finished.\r
-      debug("Skipping empty ID for querying "\r
-              + dasSource.getUrl());\r
+      debug("Skipping empty ID for querying " + dasSource.getUrl());\r
       responseComplete(dasSource, seq);\r
     }\r
   }\r
 \r
   /**\r
    * creates a jalview sequence feature from a das feature document\r
+   * \r
    * @param dasfeature\r
    * @return sequence feature object created using dasfeature information\r
    */\r
@@ -603,14 +623,10 @@ public class DasSequenceFeatureFetcher
     try\r
     {\r
       /**\r
-       * Different qNames for a DAS Feature - are string keys to the HashMaps in features\r
-       * "METHOD") ||\r
-                  qName.equals("TYPE") ||\r
-                  qName.equals("START") ||\r
-                  qName.equals("END") ||\r
-                  qName.equals("NOTE") ||\r
-                  qName.equals("LINK") ||\r
-                  qName.equals("SCORE")\r
+       * Different qNames for a DAS Feature - are string keys to the HashMaps in\r
+       * features "METHOD") || qName.equals("TYPE") || qName.equals("START") ||\r
+       * qName.equals("END") || qName.equals("NOTE") || qName.equals("LINK") ||\r
+       * qName.equals("SCORE")\r
        */\r
       String desc = new String();\r
       if (dasfeature.containsKey("NOTE"))\r
@@ -659,9 +675,12 @@ public class DasSequenceFeatureFetcher
       return null;\r
     }\r
   }\r
+\r
   /**\r
-   * query the default DAS Source Registry for sources.\r
-   * Uses value of jalview property DAS_REGISTRY_URL and the DasSourceBrowser.DEFAULT_REGISTRY if that doesn't exist. \r
+   * query the default DAS Source Registry for sources. Uses value of jalview\r
+   * property DAS_REGISTRY_URL and the DasSourceBrowser.DEFAULT_REGISTRY if that\r
+   * doesn't exist.\r
+   * \r
    * @return list of sources\r
    */\r
   public static DasSource[] getDASSources()\r
@@ -671,10 +690,12 @@ public class DasSequenceFeatureFetcher
             DasSourceBrowser.DEFAULT_REGISTRY);\r
     return getDASSources(registryURL);\r
   }\r
+\r
   /**\r
    * query the given URL for DasSources.\r
+   * \r
    * @param registryURL\r
-   * return sources from registryURL\r
+   *                return sources from registryURL\r
    */\r
   public static DasSource[] getDASSources(String registryURL)\r
   {\r