当前位置: 首页>>代码示例>>Java>>正文


Java ConstantPopulation.initByName方法代码示例

本文整理汇总了Java中beast.evolution.tree.coalescent.ConstantPopulation.initByName方法的典型用法代码示例。如果您正苦于以下问题:Java ConstantPopulation.initByName方法的具体用法?Java ConstantPopulation.initByName怎么用?Java ConstantPopulation.initByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在beast.evolution.tree.coalescent.ConstantPopulation的用法示例。


在下文中一共展示了ConstantPopulation.initByName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: randomTreeTest

import beast.evolution.tree.coalescent.ConstantPopulation; //导入方法依赖的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()));
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:27,代码来源:BeastBorrowingPluginTest.java

示例2: testConstantPopulation

import beast.evolution.tree.coalescent.ConstantPopulation; //导入方法依赖的package包/类
public void testConstantPopulation() throws Exception {
        // *********** 3 taxon **********
        Tree tree = getTree(data, trees[0]);
        TreeIntervals treeIntervals = new TreeIntervals();
        treeIntervals.initByName("tree", tree);

        ConstantPopulation cp = new ConstantPopulation();
        cp.initByName("popSize", Double.toString(pop));

        Coalescent coal = new Coalescent();
        coal.initByName("treeIntervals", treeIntervals, "populationModel", cp);

        double logL = coal.calculateLogP();

        assertEquals(logL, -(4 / pop) - 2 * Math.log(pop), PRECISION);

        // *********** 4 taxon **********
//        tree = getTree(data, trees[1]);
//        treeIntervals = new TreeIntervals();
//        treeIntervals.initByName("tree", tree);
//
//        cp = new ConstantPopulation();
//        cp.initByName("popSize", Double.toString(pop));
//
//        coal = new Coalescent();
//        coal.initByName("treeIntervals", treeIntervals, "populationModel", cp);
//
//        logL = coal.calculateLogP();
//
//        assertEquals(logL, -(4 / pop) - 2 * Math.log(pop), PRECISION);

    }
 
开发者ID:CompEvol,项目名称:beast2,代码行数:33,代码来源:CoalescentTest.java

示例3: getTree

import beast.evolution.tree.coalescent.ConstantPopulation; //导入方法依赖的package包/类
static public Tree getTree(TaxonSet taxa) throws Exception {
    Tree tree = new RandomTree();
    TraitSet dates = getDates(taxa);
    ConstantPopulation constant = new ConstantPopulation();
    constant.initByName("popSize", new RealParameter("5.0"));
    tree.initByName(
            "taxonset", taxa,
            "populationModel", constant,
            "trait", dates);
    return tree;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:12,代码来源:UnorderedAlignmentsTest.java

示例4: main

import beast.evolution.tree.coalescent.ConstantPopulation; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        ConversionGraph acg = new ConversionGraph();
        ConstantPopulation popFunc = new ConstantPopulation();


        AddRemoveConversion operator = new AddRemoveConversion();
        operator.initByName("weight", 1.0,
            "acg", acg,
            "populationModel", popFunc,
            "rho", new RealParameter(Double.toString(1.0/10000.0)),
            "delta", new RealParameter("50.0"));
        popFunc.initByName("popSize", new RealParameter("1.0"));

        TaxonSet taxonSet = new TaxonSet();
        taxonSet.taxonsetInput.setValue(new Taxon("t1"), taxonSet);
        taxonSet.taxonsetInput.setValue(new Taxon("t2"), taxonSet);

        Locus locus = new Locus("locus", 10000);

        try (PrintStream ps = new PrintStream("out.txt")) {
            for (int i=0; i<100000; i++) {
                acg.initByName(
                        "locus", locus,
                        "taxonset", taxonSet,
                        "fromString", "(0:1.0,1:1.0)2:0.0;");

                operator.drawNewConversion();
                
                ps.println(acg.getConversions(locus).get(0).getStartSite() + " "
                    + acg.getConversions(locus).get(0).getEndSite());
            }
        }
    }
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:35,代码来源:AddRemoveConversion.java

