本文整理汇总了Java中beast.evolution.alignment.Sequence类的典型用法代码示例。如果您正苦于以下问题:Java Sequence类的具体用法?Java Sequence怎么用?Java Sequence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sequence类属于beast.evolution.alignment包,在下文中一共展示了Sequence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
void process(Alignment data, int iteration) throws IOException, XMLParserException, IllegalArgumentException, IllegalAccessException {
// read template
String templateXML = BeautiDoc.load(templateFile);
templateXML = templateXML.replaceAll("\\$\\(n\\)", iteration+"");
XMLParser parser = new XMLParser();
BEASTInterface b = parser.parseBareFragment(templateXML, false);
// repalce alignment
Alignment a = getAlignment(b);
List<Sequence> sequences = a.sequenceInput.get();
sequences.clear();
sequences.addAll(data.sequenceInput.get());
// write file
String outputFile = outputFileInput.get();
outputFile = outputFile.replaceAll("\\$\\(n\\)", iteration+"");
FileWriter outfile = new FileWriter(outputFile);
Set<BEASTInterface> beastObjects = new HashSet<>();
String xml = new XMLProducer().toXML(b, beastObjects);
outfile.write(xml);
outfile.close();
}
示例2: mutateOverTree
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
public Tree mutateOverTree(Tree base) throws Exception {
ArrayList<Node> currParents = new ArrayList<Node>();
ArrayList<Node> newParents = new ArrayList<Node>();
currParents.add(base.getRoot());
while (currParents.size() > 0) {
for (Node parent : currParents) {
List<Node> children = parent.getChildren();
for (Node child : children) {
double T = Math.abs(child.getHeight() - parent.getHeight());
Sequence parentLang = getSequence(parent);
Sequence newLang = mutateLang(parentLang, T);
child.setMetaData("lang", newLang);
newParents.add(child);
addEmptyTrait(base, child);
}
}
currParents = new ArrayList<Node>(newParents);
newParents = new ArrayList<Node>();
}
return base;
}
示例3: addEmptyTrait
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
protected void addEmptyTrait(Tree t, Node newLangNode) throws Exception {
// Get all nodes in two lists.
List<Node> children = newLangNode.getAllChildNodes();
// Find nodes that aren't children (or trait lang).
List<Node> allNodes = t.getInternalNodes();
allNodes.addAll(t.getExternalNodes());
allNodes.removeAll(children);
allNodes.remove(newLangNode);
// Calculate number of [new] mutations in new language.
Sequence newLang = getSequence(newLangNode);
for (Node n : allNodes) {
Sequence nLang = getSequence(n);
String s = nLang.getData();
Sequence newNodeLang = new Sequence("", s);
while (newNodeLang.getData().length() < newLang.getData().length()) {
String sNew = newNodeLang.getData() + '0';
// System.out.println(newNodeLang);
newNodeLang.dataInput.setValue(sNew, this);
}
n.setMetaData("lang", newNodeLang);
}
}
示例4: mutateLang
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
public Sequence mutateLang(Sequence l, double T) throws Exception {
Sequence newLang = new Sequence("", l.getData());
for (int i = 0; i < newLang.getData().length(); i++) {
int currentTrait = (int) newLang.getData().charAt(i);
// Mutations are exponentially distributed.
double t = Randomizer.nextExponential(rate);
String newSeq;
while (t < T) {
currentTrait = Character.getNumericValue(newLang.getData().charAt(i));
// In binary model, a mutation switches trait.
// If death: check NoEmptyTrait.
if (1 - currentTrait == 0) {
if (noEmptyTraitCheck(newLang)) {
newSeq = replaceCharAt(newLang.getData(), i, Integer.toString((1 - currentTrait)));
} else {
newSeq = newLang.getData();
}
} else {
newSeq = replaceCharAt(newLang.getData(), i, Integer.toString((1 - currentTrait)));
}
newLang.dataInput.setValue(newSeq, newLang);
t += Randomizer.nextExponential(rate);
}
}
return newLang;
}
示例5: mutateOverTree
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
public Tree mutateOverTree(Tree base) throws Exception {
ArrayList<Node> currParents = new ArrayList<Node>();
ArrayList<Node> newParents = new ArrayList<Node>();
currParents.add(base.getRoot());
while (currParents.size() > 0) {
for (Node parent : currParents) {
List<Node> children = parent.getChildren();
for (Node child : children) {
double T = Math.abs(child.getHeight() - parent.getHeight());
Sequence parentLang = getSequence(parent);
Sequence newLang = mutateLang(parentLang, T);
child.setMetaData("lang", newLang);
newParents.add(child);
}
}
currParents = new ArrayList<Node>(newParents);
newParents = new ArrayList<Node>();
}
return base;
}
示例6: TreeSDBorrowingTest
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
private static void TreeSDBorrowingTest(String seq) throws Exception {
seq = "";
for (int j = 0; j < 5; j++) {
seq += '1';
}
Sequence l = new Sequence("", seq);
ExplicitBinaryStochasticDollo sd_mod = new ExplicitBinaryStochasticDollo(0.1, 0.2, 0.0, 0.0,
false);
System.out.println("Tree SD Borrowing Test");
Tree tree = randomYuleTree(2, 0.01);
tree.getRoot().setMetaData("lang", l);
sd_mod.mutateOverTreeBorrowing(tree);
for (Node n : tree.getExternalNodes()) {
Sequence l2 = (Sequence) n.getMetaData("lang");
System.out.println(l2.getData());
}
}
示例7: randomTreeTest
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
private static void randomTreeTest() throws Exception {
StringBuilder traitSB = new StringBuilder();
List<Sequence> seqList = new ArrayList<Sequence>();
for (int i = 0; i < 10; i++) {
String taxonID = "t " + i;
seqList.add(new Sequence(taxonID, "?"));
if (i > 0)
traitSB.append(",");
traitSB.append(taxonID).append("=").append(i);
}
Alignment alignment = new Alignment(seqList, "nucleotide");
ConstantPopulation popFunc = new ConstantPopulation();
popFunc.initByName("popSize", new RealParameter("1.0"));
RandomTree t = new RandomTree();
t.initByName("taxa", alignment, "populationModel", popFunc);
Sequence l = new Sequence("", "");
System.out.println("Tree GTR Borrowing Test");
Tree tree = randomYuleTree(2, 0.01);
tree.getRoot().setMetaData("lang", l);
System.out.println(TreeUtils.getTreeLength(tree, tree.getRoot()));
}
示例8: NoEmptyTraitTest
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
private static void NoEmptyTraitTest() throws Exception {
for (int i = 0; i < 1; i++) {
System.out.println(i);
Sequence l = new Sequence("", "00000000000001");
Tree tree = randomYuleTree(3, 0.06);
tree.getRoot().setMetaData("lang", l);
ExplicitBinaryStochasticDollo sd_mod = new ExplicitBinaryStochasticDollo(0.0, 0.5, 0.0, 0.0, true);
tree = sd_mod.mutateOverTree(tree);
for (Node n : tree.getExternalNodes()) {
Sequence l2 = (Sequence) n.getMetaData("lang");
System.out.println(l2.getData());
}
}
}
示例9: GTRTreeValidation
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
private static void GTRTreeValidation() throws Exception {
ArrayList<Integer> births = new ArrayList<Integer>();
for (int i = 0; i < 10000; i++) {
System.out.println(i);
ExplicitBinaryGTR gtr_mod = new ExplicitBinaryGTR(0.5, 0.0, 0.0, false);
String seq = "";
for (int j = 0; j < 20; j++) {
seq += Integer.toString(Randomizer.nextInt(2));
}
Sequence l = new Sequence("", seq);
Tree tree = randomYuleTree(8, 0.001);
tree.getRoot().setMetaData("lang", l);
tree = gtr_mod.mutateOverTree(tree);
for (Node n : tree.getExternalNodes()) {
Sequence l2 = (Sequence) n.getMetaData("lang");
births.add(LanguageSubsitutionModel.getBirths(l2));
}
}
listToCSV(births, "Utilities/Thesis Graph Generation/gtrtree.csv");
}
示例10: SDTreeValidation
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
private static void SDTreeValidation() throws Exception {
ArrayList<Integer> births = new ArrayList<Integer>();
for (int i = 0; i < 10000; i++) {
System.out.println(i);
ExplicitBinaryStochasticDollo sd_mod = new ExplicitBinaryStochasticDollo(0.5, 0.5, 0.0, 0.0, false);
String seq = "";
Sequence l = new Sequence("", seq);
Tree tree = randomYuleTree(8, 0.01);
tree.getRoot().setMetaData("lang", l);
tree = sd_mod.mutateOverTreeBorrowing(tree);
for (Node n : tree.getExternalNodes()) {
Sequence l2 = (Sequence) n.getMetaData("lang");
births.add(LanguageSubsitutionModel.getBirths(l2));
}
}
listToCSV(births, "Utilities/Thesis Graph Generation/sdtree.csv");
}
示例11: intArray2Sequence
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
/**
* Convert integer representation of sequence into a Sequence
*
* @param seq integer representation of the sequence
* @param node used to determine taxon for sequence
* @return Sequence
*/
Sequence intArray2Sequence(int[] seq, Node node) {
DataType dataType = m_data.get().getDataType();
String seqString = dataType.state2string(seq);
// StringBuilder seq = new StringBuilder();
// String map = m_data.get().getMap();
// if (map != null) {
// for (int i = 0; i < m_sequenceLength; i++) {
// seq.append(map.charAt(seq[i]));
// }
// } else {
// for (int i = 0; i < m_sequenceLength-1; i++) {
// seq.append(seq[i] + ",");
// }
// seq.append(seq[m_sequenceLength-1] + "");
// }
String taxon = m_data.get().getTaxaNames().get(node.getNr());
return new Sequence(taxon, seqString);
}
示例12: intArray2Sequence
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
/**
* Convert integer representation of sequence into a Sequence
*
* @param seq integer representation of the sequence
* @param node used to determine taxon for sequence
* @return Sequence
* @
*/
Sequence intArray2Sequence(int[] seq, Node node) {
DataType dataType = m_data.get().getDataType();
String seqString = dataType.state2string(seq);
// StringBuilder seq = new StringBuilder();
// String map = m_data.get().getMap();
// if (map != null) {
// for (int i = 0; i < m_sequenceLength; i++) {
// seq.append(map.charAt(seq[i]));
// }
// } else {
// for (int i = 0; i < m_sequenceLength-1; i++) {
// seq.append(seq[i] + ",");
// }
// seq.append(seq[m_sequenceLength-1] + "");
// }
List<Sequence> taxa = m_data.get().sequenceInput.get();
String taxon = taxa.get(node.getNr()).taxonInput.get();
return new Sequence(taxon, seqString);
}
示例13: needsDrawing
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
boolean needsDrawing(BEASTInterface beastObject) {
if (beastObject == null) {
return true;
}
if (!m_bViewOperators && beastObject instanceof beast.core.Operator) {
return false;
}
if (!m_bViewLoggers && beastObject instanceof beast.core.Logger) {
return false;
}
if (!m_bViewSequences && beastObject instanceof Sequence) {
return false;
}
if (!m_bViewState && beastObject instanceof beast.core.State) {
return false;
}
return true;
}
示例14: testNarrowExchange4Taxa
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
@Test
public void testNarrowExchange4Taxa() throws Exception {
int runs = 10000;
Randomizer.setSeed(666);
// test that going from source tree to target tree
// is as likely as going the other way around
// taking the HR in account.
Sequence A = new Sequence("A", "A");
Sequence B = new Sequence("B", "A");
Sequence C = new Sequence("C", "A");
Sequence D = new Sequence("D", "A");
Alignment data = new Alignment();
data.initByName("sequence", A, "sequence", B, "sequence", C, "sequence", D,
"dataType", "nucleotide"
);
String sourceTree = "((A:2.0,B:2.0):1.0,(C:1.0,D:1.0):2.0):0.0"; // ((A,B),(C,D))
String targetTree = "((A:2.0,(C:1.0,D:1.0):1.0):1.0,B:3.0):0.0"; // ((A,(C,D)),B)
testNarrowExchange(sourceTree, targetTree, runs, data);
}
示例15: testNarrowExchange5Taxa
import beast.evolution.alignment.Sequence; //导入依赖的package包/类
@Test
public void testNarrowExchange5Taxa() throws Exception {
int runs = 10000;
Randomizer.setSeed(666);
Sequence A = new Sequence("A", "A");
Sequence B = new Sequence("B", "A");
Sequence C = new Sequence("C", "A");
Sequence D = new Sequence("D", "A");
Sequence E = new Sequence("E", "A");
Alignment data = new Alignment();
data.initByName("sequence", A, "sequence", B, "sequence", C, "sequence", D, "sequence", E,
"dataType", "nucleotide"
);
String sourceTree = "(((A:2.0,B:2.0):1.0,(C:1.0,D:1.0):2.0):1.0,E:4.0):0.0"; // (((A,B),(C,D)),E)
String targetTree = "(((A:2.0,(C:1.0,D:1.0):1.0):1.0,B:3.0):1.0,E:4.0):0.0"; // (((A,(C,D)),B),E)
testNarrowExchange(sourceTree, targetTree, runs, data);
}