net.maizegenetics.stats.linearmodels.ModelEffectUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tassel Show documentation
Show all versions of tassel Show documentation
TASSEL is a software package to evaluate traits associations, evolutionary patterns, and linkage
disequilibrium.
package net.maizegenetics.stats.linearmodels;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import net.maizegenetics.analysis.modelfitter.AddPlusDomModelEffect;
import net.maizegenetics.dna.snp.GenotypeTable;
import net.maizegenetics.dna.snp.GenotypeTableUtils;
import net.maizegenetics.dna.snp.NucleotideAlignmentConstants;
import net.maizegenetics.matrixalgebra.Matrix.DoubleMatrix;
public class ModelEffectUtils {
private static final List homGeno = Arrays.asList(
NucleotideAlignmentConstants.getNucleotideDiploidByte("A"),
NucleotideAlignmentConstants.getNucleotideDiploidByte("C"),
NucleotideAlignmentConstants.getNucleotideDiploidByte("G"),
NucleotideAlignmentConstants.getNucleotideDiploidByte("T"),
NucleotideAlignmentConstants.getNucleotideDiploidByte("Z"),
NucleotideAlignmentConstants.getNucleotideDiploidByte("+"),
NucleotideAlignmentConstants.getNucleotideDiploidByte("-"));
private ModelEffectUtils() {}
public static DoubleMatrix getXtY(ModelEffect X, ModelEffect Y) {
if (X instanceof FactorModelEffect) {
FactorModelEffect fme = (FactorModelEffect) X;
if (Y instanceof FactorModelEffect) {
return fme.getXtX2((FactorModelEffect) Y);
} else if (Y instanceof CovariateModelEffect) {
return fme.getXty(((CovariateModelEffect) Y).getCovariate());
} else if (Y instanceof NestedCovariateModelEffect) {
return fme.getX().mult(Y.getX(), true, false);
} else if (Y instanceof AddPlusDomModelEffect) {
return fme.getX().crossproduct(Y.getX());
}
} else if (X instanceof CovariateModelEffect) {
double[] cov = ((CovariateModelEffect) X).getCovariate();
if (Y instanceof FactorModelEffect) {
return getXtY(Y,X).transpose();
} else if (Y instanceof CovariateModelEffect) {
return Y.getXty(cov);
} else if (Y instanceof NestedCovariateModelEffect) {
return Y.getXty(cov).transpose();
} else if (Y instanceof AddPlusDomModelEffect) {
return Y.getXty(cov).transpose();
}
} else if (X instanceof NestedCovariateModelEffect) {
if (Y instanceof FactorModelEffect) {
return X.getX().mult(Y.getX(), true, false);
} else if (Y instanceof CovariateModelEffect) {
return X.getXty(((CovariateModelEffect) Y).getCovariate());
} else if (Y instanceof NestedCovariateModelEffect) {
return ((NestedCovariateModelEffect) X).getXtX2((NestedCovariateModelEffect) Y);
} else if (Y instanceof AddPlusDomModelEffect) {
return X.getX().crossproduct(Y.getX());
}
} else if (X instanceof AddPlusDomModelEffect) {
return X.getX().crossproduct(Y.getX());
}
return null;
}
public static int[] getIntegerLevels(Object[] originalLevels) {
int nLevels = originalLevels.length;
int[] intLevels = new int[nLevels];
HashMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy