JAL-2629 hmmer searches now read domain rather than full scores
[jalview.git] / src / jalview / hmmer / Search.java
index 2fad426..5c7da7c 100644 (file)
@@ -46,6 +46,59 @@ public abstract class Search extends HmmerCommand
   {
   }
 
+  /*
+  void readOutputFile(File inputTableTemp) throws IOException
+  {
+    BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
+  
+  
+    String line = "";
+    while (!line.startsWith("//"))
+    {
+  
+      while (!line.startsWith(">> ") && !line.startsWith("//"))
+      {
+        line = br.readLine();
+      }
+  
+      if (line.startsWith("//"))
+      {
+        break;
+      }
+  
+      Scanner scanner = new Scanner(line);
+      String name = scanner.next();
+      name = scanner.next();
+  
+      br.readLine();
+      br.readLine();
+  
+      List<SequenceI> domains = new ArrayList<>();
+  
+      for (SequenceI seq : seqs)
+      {
+        if (seq.getName().contains(name))
+        {
+          domains.add(seq);
+        }
+      }
+  
+      if (domains.contains(getSequence()))
+      {
+        domains.remove(getSequence());
+      }
+  
+      if (domains.size() > 0)
+      {
+        readOutputTable(br, domains);
+      }
+  
+      line = br.readLine();
+    }
+  
+  }
+  
+  
   /**
    * Reads in the scores table output by jackhmmer and adds annotation to
    * sequences for E-value and bit score
@@ -53,22 +106,11 @@ public abstract class Search extends HmmerCommand
    * @param inputTableTemp
    * @throws IOException
    */
-  void readTable(File inputTableTemp) throws IOException
+  /*
+  void readOutputTable(BufferedReader br, List<SequenceI> seqs) throws IOException
   {
-    BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
-    String line = "";
-    while (!line.startsWith("Query:"))
-    {
-      line = br.readLine();
-    }
-    while (!line.contains("-------"))
-    {
-      line = br.readLine();
-    }
-    line = br.readLine();
-
-    int index = 0;
-
+    String line = br.readLine();
+  
     while (!"".equals(line) && line != null)
     {
       if ("  ------ inclusion threshold ------".equals(line))
@@ -76,53 +118,97 @@ public abstract class Search extends HmmerCommand
         line = br.readLine();
         continue;
       }
-
+  
       Scanner scanner = new Scanner(line);
+      scanner.next();
+      scanner.next();
+      String score = scanner.next();
+  
+      scanner.next();
+  
       String evalue = scanner.next();
-
-      if (evalue.equals("+") || evalue.equals("-"))
+  
+      scanner.next();
+      scanner.next();
+      scanner.next();
+      scanner.next();
+  
+      int start = scanner.nextInt();
+      int end = scanner.nextInt();
+  
+      SequenceI seq = null;
+      for (SequenceI sequence : seqs)
+      {
+        if (sequence.getStart() >= start && sequence.getEnd() <= end)
+        {
+          seq = sequence;
+          break;
+        }
+      }
+  
+      if (seq != null)
       {
-        evalue = scanner.next();
+        addScoreAnnotations(evalue, score, seq);
       }
-
-
-      String score = scanner.next();
-      checkSequenceOrder(index, scanner);
-      SequenceI seq = seqs[index];
-      addScoreAnnotations(evalue, score, seq);
+  
       scanner.close();
       line = br.readLine();
-      index++;
     }
-
-    br.close();
   }
+  */
 
-  void checkSequenceOrder(int index, Scanner scanner)
+  void readDomainTable(File inputTableTemp, boolean includesQuery)
+          throws IOException
   {
-    String seqName = null;
+    BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
 
-    for (int i = 0; i < 7; i++)
+    String line = br.readLine();
+    br.readLine();
+    br.readLine();
+    line = br.readLine();
+
+    int index;
+
+    if (includesQuery)
     {
-      seqName = scanner.next();
+      index = 1;
     }
-
-    if (!seqs[index].getName().equals(seqName))
+    else
     {
-      SequenceI temp = seqs[index];
+      index = 0;
+    }
+    while (!line.startsWith("#"))
+    {
+      if (line.contains("inclusion threshold"))
+      {
+        line = br.readLine();
+        continue;
+      }
+
+      Scanner scanner = new Scanner(line);
+      String name = scanner.next();
 
-      for (int j = 0; j < seqs.length; j++)
+      for (int i = 0; i < 10; i++)
       {
-        if (seqs[j].getName().equals(seqName))
-        {
-          seqs[index] = seqs[j];
-          seqs[j] = temp;
-          break;
-        }
+        scanner.next();
       }
+
+      String evalue = scanner.next();
+      scanner.next();
+      String score = scanner.next();
+
+      addScoreAnnotations(evalue, score, seqs[index]);
+      index++;
+
+      scanner.close();
+      line = br.readLine();
     }
+    br.close();
   }
 
+
+
+
   void addScoreAnnotations(String eValue, String bitScore, SequenceI seq)
   {
     String label = "Search Scores";
@@ -157,7 +243,7 @@ public abstract class Search extends HmmerCommand
   void buildArguments(List<String> args, File searchOutputFile,
           File hitsAlignmentFile, File queryFile) throws IOException
   {
-    args.add("-o");
+    args.add("--domtblout");
     args.add(getFilePath(searchOutputFile, true));
     args.add("-A");
     args.add(getFilePath(hitsAlignmentFile, true));