Search in sources :

Example 6 with SimpleAlignment

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;
}
Also used : SimpleAlignment(dr.evolution.alignment.SimpleAlignment) DataType(dr.evolution.datatype.DataType) Sequence(dr.evolution.sequence.Sequence) Logger(java.util.logging.Logger)

Example 7 with SimpleAlignment

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();
}
Also used : Partition(dr.app.beagle.tools.Partition) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) BeagleSequenceSimulator(dr.app.beagle.tools.BeagleSequenceSimulator) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) TreeModel(dr.evomodel.tree.TreeModel) SimpleAlignment(dr.evolution.alignment.SimpleAlignment) SwingWorker(javax.swing.SwingWorker) PrintWriter(java.io.PrintWriter)

Example 8 with SimpleAlignment

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;
}
Also used : SimpleAlignment(dr.evolution.alignment.SimpleAlignment) Element(org.jdom.Element) List(java.util.List)

Example 9 with SimpleAlignment

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;
}
Also used : SimpleAlignment(dr.evolution.alignment.SimpleAlignment) Taxon(dr.evolution.util.Taxon) EOFException(java.io.EOFException) Sequence(dr.evolution.sequence.Sequence)

Example 10 with SimpleAlignment

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;
}
Also used : SimpleAlignment(dr.evolution.alignment.SimpleAlignment)

Aggregations

SimpleAlignment (dr.evolution.alignment.SimpleAlignment)28 Sequence (dr.evolution.sequence.Sequence)15 Taxon (dr.evolution.util.Taxon)10 ArrayList (java.util.ArrayList)9 TreeModel (dr.evomodel.tree.TreeModel)7 Parameter (dr.inference.model.Parameter)7 Tree (dr.evolution.tree.Tree)6 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)6 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)6 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)5 Partition (dr.app.beagle.tools.Partition)5 ImportException (dr.evolution.io.Importer.ImportException)5 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)5 Date (dr.evolution.util.Date)4 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)4 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)4 HKY (dr.evomodel.substmodel.nucleotide.HKY)4 IOException (java.io.IOException)4 Taxa (dr.evolution.util.Taxa)3 BranchModel (dr.evomodel.branchmodel.BranchModel)3