Looks for missing ids using BlastClient
authoramwaterhouse <Andrew Waterhouse>
Tue, 8 Feb 2005 18:40:35 +0000 (18:40 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 8 Feb 2005 18:40:35 +0000 (18:40 +0000)
src/jalview/analysis/SequenceFeatureFetcher.java

index 8c550e9..e034b3f 100755 (executable)
@@ -10,9 +10,11 @@ public class SequenceFeatureFetcher implements Runnable
 {\r
   AlignmentI align;\r
   AlignmentPanel ap;\r
+  ArrayList unknownSequences;\r
 \r
   public SequenceFeatureFetcher(AlignmentI align, AlignmentPanel ap)\r
   {\r
+    unknownSequences = new ArrayList();\r
     this.align = align;\r
     this.ap = ap;\r
     Thread thread = new Thread(this);\r
@@ -78,7 +80,8 @@ public class SequenceFeatureFetcher implements Runnable
           remainingIds.append(ids.get(i) + ";");\r
 \r
          EBIFetchClient ebi = new EBIFetchClient();\r
-        String[] result = ebi.fetchData(remainingIds.toString(), "xml", null);\r
+         System.out.println(remainingIds.toString());\r
+         String[] result = ebi.fetchData(remainingIds.toString(), "xml", null);\r
 \r
         if(result!=null)\r
           ReadUniprotFile(result, out, align);\r
@@ -93,6 +96,13 @@ public class SequenceFeatureFetcher implements Runnable
     }\r
   }catch(Exception ex){ex.printStackTrace();}\r
 \r
+  ap.RefreshPanels();\r
+  findMissingIds(align);\r
+\r
+  if(unknownSequences.size()>0)\r
+  {\r
+    WSWUBlastClient blastClient = new WSWUBlastClient(align, unknownSequences);\r
+  }\r
 \r
 }\r
 \r
@@ -115,10 +125,21 @@ void ReadUniprotFile(String [] result, RandomAccessFile out, AlignmentI align)
         out.writeBytes("<entry>\n");\r
       }catch(Exception ex){}\r
 \r
-      sequence = align.findName( parseElement( result[r], "<name>" , out)) ;\r
+      String seqName = parseElement( result[r], "<name>" , out);\r
+      sequence = align.findName( seqName ) ;\r
       if(sequence==null)\r
       {\r
-        System.out.println("Couldnt find sequence id. Suggestion is "+result[r]);\r
+        sequence = align.findName( seqName.substring(0, seqName.indexOf('_')));\r
+        if(sequence!=null)\r
+        {\r
+          System.out.println("changing "+sequence.getName()+" to "+seqName);\r
+          sequence.setName(seqName);\r
+        }\r
+      }\r
+      if(sequence==null)\r
+      {\r
+        System.out.println("UNIPROT updated suggestion is "+result[r]);\r
+        sequence = align.findName( result[r] ) ;\r
 \r
         // this entry has been suggested by ebi.\r
         // doesn't match id in alignment file\r
@@ -180,6 +201,52 @@ void ReadUniprotFile(String [] result, RandomAccessFile out, AlignmentI align)
        }\r
      }\r
 \r
+     if(result[r].indexOf("<sequence")>-1)\r
+     {\r
+       StringBuffer seqString = new StringBuffer();\r
+\r
+       if(out!=null)\r
+         try  {  out.writeBytes(result[r]+"\n"); }   catch (Exception ex){}\r
+\r
+       while(result[++r].indexOf("</sequence>")==-1)\r
+       {\r
+         seqString.append(result[r]);\r
+         if(out!=null)\r
+         try  {  out.writeBytes(result[r]+"\n"); }   catch (Exception ex){}\r
+       }\r
+\r
+       if(out!=null)\r
+         try  {  out.writeBytes(result[r]+"\n"); }   catch (Exception ex){}\r
+\r
+       StringBuffer nonGapped = new StringBuffer();\r
+       for (int i = 0; i < sequence.getSequence().length(); i++)\r
+       {\r
+         if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))\r
+           nonGapped.append(sequence.getCharAt(i));\r
+       }\r
+\r
+       int absStart = seqString.toString().indexOf(nonGapped.toString());\r
+       if(absStart==-1)\r
+       {\r
+         unknownSequences.add(sequence.getName());\r
+         features = null;\r
+         System.out.println(sequence.getName()+ "does not match ");\r
+         continue;\r
+       }\r
+\r
+       int absEnd =   absStart + nonGapped.toString().length();\r
+       absStart+=1;\r
+\r
+       if(absStart!=sequence.getStart() || absEnd!=sequence.getEnd())\r
+         System.out.println("Updated: "+sequence.getName()+" "+\r
+                           sequence.getStart()+"/"+sequence.getEnd()+"  to  "+ absStart+"/"+absEnd);\r
+\r
+\r
+       sequence.setStart(absStart);\r
+       sequence.setEnd(absEnd);\r
+\r
+     }\r
+\r
      if(result[r].indexOf("</entry>")>-1)\r
      {\r
        if(features!=null)\r
@@ -191,8 +258,34 @@ void ReadUniprotFile(String [] result, RandomAccessFile out, AlignmentI align)
 \r
      }\r
   }\r
+}\r
+\r
+void findMissingIds(AlignmentI align)\r
+{\r
+  String data;\r
+  ArrayList cachedIds = new ArrayList();\r
+\r
+  try\r
+  {\r
+    BufferedReader in = new BufferedReader(\r
+        new FileReader(jalview.bin.Cache.getProperty("UNIPROT_CACHE")));\r
+\r
+    while ( (data = in.readLine()) != null)\r
+    {\r
+      if (data.indexOf("name") > -1)\r
+      {\r
+        String name = parseElement(data, "<name>", null);\r
+        cachedIds.add(name);\r
+      }\r
+    }\r
+  }\r
+  catch (Exception ex)\r
+  {   ex.printStackTrace();  }\r
+\r
+  for(int i=0; i<align.getHeight(); i++)\r
+    if( !cachedIds.contains( align.getSequenceAt(i).getName() ) )\r
+      unknownSequences.add( align.getSequenceAt(i).getName() );\r
 \r
-  ap.RefreshPanels();\r
 \r
 }\r
 \r