Catch exceptions
authoramwaterhouse <Andrew Waterhouse>
Mon, 14 Nov 2005 12:00:25 +0000 (12:00 +0000)
committeramwaterhouse <Andrew Waterhouse>
Mon, 14 Nov 2005 12:00:25 +0000 (12:00 +0000)
src/jalview/gui/SequenceFetcher.java

index 74312e2..4fa215f 100755 (executable)
@@ -128,35 +128,43 @@ public class SequenceFetcher
   public void run()\r
   {\r
     StringBuffer result = new StringBuffer();\r
-    if (database.getSelectedItem().equals("Uniprot")\r
-        || database.getSelectedItem().equals("EMBL")\r
-        || database.getSelectedItem().equals("EMBLCDS"))\r
-    {\r
-      EBIFetchClient dbFetch = new EBIFetchClient();\r
-      String[] reply = dbFetch.fetchData(\r
-          database.getSelectedItem().toString().toLowerCase(\r
-          ) + ":" + textfield.getText(),\r
-          "fasta", "raw");\r
-\r
-      for (int i = 0; i < reply.length; i++)\r
-        result.append(reply[i]+"\n");\r
-    }\r
-    else if (database.getSelectedItem().equals("PDB"))\r
-    {\r
-      EBIFetchClient ebi = new EBIFetchClient();\r
-      String[] reply = ebi.fetchData("pdb:" + textfield.getText(), "pdb",\r
-                                     "raw");\r
-      PDBfile pdbfile = new PDBfile(reply);\r
-      for (int i = 0; i < pdbfile.chains.size(); i++)\r
+      if (database.getSelectedItem().equals("Uniprot")\r
+          || database.getSelectedItem().equals("EMBL")\r
+          || database.getSelectedItem().equals("EMBLCDS"))\r
       {\r
-        result.append("\n>" +\r
-                     ( (PDBChain) pdbfile.chains.elementAt(i)).sequence.getName() +\r
-                     "\n"\r
-                     +\r
-                     ( (PDBChain) pdbfile.chains.elementAt(i)).sequence.\r
-                     getSequence());\r
+        EBIFetchClient dbFetch = new EBIFetchClient();\r
+        String[] reply = dbFetch.fetchData(\r
+            database.getSelectedItem().toString().toLowerCase(\r
+            ) + ":" + textfield.getText(),\r
+            "fasta", "raw");\r
+\r
+        for (int i = 0; i < reply.length; i++)\r
+          result.append(reply[i] + "\n");\r
+      }\r
+      else if (database.getSelectedItem().equals("PDB"))\r
+      {\r
+        EBIFetchClient ebi = new EBIFetchClient();\r
+        String[] reply = ebi.fetchData("pdb:" + textfield.getText(), "pdb",\r
+                                       "raw");\r
+        try{\r
+          PDBfile pdbfile = new PDBfile(reply);\r
+          for (int i = 0; i < pdbfile.chains.size(); i++)\r
+          {\r
+            result.append("\n>" +\r
+                          ( (PDBChain) pdbfile.chains.elementAt(i)).sequence.\r
+                          getName() +\r
+                          "\n"\r
+                          +\r
+                          ( (PDBChain) pdbfile.chains.elementAt(i)).sequence.\r
+                          getSequence());\r
+          }\r
+        }catch(Exception ex)// Problem parsing PDB file\r
+        {\r
+          JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+         "Error retrieving "+textfield.getText()+" from "+database.getSelectedItem(),\r
+         "Error Retrieving Data", JOptionPane.WARNING_MESSAGE);\r
+        }\r
       }\r
-    }\r
 \r
     if (result.length() > 0)\r
     {\r
@@ -166,7 +174,7 @@ public class SequenceFetcher
       if (FormatAdapter.formats.contains(format))\r
       {\r
         sequences = new FormatAdapter().readFile(result.toString(), "Paste", format);\r
-        if (sequences != null)\r
+        if (sequences != null && sequences.length>0)\r
         {\r
           if(alignFrame==null)\r
           {\r
@@ -219,6 +227,11 @@ public class SequenceFetcher
           }\r
 \r
         }\r
+        else\r
+          JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+         "Error retrieving "+textfield.getText()+" from "+database.getSelectedItem(),\r
+         "Error Retrieving Data", JOptionPane.WARNING_MESSAGE);\r
+\r
       }\r
     }\r
 \r