Use shortname
authoramwaterhouse <Andrew Waterhouse>
Mon, 14 Nov 2005 12:00:03 +0000 (12:00 +0000)
committeramwaterhouse <Andrew Waterhouse>
Mon, 14 Nov 2005 12:00:03 +0000 (12:00 +0000)
src/jalview/io/SequenceFeatureFetcher.java
src/jalview/io/WSWUBlastClient.java

index 5ecb417..a70aaef 100755 (executable)
@@ -109,10 +109,10 @@ public class SequenceFeatureFetcher implements Runnable
              seqIndex++, i++)\r
         {\r
           SequenceI sequence = (SequenceI) sequences.get(seqIndex);\r
-          if(!ids.contains(sequence.getName()))\r
+          if(!ids.contains(sequence.getShortName()))\r
           {\r
-            ids.add(sequence.getName());\r
-            unknownSequences.add(sequence.getName());\r
+            ids.add(sequence.getShortName());\r
+            unknownSequences.add(sequence);\r
           }\r
         }\r
 \r
@@ -205,13 +205,13 @@ public class SequenceFeatureFetcher implements Runnable
     {\r
       entry = (UniprotEntry) entries.elementAt(i);\r
       String idmatch = entry.getAccession().elementAt(0).toString();\r
-      sequence = dataset.findName(idmatch);\r
+      sequence = dataset.findShortName(idmatch);\r
 \r
       if (sequence == null)\r
       {\r
         //Sequence maybe Name, not Accession\r
         idmatch = entry.getName().elementAt(0).toString();;\r
-        sequence = dataset.findName(idmatch);\r
+        sequence = dataset.findShortName(idmatch);\r
       }\r
 \r
       if (sequence == null)\r
@@ -221,7 +221,7 @@ public class SequenceFeatureFetcher implements Runnable
       }\r
 \r
       ids.remove(sequence.getName());\r
-      unknownSequences.remove(sequence.getName());\r
+      unknownSequences.remove(sequence);\r
 \r
       String nonGapped = AlignSeq.extractGaps("-. ", sequence.getSequence());\r
 \r
index 99beb5f..e6800bc 100755 (executable)
@@ -29,6 +29,7 @@ import java.util.*;
 import javax.swing.*;\r
 \r
 import javax.xml.namespace.QName;\r
+import jalview.analysis.AlignSeq;\r
 \r
 \r
 /**\r
@@ -44,7 +45,7 @@ public class WSWUBlastClient
     CutAndPasteTransfer output = new CutAndPasteTransfer();\r
     int jobsRunning = 0;\r
 \r
-    Hashtable suggestedIds = new Hashtable();\r
+    Vector suggestedIds = new Vector();\r
     /**\r
      * Creates a new WSWUBlastClient object.\r
      *\r
@@ -63,21 +64,10 @@ public class WSWUBlastClient
 \r
         for (int i = 0; i < ids.size(); i++)\r
         {\r
-            SequenceI sequence = al.findName(ids.get(i).toString());\r
-            System.out.println(ids.get(i).toString());\r
-            StringBuffer nonGapped = new StringBuffer();\r
+            Sequence sequence = (Sequence)ids.get(i);\r
+            System.out.println(sequence.getName());\r
 \r
-\r
-            for (int n = 0; n < sequence.getSequence().length(); n++)\r
-            {\r
-                if (!jalview.util.Comparison.isGap(sequence.getCharAt(n)))\r
-                {\r
-                    nonGapped.append(sequence.getCharAt(n));\r
-                }\r
-            }\r
-\r
-            BlastThread thread = new BlastThread(ids.get(i).toString(),\r
-                    nonGapped.toString());\r
+            BlastThread thread = new BlastThread(sequence);\r
             thread.start();\r
             jobsRunning++;\r
         }\r
@@ -93,13 +83,13 @@ public class WSWUBlastClient
      * @param id1 DOCUMENT ME!\r
      * @param res DOCUMENT ME!\r
      */\r
-    void parseResult(String id1, String res)\r
+    void parseResult(Sequence seq, String res)\r
     {\r
         StringTokenizer st = new StringTokenizer(res, "\n");\r
         String data;\r
         String id2;\r
         int maxFound = 90;\r
-        StringBuffer buffer = new StringBuffer("\n\n" + id1 + " :");\r
+        StringBuffer buffer = new StringBuffer("\n\n" + seq.getShortName() + " :");\r
 \r
         while (st.hasMoreTokens())\r
         {\r
@@ -127,10 +117,7 @@ public class WSWUBlastClient
                         {\r
                             maxFound = value;\r
                             buffer.append(" " + id2 + " " + value + "%; ");\r
-                            if(!suggestedIds.containsKey(id1))\r
-                             {\r
-                               suggestedIds.put(id1, id2);\r
-                             }\r
+                            suggestedIds.addElement( new Object[]{seq, id2});\r
                         }\r
                     }\r
                 }\r
