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;
}
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();
}
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;
}
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;
}
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());
}
Aggregations