Search in sources :

Example 1 with TreesBlock

use of feast.nexus.TreesBlock in project bacter by tgvaughan.

the class SimulatedACG method initAndValidate.

@Override
public void initAndValidate() {
    rho = rhoInput.get();
    delta = deltaInput.get();
    popFunc = popFuncInput.get();
    // Need to do this here as Tree.processTraits(), which is called
    // by hasDateTrait() and hence simulateClonalFrame(), expects a
    // tree with nodes.
    super.initAndValidate();
    if (clonalFrameInput.get() == null)
        simulateClonalFrame();
    else
        assignFromWithoutID(clonalFrameInput.get());
    // Need to do this here as this sets the tree object that the nodes
    // point to, so without it they point to the dummy tree created by
    // super.initAndValidate().
    initArrays();
    // Generate recombinations
    generateConversions();
    // Write output file
    if (outputFileNameInput.get() != null) {
        NexusBuilder nexusBuilder = new NexusBuilder();
        nexusBuilder.append(new TaxaBlock(m_taxonset.get()));
        nexusBuilder.append((new TreesBlock() {

            @Override
            public String getTreeString(Tree tree) {
                return ((ConversionGraph) tree).getExtendedNewick();
            }
        }).addTree(this, "simulatedARG"));
        nexusBuilder.append(new NexusBlock() {

            @Override
            public String getBlockName() {
                return "bacter";
            }

            @Override
            public List<String> getBlockLines() {
                List<String> lines = new ArrayList<>();
                String lociLine = "loci";
                for (Locus locus : getLoci()) lociLine += " " + locus.getID() + ":" + locus.getSiteCount();
                lines.add(lociLine);
                lines.add("clonalframe_labeled " + root.toNewick());
                lines.add("clonalframe_numbered " + root.toShortNewick(true));
                for (Locus locus : getLoci()) {
                    for (Conversion conv : getConversions(locus)) {
                        lines.add("conversion node1=" + conv.getNode1().getNr() + " node2=" + conv.getNode2().getNr() + " site1=" + conv.getStartSite() + " site2=" + conv.getEndSite() + " locus=" + locus.getID());
                    }
                }
                return lines;
            }
        });
        try (PrintStream pstream = new PrintStream(outputFileNameInput.get())) {
            nexusBuilder.write(pstream);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
Also used : PrintStream(java.io.PrintStream) TreesBlock(feast.nexus.TreesBlock) FileNotFoundException(java.io.FileNotFoundException) Conversion(bacter.Conversion) NexusBuilder(feast.nexus.NexusBuilder) NexusBlock(feast.nexus.NexusBlock) Tree(beast.evolution.tree.Tree) TaxaBlock(feast.nexus.TaxaBlock) CFEventList(bacter.CFEventList) ArrayList(java.util.ArrayList) List(java.util.List) Locus(bacter.Locus)

Aggregations

CFEventList (bacter.CFEventList)1 Conversion (bacter.Conversion)1 Locus (bacter.Locus)1 Tree (beast.evolution.tree.Tree)1 NexusBlock (feast.nexus.NexusBlock)1 NexusBuilder (feast.nexus.NexusBuilder)1 TaxaBlock (feast.nexus.TaxaBlock)1 TreesBlock (feast.nexus.TreesBlock)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1