Search in sources :

Example 21 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class TaxaEditorTableModel method removeLastRow.

// END: addEmptyRow
public void removeLastRow() {
    int lastIndex = taxaSet.getTaxonCount() - 1;
    Taxon taxon = taxaSet.getTaxon(lastIndex);
    taxaSet.removeTaxon(taxon);
    this.fireTableDataChanged();
}
Also used : Taxon(dr.evolution.util.Taxon)

Example 22 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class AlloppSpeciesNetworkModel method testExampleNetworkToMulLabTree.

/* *********************** TEST CODE **********************************/
/*
      * Test of conversion from network to mullab tree
      * 	 * 2011-05-07 It is called from testAlloppSpeciesNetworkModel.java.
      * I don't know how to put the code in there without
      * making lots public here.
      */
// grjtodo-oneday. should be possible to pass stuff in nmltTEST. Currently
// it just signals that this is indeed a test.
//AR - removing this as it creates a dependency to test.dr.* which is bad...
public String testExampleNetworkToMulLabTree(int testcase) {
    int ntaxa = apsp.numberOfSpecies();
    Taxon[] spp = new Taxon[ntaxa];
    for (int tx = 0; tx < ntaxa; ++tx) {
        spp[tx] = new Taxon(apsp.apspeciesName(tx));
    }
    // 1,2,3 (names b,c,d) are tets, 0,4 are dips (names a,e)
    double tetheight0 = 0.0;
    double tetheight1 = 0.0;
    double tetheight2 = 0.0;
    // case 1. one tettree with one foot in each diploid branch
    // case 2. one tettree with both feet in one diploid branch
    // case 3. one tettree with one joined
    // case 4. two tettrees, 2+1, first with one foot in each diploid
    // branch, second joined
    // case 5. three tettrees, 1+1+1, one of each type of feet, as in cases 1-3
    int ntettrees = 0;
    switch(testcase) {
        case 1:
        case 2:
        case 3:
            ntettrees = 1;
            break;
        case 4:
            ntettrees = 2;
            break;
        case 5:
            ntettrees = 3;
            break;
    }
    tettrees = new ArrayList<AlloppLeggedTree>(ntettrees);
    Taxon l0 = new Taxon("L0");
    Taxon l1 = new Taxon("L1");
    Taxon l2 = new Taxon("L2");
    Taxon r0 = new Taxon("R0");
    Taxon r1 = new Taxon("R1");
    Taxon r2 = new Taxon("R2");
    Taxon[] tets123 = { spp[1], spp[2], spp[3] };
    Taxon[] tets12 = { spp[1], spp[2] };
    Taxon[] tets1 = { spp[1] };
    Taxon[] tets2 = { spp[2] };
    Taxon[] tets3 = { spp[3] };
    Taxon[] dips = new Taxon[0];
    switch(testcase) {
        case 1:
            tettrees.add(new AlloppLeggedTree(tets123));
            tetheight0 = tettrees.get(0).getRootHeight();
            dips = new Taxon[] { spp[0], l0, r0, spp[4] };
            break;
        case 2:
            tettrees.add(new AlloppLeggedTree(tets123));
            tetheight0 = tettrees.get(0).getRootHeight();
            dips = new Taxon[] { spp[0], l0, r0, spp[4] };
            break;
        case 3:
            tettrees.add(new AlloppLeggedTree(tets123));
            tetheight0 = tettrees.get(0).getRootHeight();
            dips = new Taxon[] { spp[0], l0, r0, spp[4] };
            break;
        case 4:
            tettrees.add(new AlloppLeggedTree(tets12));
            tettrees.add(new AlloppLeggedTree(tets3));
            tetheight0 = tettrees.get(0).getRootHeight();
            tetheight1 = tettrees.get(1).getRootHeight();
            dips = new Taxon[] { spp[0], l0, r0, l1, r1, spp[4] };
            break;
        case 5:
            tettrees.add(new AlloppLeggedTree(tets1));
            tettrees.add(new AlloppLeggedTree(tets2));
            tettrees.add(new AlloppLeggedTree(tets3));
            tetheight0 = tettrees.get(0).getRootHeight();
            tetheight1 = tettrees.get(1).getRootHeight();
            tetheight2 = tettrees.get(2).getRootHeight();
            dips = new Taxon[] { spp[0], l0, r0, l1, r1, l2, r2, spp[4] };
            break;
    }
    assert dips.length >= 2;
    int ndhnodes = 2 * dips.length - 1;
    SimpleNode[] dhnodes = new SimpleNode[ndhnodes];
    for (int n = 0; n < ndhnodes; n++) {
        dhnodes[n] = new SimpleNode();
        if (n < dips.length) {
            dhnodes[n].setTaxon(dips[n]);
        } else {
            dhnodes[n].setTaxon(new Taxon(""));
        }
    }
    int dhroot = -1;
    switch(testcase) {
        case 1:
            dhnodes[1].setHeight(tetheight0 + 1.0);
            dhnodes[2].setHeight(tetheight0 + 1.0);
            addSimpleNodeChildren(dhnodes[4], dhnodes[0], dhnodes[1], 1.0);
            addSimpleNodeChildren(dhnodes[5], dhnodes[2], dhnodes[3], 1.0);
            addSimpleNodeChildren(dhnodes[6], dhnodes[4], dhnodes[5], 1.0);
            dhroot = 6;
            break;
        case 2:
            dhnodes[1].setHeight(tetheight0 + 1.0);
            dhnodes[2].setHeight(tetheight0 + 1.0);
            addSimpleNodeChildren(dhnodes[4], dhnodes[0], dhnodes[1], 1.0);
            addSimpleNodeChildren(dhnodes[5], dhnodes[2], dhnodes[4], 1.0);
            addSimpleNodeChildren(dhnodes[6], dhnodes[3], dhnodes[5], 1.0);
            dhroot = 6;
            break;
        case 3:
            dhnodes[1].setHeight(tetheight0 + 1.0);
            dhnodes[2].setHeight(tetheight0 + 1.0);
            addSimpleNodeChildren(dhnodes[4], dhnodes[1], dhnodes[2], 1.0);
            addSimpleNodeChildren(dhnodes[5], dhnodes[0], dhnodes[4], 1.0);
            addSimpleNodeChildren(dhnodes[6], dhnodes[3], dhnodes[5], 1.0);
            dhroot = 6;
            break;
        case 4:
            dhnodes[1].setHeight(tetheight0 + 1.0);
            dhnodes[2].setHeight(tetheight0 + 1.0);
            dhnodes[3].setHeight(tetheight1 + 1.0);
            dhnodes[4].setHeight(tetheight1 + 1.0);
            addSimpleNodeChildren(dhnodes[6], dhnodes[0], dhnodes[1], 1.0);
            addSimpleNodeChildren(dhnodes[7], dhnodes[3], dhnodes[4], 1.0);
            addSimpleNodeChildren(dhnodes[8], dhnodes[6], dhnodes[7], 1.0);
            addSimpleNodeChildren(dhnodes[9], dhnodes[2], dhnodes[5], 1.0);
            addSimpleNodeChildren(dhnodes[10], dhnodes[8], dhnodes[9], 1.0);
            dhroot = 10;
            break;
        case 5:
            dhnodes[1].setHeight(tetheight0 + 1.0);
            dhnodes[2].setHeight(tetheight0 + 1.0);
            dhnodes[3].setHeight(tetheight1 + 1.0);
            dhnodes[4].setHeight(tetheight1 + 1.0);
            dhnodes[5].setHeight(tetheight2 + 1.0);
            dhnodes[6].setHeight(tetheight2 + 1.0);
            addSimpleNodeChildren(dhnodes[8], dhnodes[0], dhnodes[1], 1.0);
            addSimpleNodeChildren(dhnodes[9], dhnodes[5], dhnodes[6], 1.0);
            addSimpleNodeChildren(dhnodes[10], dhnodes[2], dhnodes[7], 1.0);
            addSimpleNodeChildren(dhnodes[11], dhnodes[3], dhnodes[8], 1.0);
            addSimpleNodeChildren(dhnodes[12], dhnodes[4], dhnodes[11], 1.0);
            addSimpleNodeChildren(dhnodes[13], dhnodes[9], dhnodes[12], 1.0);
            addSimpleNodeChildren(dhnodes[14], dhnodes[10], dhnodes[13], 1.0);
            dhroot = 14;
            break;
    }
    AlloppDiploidHistory adhist = new AlloppDiploidHistory(dhnodes, dhroot, tettrees, true, apsp);
    int ntippopparams = numberOfTipPopParameters();
    int nrootpopparams = numberOfRootPopParameters();
    int maxnhybpopparams = maxNumberOfHybPopParameters();
    Parameter testtippopvalues = new Parameter.Default(ntippopparams);
    Parameter testrootpopvalues = new Parameter.Default(nrootpopparams);
    double[] testhybpopvalues = new double[maxnhybpopparams];
    for (int pp = 0; pp < ntippopparams; pp++) {
        testtippopvalues.setParameterValue(pp, 1000 + pp);
    }
    for (int pp = 0; pp < nrootpopparams; pp++) {
        testrootpopvalues.setParameterValue(pp, 2000 + pp);
    }
    for (int pp = 0; pp < maxnhybpopparams; pp++) {
        testhybpopvalues[pp] = 3000 + pp;
    }
    AlloppMulLabTree testmullabtree = new AlloppMulLabTree(adhist, tettrees, apsp, testtippopvalues, testrootpopvalues, testhybpopvalues);
    System.out.println(testmullabtree.asText());
    String newick = testmullabtree.mullabTreeAsNewick();
    return newick;
}
Also used : Taxon(dr.evolution.util.Taxon) Parameter(dr.inference.model.Parameter)

