Search in sources :

Example 21 with Taxon

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

the class TaxonSetDialog method createCancelOKButtons.

// createTaxonSelector
Component createCancelOKButtons() {
    Box cancelOkBox = Box.createHorizontalBox();
    cancelOkBox.setBorder(new EtchedBorder());
    JButton okButton = new JButton("Ok");
    okButton.setName("OK");
    okButton.addActionListener(e -> {
        taxonSet.setID(id);
        List<Taxon> taxa = taxonSet.taxonsetInput.get();
        while (taxa.size() > 0) {
            taxa.remove(0);
        }
        for (int i = 0; i < listModel2.size(); i++) {
            taxa.add(listModel2.get(i));
        }
        isOK = true;
        dispose();
    });
    JButton cancelButton = new JButton("Cancel");
    cancelButton.setName("Cancel");
    cancelButton.addActionListener(e -> {
        dispose();
    });
    cancelOkBox.add(Box.createHorizontalGlue());
    cancelOkBox.add(okButton);
    cancelOkBox.add(Box.createHorizontalGlue());
    cancelOkBox.add(cancelButton);
    cancelOkBox.add(Box.createHorizontalGlue());
    return cancelOkBox;
}
Also used : EtchedBorder(javax.swing.border.EtchedBorder) Taxon(beast.evolution.alignment.Taxon) JButton(javax.swing.JButton) Box(javax.swing.Box)

Example 22 with Taxon

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

the class TaxonSetInputEditor method guess.

private void guess() {
    GuessPatternDialog dlg = new GuessPatternDialog(this, m_sPattern);
    switch(dlg.showDialog("Guess taxon sets")) {
        case canceled:
            return;
        case pattern:
            String pattern = dlg.getPattern();
            try {
                guessTaxonSets(pattern, 0);
                m_sPattern = pattern;
                break;
            } catch (Exception e) {
                e.printStackTrace();
            }
        case trait:
            String trait = dlg.getTrait();
            parseTrait(trait);
            break;
    }
    m_lineageset.clear();
    for (Taxon taxonset2 : m_taxonset) {
        for (Taxon taxon : ((TaxonSet) taxonset2).taxonsetInput.get()) {
            m_lineageset.add(taxon);
            m_taxonMap.put(taxon.getID(), taxonset2.getID());
        }
    }
    taxonSetToModel();
    modelToTaxonset();
}
Also used : Taxon(beast.evolution.alignment.Taxon) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 23 with Taxon

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

the class PriorListInputEditor method getTaxonCandidates.

Set<Taxon> getTaxonCandidates(MRCAPrior prior) {
    Set<Taxon> candidates = new HashSet<>();
    Tree tree = prior.treeInput.get();
    String[] taxa = null;
    if (tree.m_taxonset.get() != null) {
        try {
            TaxonSet set = tree.m_taxonset.get();
            set.initAndValidate();
            taxa = set.asStringList().toArray(new String[0]);
        } catch (Exception e) {
            taxa = prior.treeInput.get().getTaxaNames();
        }
    } else {
        taxa = prior.treeInput.get().getTaxaNames();
    }
    for (String taxon : taxa) {
        candidates.add(doc.getTaxon(taxon));
    }
    return candidates;
}
Also used : Taxon(beast.evolution.alignment.Taxon) Tree(beast.evolution.tree.Tree) TaxonSet(beast.evolution.alignment.TaxonSet) HashSet(java.util.HashSet)

Example 24 with Taxon

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

the class GeneTreeForSpeciesTreeDistribution method getSetID.

/**
 * @param lineageID
 * @return species ID to which the lineage ID belongs according to the TaxonSets
 */
String getSetID(final String lineageID) {
    final TaxonSet taxonSuperset = speciesTreePriorInput.get().taxonSetInput.get();
    final List<Taxon> taxonSets = taxonSuperset.taxonsetInput.get();
    for (final Taxon taxonSet : taxonSets) {
        final List<Taxon> taxa = ((TaxonSet) taxonSet).taxonsetInput.get();
        for (final Taxon aTaxa : taxa) {
            if (aTaxa.getID().equals(lineageID)) {
                return taxonSet.getID();
            }
        }
    }
    return null;
}
Also used : Taxon(beast.evolution.alignment.Taxon) TaxonSet(beast.evolution.alignment.TaxonSet)

