Package edu.msu.cme.rdp.unifrac

Examples of edu.msu.cme.rdp.unifrac.UnifracTaxon


    public void addTaxon(int parent, int taxid, String name, MCSample sample, float bl) {
        TaxonHolder<UnifracTaxon> parentHolder = taxonMap.get(parent);
        if (parentHolder == null) {
            throw new IllegalArgumentException("Couldn't find parent taxon id=" + parent);
        }
        UnifracTaxon parentTaxon = parentHolder.getTaxon();

        TaxonHolder<UnifracTaxon> holder = taxonMap.get(taxid);
        if (holder == null) {
            holder = new TaxonHolder(new UnifracTaxon(taxid, name, "", bl), parentHolder);
            UnifracTaxon t = holder.getTaxon();

            if (sample != null) {
                //xxxxx
                t.incCount(sample, 1);
            }
            parentHolder.addChild(holder);
            if (leaves.contains(parentTaxon.getTaxid())) {
                leaves.remove(parentTaxon.getTaxid());
            }
            leaves.add(t.getTaxid());
            taxonMap.put(t.getTaxid(), holder);
        }

    }
View Full Code Here


        }
    }
    private Set<Integer> leaves = new LinkedHashSet();

    public UnifracTree() {
        super(new UnifracTaxon(0, "Root", "no rank", 0));
        leaves.add(0);
    }
View Full Code Here

                    samplePool.addAll(allSamplesMap.get(samples.get(sample1)));
                    samplePool.addAll(allSamplesMap.get(samples.get(sample2)));
                    Collections.shuffle(samplePool);

                    for (int taxid : leaves) {
                        UnifracTaxon t = taxonMap.get(taxid).getTaxon();
                        if (t.containsSample(samples.get(sample1)) || t.containsSample(samples.get(sample2))) {
                            t.resetSamples(samplePool);
                        }
                    }

                    this.refreshInnerTaxa();
                    float val;
View Full Code Here

        for (Integer taxid : leaves) {
            TaxonHolder<UnifracTaxon> leaf = this.getChild(taxid);
            TaxonHolder<UnifracTaxon> parent = leaf;

            while (parent.getParent() != null) {
                UnifracTaxon taxon = parent.getTaxon();
                if (!touched.contains(parent.getTaxon().getTaxid())) {
                    touched.add(taxon.getTaxid());
                    if (parent.getTaxon().containsSample(sample1) && taxon.containsSample(sample2)) {
                        combined += taxon.getBl();
                    } else if (taxon.containsSample(sample1) || taxon.containsSample(sample2)) {
                        unique += taxon.getBl();
                    }
                }
                parent = parent.getParent();
            }
        }
View Full Code Here

    public UnifracResult computeWeightedUnifrac() {
        Set<MCSample> samplesSet = new HashSet();
        Map<MCSample, Double> totalsMap = new HashMap();

        for (int i : leaves) {
            UnifracTaxon leaf = this.getChildTaxon(i);
            for (MCSample sample : leaf.getSamples()) {
                if (!totalsMap.containsKey(sample)) {
                    totalsMap.put(sample, 0.0);
                }
                samplesSet.add(sample);
                totalsMap.put(sample, totalsMap.get(sample) + leaf.getCount(sample));
            }
        }
        List<MCSample> samples = new ArrayList(new HashSet(samplesSet));

        float[][] unifracMatrix = new float[samples.size()][samples.size()];
View Full Code Here

    private float computeUnifracMetricWeighted(MCSample sample1, MCSample sample2, Map<MCSample, Double> totalsMap) {

        float ret = 0;
        for (TaxonHolder<UnifracTaxon> taxonHolder : taxonMap.values()) {
            UnifracTaxon taxon = taxonHolder.getTaxon();
            ret += taxon.getBl() * Math.abs(( taxon.getCount(sample1)) / totalsMap.get(sample1) - ( taxon.getCount(sample2)) / totalsMap.get(sample2));
        }

        return ret;
    }
View Full Code Here

        return ret;
    }

    public void printLeaves() {
        for (Integer taxid : leaves) {
            UnifracTaxon leaf = this.getChildTaxon(taxid);
            System.out.println(leaf.getTaxid() + "\t" + leaf.getName() + "\t" + leaf.getRank() + "\t" + leaf.getSamples());
        }
    }
View Full Code Here

TOP

Related Classes of edu.msu.cme.rdp.unifrac.UnifracTaxon

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.