Search in sources :

Example 6 with NexusParser

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());
    }
}
Also used : NexusParser(beast.util.NexusParser) File(java.io.File) Test(org.junit.Test)

Example 7 with NexusParser

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();
}
Also used : FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) NexusParser(beast.util.NexusParser)

Example 8 with NexusParser

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());
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) ArrayList(java.util.ArrayList) NexusParser(beast.util.NexusParser) File(java.io.File) Test(org.junit.Test)

Example 9 with NexusParser

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);
    }
}
Also used : ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) NexusParser(beast.util.NexusParser) Test(org.junit.Test)

Aggregations

NexusParser (beast.util.NexusParser)9 File (java.io.File)6 Test (org.junit.Test)5 Alignment (beast.evolution.alignment.Alignment)3 ArrayList (java.util.ArrayList)3 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)2 FilenameFilter (java.io.FilenameFilter)2 StringReader (java.io.StringReader)2 BEASTInterface (beast.core.BEASTInterface)1 TraitSet (beast.evolution.tree.TraitSet)1 XMLParser (beast.util.XMLParser)1 XMLParserException (beast.util.XMLParserException)1 XMLProducer (beast.util.XMLProducer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 TreeSet (java.util.TreeSet)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1