Example 25 with Taxon

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

the class JSONTest method testAnnotatedConstructor.

@Test
public void testAnnotatedConstructor() throws Exception {
    List<Taxon> taxa = new ArrayList<>();
    taxa.add(new Taxon("first one"));
    taxa.add(new Taxon("second one"));
    AnnotatedRunnableTestClass t = new AnnotatedRunnableTestClass(3, taxa);
    JSONProducer producer = new JSONProducer();
    String json = producer.toJSON(t);
    assertEquals(3, (int) t.getParam1());
    FileWriter outfile = new FileWriter(new File("/tmp/JSONTest.json"));
    outfile.write(json);
    outfile.close();
    JSONParser parser = new JSONParser();
    BEASTInterface b = parser.parseFile(new File("/tmp/JSONTest.json"));
    assertEquals(3, (int) ((AnnotatedRunnableTestClass) b).getParam1());
    assertEquals(2, ((AnnotatedRunnableTestClass) b).getTaxon().size());
    // test that default value for param1 comes through
    String json2 = "{version: \"2.5\",\n" + "namespace: \"beast.core:beast.evolution.alignment:beast.evolution.tree.coalescent:beast.core.util:beast.evolution.nuc:beast.evolution.operators:beast.evolution.sitemodel:beast.evolution.substitutionmodel:beast.evolution.likelihood\",\n" + "\n" + "beast: [\n" + "\n" + "\n" + "        {id: \"JSONTest\",\n" + "         spec: \"test.beast.util.AnnotatedRunnableTestClass\",\n" + "         taxon: [\n" + "                 {id: \"first one\" },\n" + "                 {id: \"second one\" }\n" + "          ]\n" + "        }\n" + "]\n" + "}";
    outfile = new FileWriter(new File("/tmp/JSONTest2.json"));
    outfile.write(json2);
    outfile.close();
    parser = new JSONParser();
    b = parser.parseFile(new File("/tmp/JSONTest2.json"));
    assertEquals(10, (int) ((AnnotatedRunnableTestClass) b).getParam1());
    assertEquals(2, ((AnnotatedRunnableTestClass) b).getTaxon().size());
    // test that array of doubles comes through in second constructor
    String json3 = "{version: \"2.5\",\n" + "namespace: \"beast.core:beast.evolution.alignment:beast.evolution.tree.coalescent:beast.core.util:beast.evolution.nuc:beast.evolution.operators:beast.evolution.sitemodel:beast.evolution.substitutionmodel:beast.evolution.likelihood\",\n" + "\n" + "beast: [\n" + "\n" + "\n" + "        {id: \"JSONTest\",\n" + "         spec: \"test.beast.util.AnnotatedRunnableTestClass\",\n" + "         array: [1.0, 2.0, 3.0]\n" + "        }\n" + "]\n" + "}";
    outfile = new FileWriter(new File("/tmp/JSONTest3.json"));
    outfile.write(json3);
    outfile.close();
    parser = new JSONParser();
    b = parser.parseFile(new File("/tmp/JSONTest3.json"));
    assertEquals(3, ((AnnotatedRunnableTestClass) b).getArray().size());
}
Also used : JSONProducer(beast.util.JSONProducer) Taxon(beast.evolution.alignment.Taxon) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) JSONParser(beast.util.JSONParser) BEASTInterface(beast.core.BEASTInterface) File(java.io.File) Test(org.junit.Test)

Aggregations

Taxon (beast.evolution.alignment.Taxon)26 TaxonSet (beast.evolution.alignment.TaxonSet)18 ArrayList (java.util.ArrayList)7 Alignment (beast.evolution.alignment.Alignment)6 Tree (beast.evolution.tree.Tree)5 PatternSyntaxException (java.util.regex.PatternSyntaxException)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)3 MRCAPrior (beast.math.distributions.MRCAPrior)3 Box (javax.swing.Box)3 BEASTInterface (beast.core.BEASTInterface)2 RealParameter (beast.core.parameter.RealParameter)2 TreeParser (beast.util.TreeParser)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 PrintStream (java.io.PrintStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 JButton (javax.swing.JButton)2