JAL-2629 hmmer searches now read domain rather than full scores
authorThomas <170013569@dundee.ac.uk>
Fri, 12 Jul 2019 13:42:48 +0000 (14:42 +0100)
committerThomas <170013569@dundee.ac.uk>
Fri, 12 Jul 2019 13:42:48 +0000 (14:42 +0100)
src/jalview/hmmer/HMMSearch.java
src/jalview/hmmer/HmmerCommand.java
src/jalview/hmmer/JackHMMER.java
src/jalview/hmmer/Search.java

index f670633..f05823e 100644 (file)
@@ -157,6 +157,8 @@ public class HMMSearch extends Search
               inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE));
       seqs = file.getSeqsAsArray();
 
+      readDomainTable(searchOutputFile, false);
+
       if (searchAlignment)
       {
         recoverSequences(sequencesHash, seqs);
@@ -179,7 +181,7 @@ public class HMMSearch extends Search
           }
         }
       }
-      readTable(searchOutputFile);
+
 
       int seqCount = Math.min(seqs.length, seqsToReturn);
       SequenceI[] hmmAndSeqs = new SequenceI[seqCount + 1];
index b5698eb..f38be02 100644 (file)
@@ -397,8 +397,8 @@ public abstract class HmmerCommand implements Runnable
   }
 
   /**
-   * Answers the HMM profile for the profile sequence the user selected (default
-   * is just the first HMM sequence in the alignment)
+   * Answers the query sequence the user selected (default is just the first
+   * sequence in the alignment)
    * 
    * @return
    */
index d822439..12c0492 100644 (file)
@@ -26,6 +26,8 @@ import javax.swing.JOptionPane;
 public class JackHMMER extends Search
 {
 
+  SequenceI seq = null;
+
   /**
    * Constructor for the JackhmmerThread
    * 
@@ -45,7 +47,7 @@ public class JackHMMER extends Search
   @Override
   public void run()
   {
-    SequenceI seq = getSequence();
+    seq = getSequence();
     if (seq == null)
     {
       // shouldn't happen if we got this far
@@ -138,15 +140,18 @@ public class JackHMMER extends Search
               inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE));
       seqs = file.getSeqsAsArray();
 
+      readDomainTable(searchOutputFile, true);
+
       if (searchAlignment)
       {
         recoverSequences(sequencesHash, seqs);
       }
 
-      readTable(searchOutputFile);
+
 
       int seqCount = seqs.length;
 
+
       AlignmentI al = new Alignment(seqs);
 
       AlignFrame alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
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));