use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.
the class TreeLikelihood method setPartials.
/**
* set leaf partials in likelihood core *
*/
protected void setPartials(Node node, int patternCount) {
if (node.isLeaf()) {
Alignment data = dataInput.get();
int states = data.getDataType().getStateCount();
double[] partials = new double[patternCount * states];
int k = 0;
int taxonIndex = getTaxonIndex(node.getID(), data);
for (int patternIndex_ = 0; patternIndex_ < patternCount; patternIndex_++) {
double[] tipLikelihoods = data.getTipLikelihoods(taxonIndex, patternIndex_);
if (tipLikelihoods != null) {
for (int state = 0; state < states; state++) {
partials[k++] = tipLikelihoods[state];
}
} else {
int stateCount = data.getPattern(taxonIndex, patternIndex_);
boolean[] stateSet = data.getStateSet(stateCount);
for (int state = 0; state < states; state++) {
partials[k++] = (stateSet[state] ? 1.0 : 0.0);
}
}
}
likelihoodCore.setNodePartials(node.getNr(), partials);
} else {
setPartials(node.getLeft(), patternCount);
setPartials(node.getRight(), patternCount);
}
}
use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.
the class AlignmentViewer method main.
public static void main(String[] args) {
try {
NexusParser parser = new NexusParser();
parser.parseFile(new File(args[0]));
Alignment data = parser.m_alignment;
AlignmentViewer panel = new AlignmentViewer(data);
panel.showInDialog();
} catch (Exception e) {
e.printStackTrace();
}
}
use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.
the class BeautiAlignmentProvider method addAlignments.
protected void addAlignments(BeautiDoc doc, List<BEASTInterface> selectedBEASTObjects) {
for (BEASTInterface beastObject : selectedBEASTObjects) {
if (beastObject instanceof Alignment) {
// ensure ID of alignment is unique
int k = 0;
String id = beastObject.getID();
boolean found = true;
while (doc.pluginmap.containsKey(id) && found) {
found = false;
for (Alignment data : doc.alignments) {
if (data.getID().equals(beastObject.getID())) {
found = true;
break;
}
}
if (found) {
k++;
id = beastObject.getID() + k;
} else {
BEASTInterface oldData = doc.pluginmap.get(beastObject.getID());
replaceItem(doc, oldData, beastObject);
}
}
beastObject.setID(id);
sortByTaxonName(((Alignment) beastObject).sequenceInput.get());
if (getStartTemplate() != null) {
doc.addAlignmentWithSubnet((Alignment) beastObject, getStartTemplate());
}
}
}
}
use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.
the class AlignmentListInputEditor method createListBox.
protected Component createListBox() {
String[] columnData = new String[] { "Name", "File", "Taxa", "Sites", "Data Type", "Site Model", "Clock Model", "Tree", "Ambiguities" };
initTableData();
// set up table.
// special features: background shading of rows
// custom editor allowing only Date column to be edited.
table = new JTable(tableData, columnData) {
private static final long serialVersionUID = 1L;
// method that induces table row shading
@Override
public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) {
Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
// even index, selected or not selected
if (isCellSelected(Index_row, Index_col)) {
comp.setBackground(Color.gray);
} else if (Index_row % 2 == 0 && !isCellSelected(Index_row, Index_col)) {
comp.setBackground(new Color(237, 243, 255));
} else {
comp.setBackground(Color.white);
}
JComponent jcomp = (JComponent) comp;
switch(Index_col) {
case NAME_COLUMN:
case CLOCKMODEL_COLUMN:
case TREE_COLUMN:
case SITEMODEL_COLUMN:
jcomp.setToolTipText("Set " + table.getColumnName(Index_col).toLowerCase() + " for this partition");
break;
case FILE_COLUMN:
case TAXA_COLUMN:
case SITES_COLUMN:
case TYPE_COLUMN:
jcomp.setToolTipText("Report " + table.getColumnName(Index_col).toLowerCase() + " for this partition");
break;
case USE_AMBIGUITIES_COLUMN:
jcomp.setToolTipText("<html>Flag whether to use ambiguities.<br>" + "If not set, the treelikelihood will treat ambiguities in the<br>" + "data as unknowns<br>" + "If set, the treelikelihood will use ambiguities as equally<br>" + "likely values for the tips.<br>" + "This will make the computation twice as slow.</html>");
break;
default:
jcomp.setToolTipText(null);
}
updateStatus();
return comp;
}
};
int size = table.getFont().getSize();
table.setRowHeight(25 * size / 13);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setColumnSelectionAllowed(false);
table.setRowSelectionAllowed(true);
table.setName("alignmenttable");
setUpComboBoxes();
TableColumn col = table.getColumnModel().getColumn(NAME_COLUMN);
nameEditor = new JTextField();
nameEditor.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
processPartitionName();
}
@Override
public void insertUpdate(DocumentEvent e) {
processPartitionName();
}
@Override
public void changedUpdate(DocumentEvent e) {
processPartitionName();
}
});
col.setCellEditor(new DefaultCellEditor(nameEditor));
// // set up editor that makes sure only doubles are accepted as entry
// // and only the Date column is editable.
table.setDefaultEditor(Object.class, new TableCellEditor() {
JTextField m_textField = new JTextField();
int m_iRow, m_iCol;
@Override
public boolean stopCellEditing() {
// Log.warning.println("stopCellEditing()");
table.removeEditor();
String text = m_textField.getText();
try {
Double.parseDouble(text);
} catch (Exception e) {
return false;
}
tableData[m_iRow][m_iCol] = text;
return true;
}
@Override
public boolean isCellEditable(EventObject anEvent) {
// Log.warning.println("isCellEditable()");
return table.getSelectedColumn() == 0;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowNr, int colNr) {
return null;
}
@Override
public boolean shouldSelectCell(EventObject anEvent) {
return false;
}
@Override
public void removeCellEditorListener(CellEditorListener l) {
}
@Override
public Object getCellEditorValue() {
return null;
}
@Override
public void cancelCellEditing() {
}
@Override
public void addCellEditorListener(CellEditorListener l) {
}
});
// show alignment viewer when double clicking a row
table.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
try {
int alignmemt = table.rowAtPoint(e.getPoint());
Alignment alignment = alignments.get(alignmemt);
int best = 0;
BeautiAlignmentProvider provider = null;
for (BeautiAlignmentProvider provider2 : doc.beautiConfig.alignmentProvider) {
int match = provider2.matches(alignment);
if (match > best) {
best = match;
provider = provider2;
}
}
provider.editAlignment(alignment, doc);
} catch (Exception e1) {
e1.printStackTrace();
}
updateStatus();
} else if (e.getButton() == e.BUTTON3) {
int alignmemt = table.rowAtPoint(e.getPoint());
Alignment alignment = alignments.get(alignmemt);
int result = JOptionPane.showConfirmDialog(null, "Do you want to replace alignment " + alignment.getID());
if (result == JOptionPane.YES_OPTION) {
replaceItem(alignment);
}
}
}
});
scrollPane = new JScrollPane(table);
int rowsToDisplay = 3;
Dimension d = table.getPreferredSize();
scrollPane.setPreferredSize(new Dimension(d.width, table.getRowHeight() * rowsToDisplay + table.getTableHeader().getHeight()));
return scrollPane;
}
use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.
the class AlignmentListInputEditor method replaceItem.
// delItem
void replaceItem() {
int[] selected = getTableRowSelection();
if (selected.length != 1) {
// should never get here (button is disabled)
return;
}
Alignment alignment = alignments.get(selected[0]);
replaceItem(alignment);
}
Aggregations