Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package net.maizegenetics.analysis.association;
import java.awt.Frame;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.swing.ImageIcon;
import net.maizegenetics.stats.linearmodels.*;
import org.apache.commons.math3.distribution.FDistribution;
import org.apache.commons.math3.exception.OutOfRangeException;
import org.apache.log4j.Logger;
import net.maizegenetics.dna.map.Position;
import net.maizegenetics.dna.snp.GenotypeTable;
import net.maizegenetics.dna.snp.GenotypeTableUtils;
import net.maizegenetics.dna.snp.GenotypeTable.GENOTYPE_TABLE_COMPONENT;
import net.maizegenetics.phenotype.CategoricalAttribute;
import net.maizegenetics.phenotype.GenotypePhenotype;
import net.maizegenetics.phenotype.NumericAttribute;
import net.maizegenetics.phenotype.Phenotype;
import net.maizegenetics.phenotype.PhenotypeAttribute;
import net.maizegenetics.phenotype.Phenotype.ATTRIBUTE_TYPE;
import net.maizegenetics.plugindef.AbstractPlugin;
import net.maizegenetics.plugindef.DataSet;
import net.maizegenetics.plugindef.Datum;
import net.maizegenetics.plugindef.GeneratePluginCode;
import net.maizegenetics.plugindef.PluginParameter;
import net.maizegenetics.prefs.TasselPrefs;
import net.maizegenetics.util.TableReport;
import net.maizegenetics.util.TableReportBuilder;
public class FastMultithreadedAssociationPlugin extends AbstractPlugin {
private static Logger myLogger = Logger.getLogger(FastMultithreadedAssociationPlugin.class);
private GENOTYPE_TABLE_COMPONENT[] GENOTYPE_COMP = new GENOTYPE_TABLE_COMPONENT[] {
GENOTYPE_TABLE_COMPONENT.Genotype, GENOTYPE_TABLE_COMPONENT.ReferenceProbability,
GENOTYPE_TABLE_COMPONENT.AlleleProbability };
private final byte NN = GenotypeTable.UNKNOWN_DIPLOID_ALLELE;
private Phenotype myPhenotype;
private GenotypeTable myGenotype;
ListphenotypeNames;
double minR2;
private FDistribution Fdist;
GenotypePhenotype myGenoPheno;
//plugin parameter definitions
private PluginParameter maxp =
new PluginParameter.Builder<>("MaxPValue", .001, Double.class)
.guiName("MaxPValue")
.description("The maximum p-value that will be output by the analysis.")
.build();
private PluginParameter myGenotypeTable =
new PluginParameter.Builder<>("genotypeComponent", GENOTYPE_TABLE_COMPONENT.Genotype, GENOTYPE_TABLE_COMPONENT.class)
.genotypeTable()
.range(GENOTYPE_COMP)
.description("If the genotype table contains more than one type of genotype data, choose the type to use for the analysis.")
.build();
private PluginParameter saveAsFile =
new PluginParameter.Builder<>("writeToFile", false, Boolean.class)
.description("Should the results be saved to a file rather than stored in memory? It true, the results will be written to a file as each SNP is analyzed in order to reduce memory requirements"
+ "and the results will NOT be saved to the data tree. Default = false.")
.guiName("Write to file")
.build();
private PluginParameter reportFilename =
new PluginParameter.Builder<>("outputFile", null, String.class)
.outFile()
.dependentOnParameter(saveAsFile)
.description("The name of the file to which these results will be saved.")
.guiName("Output File")
.build();
private PluginParameter maxThreads = new PluginParameter.Builder<>("maxThreads", TasselPrefs.getMaxThreads(), Integer.class)
.description("the maximum number of threads to be used by this plugin.")
.guiName("Max Threads")
.build();
public FastMultithreadedAssociationPlugin() {
this(null, false);
}
public FastMultithreadedAssociationPlugin(Frame parentFrame, boolean isInteractive) {
super(parentFrame, isInteractive);
}
@Override
protected void preProcessParameters(DataSet input) {
List inData = input.getDataOfType(GenotypePhenotype.class);
if (inData.size() != 1) throw new IllegalArgumentException("Fast Association requires exactly one joined genotype-phenotype data set.");
}
@Override
public DataSet processData(DataSet input) {
long start = System.currentTimeMillis();
int maxSitesInQueue = 2000;
int maxObjectsInQueue = 1000;
Datum inDatum = input.getDataOfType(GenotypePhenotype.class).get(0);
myGenoPheno = (GenotypePhenotype) inDatum.getData();
myGenotype = myGenoPheno.genotypeTable();
myPhenotype = myGenoPheno.phenotype();
int numberOfObservations = myPhenotype.numberOfObservations();
testMissingDataInTheBaseModel();
//calculate orthogonal phenotypes
SolveByOrthogonalizing sbo = initializeOrthogonalizer();
//determine errdf
double errdf = numberOfObservations - sbo.baseDf() - 1;
Fdist = new FDistribution(1, errdf);
//calculate minR2
calculateR2Fromp(errdf);
//initialize report builder
TableReportBuilder myReport = initializeOutput(inDatum);
//create a thread pool
int nthreads = maxThreads.value();
nthreads = Math.max(nthreads, 2);
int siteTesterThreads = nthreads - 1;
ExecutorService myExecutor = Executors.newFixedThreadPool(nthreads);
//start report thread
BlockingQueue