use of beast.util.NexusParser in project beast2 by CompEvol.
the class NexusParserTest method testAssumptionsParse.
@Test
public void testAssumptionsParse() {
try {
String fileName = System.getProperty("user.dir") + "/examples/nexus/Primates.nex";
NexusParser parser = new NexusParser();
parser.parseFile(new File(fileName));
assertEquals(2, parser.filteredAlignments.size());
} catch (Exception e) {
System.out.println("exception thrown ");
System.out.println(e.getMessage());
}
}
use of beast.util.NexusParser in project beast2 by CompEvol.
the class BeautiDoc method importNexus.
public void importNexus(File file) throws IOException {
NexusParser parser = new NexusParser();
parser.parseFile(file);
if (parser.filteredAlignments.size() > 0) {
for (Alignment data : parser.filteredAlignments) {
addAlignmentWithSubnet(data, beautiConfig.partitionTemplate.get());
}
} else {
addAlignmentWithSubnet(parser.m_alignment, beautiConfig.partitionTemplate.get());
}
// connectModel();
addTraitSet(parser.traitSet);
// fireDocHasChanged();
}
use of beast.util.NexusParser in project beast2 by CompEvol.
the class NexusParserTest method testThatNexusExamplesParse.
@Test
public void testThatNexusExamplesParse() {
try {
String dirName = System.getProperty("user.dir") + "/examples/nexus";
System.out.println("Test Nexus Examples in " + dirName);
File exampleDir = new File(dirName);
String[] exampleFiles = exampleDir.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".nex") || name.endsWith(".nxs");
}
});
List<String> failedFiles = new ArrayList<>();
for (String fileName : exampleFiles) {
System.out.println("Processing " + fileName);
NexusParser parser = new NexusParser();
try {
parser.parseFile(new File(dirName + "/" + fileName));
} catch (Exception e) {
System.out.println("ExampleNexusParsing::Failed for " + fileName + ": " + e.getMessage());
failedFiles.add(fileName);
}
System.out.println("Done " + fileName);
}
if (failedFiles.size() > 0) {
System.out.println("\ntest_ThatNexusExamplesParse::Failed for : " + failedFiles.toString());
} else {
System.out.println("\ntest_ThatNexusExamplesParse::Success");
}
assertTrue(failedFiles.toString(), failedFiles.size() == 0);
} catch (Exception e) {
System.out.println("exception thrown ");
System.out.println(e.getMessage());
}
}
use of beast.util.NexusParser in project beast2 by CompEvol.
the class NexusParserTest method testTranslateBlock2.
@Test
public void testTranslateBlock2() {
String nexusTreeWithTranslateBlock = "#NEXUS\n" + "\n" + "Begin trees;\n" + "\tTranslate\n" + "\t\t1 C,\n" + "\t\t2 B,\n" + "\t\t3 A\n" + "\t\t;\n" + "tree TREE1 = [&R] (1:10,(3:30,2:20):10);\n" + "End;\n";
NexusParser parser = new NexusParser();
try {
List<String> taxa = new ArrayList<>();
taxa.add("2");
taxa.add("0");
taxa.add("1");
parser.parseFile("testTranslateBlock", new StringReader(nexusTreeWithTranslateBlock));
assertEquals(1, parser.trees.size());
assertNotNull(parser.trees.get(0));
String t = parser.trees.get(0).getRoot().toNewick();
System.out.println(t);
assertEquals("(C:10.0,(B:20.0,A:30.0):10.0):0.0", t);
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
}
Aggregations