JAL-161 JAL-4173 patch to stockholm parser and tests covering import of a single...
authorJames Procter <j.procter@dundee.ac.uk>
Fri, 28 Apr 2023 15:50:20 +0000 (16:50 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Thu, 1 Jun 2023 14:51:14 +0000 (15:51 +0100)
src/jalview/io/StockholmFile.java
test/jalview/io/StockholmFileTest.java

index a3f7531..f1c94bc 100644 (file)
@@ -436,7 +436,7 @@ public class StockholmFile extends AlignFile
           // + ": " + seq);
           this.seqs.addElement(seqO);
         }
-        return; // finished parsing this segment of source
+        break; // finished parsing this segment of source
       }
       else if (!r.search(line))
       {
@@ -706,6 +706,19 @@ public class StockholmFile extends AlignFile
       }
       addNewickTree(treeName, treeString.toString());
     }
+    Object nhtree = getAlignmentProperty("NH");
+    if (nhtree != null && nhtree instanceof String)
+    {
+      if (!((String)nhtree).equals(treeString.toString()))
+      {
+        treeName = (String) getAlignmentProperty("TN");
+        if (treeName==null) {
+          treeName = "Tree " + (1 + getTreeCount());
+        }
+
+        addNewickTree(treeName, (String) nhtree);
+      }
+    }
   }
 
   /**
index b1995ab..532542b 100644 (file)
@@ -62,7 +62,7 @@ public class StockholmFileTest
 
   static String PfamFile = "examples/PF00111_seed.stk",
           RfamFile = "examples/RF00031_folded.stk",
-          RnaSSTestFile = "examples/rna_ss_test.stk";
+          RnaSSTestFile = "examples/rna_ss_test.stk",StockholmAndTree="examples/ferredoxins.sto";
 
   @Test(groups = { "Functional" })
   public void pfamFileIO() throws Exception
@@ -91,6 +91,21 @@ public class StockholmFileTest
   }
 
   @Test(groups = { "Functional" })
+  public void stockholmFileWithEmbeddedNhx() throws Exception
+  {
+    AppletFormatAdapter af = new AppletFormatAdapter();
+    AlignmentI al = af.readFile(StockholmAndTree, DataSourceType.FILE,
+            new IdentifyFile().identify(StockholmAndTree, DataSourceType.FILE));
+    assertTrue("Expected trees",af.getAlignFile().hasTrees());
+    assertTrue("Expected 1 tree",af.getAlignFile().getTreeCount()==1);
+    List<String[]> trees = af.getAlignFile().getNewickTrees();
+    assertNotNull(trees);
+    assertEquals(1,trees.size());
+    assertEquals("Tree 1",trees.get(0)[0]);
+    assertEquals("(((FER_BRANA:128.0,FER3_RAPSA:128.0):50.75,FER_CAPAA:178.75):121.94443,(Q93Z60_ARATH:271.45456,((O80429_MAIZE:183.0,FER1_MAIZE:183.0):30.5,((Q7XA98_TRIPR:90.0,FER1_PEA:90.0):83.32143,(((FER1_ARATH:64.0,FER2_ARATH:64.0):94.375,(FER1_SPIOL:124.5,FER1_MESCR:124.5):33.875):6.4166718,((Q93XJ9_SOLTU:33.5,FER1_SOLLC:33.5):49.0,FER_CAPAN:82.5):82.29167):8.529755):40.178574):57.95456):29.239868);",trees.get(0)[1]);
+  }
+
+  @Test(groups = { "Functional" })
   public void rfamFileIO() throws Exception
   {
     testFileIOwithFormat(new File(RfamFile), FileFormat.Stockholm, 2, 1,