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();
}
}
}
Aggregations