Skip to content

Commit

Permalink
Merge pull request molgenis#561 from Bonder-MJ/master
Browse files Browse the repository at this point in the history
Minor updates
  • Loading branch information
PatrickDeelen authored Jan 14, 2020
2 parents 776b530 + af12d74 commit 54d08a4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public String toString() {
"useAbsoluteZscore\t" + useAbsoluteZscore + "\n" +
"finalEQTLBufferMaxLength\t" + finalEQTLBufferMaxLength + "\n" +
"includeSNPsWithoutProperMapping\t" + includeSNPsWithoutProperMapping + "\n" +
"includeProbesWithoutProperMapping\t" + includeProbesWithoutProperMapping +
"includeProbesWithoutProperMapping\t" + includeProbesWithoutProperMapping + "\n" +
"analysisType\t" + analysisType + "\n" +
"cisdistance\t" + cisdistance + "\n" +
"transdistance\t" + transdistance + "\n" +
Expand All @@ -45,6 +45,7 @@ public String toString() {
"snpselection\t'" + snpselection + '\'' + "\n" +
"snpprobeselection\t'" + snpprobeselection + '\'' + "\n" +
"snpAnnotationFile\t'" + snpAnnotationFile + '\'' + "\n" +
"probeRescaling\t" + rescalingOfSampleSize + "\n" +
"minimalNumberOfDatasets\t" + minimalNumberOfDatasets + "\n" +
"debug\t" + debug + "\n" +
"fullpermutationoutput\t" + fullpermutationoutput + "\n" +
Expand Down Expand Up @@ -249,7 +250,6 @@ public void parse(String settings, String texttoreplace, String replacetextwith)
}
i++;
}