Example 23 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class MulSpeciesBindings method apspeciesId2speciesindiv.

// grj
public SpeciesIndivPair apspeciesId2speciesindiv(String apspId) {
    int sp = -1;
    int iv = -1;
    for (int s = 0; s < apspecies.length; s++) {
        for (int i = 0; i < apspecies[s].individuals.length; i++) {
            for (int t = 0; t < apspecies[s].individuals[i].taxa.length; t++) {
                Taxon taxon = apspecies[s].individuals[i].taxa[t];
                if (taxon.getId().compareTo(apspId) == 0) {
                    sp = s;
                    iv = i;
                }
            }
        }
    }
    assert sp != -1;
    SpeciesIndivPair x = new SpeciesIndivPair(sp, iv);
    return x;
}
Also used : Taxon(dr.evolution.util.Taxon)

Example 24 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class MulSpeciesBindings method collectCoalInfo.

// jh + grj
/**
     * Collect coalescence information for sub-tree rooted at 'node'.
     *
     * @param tree
     * @param node
     * @param loc  Place node data in loc, sub-tree info before that.
     * @param info array to fill
     * @return location of next available location
     */
private int collectCoalInfo(Tree tree, NodeRef node, GeneTreeInfo.SequenceAssignment[] seqassigns, int loc, CoalInfo[] info) {
    info[loc] = new CoalInfo(tree.getNodeHeight(node), tree.getChildCount(node));
    int newLoc = loc - 1;
    for (int i = 0; i < 2; i++) {
        NodeRef child = tree.getChild(node, i);
        info[loc].sinfo[i] = new FixedBitSet(nSpSeqs());
        if (tree.isExternal(child)) {
            Taxon taxon = tree.getNodeTaxon(child);
            int ti = taxon2index.get(taxon);
            int spseq = spsq[seqassigns[ti].spIndex][seqassigns[ti].seqIndex];
            info[loc].sinfo[i].set(spseq);
            assert tree.getNodeHeight(child) == 0;
        } else {
            final int used = collectCoalInfo(tree, child, seqassigns, newLoc, info);
            for (int j = 0; j < info[newLoc].sinfo.length; ++j) {
                info[loc].sinfo[i].union(info[newLoc].sinfo[j]);
            }
            newLoc = used;
        }
    }
    return newLoc;
}
Also used : NodeRef(dr.evolution.tree.NodeRef) FixedBitSet(jebl.util.FixedBitSet) Taxon(dr.evolution.util.Taxon)

Example 25 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class DriftedTraitsLogger method computeMaxHeight.

private void computeMaxHeight(Tree tree) {
    if (maxHeight < 0) {
        int m = tree.getTaxonCount();
        for (int i = 0; i < m; i++) {
            Taxon taxon = tree.getTaxon(i);
            double height = taxon.getHeight();
            if (height > maxHeight) {
                maxHeight = height;
            }
        }
    }
}
Also used : Taxon(dr.evolution.util.Taxon)

Aggregations

Taxon (dr.evolution.util.Taxon)151 Taxa (dr.evolution.util.Taxa)31 ArrayList (java.util.ArrayList)24 TaxonList (dr.evolution.util.TaxonList)19 NodeRef (dr.evolution.tree.NodeRef)18 Date (dr.evolution.util.Date)18 Tree (dr.evolution.tree.Tree)15 Sequence (dr.evolution.sequence.Sequence)12 TreeModel (dr.evomodel.tree.TreeModel)12 Parameter (dr.inference.model.Parameter)12 Attribute (dr.util.Attribute)11 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)10 Patterns (dr.evolution.alignment.Patterns)9 NewickImporter (dr.evolution.io.NewickImporter)7 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)7 Microsatellite (dr.evolution.datatype.Microsatellite)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 PatternList (dr.evolution.alignment.PatternList)4 DataType (dr.evolution.datatype.DataType)4