use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.
the class STARBEASTGenerator method writeSpeciesTreeLikelihood.
private void writeSpeciesTreeLikelihood(XMLWriter writer) {
TreePriorType nodeHeightPrior = options.getPartitionTreePriors().get(0).getNodeHeightPrior();
if (nodeHeightPrior == TreePriorType.SPECIES_BIRTH_DEATH) {
writer.writeComment("Species Tree Likelihood: Birth Death Model");
writer.writeOpenTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, SPECIATION_LIKE) });
writer.writeOpenTag(SpeciationLikelihoodParser.MODEL);
writer.writeIDref(BirthDeathModelParser.BIRTH_DEATH_MODEL, BirthDeathModelParser.BIRTH_DEATH);
writer.writeCloseTag(SpeciationLikelihoodParser.MODEL);
} else if (nodeHeightPrior == TreePriorType.SPECIES_YULE || nodeHeightPrior == TreePriorType.SPECIES_YULE_CALIBRATION) {
writer.writeComment("Species Tree Likelihood: Yule Model");
writer.writeOpenTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, SPECIATION_LIKE) });
writer.writeOpenTag(SpeciationLikelihoodParser.MODEL);
writer.writeIDref(YuleModelParser.YULE_MODEL, YuleModelParser.YULE);
writer.writeCloseTag(SpeciationLikelihoodParser.MODEL);
if (nodeHeightPrior == TreePriorType.SPECIES_YULE_CALIBRATION) {
// should be only 1 calibrated node with monophyletic for species tree at moment
if (options.speciesSets.size() == 1 && options.speciesSetsMono.size() == 1) {
Taxa t = options.speciesSets.get(0);
Parameter nodeCalib = options.getStatistic(t);
writer.writeOpenTag(SpeciationLikelihoodParser.CALIBRATION, new Attribute[] { new Attribute.Default<String>(SpeciationLikelihoodParser.CORRECTION, CalibrationPoints.CorrectionType.EXACT.toString()) });
writer.writeOpenTag(SpeciationLikelihoodParser.POINT);
writer.writeIDref(TaxaParser.TAXA, t.getId());
writeDistribution(nodeCalib, true, writer);
writer.writeCloseTag(SpeciationLikelihoodParser.POINT);
writer.writeCloseTag(SpeciationLikelihoodParser.CALIBRATION);
if (!options.treeModelOptions.isNodeCalibrated(nodeCalib)) {
}
} else {
throw new IllegalArgumentException("Calibrated Yule model is only applied to 1 calibrated node with monophyletic for species tree at moment !");
}
}
} else {
throw new IllegalArgumentException("Get wrong species tree prior using *BEAST : " + nodeHeightPrior.toString());
}
// <sp> tree
writer.writeOpenTag(SpeciesTreeModelParser.SPECIES_TREE);
writer.writeIDref(SpeciesTreeModelParser.SPECIES_TREE, SP_TREE);
writer.writeCloseTag(SpeciesTreeModelParser.SPECIES_TREE);
writer.writeCloseTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD);
}
use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.
the class DataPanel method linkTrees.
public void linkTrees() {
// keep previous PartitionTreePrior for reuse
int[] selRows = dataTable.getSelectedRows();
List<AbstractPartitionData> selectedPartitionData = new ArrayList<AbstractPartitionData>();
for (int row : selRows) {
AbstractPartitionData partition = options.dataPartitions.get(row);
if (!selectedPartitionData.contains(partition))
selectedPartitionData.add(partition);
}
if (selectedPartitionData.size() > 1) {
if (!options.hasIdenticalTaxa(selectedPartitionData)) {
String errMsg = "To share a tree, partitions need to have identical taxa.";
if (selectedPartitionData.get(0).getDataType().getType() == DataType.MICRO_SAT)
errMsg += "\nThe data must be all diploid or all haploid when you want to link the tree.";
JOptionPane.showMessageDialog(this, errMsg, "Illegal Configuration", JOptionPane.ERROR_MESSAGE);
return;
}
}
Object[] treeArray = options.getPartitionTreeModels(selectedPartitionData).toArray();
if (selectTreeDialog == null) {
selectTreeDialog = new SelectTreeDialog(frame);
}
int result = selectTreeDialog.showDialog(treeArray);
if (result != JOptionPane.CANCEL_OPTION) {
PartitionTreeModel model = selectTreeDialog.getTree();
if (selectTreeDialog.getMakeCopy()) {
model.setName(selectTreeDialog.getName());
}
PartitionTreePrior prior = model.getPartitionTreePrior();
options.linkTreePriors(prior);
for (AbstractPartitionData partition : selectedPartitionData) {
partition.setPartitionTreeModel(model);
}
for (Taxa taxa : options.taxonSets) {
// Issue 454: all the taxon sets are deleted when link/unlink tree
PartitionTreeModel prevModel = options.taxonSetsTreeModel.get(taxa);
if (prevModel != model)
options.taxonSetsTreeModel.put(taxa, model);
}
}
modelsChanged();
fireDataChanged();
repaint();
}
use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.
the class TaxaParser method parseXMLObject.
/** @return an instance of Node created from a DOM element */
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Taxa taxonList = new Taxa();
for (int i = 0; i < xo.getChildCount(); i++) {
Object child = xo.getChild(i);
if (child instanceof Taxon) {
Taxon taxon = (Taxon) child;
taxonList.addTaxon(taxon);
} else if (child instanceof TaxonList) {
TaxonList taxonList1 = (TaxonList) child;
for (int j = 0; j < taxonList1.getTaxonCount(); j++) {
taxonList.addTaxon(taxonList1.getTaxon(j));
}
} else {
throwUnrecognizedElement(xo);
}
}
return taxonList;
}
use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.
the class TaxonSetPanel method initPanel.
protected void initPanel(Action addTaxonSetAction, Action removeTaxonSetAction) {
JScrollPane scrollPane1 = new JScrollPane(taxonSetsTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JToolBar toolBar1 = new JToolBar();
toolBar1.setFloatable(false);
toolBar1.setOpaque(false);
toolBar1.setBorder(BorderFactory.createEmptyBorder());
toolBar1.setLayout(new FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
JButton button = new JButton(importTaxonSetsAction);
PanelUtils.setupComponent(button);
toolBar1.add(button);
ActionPanel actionPanel1 = new ActionPanel(false);
actionPanel1.setAddAction(addTaxonSetAction);
actionPanel1.setRemoveAction(removeTaxonSetAction);
addTaxonSetAction.setEnabled(false);
removeTaxonSetAction.setEnabled(false);
JPanel controlPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
controlPanel1.add(actionPanel1);
// Excluded Taxon List
excludedTaxaTableModel = new TaxaTableModel(false);
excludedTaxaTable = new JTable(excludedTaxaTableModel);
excludedTaxaTable.getColumnModel().getColumn(0).setCellRenderer(new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
excludedTaxaTable.getColumnModel().getColumn(0).setMinWidth(20);
excludedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
excludedTaxaTableSelectionChanged();
}
});
JScrollPane scrollPane2 = new JScrollPane(excludedTaxaTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
includedTaxonSetsComboBox = new JComboBox(new String[] { TAXON.toLowerCase() + "..." });
excludedTaxonSetsComboBox = new JComboBox(new String[] { TAXON.toLowerCase() + "..." });
includedTaxaLabel.setText("");
excludedTaxaLabel.setText("");
Box panel1 = new Box(BoxLayout.X_AXIS);
panel1.add(new JLabel("Select: "));
panel1.setOpaque(false);
excludedTaxonSetsComboBox.setOpaque(false);
panel1.add(excludedTaxonSetsComboBox);
// Included Taxon List
includedTaxaTableModel = new TaxaTableModel(true);
includedTaxaTable = new JTable(includedTaxaTableModel);
includedTaxaTable.getColumnModel().getColumn(0).setCellRenderer(new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
includedTaxaTable.getColumnModel().getColumn(0).setMinWidth(20);
includedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
includedTaxaTableSelectionChanged();
}
});
includedTaxaTable.doLayout();
JScrollPane scrollPane3 = new JScrollPane(includedTaxaTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Box panel2 = new Box(BoxLayout.X_AXIS);
panel2.add(new JLabel("Select: "));
panel2.setOpaque(false);
includedTaxonSetsComboBox.setOpaque(false);
panel2.add(includedTaxonSetsComboBox);
Icon includeIcon = null, excludeIcon = null;
try {
includeIcon = new ImageIcon(IconUtils.getImage(BeautiApp.class, "images/include.png"));
excludeIcon = new ImageIcon(IconUtils.getImage(BeautiApp.class, "images/exclude.png"));
} catch (Exception e) {
// do nothing
}
JPanel buttonPanel = createAddRemoveButtonPanel(includeTaxonAction, includeIcon, "Include selected " + TAXA.toLowerCase() + " in the " + TAXON.toLowerCase(), excludeTaxonAction, excludeIcon, "Exclude selected " + TAXA.toLowerCase() + " from the " + TAXON.toLowerCase(), BoxLayout.Y_AXIS);
taxonSetEditingPanel = new JPanel();
taxonSetEditingPanel.setBorder(BorderFactory.createTitledBorder(""));
taxonSetEditingPanel.setOpaque(false);
taxonSetEditingPanel.setLayout(new GridBagLayout());
excludedTaxaSearchField.setColumns(12);
// excludedTaxaSearchField.putClientProperty("JTextField.variant", "search");
excludedTaxaSearchField.putClientProperty("Quaqua.TextField.style", "search");
excludedTaxaSearchField.putClientProperty("Quaqua.TextField.sizeVariant", "small");
includedTaxaSearchField.setColumns(12);
// includedTaxaSearchField.putClientProperty("JTextField.variant", "search");
includedTaxaSearchField.putClientProperty("Quaqua.TextField.style", "search");
includedTaxaSearchField.putClientProperty("Quaqua.TextField.sizeVariant", "small");
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.5;
c.weighty = 0;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(3, 6, 3, 0);
taxonSetEditingPanel.add(excludedTaxaSearchField, c);
c.gridx = 0;
c.gridy = 1;
c.weightx = 0.5;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(0, 6, 0, 0);
taxonSetEditingPanel.add(scrollPane2, c);
c.gridx = 0;
c.gridy = 2;
c.weightx = 0.5;
c.weighty = 0;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(0, 6, 3, 0);
taxonSetEditingPanel.add(excludedTaxaLabel, c);
c.gridx = 0;
c.gridy = 3;
c.weightx = 0.5;
c.weighty = 0;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(0, 6, 3, 0);
taxonSetEditingPanel.add(panel1, c);
c.gridx = 1;
c.gridy = 0;
c.weightx = 0;
c.weighty = 1;
c.gridheight = 4;
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(12, 2, 12, 4);
taxonSetEditingPanel.add(buttonPanel, c);
c.gridx = 2;
c.gridy = 0;
c.weightx = 0.5;
c.weighty = 0;
c.gridheight = 1;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(3, 0, 3, 6);
taxonSetEditingPanel.add(includedTaxaSearchField, c);
c.gridx = 2;
c.gridy = 1;
c.weightx = 0.5;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(0, 0, 0, 6);
taxonSetEditingPanel.add(scrollPane3, c);
c.gridx = 2;
c.gridy = 2;
c.weightx = 0.5;
c.weighty = 0;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(0, 0, 3, 6);
taxonSetEditingPanel.add(includedTaxaLabel, c);
c.gridx = 2;
c.gridy = 3;
c.weightx = 0.5;
c.weighty = 0;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(0, 0, 3, 6);
taxonSetEditingPanel.add(panel2, c);
JPanel panel3 = new JPanel();
panel3.setOpaque(false);
panel3.setLayout(new GridBagLayout());
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.5;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(0, 0, 2, 12);
panel3.add(scrollPane1, c);
c.gridx = 0;
c.gridy = 1;
c.weightx = 0;
c.weighty = 0;
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(2, 0, 0, 12);
panel3.add(actionPanel1, c);
c.gridx = 1;
c.gridy = 0;
c.weightx = 0.5;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(0, 0, 0, 0);
panel3.add(taxonSetEditingPanel, c);
setOpaque(false);
setBorder(new BorderUIResource.EmptyBorderUIResource(new Insets(12, 12, 12, 12)));
setLayout(new BorderLayout(0, 0));
add(toolBar1, BorderLayout.NORTH);
add(panel3, BorderLayout.CENTER);
// taxonSetsTable.addMouseListener(new MouseAdapter() {
// public void mouseClicked(MouseEvent e) {
// if (e.getClickCount() == 2) {
// JTable target = (JTable)e.getSource();
// int row = target.getSelectedRow();
// taxonSetsTableDoubleClicked(row);
// }
// }
// });
includedTaxaSearchField.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
selectIncludedTaxa(includedTaxaSearchField.getText());
}
public void removeUpdate(DocumentEvent e) {
selectIncludedTaxa(includedTaxaSearchField.getText());
}
public void insertUpdate(DocumentEvent e) {
selectIncludedTaxa(includedTaxaSearchField.getText());
}
});
excludedTaxaSearchField.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
selectExcludedTaxa(excludedTaxaSearchField.getText());
}
public void removeUpdate(DocumentEvent e) {
selectExcludedTaxa(excludedTaxaSearchField.getText());
}
public void insertUpdate(DocumentEvent e) {
selectExcludedTaxa(excludedTaxaSearchField.getText());
}
});
includedTaxaTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
includeSelectedTaxa();
}
}
});
excludedTaxaTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
excludeSelectedTaxa();
}
}
});
includedTaxaTable.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent focusEvent) {
excludedTaxaTable.clearSelection();
}
});
excludedTaxaTable.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent focusEvent) {
includedTaxaTable.clearSelection();
}
});
includedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!includedSelectionChanging) {
if (includedTaxonSetsComboBox.getSelectedIndex() != 0) {
includedTaxonSetsComboBox.setSelectedIndex(0);
}
includedTaxaSearchField.setText("");
}
}
});
includedTaxonSetsComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
includedSelectionChanging = true;
includedTaxaTable.clearSelection();
if (includedTaxonSetsComboBox.getSelectedIndex() > 0) {
String taxaName = includedTaxonSetsComboBox.getSelectedItem().toString();
if (!taxaName.endsWith("...")) {
Taxa taxa = options.getTaxa(taxaName);
if (taxa != null) {
for (int i = 0; i < taxa.getTaxonCount(); i++) {
Taxon taxon = taxa.getTaxon(i);
int index = includedTaxa.indexOf(taxon);
includedTaxaTable.getSelectionModel().addSelectionInterval(index, index);
}
}
}
}
includedSelectionChanging = false;
}
});
excludedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!excludedSelectionChanging) {
if (excludedTaxonSetsComboBox.getSelectedIndex() != 0) {
excludedTaxonSetsComboBox.setSelectedIndex(0);
}
excludedTaxaSearchField.setText("");
}
}
});
excludedTaxonSetsComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
excludedSelectionChanging = true;
excludedTaxaTable.clearSelection();
if (excludedTaxonSetsComboBox.getSelectedIndex() > 0) {
String taxaName = excludedTaxonSetsComboBox.getSelectedItem().toString();
if (!taxaName.endsWith("...")) {
Taxa taxa = options.getTaxa(taxaName);
if (taxa != null) {
for (int i = 0; i < taxa.getTaxonCount(); i++) {
Taxon taxon = taxa.getTaxon(i);
int index = excludedTaxa.indexOf(taxon);
excludedTaxaTable.getSelectionModel().addSelectionInterval(index, index);
}
}
}
}
excludedSelectionChanging = false;
}
});
includedTaxaTable.doLayout();
excludedTaxaTable.doLayout();
}
use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.
the class BEAUTiImporter method importBEASTFile.
// xml
private void importBEASTFile(File file) throws IOException, ImportException, JDOMException {
try {
FileReader reader = new FileReader(file);
BeastImporter importer = new BeastImporter(reader);
List<TaxonList> taxonLists = new ArrayList<TaxonList>();
List<Alignment> alignments = new ArrayList<Alignment>();
importer.importBEAST(taxonLists, alignments);
TaxonList taxa = taxonLists.get(0);
int count = 1;
for (Alignment alignment : alignments) {
String name = file.getName();
if (alignment.getId() != null && alignment.getId().length() > 0) {
name = alignment.getId();
} else {
if (alignments.size() > 1) {
name += count;
}
}
setData(name, taxa, alignment, null, null, null, null, null);
count++;
}
// assume that any additional taxon lists are taxon sets...
for (int i = 1; i < taxonLists.size(); i++) {
Taxa taxonSet = (Taxa) taxonLists.get(i);
options.taxonSets.add(taxonSet);
options.taxonSetsMono.put(taxonSet, false);
options.taxonSetsIncludeStem.put(taxonSet, false);
options.taxonSetsTreeModel.put(taxonSet, options.getPartitionTreeModels().get(0));
// force the creation of a tmrca statistic
options.updateTMRCAStatistic(taxonSet);
}
Collections.sort(options.taxonSets);
reader.close();
} catch (JDOMException e) {
throw new JDOMException(e.getMessage());
} catch (ImportException e) {
throw new ImportException(e.getMessage());
} catch (IOException e) {
throw new IOException(e.getMessage());
}
}
Aggregations