use of feast.nexus.NexusBuilder 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();
}
}
}
use of feast.nexus.NexusBuilder in project bacter by tgvaughan.
the class SimulatedAlignment method initAndValidate.
@Override
public void initAndValidate() {
acg = acgInput.get();
siteModel = siteModelInput.get();
Locus locus;
if (acg.getLoci().size() == 1)
locus = acg.getLoci().get(0);
else {
locus = locusInput.get();
if (locus == null)
throw new IllegalArgumentException("Must specify locus" + " when simulating alignment from ACG associated" + " with multiple loci.");
}
// We can't wait for Alignment.initAndValidate() to get the
// data type for us.
grabDataType();
// Simulate alignment
simulate(locus);
super.initAndValidate();
// Write simulated alignment to disk if requested:
if (outputFileNameInput.get() != null) {
try (PrintStream pstream = new PrintStream(outputFileNameInput.get())) {
if (useNexusInput.get()) {
NexusBuilder nb = new NexusBuilder();
nb.append(new TaxaBlock(acg.getTaxonset()));
nb.append(new CharactersBlock(this));
nb.write(pstream);
} else {
for (String taxonName : acg.getTaxaNames()) {
pstream.print(">" + taxonName + "\n");
pstream.print(getSequenceAsString(taxonName) + "\n");
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
Aggregations