use of beast.evolution.alignment.Sequence in project bacter by tgvaughan.
the class ACGLikelihoodApproxTest method testPairwiseDistances.
@Test
public void testPairwiseDistances() throws Exception {
List<Sequence> sequences = new ArrayList<>();
// 01234567890123456789
sequences.add(new Sequence("t1", "AAAAAAAAAAAAAAAAAAAA"));
sequences.add(new Sequence("t2", "AAAACAAAAAAGAAAAAAAA"));
sequences.add(new Sequence("t3", "CCCCCCCCCCCCCCCCCCCC"));
Alignment alignment = new Alignment(sequences, "nucleotide");
Locus locus = new Locus("locus", alignment);
ConversionGraph acg = new ConversionGraph();
ClusterTree tree = new ClusterTree();
tree.initByName("clusterType", "upgma", "taxa", locus.getAlignment());
acg.assignFrom(tree);
acg.initByName("locus", locus);
ACGLikelihoodApprox likelihoodApprox = new ACGLikelihoodApprox();
likelihoodApprox.initByName("acg", acg, "substitutionRate", "1.0", "alignment", alignment, "locus", locus);
Assert.assertEquals(0, likelihoodApprox.getPairwiseDistance(0, 1, 0, 4));
Assert.assertEquals(1, likelihoodApprox.getPairwiseDistance(0, 1, 0, 5));
Assert.assertEquals(1, likelihoodApprox.getPairwiseDistance(0, 1, 0, 11));
Assert.assertEquals(2, likelihoodApprox.getPairwiseDistance(0, 1, 0, 12));
Assert.assertEquals(2, likelihoodApprox.getPairwiseDistance(0, 1, 0, 20));
Assert.assertEquals(5, likelihoodApprox.getPairwiseDistance(1, 2, 2, 8));
Assert.assertEquals(19, likelihoodApprox.getPairwiseDistance(1, 2, 0, 20));
Assert.assertEquals(6, likelihoodApprox.getPairwiseDistance(0, 2, 2, 8));
Assert.assertEquals(20, likelihoodApprox.getPairwiseDistance(0, 2, 0, 20));
}
use of beast.evolution.alignment.Sequence in project bacter by tgvaughan.
the class SimulatedAlignment method simulate.
/**
* Perform actual sequence simulation.
*/
private void simulate(Locus locus) {
Node cfRoot = acg.getRoot();
int nTaxa = acg.getLeafNodeCount();
double[] categoryProbs = siteModel.getCategoryProportions(cfRoot);
int nCategories = siteModel.getCategoryCount();
int nStates = dataType.getStateCount();
double[][] transitionProbs = new double[nCategories][nStates * nStates];
int[][] alignment = new int[nTaxa][locus.getSiteCount()];
for (Region region : acg.getRegions(locus)) {
int thisLength = region.getRegionLength();
MarginalTree marginalTree = new MarginalTree(acg, region);
int[] categories = new int[thisLength];
for (int i = 0; i < thisLength; i++) categories[i] = Randomizer.randomChoicePDF(categoryProbs);
int[][] regionAlignment = new int[nTaxa][thisLength];
Node thisRoot = marginalTree.getRoot();
int[] parentSequence = new int[region.getRegionLength()];
double[] frequencies = siteModel.getSubstitutionModel().getFrequencies();
for (int i = 0; i < parentSequence.length; i++) parentSequence[i] = Randomizer.randomChoicePDF(frequencies);
traverse(thisRoot, parentSequence, categories, transitionProbs, regionAlignment);
// DEBUG: Count differences
int segsites = 0;
for (int s = 0; s < regionAlignment[0].length; s++) {
int state = regionAlignment[0][s];
for (int l = 1; l < nTaxa; l++) {
if (state != regionAlignment[l][s]) {
segsites += 1;
break;
}
}
}
System.out.println(segsites + " segregating sites in region " + region);
copyToAlignment(alignment, regionAlignment, region);
}
for (int leafIdx = 0; leafIdx < nTaxa; leafIdx++) {
String sSeq = dataType.encodingToString(alignment[leafIdx]);
String sTaxon = acg.getNode(leafIdx).getID();
sequenceInput.setValue(new Sequence(sTaxon, sSeq), this);
}
}
use of beast.evolution.alignment.Sequence 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.Sequence in project beast2 by CompEvol.
the class FilteredAlignmentTest method getAlignmentNoTInHuman.
public static Alignment getAlignmentNoTInHuman() throws Exception {
Sequence human = new Sequence("0human", "AAAACCCCGGGGAAAA");
Sequence chimp = new Sequence("1chimp", "ACGTACGTACGTACGT");
Alignment data = new Alignment();
data.initByName("sequence", human, "sequence", chimp, "dataType", "nucleotide");
return data;
}
use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.
the class FilteredAlignmentTest method getAlignment3.
public static Alignment getAlignment3() throws Exception {
// reordered from getAlignment() & with duplicates
Sequence human = new Sequence("0human", "GGGAAA");
Sequence chimp = new Sequence("1chimp", "AGGACA");
Alignment data = new Alignment();
data.initByName("sequence", human, "sequence", chimp, "dataType", "nucleotide");
return data;
}
Aggregations