JAL-2629 tidy tests, refactor hmmer node mapping slightly
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 22 Feb 2018 16:05:43 +0000 (16:05 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 22 Feb 2018 16:05:43 +0000 (16:05 +0000)
src/jalview/datamodel/HiddenMarkovModel.java
src/jalview/datamodel/Sequence.java
src/jalview/datamodel/SequenceI.java
src/jalview/hmmer/HMMAlignThread.java
src/jalview/hmmer/HMMBuildThread.java
src/jalview/io/HMMFile.java
test/jalview/hmmer/HMMERTest.java
test/jalview/hmmer/testProps.jvprops [new file with mode: 0644]
test/jalview/io/HMMFileTest.java

index 1b12945..506d73a 100644 (file)
@@ -1,6 +1,7 @@
 package jalview.datamodel;
 
 import jalview.schemes.ResidueProperties;
+import jalview.util.Comparison;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -34,7 +35,7 @@ public class HiddenMarkovModel
 
   // contains the HMM node for each alignment column, alignment columns start at
   // index 0;
-  Map<Integer, Integer> nodeLookup = new HashMap<>();
+  Map<Integer, HMMNode> nodeLookup = new HashMap<>();
   
   // contains the symbol index for each symbol
   Map<Character, Integer> symbolIndexLookup = new HashMap<>();
@@ -44,59 +45,59 @@ public class HiddenMarkovModel
   final static String NO = "no";
   
   // keys for file properties hashmap
-  private final String NAME = "NAME";
+  private static final String NAME = "NAME";
 
-  private final String ACCESSION_NUMBER = "ACC";
+  private static final String ACCESSION_NUMBER = "ACC";
 
-  private final String DESCRIPTION = "DESC";
+  private static final String DESCRIPTION = "DESC";
 
-  private final String LENGTH = "LENG";
+  private static final String LENGTH = "LENG";
 
-  private final String MAX_LENGTH = "MAXL";
+  private static final String MAX_LENGTH = "MAXL";
 
-  private final String ALPHABET = "ALPH";
+  private static final String ALPHABET = "ALPH";
 
-  private final String DATE = "DATE";
+  private static final String DATE = "DATE";
 
-  private final String COMMAND_LOG = "COM";
+  private static final String COMMAND_LOG = "COM";
 
-  private final String NUMBER_OF_SEQUENCES = "NSEQ";
+  private static final String NUMBER_OF_SEQUENCES = "NSEQ";
 
-  private final String EFF_NUMBER_OF_SEQUENCES = "EFFN";
+  private static final String EFF_NUMBER_OF_SEQUENCES = "EFFN";
 
-  private final String CHECK_SUM = "CKSUM";
+  private static final String CHECK_SUM = "CKSUM";
 
-  private final String GATHERING_THRESHOLDS = "GA";
+  private static final String GATHERING_THRESHOLDS = "GA";
 
-  private final String TRUSTED_CUTOFFS = "TC";
+  private static final String TRUSTED_CUTOFFS = "TC";
 
-  private final String NOISE_CUTOFFS = "NC";
+  private static final String NOISE_CUTOFFS = "NC";
 
-  private final String STATISTICS = "STATS";
+  private static final String STATISTICS = "STATS";
 
-  private final String COMPO = "COMPO";
+  private static final String COMPO = "COMPO";
   
-  private final String GATHERING_THRESHOLD = "GA";
+  private static final String GATHERING_THRESHOLD = "GA";
 
-  private final String TRUSTED_CUTOFF = "TC";
+  private static final String TRUSTED_CUTOFF = "TC";
 
   private final String NOISE_CUTOFF = "NC";
 
-  private final String VITERBI = "VITERBI";
+  private static final String VITERBI = "VITERBI";
 
-  private final String MSV = "MSV";
+  private static final String MSV = "MSV";
 
-  private final String FORWARD = "FORWARD";
+  private static final String FORWARD = "FORWARD";
 
-  private final String MAP = "MAP";
+  private static final String MAP = "MAP";
 
-  private final String REFERENCE_ANNOTATION = "RF";
+  private static final String REFERENCE_ANNOTATION = "RF";
 
-  private final String CONSENSUS_RESIDUE = "CONS";
+  private static final String CONSENSUS_RESIDUE = "CONS";
 
-  private final String CONSENSUS_STRUCTURE = "CS";
+  private static final String CONSENSUS_STRUCTURE = "CS";
 
-  private final String MASKED_VALUE = "MM";
+  private static final String MASKED_VALUE = "MM";
   
   public static final int MATCHTOMATCH = 0;
 
@@ -189,7 +190,7 @@ public class HiddenMarkovModel
    * @return
    * 
    */
-  public Map<Integer, Integer> getNodeLookup()
+  public Map<Integer, HMMNode> getNodeLookup()
   {
     return nodeLookup;
   }
@@ -411,24 +412,18 @@ public class HiddenMarkovModel
    */
   public double getMatchEmissionProbability(int alignColumn, char symbol)
   {
-    int symbolIndex;
-    int nodeIndex;
-    double probability;
     if (!symbolIndexLookup.containsKey(symbol))
     {
       return 0d;
     }
-    symbolIndex = symbolIndexLookup.get(symbol);
+    int symbolIndex = symbolIndexLookup.get(symbol);
+    double probability = 0d;
     if (nodeLookup.containsKey(alignColumn))
     {
-      nodeIndex = nodeLookup.get(alignColumn);
-      probability = getNode(nodeIndex).getMatchEmissions().get(symbolIndex);
-      return probability;
-    }
-    else
-    {
-      return 0d;
+      HMMNode node = nodeLookup.get(alignColumn);
+      probability = node.getMatchEmissions().get(symbolIndex);
     }
+    return probability;
   }
 
   /**
@@ -445,26 +440,18 @@ public class HiddenMarkovModel
    */
   public double getInsertEmissionProbability(int alignColumn, char symbol)
   {
-    int symbolIndex;
-    int nodeIndex;
-    double probability;
     if (!symbolIndexLookup.containsKey(symbol))
     {
       return 0d;
     }
-    symbolIndex = symbolIndexLookup.get(symbol);
+    int symbolIndex = symbolIndexLookup.get(symbol);
+    double probability = 0d;
     if (nodeLookup.containsKey(alignColumn))
     {
-      nodeIndex = nodeLookup.get(alignColumn);
-      probability = getNode(nodeIndex).getInsertEmissions()
-              .get(symbolIndex);
-      return probability;
-    }
-    else
-    {
-      return 0d;
+      HMMNode node = nodeLookup.get(alignColumn);
+      probability = node.getInsertEmissions().get(symbolIndex);
     }
-
+    return probability;
   }
   
   /**
@@ -482,20 +469,13 @@ public class HiddenMarkovModel
   public Double getStateTransitionProbability(int alignColumn,
           int transition)
   {
-    int nodeIndex;
-    Double probability;
+    double probability = 0d;
     if (nodeLookup.containsKey(alignColumn))
     {
-      nodeIndex = nodeLookup.get(alignColumn);
-      probability = getNode(nodeIndex).getStateTransitions()
-              .get(transition);
-      return probability;
+      HMMNode node = nodeLookup.get(alignColumn);
+      probability = node.getStateTransitions().get(transition);
     }
-    else
-    {
-      return 0d;
-    }
-
+    return probability;
   }
   
   /**
@@ -539,13 +519,12 @@ public class HiddenMarkovModel
     char mostLikely = '-';
     if (consensusResidueIsActive())
     {
-
-    Integer index = findNodeIndex(columnIndex);
-    if (index == null)
-    {
-      return '-';
-    }
-      mostLikely = getNodes().get(index).getConsensusResidue();
+      HMMNode node = nodeLookup.get(columnIndex);
+      if (node == null)
+      {
+        return '-';
+      }
+      mostLikely = node.getConsensusResidue();
       return mostLikely;
     }
     else
@@ -553,7 +532,7 @@ public class HiddenMarkovModel
       double highestProb = 0;
       for (char character : symbols)
       {
-        Double prob = getMatchEmissionProbability(columnIndex, character);
+        double prob = getMatchEmissionProbability(columnIndex, character);
         if (prob > highestProb)
         {
           highestProb = prob;
@@ -771,28 +750,52 @@ public class HiddenMarkovModel
   }
 
   /**
-   * Sets the alignment column of the specified node.
+   * Sets the alignment column of the specified node
    * 
    * @param nodeIndex
    * 
    * @param column
    * 
    */
-  public void setAlignmentColumn(int nodeIndex, int column)
+  public void setAlignmentColumn(HMMNode node, int column)
   {
-    nodes.get(nodeIndex).setAlignmentColumn(column);
-    nodeLookup.put(column, nodeIndex);
+    node.setAlignmentColumn(column);
+    nodeLookup.put(column, node);
+  }
+
+  public void updateMapping(char[] sequence)
+  {
+    int nodeNo = 1;
+    int column = 0;
+    synchronized (nodeLookup)
+    {
+      clearNodeLookup();
+      for (char residue : sequence)
+      {
+        if (!Comparison.isGap(residue))
+        {
+          HMMNode node = nodes.get(nodeNo);
+          if (node == null)
+          {
+            // error : too few nodes for sequence
+            break;
+          }
+          setAlignmentColumn(node, column);
+          nodeNo++;
+        }
+        column++;
+      }
+    }
   }
 
   /**
    * Clears all data in the node lookup map
    */
-  public void emptyNodeLookup()
+  public void clearNodeLookup()
   {
-    nodeLookup = new HashMap<>();
+    nodeLookup.clear();
   }
 
-
   /**
    * Sets the reference annotation at a given node.
    * 
@@ -960,19 +963,14 @@ public class HiddenMarkovModel
   }
 
   /**
-   * Finds the index of the node in a hidden Markov model based on the column in
-   * the alignment
+   * Answers the HMMNode mapped to the given alignment column (base 0), or null
+   * if none is mapped
    * 
    * @param alignmentColumn
-   *          The index of the column in the alignment, with the indexes
-   *          starting from 0.
    */
-
-  public Integer findNodeIndex(int alignmentColumn)
+  public HMMNode getNodeForColumn(int alignmentColumn)
   {
-    Integer index;
-    index = nodeLookup.get(alignmentColumn);
-    return index;
+    return nodeLookup.get(alignmentColumn);
   }
 
   /**
index 4d51c0c..e798525 100755 (executable)
@@ -1897,18 +1897,11 @@ public class Sequence extends ASequence implements SequenceI
   @Override
   public void updateHMMMapping()
   {
-    int node = 1;
-    int column = 0;
-    hmm.emptyNodeLookup();
-    for (char residue : sequence)
+    if (hmm == null)
     {
-      if (!Comparison.isGap(residue))
-      {
-        hmm.setAlignmentColumn(node, column);
-        node++;
-      }
-      column++;
+      return;
     }
+    hmm.updateMapping(sequence);
   }
 
   /**
@@ -1922,7 +1915,7 @@ public class Sequence extends ASequence implements SequenceI
     if (this.isHMMConsensusSequence)
     {
       int node = 1;
-      hmm.emptyNodeLookup();
+      hmm.clearNodeLookup();
       for (int i = 0; i < getLength(); i++)
       {
         if (rf.annotations[i].displayCharacter.equals("x")
index e5edc91..ee8c052 100755 (executable)
@@ -491,6 +491,12 @@ public interface SequenceI extends ASequenceI
    */
   public List<DBRefEntry> getPrimaryDBRefs();
 
+  /**
+   * Updates mapping of Hidden Markov Model nodes to aligned sequence positions
+   * (e.g. after an alignment edit). The nodes of the HMM (excluding the first
+   * node, with model average values), are associated in turn with non-gapped
+   * sequence positions.
+   */
   public void updateHMMMapping();
 
   boolean isHMMConsensusSequence();
index 582dc06..fdc1c1c 100644 (file)
@@ -75,6 +75,11 @@ public class HMMAlignThread extends HmmerCommand implements Runnable
   public void run()
   {
     hmm = af.getSelectedHMM();
+    if (hmm == null)
+    {
+      System.err.println("Can't run hmmalign as no HMM profile selected");
+      return;
+    }
 
     long msgId = System.currentTimeMillis();
     af.setProgressBar(MessageManager.getString("status.running_hmmalign"),
index e7bc58c..c52fb86 100644 (file)
@@ -59,6 +59,10 @@ public class HMMBuildThread extends HmmerCommand implements Runnable
     AlignViewportI viewport = af.getViewport();
     try
     {
+      if (viewport != null)
+      {
+        alignment = viewport.getAlignment();
+      }
       List<SequenceGroup> groups = new ArrayList<>();
       if (params != null)
       {
@@ -102,10 +106,6 @@ public class HMMBuildThread extends HmmerCommand implements Runnable
           }
         }
       }
-      else if (viewport != null)
-      {
-        alignment = viewport.getAlignment();
-      }
 
       if (alignment != null)
       {
index 95c6f32..ca5cf1c 100644 (file)
@@ -23,25 +23,25 @@ import java.util.Scanner;
 public class HMMFile extends AlignFile
         implements AlignmentFileReaderI, AlignmentFileWriterI
 {
-  // HMM to store file data
-  private HiddenMarkovModel hmm;
-
-  // number of possible transitions
   private static final int NUMBER_OF_TRANSITIONS = 7;
 
-  private String NL = "\n";
+  private static final String SPACE = " ";
 
-  //number of symbols in the alphabet used in the hidden Markov model
-  int numberOfSymbols;
+  private static final String COMPO = "COMPO";
 
-  private final String SPACE = " ";
+  private static final String EMPTY = "";
 
-  private final String COMPO = "COMPO";
+  /*
+   * guide line added to an output HMMER file, purely for readability
+   */
+  private static final String TRANSITIONTYPELINE = "            m->m     m->i     m->d     i->m     i->i     d->m     d->d";
 
-  private final String EMPTY = "";
+  private static String NL = "\n";
 
-  //This is a line that needs to be added to each HMMER� file. It is purely for readability.
-  private static final String TRANSITIONTYPELINE = "            m->m     m->i     m->d     i->m     i->i     d->m     d->d";
+  private HiddenMarkovModel hmm;
+
+  // number of symbols in the alphabet used in the hidden Markov model
+  int numberOfSymbols;
 
   /**
    * Parses immediately.
@@ -223,23 +223,24 @@ public class HMMFile extends AlignFile
    */
   void parseModel(BufferedReader input) throws IOException
   {
+    boolean first = true;
     String line = input.readLine();
-    int node = 0;
     while (!"//".equals(line))
     {
-      hmm.getNodes().add(new HMMNode());
-      String next;
+      HMMNode node = new HMMNode();
+      hmm.getNodes().add(node);
       Scanner matchReader = new Scanner(line);
-      next = matchReader.next();
-      if (next.equals(COMPO) || node > 0)
+      String next = matchReader.next();
+      if (next.equals(COMPO) || !first)
       {
         // stores match emission line in list
         List<Double> matches = new ArrayList<>();
         matches = fillList(matchReader, numberOfSymbols);
-        hmm.getNodes().get(node).setMatchEmissions(matches);
-        if (node > 0)
+        node.setMatchEmissions(matches);
+        if (!first)
         {
-          parseAnnotations(matchReader, node);
+          int column = parseAnnotations(matchReader, node);
+          hmm.setAlignmentColumn(node, column - 1);
         }
       }
       matchReader.close();
@@ -248,7 +249,7 @@ public class HMMFile extends AlignFile
       Scanner insertReader = new Scanner(line);
       List<Double> inserts = new ArrayList<>();
       inserts = fillList(insertReader, numberOfSymbols);
-      hmm.getNodes().get(node).setInsertEmissions(inserts);
+      node.setInsertEmissions(inserts);
       insertReader.close();
 
       // stores state transition line in list
@@ -256,68 +257,85 @@ public class HMMFile extends AlignFile
       Scanner transitionReader = new Scanner(line);
       List<Double> transitions = new ArrayList<>();
       transitions = fillList(transitionReader, NUMBER_OF_TRANSITIONS);
-      hmm.getNodes().get(node).setStateTransitions(transitions);
+      node.setStateTransitions(transitions);
       transitionReader.close();
       line = input.readLine();
-      node++;
-    }
 
+      first = false;
+    }
   }
 
   /**
-   * Parses the annotations on the match emission line.
+   * Parses the annotations on the match emission line and add them to the node.
+   * (See p109 of the HMMER User Guide (V3.1b2) for the specification.) Returns
+   * the alignment column number (base 1) that the node maps to, if provided,
+   * else zero.
    * 
    * @param scanner
-   *          The scanner which is processing match emission line.
-   * @param index
-   *          The index of node which is being scanned.
+   * @param node
    */
-  void parseAnnotations(Scanner scanner, int index)
+  int parseAnnotations(Scanner scanner, HMMNode node)
   {
+    /*
+     * map from hmm node to alignment column index, if provided
+     * HMM counts columns from 1, convert to base 0 for Jalview
+     */
+    int column = 0;
     if (hmm.mapIsActive() && scanner.hasNext())
     {
-      int column;
       column = scanner.nextInt();
-      hmm.getNodes().get(index).setAlignmentColumn(column - 1);
-      hmm.getNodeLookup().put(column - 1, index);
+      node.setAlignmentColumn(column - 1);
     }
     else
     {
       scanner.next();
     }
 
+    /*
+     * hmm consensus residue if provided, else -
+     */
     if (scanner.hasNext())
     {
       char consensusR;
       consensusR = charValue(scanner.next());
-      hmm.getNodes().get(index).setConsensusResidue(consensusR);
+      node.setConsensusResidue(consensusR);
     }
 
+    /*
+     * RF reference annotation, if provided, else -
+     */
     if (scanner.hasNext())
     {
       char reference;
       reference = charValue(scanner.next());
-      hmm.getNodes().get(index).setReferenceAnnotation(reference);
+      node.setReferenceAnnotation(reference);
     }
 
+    /*
+     * 'm' for masked position, if provided, else -
+     */
     if (scanner.hasNext())
     {
       char value;
       value = charValue(scanner.next());
-      hmm.getNodes().get(index).setMaskValue(value);
+      node.setMaskValue(value);
     }
+
+    /*
+     * structure consensus symbol, if provided, else -
+     */
     if (scanner.hasNext())
     {
       char consensusS;
       consensusS = charValue(scanner.next());
-      hmm.getNodes().get(index).setConsensusStructure(consensusS);
+      node.setConsensusStructure(consensusS);
     }
-  }
-
 
+    return column;
+  }
 
   /**
-   * Fills a list of doubles based on an input line.
+   * Fills a list of doubles from an input line
    * 
    * @param input
    *          The scanner for the line containing the data to be transferred to
index da6140b..112ce21 100644 (file)
@@ -1,43 +1,45 @@
 package jalview.hmmer;
 
 import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
 import jalview.bin.Jalview;
-import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.HiddenMarkovModel;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
-import jalview.io.DataSourceType;
-import jalview.io.FastaFile;
-import jalview.io.FileParse;
 import jalview.ws.params.ArgumentI;
 
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
-import java.util.List;
 
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-
 public class HMMERTest {
 
   AlignFrame frame;
 
   @BeforeClass(alwaysRun = true)
-  public static void setUpBeforeClass() throws Exception
+  public void setUpBeforeClass() throws Exception
   {
     Jalview.main(
             new String[]
     { "-noquestionnaire", "-nonews", "-props",
-        "test/jalview/hmmer/testProps.jvprops" });
+                "test/jalview/hmmer/testProps.jvprops", "-open",
+                "examples/uniref50.fa" });
+    // FastaFile file = null;
+    // file = new FastaFile(
+    // new FileParse("examples/uniref50.fa", DataSourceType.FILE));
+    // SequenceI[] seqs = file.getSeqsAsArray();
+    // AlignmentI al = new Alignment(seqs);
+    // frame = new AlignFrame(al, 150, 20);
+    frame = Desktop.getAlignFrames()[0];
   }
 
   @AfterClass(alwaysRun = true)
@@ -46,33 +48,38 @@ public class HMMERTest {
     Desktop.instance.closeAll_actionPerformed(null);
   }
 
-  @Test(priority = 0)
-  public void testHMMBuild() throws MalformedURLException, IOException
+  /**
+   * Test with a dependency on locally installed hmmbuild binaries
+   * 
+   * @throws MalformedURLException
+   * @throws IOException
+   */
+  @Test(groups = "External")
+  public void testHMMBuildThenHMMAlign()
+          throws MalformedURLException, IOException
   {
-    FastaFile file = null;
-    try
-    {
-      file = new FastaFile(
-              new FileParse("examples/uniref50.fa", DataSourceType.FILE));
-    } catch (IOException e)
-    {
-      e.printStackTrace();
-      fail();
-    }
-    SequenceI[] seqs = file.getSeqsAsArray();
-    AlignmentI al = new Alignment(seqs);
-    frame = new AlignFrame(al, 150, 20);
+    /*
+     * run hmmbuild - not the side-effect of selecting the HMM
+     * sequence that gets added to the alignment
+     */
+    testHMMBuild();
+    HiddenMarkovModel hmm = frame.getSelectedHMM();
+
+    /*
+     * now run hmmalign - with respect to the select HMM profile
+     */
+    testHMMAlign();
+  }
 
+  public void testHMMBuild()
+  {
     HMMBuildThread thread = new HMMBuildThread(frame,
             new ArrayList<ArgumentI>());
     thread.hmmbuildWaitTillComplete();
 
     SequenceI seq = frame.getViewport().getAlignment().getSequenceAt(0);
     HiddenMarkovModel hmm = seq.getHMM();
-    if (hmm == null)
-    {
-      fail();
-    }
+    assertNotNull(hmm);
 
     assertEquals(hmm.getLength().intValue(), 148);
     assertEquals(hmm.getAlphabetType(), "amino");
@@ -81,30 +88,35 @@ public class HMMERTest {
     assertEquals(hmm.getConsensusAtAlignColumn(15), 's');
   }
 
-  @Test(priority = 1)
-  public void testHMMAlign() throws MalformedURLException, IOException
+  public void testHMMAlign()
   {
     HMMAlignThread thread = new HMMAlignThread(frame,
             new ArrayList<ArgumentI>());
-    try
-    {
-      thread.hmmalignWaitTillComplete();
-    } catch (Exception e)
-    {
-      e.printStackTrace();
-      fail();
-    }
+    thread.hmmalignWaitTillComplete();
 
-    if (Desktop.getAlignFrames() == null)
+    AlignFrame[] alignFrames = Desktop.getAlignFrames();
+    if (alignFrames == null)
     {
-      fail();
+      fail("No align frame loaded");
     }
 
-    AlignFrame fr = Desktop.getAlignFrames()[0];
-    AlignmentI al = fr.getViewport().getAlignment();
-    assertNotEquals(al, null);
-    List<SequenceI> hmmSeqs = al.getHMMConsensusSequences();
-    assertNotNull(hmmSeqs);
+    /*
+     * now have the original align frame, and another for realigned sequences
+     */
+    assertEquals(alignFrames.length, 2);
+    AlignmentI original = alignFrames[0].getViewport().getAlignment();
+    assertNotNull(original);
+    AlignmentI realigned = alignFrames[1].getViewport().getAlignment();
+    assertNotNull(realigned);
+    assertNotNull(original.getHMMConsensusSequences());
+    assertNotNull(realigned.getHMMConsensusSequences());
+
+    SequenceI ferCapan = original.findName("FER_CAPAN");
+    assertTrue(ferCapan.getSequenceAsString().startsWith("MA------SVSAT"));
+
+    SequenceI ferCapanRealigned = realigned.findName("FER_CAPAN");
+    assertTrue(ferCapanRealigned.getSequenceAsString()
+            .startsWith("-------m-A----SVSAT"));
   }
 }
 
diff --git a/test/jalview/hmmer/testProps.jvprops b/test/jalview/hmmer/testProps.jvprops
new file mode 100644 (file)
index 0000000..05cd493
--- /dev/null
@@ -0,0 +1,88 @@
+#---JalviewX Properties File---
+#Fri Apr 25 09:54:25 BST 2014
+SCREEN_Y=768
+SCREEN_X=936
+SHOW_WSDISCOVERY_ERRORS=true
+LATEST_VERSION=2.8.0b1
+SHOW_CONSERVATION=true
+JALVIEW_RSS_WINDOW_SCREEN_WIDTH=550
+JAVA_CONSOLE_SCREEN_WIDTH=450
+LAST_DIRECTORY=/Volumes/Data/Users/jimp/Documents/testing/Jalview/examples
+ID_ITALICS=true
+SORT_ALIGNMENT=No sort
+SHOW_IDENTITY=true
+WSMENU_BYHOST=false
+SEQUENCE_LINKS=EMBL-EBI Search|http\://www.ebi.ac.uk/ebisearch/search.ebi?db\=allebi&query\=$SEQUENCE_ID$
+SHOW_FULLSCREEN=false
+RECENT_URL=http\://www.jalview.org/examples/exampleFile_2_7.jar
+FONT_NAME=SansSerif
+BLC_JVSUFFIX=true
+VERSION_CHECK=false
+YEAR=2011
+SHOW_DBREFS_TOOLTIP=true
+MSF_JVSUFFIX=true
+SCREENGEOMETRY_HEIGHT=1600
+JAVA_CONSOLE_SCREEN_Y=475
+JAVA_CONSOLE_SCREEN_X=830
+PFAM_JVSUFFIX=true
+PIR_JVSUFFIX=true
+STARTUP_FILE=http\://www.jalview.org/examples/exampleFile_2_3.jar
+JAVA_CONSOLE_SCREEN_HEIGHT=162
+PIR_MODELLER=false
+GAP_SYMBOL=-
+SHOW_QUALITY=true
+SHOW_OCCUPANCY=true
+SHOW_GROUP_CONSERVATION=false
+SHOW_JWS2_SERVICES=true
+SHOW_NPFEATS_TOOLTIP=true
+FONT_STYLE=plain
+ANTI_ALIAS=false
+SORT_BY_TREE=false
+RSBS_SERVICES=|Multi-Harmony|Analysis|Sequence Harmony and Multi-Relief (Brandt et al. 2010)|hseparable,gapCharacter\='-',returns\='ANNOTATION'|?tool\=jalview|http\://zeus.few.vu.nl/programs/shmrwww/index.php?tool\=jalview&groups\=$PARTITION\:min\='2',minsize\='2',sep\=' '$&ali_file\=$ALIGNMENT\:format\='FASTA',writeasfile$
+AUTHORFNAMES=Jim Procter, Andrew Waterhouse, Jan Engelhardt, Lauren Lui, Michele Clamp, James Cuff, Steve Searle, David Martin & Geoff Barton
+JALVIEW_RSS_WINDOW_SCREEN_HEIGHT=328
+SHOW_GROUP_CONSENSUS=false
+SHOW_CONSENSUS_HISTOGRAM=true
+SHOW_OVERVIEW=false
+AUTHORS=J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+FIGURE_AUTOIDWIDTH=false
+SCREEN_WIDTH=900
+ANNOTATIONCOLOUR_MIN=ffc800
+SHOW_STARTUP_FILE=false
+RECENT_FILE=examples/uniref50.fa\t/Volumes/Data/Users/jimp/Documents/testing/Jalview/examples/RF00031_folded.stk\t/Volumes/Data/Users/jimp/bs_ig_mult.out
+DEFAULT_FILE_FORMAT=FASTA
+SHOW_JAVA_CONSOLE=false
+VERSION=2.8b1
+FIGURE_USERIDWIDTH=
+WSMENU_BYTYPE=false
+DEFAULT_COLOUR=None
+NOQUESTIONNAIRES=true
+JALVIEW_NEWS_RSS_LASTMODIFIED=Apr 23, 2014 2\:53\:26 PM
+BUILD_DATE=01 November 2013
+PILEUP_JVSUFFIX=true
+SHOW_CONSENSUS_LOGO=false
+SCREENGEOMETRY_WIDTH=2560
+SHOW_ANNOTATIONS=true
+JALVIEW_RSS_WINDOW_SCREEN_Y=0
+USAGESTATS=false
+JALVIEW_RSS_WINDOW_SCREEN_X=0
+SHOW_UNCONSERVED=false
+SHOW_JVSUFFIX=true
+DAS_LOCAL_SOURCE=
+SCREEN_HEIGHT=650
+ANNOTATIONCOLOUR_MAX=ff0000
+AUTO_CALC_CONSENSUS=true
+FASTA_JVSUFFIX=true
+DAS_ACTIVE_SOURCE=uniprot\t
+JWS2HOSTURLS=http\://www.compbio.dundee.ac.uk/jabaws
+PAD_GAPS=false
+CLUSTAL_JVSUFFIX=true
+SHOW_ENFIN_SERVICES=true
+FONT_SIZE=10
+RIGHT_ALIGN_IDS=false
+USE_PROXY=false
+WRAP_ALIGNMENT=false
+#DAS_REGISTRY_URL=http\://www.dasregistry.org/das/ # retired 01/05/2015
+DAS_REGISTRY_URL=http\://www.ebi.ac.uk/das-srv/registry/das/
+logs.Jalview.level=DEBUG
+HMMER_PATH=/Users/gmcarstairs/software/hmmer-3.1b2-macosx-intel/binaries
index be4178b..dadc1c7 100644 (file)
@@ -13,36 +13,37 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Scanner;
 
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 public class HMMFileTest {
 
+  HMMFile fn3;
 
+  HMMFile pKinase;
 
-  HMMFile fn3 = new HMMFile(new BufferedReader(
-          new FileReader(("test/jalview/io/test_fn3_hmm.txt"))));
+  HMMFile made1;
 
-  HMMFile pKinase = new HMMFile(new BufferedReader(
-          new FileReader(("test/jalview/io/test_PKinase_hmm.txt"))));
-
-  HMMFile made1 = new HMMFile(new BufferedReader(
-          new FileReader(("test/jalview/io/test_MADE1_hmm.txt"))));
-
-  HMMFileTest() throws IOException
+  @BeforeClass(alwaysRun = true)
+  public void setUp() throws FileNotFoundException
   {
+    fn3 = new HMMFile(new BufferedReader(
+            new FileReader(("test/jalview/io/test_fn3_hmm.txt"))));
 
-  }
-
-  
+    pKinase = new HMMFile(new BufferedReader(
+            new FileReader(("test/jalview/io/test_PKinase_hmm.txt"))));
 
+    made1 = new HMMFile(new BufferedReader(
+            new FileReader(("test/jalview/io/test_MADE1_hmm.txt"))));
+  }
 
-  @Test
+  @Test(groups = "Functional")
   public void testParse() throws IOException
   {
-  
     pKinase.parse();
     HiddenMarkovModel hmm = pKinase.getHMM();
     assertEquals(hmm.getName(), "Pkinase");
@@ -66,28 +67,10 @@ public class HMMFileTest {
     assertEquals(hmm.getTrustedCutoff(), "70.30 70.30");
     assertEquals(hmm.getNoiseCutoff(), "70.20 70.20");
   
-    List<Character> symbols = new ArrayList<>();
-    symbols.add('A');
-    symbols.add('C');
-    symbols.add('D');
-    symbols.add('E');
-    symbols.add('F');
-    symbols.add('G');
-    symbols.add('H');
-    symbols.add('I');
-    symbols.add('K');
-    symbols.add('L');
-    symbols.add('M');
-    symbols.add('N');
-    symbols.add('P');
-    symbols.add('Q');
-    symbols.add('R');
-    symbols.add('S');
-    symbols.add('T');
-    symbols.add('V');
-    symbols.add('W');
-    symbols.add('Y');
-  
+    List<Character> symbols = Arrays
+            .asList(new Character[]
+            { 'A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N',
+                'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y' });
     assertEquals(hmm.getSymbols(), symbols);
   
     assertEquals(hmm.getMatchEmissionProbability(0, 'Y'), 0.16102, 0.001d);
@@ -307,29 +290,29 @@ public class HMMFileTest {
   public void testParseAnnotations()
   {
     HMMFile testFile = new HMMFile();
-    testFile.setHMM(new HiddenMarkovModel());
-    testFile.getHMM().getNodes().add(new HMMNode());
-    testFile.getHMM().getNodes().add(new HMMNode());
-    testFile.getHMM().getNodes().add(new HMMNode());
-  
-  
-    testFile.getHMM().setConsensusResidueStatus(true);
-    testFile.getHMM().setMAPStatus(true);
-    testFile.getHMM().setReferenceAnnotationStatus(true);
-    testFile.getHMM().setConsensusStructureStatus(true);
-    testFile.getHMM().setMaskedValueStatus(true);
+    HiddenMarkovModel hmm = new HiddenMarkovModel();
+    testFile.setHMM(hmm);
+    hmm.getNodes().add(new HMMNode());
+  
+    hmm.setConsensusResidueStatus(true);
+    hmm.setMAPStatus(true);
+    hmm.setReferenceAnnotationStatus(true);
+    hmm.setConsensusStructureStatus(true);
+    hmm.setMaskedValueStatus(true);
     Scanner scanner = new Scanner("1345 t t t t");
-    testFile.parseAnnotations(scanner, 1);
-  
-    testFile.getHMM().setConsensusResidueStatus(true);
-    testFile.getHMM().setMAPStatus(false);
-    testFile.getHMM().setReferenceAnnotationStatus(true);
-    testFile.getHMM().setConsensusStructureStatus(false);
-    testFile.getHMM().setMaskedValueStatus(false);
+    HMMNode node = new HMMNode();
+    hmm.getNodes().add(node);
+    testFile.parseAnnotations(scanner, node);
+  
+    hmm.setConsensusResidueStatus(true);
+    hmm.setMAPStatus(false);
+    hmm.setReferenceAnnotationStatus(true);
+    hmm.setConsensusStructureStatus(false);
+    hmm.setMaskedValueStatus(false);
     Scanner scanner2 = new Scanner("- y x - -");
-    testFile.parseAnnotations(scanner2, 2);
-  
-    HiddenMarkovModel hmm = testFile.getHMM();
+    node = new HMMNode();
+    hmm.getNodes().add(node);
+    testFile.parseAnnotations(scanner2, node);
   
     assertEquals(hmm.getNodeAlignmentColumn(1).intValue(), 1344);
     assertEquals(hmm.getConsensusResidue(1), 't');
@@ -337,10 +320,7 @@ public class HMMFileTest {
     assertEquals(hmm.getMaskedValue(1), 't');
     assertEquals(hmm.getConsensusStructure(1), 't');
   
-    assertEquals(hmm.findNodeIndex(1344).intValue(), 1);
-  
     scanner.close();
-  
   }
   
   /**