示例5: getRandomTree

import beast.evolution.tree.coalescent.ConstantPopulation; //导入方法依赖的package包/类
public Tree getRandomTree(double popSize, Alignment dummyAlg, String[] taxa, int[] dates) throws Exception {
        TaxonSet taxonSet = new TaxonSet(dummyAlg);
        StringBuilder traitSB = new StringBuilder();
        for (int i=0; i<taxa.length; i++) {
            if (i>0)
                traitSB.append(",");
            traitSB.append(taxa[i]).append("=").append(dates[i]);
        }
//        out.println(traitSB.toString());

        TraitSet timeTrait = new TraitSet();
        timeTrait.initByName(
                "traitname", "date-backward",
                "taxa", taxonSet,
                "value", traitSB.toString());

        ConstantPopulation popFunc = new ConstantPopulation();
        popFunc.initByName("popSize", new RealParameter(Double.toString(popSize)));

        // Create RandomTree and TreeInterval instances
        RandomTree tree = new RandomTree();
//        TreeIntervals intervals = new TreeIntervals();

        tree.initByName(
                "taxa", dummyAlg,
                "populationModel", popFunc,
                "trait", timeTrait);

//        intervals.initByName("tree", tree);

        return tree;
    }
 
开发者ID:CompEvol,项目名称:NZGOT,代码行数:33,代码来源:TreeSeqSimulatorCustomized.java

示例6: getRandomTree

import beast.evolution.tree.coalescent.ConstantPopulation; //导入方法依赖的package包/类
public Tree getRandomTree(double popSize, Alignment dummyAlg, String[] taxa, int[] dates) throws Exception {
        TaxonSet taxonSet = new TaxonSet(dummyAlg);
        traitSB = new StringBuilder();
        for (int i=0; i<taxa.length; i++) {
            if (i>0)
                traitSB.append(",");
            traitSB.append(taxa[i]).append("=").append(dates[i]);
        }
//        out.println(traitSB.toString());

        TraitSet timeTrait = new TraitSet();
        timeTrait.initByName(
                "traitname", traitName,
                "taxa", taxonSet,
                "value", traitSB.toString());

        ConstantPopulation popFunc = new ConstantPopulation();
        popFunc.initByName("popSize", new RealParameter(Double.toString(popSize)));

        // Create RandomTree and TreeInterval instances
        RandomTree tree = new RandomTree();
//        TreeIntervals intervals = new TreeIntervals();

        tree.initByName(
                "taxa", dummyAlg,
                "populationModel", popFunc,
                "trait", timeTrait);

//        intervals.initByName("tree", tree);

        return tree;
    }
 
开发者ID:CompEvol,项目名称:NZGOT,代码行数:33,代码来源:TreeSeqSimulator.java

示例7: testMascotUnstructured

