JAL-2719 parse bit score annotation from search results
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 15 May 2018 11:19:02 +0000 (12:19 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 15 May 2018 11:19:02 +0000 (12:19 +0100)
src/jalview/hmmer/HMMSearch.java

index 21a3b20..4c5bfb3 100644 (file)
@@ -398,24 +398,14 @@ public class HMMSearch extends HmmerCommand
     while (!"  ------ inclusion threshold ------".equals(line)
             && !"".equals(line))
     {
+      SequenceI seq = seqs[index];
       Scanner scanner = new Scanner(line);
-
-      String str = scanner.next(); // full sequence eValue score
-      // float eValue = Float.parseFloat(str);
-      // int seqLength = seqs[index].getLength();
-      // Annotation[] annots = new Annotation[seqLength];
-      // for (int j = 0; j < seqLength; j++)
-      // {
-      // annots[j] = new Annotation(eValue);
-      // }
-      AlignmentAnnotation annot = new AlignmentAnnotation("E-value",
-              "Score", null);
-      annot.setCalcId(HMMSEARCH);
-      double eValue = Double.parseDouble(str);
-      annot.setScore(eValue);
-      annot.setSequenceRef(seqs[index]);
-      seqs[index].addAlignmentAnnotation(annot);
-
+      String str = scanner.next();
+      addScoreAnnotation(str, seq, "hmmsearch E-value",
+              "Full sequence E-value");
+      str = scanner.next();
+      addScoreAnnotation(str, seq, "hmmsearch Score",
+              "Full sequence bit score");
       scanner.close();
       line = br.readLine();
       index++;
@@ -424,4 +414,31 @@ public class HMMSearch extends HmmerCommand
     br.close();
   }
 
+  /**
+   * A helper method that adds one score-only (non-positional) annotation to a
+   * sequence
+   * 
+   * @param value
+   * @param seq
+   * @param label
+   * @param description
+   */
+  protected void addScoreAnnotation(String value, SequenceI seq,
+          String label, String description)
+  {
+    try
+    {
+      AlignmentAnnotation annot = new AlignmentAnnotation(label,
+              description, null);
+      annot.setCalcId(HMMSEARCH);
+      double eValue = Double.parseDouble(value);
+      annot.setScore(eValue);
+      annot.setSequenceRef(seq);
+      seq.addAlignmentAnnotation(annot);
+    } catch (NumberFormatException e)
+    {
+      System.err.println("Error parsing " + label + " from " + value);
+    }
+  }
+
 }