apply version 2.7 copyright
[jalview.git] / src / jalview / ws / DasSequenceFeatureFetcher.java
index 2448402..bf200ce 100644 (file)
@@ -1,20 +1,19 @@
 /*\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
+ * 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 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
+ * This file is part of Jalview.\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
+ * 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
- * 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 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
@@ -80,9 +79,9 @@ public class DasSequenceFeatureFetcher
    * Creates a new SequenceFeatureFetcher object. Uses default\r
    * \r
    * @param align\r
-   *                DOCUMENT ME!\r
+   *          DOCUMENT ME!\r
    * @param ap\r
-   *                DOCUMENT ME!\r
+   *          DOCUMENT ME!\r
    */\r
   public DasSequenceFeatureFetcher(SequenceI[] sequences,\r
           FeatureSettings fsettings, Vector selectedSources)\r
@@ -91,19 +90,23 @@ public class DasSequenceFeatureFetcher
   }\r
 \r
   public DasSequenceFeatureFetcher(SequenceI[] oursequences,\r
-          FeatureSettings fsettings, Vector selectedSources,\r
+          FeatureSettings fsettings, Vector ourselectedSources,\r
           boolean checkDbrefs, boolean promptFetchDbrefs)\r
   {\r
-    this.selectedSources = new Vector(); \r
-    Enumeration sources = selectedSources.elements();\r
+    this.selectedSources = new Vector();\r
+    Enumeration sources = ourselectedSources.elements();\r
     // filter both sequences and sources to eliminate duplicates\r
     while (sources.hasMoreElements())\r
     {\r
       Object src = sources.nextElement();\r
-      if (this.selectedSources.contains(src)) { selectedSources.addElement(src); };\r
+      if (!selectedSources.contains(src))\r
+      {\r
+        selectedSources.addElement(src);\r
+      }\r
+      ;\r
     }\r
     Vector sqs = new Vector();\r
-    for (int i=0; i<oursequences.length; i++)\r
+    for (int i = 0; i < oursequences.length; i++)\r
     {\r
       if (!sqs.contains(oursequences[i]))\r
       {\r
@@ -111,7 +114,8 @@ public class DasSequenceFeatureFetcher
       }\r
     }\r
     sequences = new SequenceI[sqs.size()];\r
-    for (int i=0; i<sequences.length; i++) {\r
+    for (int i = 0; i < sequences.length; i++)\r
+    {\r
       sequences[i] = (SequenceI) sqs.elementAt(i);\r
     }\r
     if (fsettings != null)\r
@@ -210,32 +214,34 @@ public class DasSequenceFeatureFetcher
       af.setProgressBar("Fetching DAS Sequence Features", startTime);\r
     }\r
 \r
-\r
     if (selectedSources == null || selectedSources.size() == 0)\r
     {\r
-      try {\r
-        DasSource[] sources = new jalview.gui.DasSourceBrowser().getDASSource();\r
-      \r
-      String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",\r
-              "uniprot");\r
-      StringTokenizer st = new StringTokenizer(active, "\t");\r
-      selectedSources = new Vector();\r
-      String token;\r
-      while (st.hasMoreTokens())\r
+      try\r
       {\r
-        token = st.nextToken();\r
-        for (int i = 0; i < sources.length; i++)\r
+        DasSource[] sources = new jalview.gui.DasSourceBrowser()\r
+                .getDASSource();\r
+\r
+        String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",\r
+                "uniprot");\r
+        StringTokenizer st = new StringTokenizer(active, "\t");\r
+        selectedSources = new Vector();\r
+        String token;\r
+        while (st.hasMoreTokens())\r
         {\r
-          if (sources[i].getNickname().equals(token))\r
+          token = st.nextToken();\r
+          for (int i = 0; i < sources.length; i++)\r
           {\r
-            selectedSources.addElement(sources[i]);\r
-            break;\r
+            if (sources[i].getNickname().equals(token))\r
+            {\r
+              selectedSources.addElement(sources[i]);\r
+              break;\r
+            }\r
           }\r
         }\r
-      }\r
       } catch (Exception ex)\r
       {\r
-        debug("Exception whilst setting default feature sources from registry and local preferences.",ex);\r
+        debug("Exception whilst setting default feature sources from registry and local preferences.",\r
+                ex);\r
       }\r
     }\r
 \r
