use of beast.evolution.alignment.Alignment in project bacter by tgvaughan.
the class ACGLikelihoodSlow method calculateLogP.
@Override
public double calculateLogP() {
logP = 0.0;
for (Region region : acg.getRegions(locus)) {
Alignment margAlign = createMarginalAlignment(alignment, acg, region);
Tree margTree = new Tree(new MarginalTree(acg, region).getRoot());
TreeLikelihood treeLikelihood = new TreeLikelihood();
treeLikelihood.initByName("data", margAlign, "tree", margTree, "siteModel", siteModel, "useAmbiguities", useAmbiguitiesInput.get());
logP += treeLikelihood.calculateLogP();
}
return logP;
}
use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.
the class BeautiAlignmentProvider method parseBeast1XML.
private static BEASTInterface parseBeast1XML(String ID, String xml) throws SAXException, IOException, ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
doc.normalize();
NodeList alignments = doc.getElementsByTagName("alignment");
Alignment alignment = new Alignment();
alignment.dataTypeInput.setValue("nucleotide", alignment);
// parse first alignment
org.w3c.dom.Node node = alignments.item(0);
String dataTypeName = node.getAttributes().getNamedItem("dataType").getNodeValue();
int totalCount = 4;
if (dataTypeName == null) {
alignment.dataTypeInput.setValue("integer", alignment);
} else if (dataTypeName.toLowerCase().equals("dna") || dataTypeName.toLowerCase().equals("nucleotide")) {
alignment.dataTypeInput.setValue("nucleotide", alignment);
totalCount = 4;
} else if (dataTypeName.toLowerCase().equals("aminoacid") || dataTypeName.toLowerCase().equals("protein")) {
alignment.dataTypeInput.setValue("aminoacid", alignment);
totalCount = 20;
} else {
alignment.dataTypeInput.setValue("integer", alignment);
}
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
org.w3c.dom.Node child = children.item(i);
if (child.getNodeName().equals("sequence")) {
Sequence sequence = new Sequence();
// find the taxon
String taxon = "";
NodeList sequenceChildren = child.getChildNodes();
for (int j = 0; j < sequenceChildren.getLength(); j++) {
org.w3c.dom.Node child2 = sequenceChildren.item(j);
if (child2.getNodeName().equals("taxon")) {
taxon = child2.getAttributes().getNamedItem("idref").getNodeValue();
}
}
String data = child.getTextContent();
sequence.initByName("totalcount", totalCount, "taxon", taxon, "value", data);
sequence.setID("seq_" + taxon);
alignment.sequenceInput.setValue(sequence, alignment);
}
}
alignment.setID(ID);
alignment.initAndValidate();
return alignment;
}
use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.
the class AlignmentListInputEditor method splitItem.
// replaceItem
void splitItem() {
int[] selected = getTableRowSelection();
if (selected.length == 0) {
JOptionPane.showMessageDialog(this, "Select partitions to split, before hitting the split button");
return;
}
String[] options = { "{1,2} + 3", "{1,2} + 3 frame 2", "{1,2} + 3 frame 3", "1 + 2 + 3", "1 + 2 + 3 frame 2", "1 + 2 + 3 frame 3" };
String option = (String) JOptionPane.showInputDialog(null, "Split selected alignments into partitions", "Option", JOptionPane.WARNING_MESSAGE, null, options, "1 + 2 + 3");
if (option == null) {
return;
}
String[] filters = null;
String[] ids = null;
if (option.equals(options[0])) {
filters = new String[] { "1::3,2::3", "3::3" };
ids = new String[] { "_1,2", "_3" };
} else if (option.equals(options[1])) {
filters = new String[] { "1::3,3::3", "2::3" };
ids = new String[] { "_1,2", "_3" };
} else if (option.equals(options[2])) {
filters = new String[] { "2::3,3::3", "1::3" };
ids = new String[] { "_1,2", "_3" };
} else if (option.equals(options[3])) {
filters = new String[] { "1::3", "2::3", "3::3" };
ids = new String[] { "_1", "_2", "_3" };
} else if (option.equals(options[4])) {
filters = new String[] { "2::3", "3::3", "1::3" };
ids = new String[] { "_1", "_2", "_3" };
} else if (option.equals(options[5])) {
filters = new String[] { "3::3", "1::3", "2::3" };
ids = new String[] { "_1", "_2", "_3" };
} else {
return;
}
for (int i = selected.length - 1; i >= 0; i--) {
int rowNr = selected[i];
Alignment alignment = alignments.remove(rowNr);
getDoc().delAlignmentWithSubnet(alignment);
try {
List<Alignment> newAlignments = new ArrayList<>();
for (int j = 0; j < filters.length; j++) {
FilteredAlignment f = new FilteredAlignment();
f.initByName("data", alignment, "filter", filters[j], "dataType", alignment.dataTypeInput.get());
f.setID(alignment.getID() + ids[j]);
getDoc().addAlignmentWithSubnet(f, getDoc().beautiConfig.partitionTemplate.get());
newAlignments.add(f);
}
alignments.addAll(newAlignments);
partitionCount = alignments.size();
tableData = null;
initTableData();
if (newAlignments.size() == 2) {
link(TREE_COLUMN, alignments.size() - 1, alignments.size() - 2);
} else {
link(TREE_COLUMN, alignments.size() - 2, alignments.size() - 3);
tableData = null;
initTableData();
link(TREE_COLUMN, alignments.size() - 1, alignments.size() - 2);
}
} catch (Exception e) {
e.printStackTrace();
}
}
refreshPanel();
}
use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.
the class Beauti method addAlignmentProviderMenus.
private void addAlignmentProviderMenus(JMenu fileMenu) {
List<BeautiAlignmentProvider> providers = doc.beautiConfig.alignmentProvider;
for (BeautiAlignmentProvider provider : providers) {
AbstractAction action = new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
try {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
// get user-specified alignments
List<BEASTInterface> beastObjects = provider.getAlignments(doc);
if (beastObjects != null) {
for (BEASTInterface o : beastObjects) {
if (o instanceof Alignment) {
try {
BeautiDoc.createTaxonSet((Alignment) o, doc);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
doc.connectModel();
doc.fireDocHasChanged();
if (beastObjects != null) {
for (BEASTInterface o : beastObjects) {
if (o instanceof MRCAPrior) {
doc.addMRCAPrior((MRCAPrior) o);
}
}
}
a_save.setEnabled(true);
a_saveas.setEnabled(true);
} catch (Exception exx) {
exx.printStackTrace();
String text = "Something went wrong importing the alignment:\n";
JTextArea textArea = new JTextArea(text);
textArea.setColumns(30);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.append(exx.getMessage());
textArea.setSize(textArea.getPreferredSize().width, 1);
textArea.setOpaque(false);
JOptionPane.showMessageDialog(null, textArea, "Error importing alignment", JOptionPane.WARNING_MESSAGE);
}
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
};
String providerInfo = provider.toString().replaceAll("Add ", "Add partition for ");
action.putValue(Action.SHORT_DESCRIPTION, providerInfo);
action.putValue(Action.LONG_DESCRIPTION, providerInfo);
action.putValue(Action.NAME, provider.toString());
fileMenu.add(action);
}
}
use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.
the class BeautiConfig method selectAlignments.
/**
* if fileArray == null, then use getAlignments(doc)
* @param doc
* @param parent
* @param fileArray
* @return a list of alignments based on the user selected alignment provider
*/
public List<BEASTInterface> selectAlignments(BeautiDoc doc, JComponent parent, File[] fileArray) {
List<BeautiAlignmentProvider> providers = alignmentProvider;
BeautiAlignmentProvider selectedProvider = null;
if (providers.size() == 1) {
selectedProvider = providers.get(0);
} else {
selectedProvider = (BeautiAlignmentProvider) JOptionPane.showInputDialog(parent, "Select what to add", "Add partition", JOptionPane.QUESTION_MESSAGE, null, providers.toArray(), providers.get(0));
if (selectedProvider == null) {
return null;
}
}
List<BEASTInterface> beastObjects = selectedProvider.getAlignments(doc, fileArray);
// create taxon sets, if any
if (beastObjects != null) {
for (BEASTInterface o : beastObjects) {
if (o instanceof Alignment) {
try {
BeautiDoc.createTaxonSet((Alignment) o, doc);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
doc.connectModel();
if (beastObjects != null) {
for (BEASTInterface o : beastObjects) {
if (o instanceof MRCAPrior) {
doc.addMRCAPrior((MRCAPrior) o);
}
}
}
return beastObjects;
}
Aggregations