Search in sources :

Example 16 with Alignment

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);
    }
}
Also used : Alignment(beast.evolution.alignment.Alignment)

Example 17 with Alignment

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();
    }
}
Also used : Alignment(beast.evolution.alignment.Alignment) NexusParser(beast.util.NexusParser) File(java.io.File)

Example 18 with Alignment

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());
            }
        }
    }
}
Also used : FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) BEASTInterface(beast.core.BEASTInterface)

Example 19 with Alignment

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;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) CellEditorListener(javax.swing.event.CellEditorListener) JTextField(javax.swing.JTextField) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) MouseListener(java.awt.event.MouseListener) TableCellEditor(javax.swing.table.TableCellEditor) Component(java.awt.Component) JComponent(javax.swing.JComponent) JScrollPane(javax.swing.JScrollPane) TableCellRenderer(javax.swing.table.TableCellRenderer) MouseEvent(java.awt.event.MouseEvent) Color(java.awt.Color) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) TableColumn(javax.swing.table.TableColumn) EventObject(java.util.EventObject) DefaultCellEditor(javax.swing.DefaultCellEditor) JTable(javax.swing.JTable) EventObject(java.util.EventObject)

Example 20 with Alignment

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);
}
Also used : FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment)

Aggregations

Alignment (beast.evolution.alignment.Alignment)102 Test (org.junit.Test)43 Sequence (beast.evolution.alignment.Sequence)31 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)30 Tree (beast.evolution.tree.Tree)29 SiteModel (beast.evolution.sitemodel.SiteModel)27 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)22 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)20 ArrayList (java.util.ArrayList)17 UncertainAlignmentTest (test.beast.evolution.alignment.UncertainAlignmentTest)17 Frequencies (beast.evolution.substitutionmodel.Frequencies)13 RealParameter (beast.core.parameter.RealParameter)12 TaxonSet (beast.evolution.alignment.TaxonSet)11 BEASTInterface (beast.core.BEASTInterface)10 ClusterTree (beast.util.ClusterTree)9 Taxon (beast.evolution.alignment.Taxon)6 HKY (beast.evolution.substitutionmodel.HKY)6 Node (beast.evolution.tree.Node)6 TreeParser (beast.util.TreeParser)6 IOException (java.io.IOException)6