import beast.evolution.tree.coalescent.ConstantPopulation; //导入方法依赖的package包/类
@Test
public void testMascotUnstructured(){
	
	//build alignment
	Sequence sequence1 = new Sequence();
	Sequence sequence2 = new Sequence();
	Sequence sequence3 = new Sequence();
	Sequence sequence4 = new Sequence();
	Sequence sequence5 = new Sequence();
	sequence1.initByName("taxon", "a1", "value", "???");
	sequence2.initByName("taxon", "a2", "value", "???");
	sequence3.initByName("taxon", "a3", "value", "???");
	sequence4.initByName("taxon", "b1", "value", "???");
	sequence5.initByName("taxon", "b2", "value", "???");
	
	
	Alignment alignment = new Alignment();
	alignment.initByName("sequence", sequence1,"sequence", sequence2,"sequence", sequence3,"sequence", sequence4, "sequence", sequence5);
	
	
	TaxonSet taxa = new TaxonSet();
	taxa.initByName("alignment", alignment);
	
	//build trait set
	TraitSet traitSet = new TraitSet();
	traitSet.initByName("value", "a1=a,a2=a,a3=a,b1=a,b2=a", "traitname", "type", "taxa", taxa);
	
	Tree tree = new TreeParser("(((a1:1,a2:2):1,(b1:1,b2:1.5):2):1,a3:1)");
	Tree traitTree = new Tree();
	tree.initByName("taxonset", taxa, "trait", traitSet);
	StructuredTreeIntervals st = new StructuredTreeIntervals();
	st.initByName("tree",tree);
	
	// build constant dynamics
	RealParameter Ne = new RealParameter("1.5 2");
	RealParameter backwardsMigration = new RealParameter("0 0");
	int dim = 2;
	Constant constant = new Constant();
	constant.initByName("backwardsMigration", backwardsMigration, "Ne", Ne, "dimension", dim, "typeTrait", traitSet);

	
	Mascot mascot = new Mascot();
	
	mascot.initByName("structuredTreeIntervals", st, "dynamics", constant);
	
	// also set up the constant coalescent
	TreeIntervals ti = new TreeIntervals();
	ti.initByName("tree",tree);
	
	RealParameter Nec = new RealParameter("1.5");
	
	
	ConstantPopulation cp = new ConstantPopulation();
	cp.initByName("popSize", Nec);
	
	Coalescent coalescent = new Coalescent();
	coalescent.initByName("populationModel", cp, "treeIntervals", ti);
	
	Assert.assertTrue(Math.abs(mascot.calculateLogP()-coalescent.calculateLogP())<0.000000001);
}
 
开发者ID:nicfel,项目名称:Mascot,代码行数:61,代码来源:MascotTest.java

示例8: testLikelihoodUsingSimulatedData