@@ -328,8 +334,9 @@ public class DasSequenceFeatureFetcher
   private void setGuiFetchComplete()\r
   {\r
 \r
-    if (af != null)\r
+    if (!cancelled && af != null)\r
     {\r
+      // only update the progress bar if we've completed the fetch normally\r
       af.setProgressBar("DAS Feature Fetching Complete", startTime);\r
     }\r
 \r
@@ -503,8 +510,8 @@ public class DasSequenceFeatureFetcher
           for (int i = 0; i < features.length; i++)\r
           {\r
             // standard DAS feature-> jalview sequence feature transformation\r
-            SequenceFeature f = newSequenceFeature(features[i], source\r
-                    .getNickname());\r
+            SequenceFeature f = newSequenceFeature(features[i],\r
+                    source.getNickname());\r
             if (!parseSeqFeature(seq, f, features[i], source))\r
             {\r
               if (dbref.getMap() != null && f.getBegin() > 0\r
@@ -607,8 +614,8 @@ public class DasSequenceFeatureFetcher
             for (int i = 0; i < features.length; i++)\r
             {\r
               // standard DAS feature-> jalview sequence feature transformation\r
-              SequenceFeature f = newSequenceFeature(features[i], source\r
-                      .getNickname());\r
+              SequenceFeature f = newSequenceFeature(features[i],\r
+                      source.getNickname());\r
               if (!parseSeqFeature(seq, f, features[i], source))\r
               {\r
                 // just add as a simple sequence feature\r
@@ -646,20 +653,20 @@ public class DasSequenceFeatureFetcher
    * simple sequence feature.\r
    * \r
    * @param seq\r
-   *                the sequence to annotate\r
+   *          the sequence to annotate\r
    * @param f\r
-   *                the jalview sequence feature generated from the DAS feature\r
+   *          the jalview sequence feature generated from the DAS feature\r
    * @param map\r
-   *                the sequence feature attributes\r
+   *          the sequence feature attributes\r
    * @param source\r
-   *                the source that emitted the feature\r
+   *          the source that emitted the feature\r
    * @return true if feature was consumed as another kind of annotation.\r
    */\r
   protected boolean parseSeqFeature(SequenceI seq, SequenceFeature f,\r
           Map map, Das1Source source)\r
   {\r
     SequenceI mseq = seq;\r
-    while (seq.getDatasetSequence()!=null)\r
+    while (seq.getDatasetSequence() != null)\r
     {\r
       seq = seq.getDatasetSequence();\r
     }\r
@@ -669,14 +676,18 @@ public class DasSequenceFeatureFetcher
       if (type.equalsIgnoreCase("protein_name"))\r
       {\r
         // parse name onto the alignment sequence or the dataset sequence.\r
-        if (seq.getDescription()==null || seq.getDescription().trim().length() == 0)\r
+        if (seq.getDescription() == null\r
+                || seq.getDescription().trim().length() == 0)\r
         {\r
-          // could look at the note series to pick out the first long name, for the moment just use the whole description string \r
+          // could look at the note series to pick out the first long name, for\r
+          // the moment just use the whole description string\r
           seq.setDescription(f.getDescription());\r
         }\r
-        if (mseq.getDescription()==null || mseq.getDescription().trim().length() == 0)\r
+        if (mseq.getDescription() == null\r
+                || mseq.getDescription().trim().length() == 0)\r
         {\r
-          // could look at the note series to pick out the first long name, for the moment just use the whole description string \r
+          // could look at the note series to pick out the first long name, for\r
+          // the moment just use the whole description string\r
           mseq.setDescription(f.getDescription());\r
         }\r
         return true;\r
@@ -698,29 +709,36 @@ public class DasSequenceFeatureFetcher
           dbr.setAccessionId(st.nextToken());\r
         }\r
         seq.addDBRef(dbr);\r
-        \r
+\r
         if (f.links != null && f.links.size() > 0)\r
         {\r
           // feature is also appended to enable links to be seen.\r
           // TODO: consider extending dbrefs to have their own links ?\r
-          // TODO: new feature: extract dbref links from DAS servers and add the URL pattern to the list of DB name associated links in the user's preferences ?\r
-          // for the moment - just fix up the existing feature so it displays correctly.\r
+          // TODO: new feature: extract dbref links from DAS servers and add the\r
+          // URL pattern to the list of DB name associated links in the user's\r
+          // preferences ?\r
+          // for the moment - just fix up the existing feature so it displays\r
+          // correctly.\r
           // f.setType(dbr.getSource());\r
-          //f.setDescription();\r
+          // f.setDescription();\r
           f.setValue("linkonly", Boolean.TRUE);\r
-          //f.setDescription("");\r
+          // f.setDescription("");\r
           Vector newlinks = new Vector();\r
           Enumeration it = f.links.elements();\r
           while (it.hasMoreElements())\r
           {\r
             String elm;\r
-            UrlLink urllink = new UrlLink(elm = (String)it.nextElement());\r
-            if (urllink.isValid()) {\r
+            UrlLink urllink = new UrlLink(elm = (String) it.nextElement());\r
+            if (urllink.isValid())\r
+            {\r
               urllink.setLabel(f.getDescription());\r
               newlinks.addElement(urllink.toString());\r
-            } else {\r
-              // couldn't parse the link properly. Keep it anyway - just in case.\r
-              debug("couldn't parse link string - "+elm);\r
+            }\r
+            else\r
+            {\r
+              // couldn't parse the link properly. Keep it anyway - just in\r
+              // case.\r
+              debug("couldn't parse link string - " + elm);\r
               newlinks.addElement(elm);\r
             }\r
           }\r
@@ -786,8 +804,9 @@ public class DasSequenceFeatureFetcher
       {\r
       }\r
 \r
-      SequenceFeature f = new SequenceFeature((String) dasfeature\r
-              .get("TYPE"), desc, start, end, score, nickname);\r
+      SequenceFeature f = new SequenceFeature(\r
+              (String) dasfeature.get("TYPE"), desc, start, end, score,\r
+              nickname);\r
 \r
       if (dasfeature.containsKey("LINK"))\r
       {\r
@@ -833,7 +852,7 @@ public class DasSequenceFeatureFetcher
    * 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
@@ -869,6 +888,8 @@ public class DasSequenceFeatureFetcher
               .size()]);\r
     } catch (Exception ex)\r
     {\r
+      System.err.println("Failed to contact DAS1 registry at "\r
+              + registryURL);\r
       ex.printStackTrace();\r
       return null;\r
     }\r