Merge branch 'alpha/JAL-3362_Jalview_212_alpha' into alpha/merge_212_JalviewJS_2112
[jalview.git] / src / jalview / io / HMMFile.java
index a05425c..2fce4cc 100644 (file)
@@ -1,6 +1,6 @@
 package jalview.io;
 
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
 import jalview.api.AlignmentViewPanel;
 import jalview.datamodel.HMMNode;
 import jalview.datamodel.HiddenMarkovModel;
@@ -140,7 +140,6 @@ public class HMMFile extends AlignFile
    * Constructor for HMMFile used for exporting
    * 
    * @param hmm
-   * @param exportImmediately
    */
   public HMMFile(HiddenMarkovModel markov)
   {
@@ -257,10 +256,12 @@ public class HMMFile extends AlignFile
      */
     int nodeNo = 0;
     String line = input.readLine();
+    List<HMMNode> nodes = new ArrayList<>();
+
     while (line != null && !TERMINATOR.equals(line))
     {
       HMMNode node = new HMMNode();
-      hmm.addNode(node);
+      nodes.add(node);
       Scanner scanner = new Scanner(line);
       String next = scanner.next();
 
@@ -277,15 +278,15 @@ public class HMMFile extends AlignFile
         node.setMatchEmissions(matches);
         if (!COMPO.equals(next))
         {
-          int column = parseAnnotations(scanner, node);
-          if (column == 0)
+          int resNo = parseAnnotations(scanner, node);
+          if (resNo == 0)
           {
             /*
              * no MAP annotation provided, just number off from 0 (begin node)
              */
-            column = nodeNo;
+            resNo = nodeNo;
           }
-          hmm.setAlignmentColumn(node, column - 1); // node 1 <==> column 0
+          node.setResidueNumber(resNo);
         }
         line = input.readLine();
       }
@@ -312,34 +313,34 @@ public class HMMFile extends AlignFile
 
       nodeNo++;
     }
+
+    hmm.setNodes(nodes);
   }
 
   /**
    * 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.
+   * the residue position that the node maps to, if provided, else zero.
    * 
    * @param scanner
    * @param node
    */
   int parseAnnotations(Scanner scanner, HMMNode node)
   {
+    int mapTo = 0;
+
     /*
-     * map from hmm node to alignment column index, if provided
-     * HMM counts columns from 1, convert to base 0 for Jalview
+     * map from hmm node to sequence position, if provided
      */
-    int column = 0;
-    String value;
     if (scanner.hasNext())
     {
-      value = scanner.next();
+      String value = scanner.next();
       if (!"-".equals(value))
       {
         try
         {
-          column = Integer.parseInt(value);
-          node.setAlignmentColumn(column - 1);
+          mapTo = Integer.parseInt(value);
+          node.setResidueNumber(mapTo);
         } catch (NumberFormatException e)
         {
           // ignore
@@ -379,7 +380,7 @@ public class HMMFile extends AlignFile
       node.setConsensusStructure(scanner.next().charAt(0));
     }
 
-    return column;
+    return mapTo;
   }
 
   /**
@@ -519,7 +520,7 @@ public class HMMFile extends AlignFile
 
       if (nodeNo != 0)
       {
-        matchLine += SPACE + (hmm.getNodeAlignmentColumn(nodeNo) + 1);
+        matchLine += SPACE + (hmm.getNodeMapPosition(nodeNo));
         matchLine += SPACE + hmm.getConsensusResidue(nodeNo);
         matchLine += SPACE + hmm.getReferenceAnnotation(nodeNo);
         if (hmm.getFileHeader().contains("HMMER3/f"))
@@ -675,7 +676,7 @@ public class HMMFile extends AlignFile
   @Override
   public SequenceI[] getSeqsAsArray()
   {
-    SequenceI hmmSeq = hmm.initHMMSequence();
+    SequenceI hmmSeq = hmm.getConsensusSequence();
     SequenceI[] seq = new SequenceI[1];
     seq[0] = hmmSeq;
     return seq;
@@ -688,7 +689,7 @@ public class HMMFile extends AlignFile
   }
 
   @Override
-  public void setExportSettings(AlignExportSettingI exportSettings)
+  public void setExportSettings(AlignExportSettingsI exportSettings)
   {
 
   }