Search in sources :

Example 21 with Sequence

use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.

the class SequenceSimulator method intArray2Sequence.

/**
 * Convert integer representation of sequence into a Sequence
 *
 * @param seq  integer representation of the sequence
 * @param node used to determine taxon for sequence
 * @return Sequence
 * @
 */
Sequence intArray2Sequence(int[] seq, Node node) {
    DataType dataType = m_data.get().getDataType();
    String seqString = dataType.state2string(seq);
    // StringBuilder seq = new StringBuilder();
    // String map = m_data.get().getMap();
    // if (map != null) {
    // for (int i  = 0; i < m_sequenceLength; i++) {
    // seq.append(map.charAt(seq[i]));
    // }
    // } else {
    // for (int i  = 0; i < m_sequenceLength-1; i++) {
    // seq.append(seq[i] + ",");
    // }
    // seq.append(seq[m_sequenceLength-1] + "");
    // }
    List<Sequence> taxa = m_data.get().sequenceInput.get();
    String taxon = taxa.get(node.getNr()).taxonInput.get();
    return new Sequence(taxon, seqString);
}
Also used : DataType(beast.evolution.datatype.DataType) Sequence(beast.evolution.alignment.Sequence)

Example 22 with Sequence

use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.

the class MergeDataWith method process.

// initAndValidate
void process(Alignment data, int iteration) throws IOException, XMLParserException, IllegalArgumentException, IllegalAccessException {
    // read template
    String templateXML = BeautiDoc.load(templateFile);
    templateXML = templateXML.replaceAll("\\$\\(n\\)", iteration + "");
    XMLParser parser = new XMLParser();
    BEASTInterface b = parser.parseBareFragment(templateXML, false);
    // repalce alignment
    Alignment a = getAlignment(b);
    List<Sequence> sequences = a.sequenceInput.get();
    sequences.clear();
    sequences.addAll(data.sequenceInput.get());
    // write file
    String outputFile = outputFileInput.get();
    outputFile = outputFile.replaceAll("\\$\\(n\\)", iteration + "");
    FileWriter outfile = new FileWriter(outputFile);
    Set<BEASTInterface> beastObjects = new HashSet<>();
    String xml = new XMLProducer().toXML(b, beastObjects);
    outfile.write(xml);
    outfile.close();
}
Also used : Alignment(beast.evolution.alignment.Alignment) XMLProducer(beast.util.XMLProducer) FileWriter(java.io.FileWriter) BEASTInterface(beast.core.BEASTInterface) Sequence(beast.evolution.alignment.Sequence) XMLParser(beast.util.XMLParser) HashSet(java.util.HashSet)

Example 23 with Sequence

use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.

the class SimulatedAlignment method intArray2Sequence.

/**
 * Convert integer representation of sequence into a Sequence
 *
 * @param seq  integer representation of the sequence
 * @param node used to determine taxon for sequence
 * @return Sequence
 */
Sequence intArray2Sequence(int[] seq, Node node) {
    DataType dataType = m_data.get().getDataType();
    String seqString = dataType.state2string(seq);
    // StringBuilder seq = new StringBuilder();
    // String map = m_data.get().getMap();
    // if (map != null) {
    // for (int i  = 0; i < m_sequenceLength; i++) {
    // seq.append(map.charAt(seq[i]));
    // }
    // } else {
    // for (int i  = 0; i < m_sequenceLength-1; i++) {
    // seq.append(seq[i] + ",");
    // }
    // seq.append(seq[m_sequenceLength-1] + "");
    // }
    String taxon = m_data.get().getTaxaNames().get(node.getNr());
    return new Sequence(taxon, seqString);
}
Also used : DataType(beast.evolution.datatype.DataType) Sequence(beast.evolution.alignment.Sequence)

Example 24 with Sequence

use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.

the class Utils method main.

public static void main(String[] args) {
    try {
        Sequence a = new Sequence("A", "A");
        Sequence b = new Sequence("B", "A");
        Sequence c = new Sequence("C", "A");
        Sequence d = new Sequence("D", "A");
        Alignment data = new Alignment();
        data.initByName("sequence", a, "sequence", b, "sequence", c, "sequence", d, "dataType", "nucleotide");
        TreeParser tree = new TreeParser();
        tree.initByName("taxa", data, "newick", "(((A:1,B:1):1,C:2):1,D:3)", "IsLabelledNewick", true);
        JukesCantor JC = new JukesCantor();
        JC.initAndValidate();
        SiteModel siteModel = new SiteModel();
        siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", JC);
        BeagleTreeLikelihood likelihood = new BeagleTreeLikelihood();
        likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("Success");
    // if we got this far, exit with status 0
    System.exit(0);
}
Also used : BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) Alignment(beast.evolution.alignment.Alignment) TreeParser(beast.util.TreeParser) SiteModel(beast.evolution.sitemodel.SiteModel) Sequence(beast.evolution.alignment.Sequence) JukesCantor(beast.evolution.substitutionmodel.JukesCantor) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) IOException(java.io.IOException)

Example 25 with Sequence

use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.

the class BEASTTestCase method getFourTaxaNoData.

public Alignment getFourTaxaNoData() throws Exception {
    Sequence a = new Sequence("A", "A");
    Sequence b = new Sequence("B", "A");
    Sequence c = new Sequence("C", "A");
    Sequence d = new Sequence("D", "A");
    Alignment data = new Alignment();
    data.initByName("sequence", a, "sequence", b, "sequence", c, "sequence", d, "dataType", "nucleotide");
    return data;
}
Also used : Alignment(beast.evolution.alignment.Alignment) Sequence(beast.evolution.alignment.Sequence)

Aggregations

Sequence (beast.evolution.alignment.Sequence)34 Alignment (beast.evolution.alignment.Alignment)31 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)6 SiteModel (beast.evolution.sitemodel.SiteModel)6 RealParameter (beast.core.parameter.RealParameter)5 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)5 Tree (beast.evolution.tree.Tree)5 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)4 UncertainAlignmentTest (test.beast.evolution.alignment.UncertainAlignmentTest)4 TaxonSet (beast.evolution.alignment.TaxonSet)3 DataType (beast.evolution.datatype.DataType)3 Frequencies (beast.evolution.substitutionmodel.Frequencies)3 JukesCantor (beast.evolution.substitutionmodel.JukesCantor)3 TreeParser (beast.util.TreeParser)3 GeneralSubstitutionModel (beast.evolution.substitutionmodel.GeneralSubstitutionModel)2 RandomTree (beast.evolution.tree.RandomTree)2 ConstantPopulation (beast.evolution.tree.coalescent.ConstantPopulation)2 TreeIntervals (beast.evolution.tree.coalescent.TreeIntervals)2