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

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

Go to download

TASSEL 6 is a software package to evaluate traits association. Feature Tables are at the heart of the package where, a feature is a range of positions or a single position. Row in the that table are taxon.

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

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.maizegenetics.dna.snp.byte2d.Byte2D;

/**
 *
 * @author Terry Casstevens
 */
public class AlleleProbability implements SiteScore {

    public static final SiteScore.SITE_SCORE_TYPE[] ALLELE_PROBABILITY_TYPES = new SiteScore.SITE_SCORE_TYPE[]{
        SiteScore.SITE_SCORE_TYPE.ProbA, SiteScore.SITE_SCORE_TYPE.ProbC,
        SiteScore.SITE_SCORE_TYPE.ProbG, SiteScore.SITE_SCORE_TYPE.ProbT,
        SiteScore.SITE_SCORE_TYPE.ProbGap, SiteScore.SITE_SCORE_TYPE.ProbInsertion};

    private final Map myValues;
    private final int myNumTaxa;
    private final int myNumSites;

    AlleleProbability(Byte2D[] values) {
        if (values.length == 0) {
            throw new IllegalArgumentException("AlleleProbability: init: no values provided.");
        }
        myValues = new HashMap<>();
        myNumTaxa = values[0].numTaxa();
        myNumSites = values[0].numSites();
        for (int i = 0; i < values.length; i++) {
            if ((myNumTaxa != values[i].numTaxa()) || (myNumSites != values[i].numSites())) {
                throw new IllegalArgumentException("AlleleProbability: init: number of taxa or sites don't match for all values.");
            }
            myValues.put(values[i].siteScoreType(), values[i]);
        }
    }

    public AlleleProbability(int numTaxa, int numSites) {
        myNumTaxa = numTaxa;
        myNumSites = numSites;
        myValues = null;
    }

    public float value(int taxon, int site, SITE_SCORE_TYPE scoreType) {
        return SiteScoreUtil.byteToFloatPercentage(myValues.get(scoreType).valueForAllele(taxon, site));
    }

    Collection byteStorage() {
        return myValues.values();
    }

    @Override
    public Set siteScoreTypes() {
        return new HashSet<>(Arrays.asList(ALLELE_PROBABILITY_TYPES));
    }

    @Override
    public int numTaxa() {
        return myNumTaxa;
    }

    @Override
    public int numSites() {
        return myNumSites;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy