use of dr.evolution.alignment.SimpleAlignment in project beast-mcmc by beast-dev.
the class AlignmentParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final SimpleAlignment alignment = new SimpleAlignment();
final DataType dataType = DataTypeUtils.getDataType(xo);
if (dataType == null) {
throw new XMLParseException("dataType attribute expected for alignment element");
}
alignment.setDataType(dataType);
for (int i = 0; i < xo.getChildCount(); i++) {
final Object child = xo.getChild(i);
if (child instanceof Sequence) {
alignment.addSequence((Sequence) child);
} else if (child instanceof DataType) {
// already dealt with
} else {
throw new XMLParseException("Unknown child element found in alignment");
}
}
final Logger logger = Logger.getLogger("dr.evoxml");
logger.info("\nRead alignment" + (xo.hasAttribute(XMLParser.ID) ? ": " + xo.getId() : "") + "\n Sequences = " + alignment.getSequenceCount() + "\n Sites = " + alignment.getSiteCount() + "\n Datatype = " + alignment.getDataType().getDescription());
return alignment;
}
use of dr.evolution.alignment.SimpleAlignment in project beast-mcmc by beast-dev.
the class MainFrame method generateNumberOfSimulations.
// END: doExport
// threading, UI, exceptions handling
private void generateNumberOfSimulations(final File outFile) {
setBusy();
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
ArrayList<TreeModel> simulatedTreeModelList = new ArrayList<TreeModel>();
// Executed in background thread
public Void doInBackground() {
try {
if (BeagleSequenceSimulatorApp.VERBOSE) {
Utils.printPartitionDataList(dataList);
System.out.println();
}
long startingSeed = dataList.startingSeed;
for (int i = 0; i < dataList.simulationsCount; i++) {
String fullPath = Utils.getMultipleWritePath(outFile, dataList.outputFormat.toString().toLowerCase(), i);
PrintWriter writer = new PrintWriter(new FileWriter(fullPath));
ArrayList<Partition> partitionsList = new ArrayList<Partition>();
for (PartitionData data : dataList) {
if (data.record == null) {
writer.close();
throw new RuntimeException("Set data in Partitions tab for " + (partitionsList.size() + 1) + " partition.");
} else {
TreeModel treeModel = data.createTreeModel();
simulatedTreeModelList.add(treeModel);
// create partition
Partition partition = new Partition(//
treeModel, //
data.createBranchModel(), //
data.createSiteRateModel(), //
data.createClockRateModel(), //
data.createFrequencyModel(), // from
data.from - 1, // to
data.to - 1, // every
data.every);
if (data.ancestralSequenceString != null) {
partition.setRootSequence(data.createAncestralSequence());
}
partitionsList.add(partition);
}
}
if (dataList.setSeed) {
MathUtils.setSeed(startingSeed);
startingSeed += 1;
}
beagleSequenceSimulator = new BeagleSequenceSimulator(partitionsList);
SimpleAlignment alignment = beagleSequenceSimulator.simulate(dataList.useParallel, dataList.outputAncestralSequences);
alignment.setOutputType(dataList.outputFormat);
// if (dataList.outputFormat == SimpleAlignment.OutputType.NEXUS) {
// alignment.setOutputType(dataList.outputFormat);
// } else if(dataList.outputFormat == SimpleAlignment.OutputType.XML) {
// alignment.setOutputType(dataList.outputFormat);
// }else {
// //
// }
writer.println(alignment.toString());
writer.close();
}
// END: simulationsCount loop
} catch (Exception e) {
Utils.handleException(e);
setStatus("Exception occured.");
setIdle();
}
return null;
}
// END: doInBackground
// Executed in event dispatch thread
public void done() {
// LinkedHashMap<Integer, LinkedHashMap<NodeRef, int[]>> partitionSequencesMap = beagleSequenceSimulator.getPartitionSequencesMap();
terminalPanel.setText(Utils.partitionDataListToString(dataList, simulatedTreeModelList));
setStatus("Generated " + Utils.getSiteCount(dataList) + " sites.");
setIdle();
}
};
worker.execute();
}
use of dr.evolution.alignment.SimpleAlignment in project beast-mcmc by beast-dev.
the class BeastImporter method readAlignment.
private Alignment readAlignment(Element e, TaxonList taxa) throws Importer.ImportException {
SimpleAlignment alignment = new SimpleAlignment();
List children = e.getChildren();
for (Object aChildren : children) {
Element child = (Element) aChildren;
if (child.getName().equalsIgnoreCase(SequenceParser.SEQUENCE)) {
alignment.addSequence(readSequence(child, taxa));
}
}
return alignment;
}
use of dr.evolution.alignment.SimpleAlignment in project beast-mcmc by beast-dev.
the class FastaImporter method importAlignment.
/**
* importAlignment.
*/
public Alignment importAlignment() throws IOException, ImportException {
SimpleAlignment alignment = null;
try {
// find fasta line start
while (read() != FASTA_FIRST_CHAR) {
}
do {
final String name = readLine().trim();
StringBuffer seq = new StringBuffer();
readSequence(seq, dataType, "" + FASTA_FIRST_CHAR, Integer.MAX_VALUE, "-", "?", "", "");
if (alignment == null) {
alignment = new SimpleAlignment();
}
alignment.addSequence(new Sequence(new Taxon(name.toString()), seq.toString()));
} while (getLastDelimiter() == FASTA_FIRST_CHAR);
} catch (EOFException e) {
// catch end of file the ugly way.
}
return alignment;
}
use of dr.evolution.alignment.SimpleAlignment in project beast-mcmc by beast-dev.
the class NexusImporter method readDataBlock.
/**
* Reads a 'DATA' block.
*/
private Alignment readDataBlock() throws /*TaxonList taxonList*/
ImportException, IOException {
taxonCount = 0;
siteCount = 0;
dataType = null;
readDataBlockHeader("MATRIX", DATA_BLOCK);
SimpleAlignment alignment = new SimpleAlignment();
readSequenceData(alignment, null);
alignment.updateSiteCount();
findEndBlock();
return alignment;
}
Aggregations