@@ -150,29 +137,35 @@ public class WSWUBlastClient
 \r
       if (reply == JOptionPane.YES_OPTION)\r
       {\r
-        Enumeration keys = suggestedIds.keys();\r
+        Enumeration keys = suggestedIds.elements();\r
         while(keys.hasMoreElements())\r
         {\r
-          String oldid = keys.nextElement().toString();\r
-          SequenceI sequence = al.findName(oldid);\r
-          sequence.setName( suggestedIds.get(oldid).toString() );\r
+          Object [] object = (Object[])keys.nextElement();\r
 \r
-          sequence = sequence.getDatasetSequence();\r
-          if(sequence!=null)\r
-          {\r
+          Sequence oldseq = (Sequence)object[0];\r
 \r
-            sequence.setName(suggestedIds.get(oldid).toString());\r
+          oldseq.setName( object[1].toString() );\r
 \r
-            Vector entries = sequence.getDBRef();\r
-            if(entries!=null)\r
+          // Oldseq is actually in the dataset, we must find the\r
+          // Visible seq and change its name also.\r
+          for (int i = 0; i < al.getHeight(); i++)\r
+          {\r
+            if (al.getSequenceAt(i).getDatasetSequence() == oldseq)\r
             {\r
-              DBRefEntry entry = (DBRefEntry) entries.elementAt(0);\r
-              sequence.addDBRef(new jalview.datamodel.DBRefEntry("UNIPROT",\r
-                  "0",\r
-                  entry.getAccessionId()));\r
+              al.getSequenceAt(i).setName(oldseq.getName());\r
+              break;\r
             }\r
           }\r
-          System.out.println("replace "+oldid+" with "+suggestedIds.get(oldid));\r
+\r
+          Vector entries = oldseq.getDBRef();\r
+          if (entries != null)\r
+          {\r
+            DBRefEntry entry = (DBRefEntry) entries.elementAt(0);\r
+            oldseq.addDBRef(new jalview.datamodel.\r
+                                                 DBRefEntry("UNIPROT",\r
+                "0",\r
+                entry.getAccessionId()));\r
+          }\r
         }\r
       }\r
       ap.repaint();\r
@@ -227,16 +220,14 @@ public class WSWUBlastClient
 \r
     class BlastThread extends Thread\r
     {\r
-        String sequence;\r
-        String seqid;\r
+        Sequence sequence;\r
         String jobid;\r
         boolean jobComplete = false;\r
 \r
-        BlastThread(String id, String sequence)\r
+        BlastThread(Sequence sequence)\r
         {\r
-          System.out.println("blasting for: "+id);\r
-            this.sequence = sequence;\r
-            seqid = id;\r
+          System.out.println("blasting for: "+sequence.getName());\r
+          this.sequence = sequence;\r
         }\r
 \r
         public void run()\r
@@ -259,14 +250,14 @@ public class WSWUBlastClient
 \r
                     if(object instanceof String)\r
                     {\r
-                      parseResult(seqid, (String)object);\r
+                      parseResult(sequence, (String)object);\r
                       jobComplete = true;\r
                       jobsRunning--;\r
                     }\r
 \r
                     Thread.sleep(5000);\r
 \r
-                    System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug\r
+                    System.out.println("WSWuBlastClient: I'm alive "+sequence.getShortName()+" "+jobid); // log.debug\r
                 }\r
                 catch (Exception ex)\r
                 {\r
@@ -286,7 +277,8 @@ public class WSWUBlastClient
             params.put("type", "xml");\r
             params.put("async", "true");\r
 \r
-            byte[] seqbytes = sequence.getBytes();\r
+            byte[] seqbytes = AlignSeq.extractGaps("-. ",\r
+                                                  sequence.getSequence()).getBytes();\r
 \r
             try\r
             {\r
@@ -307,7 +299,7 @@ public class WSWUBlastClient
                 {\r
                   jobComplete = true;\r
                   jobsRunning--;\r
-                  parseResult(seqid, (String)object);\r
+                  parseResult(sequence, (String)object);\r
                 }\r
 \r
             }\r