Jalview 2.6 source licence
[jalview.git] / src / jalview / ws / DBRefFetcher.java
index 73d106a..ad8c0f0 100644 (file)
@@ -1,20 +1,19 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)\r
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)\r
+ * Copyright (C) 2010 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
@@ -500,6 +499,13 @@ public class DBRefFetcher implements Runnable
       DBRefEntry[] entryRefs = jalview.util.DBRefUtils.selectRefs(entry\r
               .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
@@ -612,24 +618,26 @@ 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) {\r
+          if (updateRefFrame)\r
+          {\r
             if (sequence.getSequenceFeatures() != null)\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\r
-            // to be shifted by\r
-            for (int sfi = 0; sfi < sf.length; sfi++)\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
           }\r
         }\r
 \r
@@ -645,21 +653,28 @@ public class DBRefFetcher implements Runnable
           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
+          for (int alsq = 0; alsq < alseqs.length; alsq++)\r
           {\r
-            if (alseqs[alsq].getDatasetSequence()==sequence)\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().toUpperCase().indexOf(ngAlsq)+sequence.getStart());\r
-              if (oldstrt != alseqs[alsq].getStart()) {\r
-                alseqs[alsq].setEnd(ngAlsq.length()+alseqs[alsq].getStart()-1);\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 update start/end\r
-          // TODO: update all AlCodonMappings which involve this alignment sequence (e.g. Q30167 cdna translation from exon2 product (vamsas demo)\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