import beast.evolution.tree.coalescent.ConstantPopulation; //导入方法依赖的package包/类
@Test
public void testLikelihoodUsingSimulatedData() throws Exception {

    ConstantPopulation popFunc = new ConstantPopulation();
    popFunc.initByName("popSize", new RealParameter("1.0"));

    Locus locus = new Locus("locus", 10000);
    TaxonSet taxonSet = getTaxonSet(10);
    
    ConversionGraph acg = new SimulatedACG();
    acg.initByName(
            "rho", 5.0/locus.getSiteCount(),
            "delta", 1000.0,
            "populationModel", popFunc,
            "locus", locus,
            "taxonset", taxonSet);
    
    System.out.println(acg);

    // Site model:
    JukesCantor jc = new JukesCantor();
    jc.initByName();
    SiteModel siteModel = new SiteModel();
    siteModel.initByName(
            "mutationRate", new RealParameter("1"),
            "substModel", jc);

    // Simulate alignment:
    SimulatedAlignment alignment = new SimulatedAlignment();
    alignment.initByName(
            "acg", acg,
            "siteModel", siteModel,
            "outputFileName", "simulated_alignment.nexus",
            "useNexus", true);
    
    // Calculate likelihood:
    ACGLikelihood argLikelihood = new ACGLikelihood();
    argLikelihood.initByName(
            "locus", locus,
            "data", alignment,
            "tree", acg,
            "siteModel", siteModel);
    
    double logP = argLikelihood.calculateLogP();

    // Compare product of likelihoods of "marginal alignments" with
    // likelihood computed using RGL.
    ACGLikelihoodSlow argLikelihoodSlow = new ACGLikelihoodSlow();
    argLikelihoodSlow.initByName(
            "locus", locus,
            "data", alignment,
            "tree", acg,
            "siteModel", siteModel);

    double logPprime = argLikelihoodSlow.calculateLogP();


    double relError = 2.0*Math.abs(logP-logPprime)/Math.abs(logP + logPprime);
    System.out.format("logP=%g\nlogPprime=%g\nrelError=%g\n",
            logP, logPprime, relError);
    assertTrue(relError<1e-13);
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:63,代码来源:ACGLikelihoodTest.java

示例9: drawNewConversion

import beast.evolution.tree.coalescent.ConstantPopulation; //导入方法依赖的package包/类
/**
    * Tests that probability density of forward move calculated
by drawNewConversion() matches probability density of backward
move calculated by getConversionProb().
    * 
    * @throws Exception 
    */
   @Test
   public void testHR() throws Exception {
       
       ConstantPopulation popFunc = new ConstantPopulation();
       popFunc.initByName("popSize", new RealParameter("1.0"));

       Locus locus = new Locus("locus", 10000);
       TaxonSet taxonSet = getTaxonSet(10);

       SimulatedACG acg = new SimulatedACG();
       acg.initByName(
               "rho", 1.0/locus.getSiteCount(),
               "delta", 50.0,
               "locus", locus,
               "taxonset", taxonSet,
               "populationModel", popFunc);
       

       AddRemoveConversion operator = new AddRemoveConversion();
       
       // Loop until a valid proposal is made
       double logP1;
       List<Conversion> oldConversions;
       do {
           operator.initByName(
                   "weight", 1.0,
                   "acg", acg,
                   "delta", new RealParameter("50.0"),
                   "populationModel", popFunc);
           
           oldConversions = Lists.newArrayList(
                   acg.getConversions(locus));
       
           logP1 = operator.drawNewConversion();
       } while (Double.isInfinite(logP1));
       
       System.out.println("logP1 = " + logP1);
       
       // Identify new recomination
       Conversion newRecomb = null;
       for (Conversion recomb : acg.getConversions(locus)) {
           if (!oldConversions.contains(recomb))
               newRecomb = recomb;
       }
       assertNotNull(newRecomb);
       
       double logP2 = operator.getConversionProb(newRecomb);
       System.out.println("logP2 = " + logP2);
       
       assertTrue(Math.abs(logP1-logP2)<1e-10);
   }
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:59,代码来源:AddRemoveConversionTest.java

示例10: testProbability

import beast.evolution.tree.coalescent.ConstantPopulation; //导入方法依赖的package包/类
/**
 * Tests whether probability of proposing a conversion lines up with
 * conversion probability found in ACGCoalescent.
 * @throws java.lang.Exception
 */
@Test
public void testProbability() throws Exception {

    ConstantPopulation popFunc = new ConstantPopulation();
    popFunc.initByName("popSize", new RealParameter("1.0"));

    Locus locus = new Locus("locus", 10000);

    TaxonSet taxonSet = getTaxonSet(10);
    
    SimulatedACG acg = new SimulatedACG();
    acg.initByName(
            "rho", 1.0/locus.getSiteCount(),
            "delta", 50.0,
            "locus", locus,
            "taxonset", taxonSet,
            "populationModel", popFunc);
    
    RealParameter rho = new RealParameter(Double.toString(1.0/locus.getSiteCount()));
    RealParameter delta = new RealParameter("50.0");

    AddRemoveConversion operator = new AddRemoveConversion();
    operator.initByName(
        "weight", 1.0,
        "acg", acg,
        "delta", delta,
        "populationModel", popFunc);

    ACGCoalescent coal = new ACGCoalescent();
    coal.initByName(
        "tree", acg,
        "populationModel", popFunc,
        "rho", rho,
        "delta", delta);
    
    double logP1 = 0.0;
    double logP2 = 0.0;
    for (Conversion conv : acg.getConversions(locus)) {
        logP1 += operator.getConversionProb(conv);
        logP2 += coal.calculateConversionLogP(conv);
    }

    System.out.println("logP1 = " + logP1);
    System.out.println("logP2 = " + logP2);

    assertTrue(Math.abs(logP1-logP2)<1e-10);

}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:54,代码来源:AddRemoveConversionTest.java


注:本文中的beast.evolution.tree.coalescent.ConstantPopulation.initByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。