Search in sources :

Example 1 with CharactersBlock

use of feast.nexus.CharactersBlock 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();
        }
    }
}
Also used : PrintStream(java.io.PrintStream) CharactersBlock(feast.nexus.CharactersBlock) FileNotFoundException(java.io.FileNotFoundException) TaxaBlock(feast.nexus.TaxaBlock) Locus(bacter.Locus) NexusBuilder(feast.nexus.NexusBuilder)

Aggregations

Locus (bacter.Locus)1 CharactersBlock (feast.nexus.CharactersBlock)1 NexusBuilder (feast.nexus.NexusBuilder)1 TaxaBlock (feast.nexus.TaxaBlock)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintStream (java.io.PrintStream)1