summarize();
// parse datasets
} catch (ConfigurationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,21 @@ public Triple<ArrayList<QTL>, String, String> call() {

if (settings.getRescalingOfSampleSize()) {
weights = new double[sampleSizes.length];
for (int d = 0; d < datasetZScores.length; d++) {
Double rescaleValue = datasets[d].getFeatureOccuranceScaleMap().get(t.getPlatformIds()[d]);
if (!Double.isFinite(rescaleValue)) {
System.out.println("Warning for feature: " + t.getPlatformIds()[d] + " no rescale value set for: " + datasets[d].getName() + "\n Defaulted to weight of 1.");
for(int d=0; d<datasetZScores.length;d++){
if(debug){
System.out.println("Dataset: "+d);
System.out.println("Dataset name: "+datasets[d].getName());
System.out.println("Dataset platformId: "+t.getPlatformIds()[0]);
System.out.println("Dataset rescaling size: "+datasets[d].getFeatureOccuranceScaleMap().size());
System.out.println("Dataset rescaling contains key: "+datasets[d].getFeatureOccuranceScaleMap().containsKey(t.getPlatformIds()[0]));
}
Double rescaleValue = datasets[d].getFeatureOccuranceScaleMap().get(t.getPlatformIds()[0]);
if(rescaleValue==null || !Double.isFinite(rescaleValue)){
System.out.println("Warning for feature: "+ t.getPlatformIds()[0] + " no rescale value set for: " + datasets[d].getName()+"\n Defaulted to weight of 1.");
rescaleValue = 1.0d;
}
if (debug) {
System.out.println("Weight for: " + t.getPlatformIds()[d] + " is: " + rescaleValue);
if(debug){
System.out.println("Weight for: "+t.getPlatformIds()[0]+" is: "+rescaleValue);
}
weights[d] = rescaleValue;
}
Expand All @@ -411,7 +418,7 @@ public Triple<ArrayList<QTL>, String, String> call() {
if (!settings.getRescalingOfSampleSize()) {
metaAnalysisZ = ZScores.getWeightedZ(datasetZScores, sampleSizes);
} else {
metaAnalysisZ = ZScores.getWeightedZ(datasetZScores, sampleSizes, weights);
metaAnalysisZ = ZScores.getDatasetSizeWeightedZ(datasetZScores, sampleSizes, weights);
}

if (debug && traitList[probe].getMetaTraitName().equals("ENSG00000132465")) {
Expand Down
2 changes: 1 addition & 1 deletion GeneticRiskScoreCalculator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<classpathPrefix>lib/</classpathPrefix>
<!-- Specifies the main class of the application -->
<mainClass>nl.systemsgenetics.simplegeneticriskscorecalculator.Main</mainClass>
<!-- <mainClass>nl.systemsgenetics.benchmark.Benchmark</mainClass>-->
<!--<mainClass>nl.systemsgenetics.benchmark.Benchmark</mainClass>-->
</manifest>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void main(String[] args) {
Option FileOut = OptionBuilder.withArgName("path").hasArg().withDescription("Location (folder) for the output.").withLongOpt("OutputFolder").create("o");
Option GenotypeTypeIn = OptionBuilder.withArgName("type").hasArg().withDescription("Type of reference data.").withLongOpt("GenotypeType").create("gt");
Option GenotypeIn = OptionBuilder.withArgName("path").hasArg().withDescription("Location for the reference data.").withLongOpt("GenotypeLocation").create("gi");
Option InFolder = OptionBuilder.withArgName("path").hasArg().withDescription("Location of the folder with genetic risk score information.").withLongOpt("input").create("i");
Option InFolder = OptionBuilder.withArgName("path").hasArg().withDescription("Location of the file/folder with genetic risk score information.").withLongOpt("input").create("i");
Option rSquared = OptionBuilder.withArgName("double").hasArg().withDescription("R2 for pruning.").withLongOpt("rSquared").create("r");
Option pValueThreshold = OptionBuilder.withArgName("double").hasArg().withDescription("P-value thresholds for genetic risk score inclusion, colon separated should be ordered from most stringent to least stringent.").withLongOpt("pValue").create("p");
Option WindowSize = OptionBuilder.withArgName("double").hasArg().withDescription("Window size for pruning, if given two window-sizes (colon separated), a two step window approach is used.").withLongOpt("wSize").create("w");
Expand Down Expand Up @@ -205,11 +205,17 @@ private static THashMap<String, THashMap<String, THashMap<String, ArrayList<Risk

File riskFileFolder = new File(riskFolder);
if (!riskFileFolder.exists()) {
System.out.println("Warning: input risk folder does not exists:\n");
System.out.println("Warning: input risk file / folder does not exists:\n");
System.out.println(riskFileFolder);
System.exit(-1);
}
File[] riskFiles = riskFileFolder.listFiles();
File[] riskFiles;
if(riskFileFolder.isDirectory()){
riskFiles = riskFileFolder.listFiles();
} else {
riskFiles = new File[1];
riskFiles[0] = riskFileFolder;
}


IntStream.range(0, riskFiles.length).parallel().forEach(fi -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,4 @@ public void TestBgenGenotypeDataBgenix() throws URISyntaxException, IOException
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ public static double getWeightedZ(float[] zScores, int[] sampleSizes, double[] w
return weightedZ;
}

/**
* Calculates a weighted Z-score according to Whitlock's paper:
* http://www.ncbi.nlm.nih.gov/pubmed/16135132 Square root of the sample
* size is used as the weight for each test.
*
* @param zScores Z-scores from individual tests
* @param sampleSizes sample sizes of these tests
* @return
*/
public static double getDatasetSizeWeightedZ(float[] zScores, int[] sampleSizes, double[] weights) {
if (zScores.length != sampleSizes.length) {
throw new IllegalArgumentException("Zscores and sample sizes should have same length!");
}
double weightedZ = 0;
double sampleSizeSum = 0;
for (int j = 0; j < zScores.length; j++) {
if (!Double.isNaN(zScores[j])) {
weightedZ += Math.sqrt(sampleSizes[j]* weights[j]) * zScores[j];
sampleSizeSum += (sampleSizes[j] * weights[j]);
}
}
weightedZ /= Math.sqrt(sampleSizeSum);
return weightedZ;
}
/**
* Calculates a weighted Z-score according to Whitlock's paper:
* http://www.ncbi.nlm.nih.gov/pubmed/16135132 Square root of the sample
Expand Down

0 comments on commit 54d08a4

Please sign in to comment.