All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.maizegenetics.dna.snp.score.ReferenceProbabilityBuilder Maven / Gradle / Ivy

Go to download

TASSEL is a software package to evaluate traits associations, evolutionary patterns, and linkage disequilibrium.

There is a newer version: 5.2.94
Show newest version
/*
 *  ReferenceProbabilityBuilder
 */
package net.maizegenetics.dna.snp.score;

import ch.systemsx.cisd.hdf5.IHDF5Reader;
import ch.systemsx.cisd.hdf5.IHDF5Writer;
import net.maizegenetics.dna.snp.MaskMatrix;

import net.maizegenetics.dna.snp.Translate;
import net.maizegenetics.dna.snp.TranslateBuilder;
import net.maizegenetics.dna.snp.byte2d.Byte2D;
import net.maizegenetics.dna.snp.byte2d.Byte2DBuilder;
import net.maizegenetics.taxa.TaxaList;

/**
 *
 * @author Terry Casstevens
 */
public class ReferenceProbabilityBuilder {

    private Byte2DBuilder myBuilder;
    private final int myNumSites;

    private ReferenceProbabilityBuilder(int numTaxa, int numSites, TaxaList taxaList) {
        myBuilder = Byte2DBuilder.getInstance(numTaxa, numSites, SiteScore.SITE_SCORE_TYPE.ReferenceProbablity, taxaList);
        myNumSites = numSites;
    }

    private ReferenceProbabilityBuilder(IHDF5Writer writer, int numTaxa, int numSites, TaxaList taxaList) {
        myBuilder = Byte2DBuilder.getInstance(writer, numSites, SiteScore.SITE_SCORE_TYPE.ReferenceProbablity, taxaList);
        myNumSites = numSites;
    }

    public static ReferenceProbabilityBuilder getInstance(IHDF5Writer writer, int numTaxa, int numSites, TaxaList taxaList) {
        return new ReferenceProbabilityBuilder(writer, numTaxa, numSites, taxaList);
    }

    public static ReferenceProbabilityBuilder getInstance(int numTaxa, int numSites, TaxaList taxaList) {
        return new ReferenceProbabilityBuilder(numTaxa, numSites, taxaList);
    }

    public static ReferenceProbability getFilteredInstance(ReferenceProbability base, Translate translate) {
        if (base instanceof FilterReferenceProbability) {
            FilterReferenceProbability filter = (FilterReferenceProbability) base;
            Translate merged = TranslateBuilder.getInstance(filter.myTranslate, translate);
            return new FilterReferenceProbability(filter.myBase, merged);
        }
        return new FilterReferenceProbability(base, translate);
    }

    public static ReferenceProbability getMaskInstance(ReferenceProbability base, MaskMatrix mask) {
        return new MaskReferenceProbability(base, mask);
    }

    public static ReferenceProbability getInstance(IHDF5Reader reader) {
        return new ReferenceProbability(Byte2DBuilder.getInstance(reader, SiteScore.SITE_SCORE_TYPE.ReferenceProbablity));
    }

    public ReferenceProbabilityBuilder addTaxon(int taxon, float[] values) {
        if (myNumSites != values.length) {
            throw new IllegalArgumentException("ImputeProbabilityBuilder: addTaxon: number of values: " + values.length + " doesn't equal number of sites: " + myNumSites);
        }
        try {
            myBuilder.addTaxon(taxon, SiteScoreUtil.floatToBytePercentage(values));
        } catch (Exception e) {
            throw new IllegalArgumentException("ImputeProbabilityBuilder: addTaxon: taxon number: " + taxon + ". " + e.getMessage());
        }
        return this;
    }

    public ReferenceProbability build() {
        Byte2D input = myBuilder.build();
        myBuilder = null;
        return new ReferenceProbability(input);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy