Skip to content

Commit

Permalink
Fixed merge conflict of the celltype specific allele specific express…
Browse files Browse the repository at this point in the history
…ion readme.
  • Loading branch information
adriaan-vd-graaf committed Oct 5, 2015
2 parents c858a0e + c2db29a commit e22a739
Show file tree
Hide file tree
Showing 97 changed files with 12,117 additions and 5,579 deletions.
Binary file added .DS_Store
Binary file not shown.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ nbactions*.xml

nb-configuration.xml

eqtl-mapping-pipeline/nb-configuration.xml
eqtl-mapping-pipeline/nb-configuration.xml
/eQTLInteractionAnalyser/nbproject/private/
/eQTLInteractionAnalyser/build/
/eQTLInteractionAnalyser/dist/
/eQTLInteractionAnalyser2/build/
/eQTLInteractionAnalyser2/dist/
/eQTLInteractionAnalyser2/nbproject/private/
4 changes: 2 additions & 2 deletions BinaryMetaAnalyzer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<version>1.0.2-SNAPSHOT</version>
</parent>
<artifactId>BinaryMetaAnalyzer</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.7-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>genetica-libraries</artifactId>
<version>1.0.5</version>
<version>1.0.7-SNAPSHOT</version>
</dependency>
</dependencies>
<name>BinaryMetaAnalyzer</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,15 @@ public void run(int bufferSize) throws IOException {
loadProbeAnnotation();

for (int permutation = 0; permutation < settings.getNrPermutations() + 1; permutation++) {
finalEQTLs = new QTL[bufferSize];
locationToStoreResult = 0;
bufferHasOverFlown = false;
clearResultsBuffer();
maxSavedPvalue = -Double.MAX_VALUE;
// create dataset objects
System.out.println("Running permutation " + permutation);
datasets = new BinaryMetaAnalysisDataset[settings.getDatasetlocations().size()];

System.out.println("Loading datasets");
for (int d = 0; d < datasets.length; d++) {
datasets[d] = new BinaryMetaAnalysisDataset(settings.getDatasetlocations().get(d), settings.getDatasetPrefix().get(d), permutation, settings.getDatasetannotations().get(d), probeAnnotation);
datasets[d] = new BinaryMetaAnalysisDataset(settings.getDatasetlocations().get(d), settings.getDatasetnames().get(d), settings.getDatasetPrefix().get(d), permutation, settings.getDatasetannotations().get(d), probeAnnotation);
}
System.out.println("Loaded " + datasets.length + " datasets");

Expand Down Expand Up @@ -224,7 +222,7 @@ public void run(int bufferSize) throws IOException {
for (int probe = 0; probe < traitList.length; probe++) {
double metaAnalysisZ = ZScores.getWeightedZ(finalZScores[probe], sampleSizes);
double tScore = ZScores.zScoreToCorrelation(metaAnalysisZ, totalSampleSize);
summedRsquare += tScore*tScore;
summedRsquare += tScore * tScore;
}
double newMetaZ = Correlation.convertCorrelationToZScore(totalSampleSize, Math.sqrt(summedRsquare));
double newMetaAnalysisP = Descriptives.convertZscoreToPvalue(newMetaZ);
Expand All @@ -244,10 +242,10 @@ public void run(int bufferSize) throws IOException {
double metaAnalysisZ = ZScores.getWeightedZ(finalZScores[probe], sampleSizes);
for (int i = 0; i < finalZScores[probe].length; i++) {
double tScore = ZScores.zScoreToCorrelation(finalZScores[probe][i], sampleSizes[i]);
summedPerDataSet[i] += tScore*tScore;
summedPerDataSet[i] += tScore * tScore;
}
double tScore = ZScores.zScoreToCorrelation(metaAnalysisZ, totalSampleSize);
summedRsquare += tScore*tScore;
summedRsquare += tScore * tScore;
}

for (int i = 0; i < summedPerDataSet.length; i++) {
Expand All @@ -261,7 +259,7 @@ public void run(int bufferSize) throws IOException {
MetaQTL4MetaTrait t = new MetaQTL4MetaTrait(21, "Microbe_Components", "-", -1, -1, "", traitList[0].getPlatformIds());
QTL q = new QTL(newMetaAnalysisP, t, snp, BaseAnnot.toByte(alleleAssessed), newMetaZ, BaseAnnot.toByteArray(alleles), summedPerDataSet, sampleSizes); // sort buffer if needed.
addEQTL(q);
} else {
} else {
System.out.println("Error in procedure.");
}
}
Expand Down Expand Up @@ -546,4 +544,11 @@ private void writeBuffer(String outdir, int permutation) throws IOException {
System.out.println(
"Done.");
}

private void clearResultsBuffer() {
Arrays.fill(finalEQTLs, null);
bufferHasOverFlown = false;
locationToStoreResult = 0;
maxSavedPvalue = -Double.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public static void main(String[] args) {
settingsFile = args[0];

} else {
System.out.println("Usage: settings.xml replacetext replacetextwith");
System.out.println("Usage of the binary meta-analysis: settings.xml replacetext replacetextwith");
System.exit(-1);
}

BinaryMetaAnalysis meta = new BinaryMetaAnalysis(settingsFile, textToReplace, replaceTextWith);
System.exit(0);

}

private MetaQTL4TraitAnnotation probeAnnotation;
private BinaryMetaAnalysisDataset[] datasets = new BinaryMetaAnalysisDataset[0];
private int[][] snpIndex;
Expand Down Expand Up @@ -105,24 +105,36 @@ public void run() throws IOException {
System.out.println("Loading probe annotation from: " + settings.getProbetranslationfile());
loadProbeAnnotation();

if (traitList.length == 0) {
System.err.println("Error: no annotation loaded.");
System.exit(-1);
}

for (int permutation = 0; permutation < settings.getNrPermutations() + 1; permutation++) {
clearResultsBuffer();

// create dataset objects
System.out.println("Running permutation " + permutation);
datasets = new BinaryMetaAnalysisDataset[settings.getDatasetlocations().size()];

System.out.println("Loading datasets");
for (int d = 0; d < datasets.length; d++) {
datasets[d] = new BinaryMetaAnalysisDataset(settings.getDatasetlocations().get(d), settings.getDatasetPrefix().get(d), permutation, settings.getDatasetannotations().get(d), probeAnnotation);
datasets[d] = new BinaryMetaAnalysisDataset(settings.getDatasetlocations().get(d),
settings.getDatasetnames().get(d),
settings.getDatasetPrefix().get(d),
permutation,
settings.getDatasetannotations().get(d),
probeAnnotation);
}
System.out.println("Loaded " + datasets.length + " datasets");

// create meta-analysis SNP index. have to recreate this every permutation,
// since the order of SNPs is generated at random.
System.out.println("Creating SNP index");
createSNPIndex();
createSNPIndex(outdir);
System.out.println("Total of " + snpIndex.length + " SNPs");
System.out.println("Creating probe index");
createProbeIndex();
createProbeIndex(outdir);
System.out.println("Total of " + probeIndex.length + " probes");

if (snpChr == null) {
Expand Down Expand Up @@ -245,9 +257,10 @@ public void run() throws IOException {
double metaZ = ZScores.getWeightedZ(finalZScores[probe], sampleSizes);
double p = Descriptives.convertZscoreToPvalue(metaZ);

if (!Double.isNaN(p)) {
if (!Double.isNaN(p) && !Double.isNaN(metaZ)) {
// create output object
QTL q = new QTL(p, t, snp, BaseAnnot.toByte(alleleAssessed), metaZ, BaseAnnot.toByteArray(alleles), finalZScores[probe], sampleSizes); // sort buffer if needed.
// System.out.println(q.getSNPId()+"\t"+q.getMetaTrait().getMetaTraitName()+"\t"+q.toString());
addEQTL(q);
} else {
// if (!printed) {
Expand Down Expand Up @@ -307,8 +320,9 @@ public void run() throws IOException {
double metaAnalysisP = Descriptives.convertZscoreToPvalue(metaAnalysisZ);

// create output object
if (!Double.isNaN(metaAnalysisP)) {
if (!Double.isNaN(metaAnalysisP) && !Double.isNaN(metaAnalysisZ)) {
QTL q = new QTL(metaAnalysisP, t, snp, BaseAnnot.toByte(alleleAssessed), metaAnalysisZ, BaseAnnot.toByteArray(alleles), finalZScores[probe], sampleSizes); // sort buffer if needed.
// System.out.println(q.getSNPId()+"\t"+q.getMetaTrait().getMetaTraitName()+"\t"+q.toString());
addEQTL(q);
}
}
Expand All @@ -332,7 +346,7 @@ public void run() throws IOException {
*/
}

private void createSNPIndex() throws IOException {
private void createSNPIndex(String outdir) throws IOException {

HashSet<String> confineToTheseSNPs = null;
if (settings.getSNPSelection() != null) {
Expand Down Expand Up @@ -384,6 +398,21 @@ private void createSNPIndex() throws IOException {
}
}
}

TextFile tf = new TextFile(outdir + "snpindex.txt", TextFile.W);
String header = "metaID";
for (int d = 0; d < datasets.length; d++) {
header += "\t" + datasets[d].getName() + "-sid";
}
tf.writeln(header);
for (int s = 0; s < snpList.length; s++) {
String ln = snpList[s];
for (int d = 0; d < datasets.length; d++) {
ln += "\t" + snpIndex[s][d];
}
tf.writeln(ln);
}
tf.close();
}

private void loadProbeAnnotation() throws IOException {
Expand Down Expand Up @@ -432,31 +461,73 @@ private void loadSNPAnnotation() throws IOException {
}

// index the probes
private void createProbeIndex() throws IOException {
private void createProbeIndex(String outdir) throws IOException {

HashSet<String> confineToTheseProbes = null;
if (settings.getProbeselection()!= null) {
if (settings.getProbeselection() != null) {
System.out.println("Selecting Probes from file: " + settings.getProbeselection());
confineToTheseProbes = new HashSet<String>();
TextFile tf = new TextFile(settings.getProbeselection(), TextFile.R);
confineToTheseProbes.addAll(tf.readAsArrayList());
tf.close();

System.out.println(confineToTheseProbes.size() + " Probes loaded.");
}


System.out.println("");
probeIndex = new Integer[traitList.length][datasets.length];

for (int d = 0; d < datasets.length; d++) {
String[] probes = datasets[d].getProbeList();
int platformId = probeAnnotation.getPlatformId(settings.getDatasetannotations().get(d));
int platformId = probeAnnotation.getPlatformId(datasets[d].getPlatform());

HashMap<String, MetaQTL4MetaTrait> traitHashForPlatform = probeAnnotation.getTraitHashForPlatform(platformId);
System.out.println(probeAnnotation.getTraitHashPerPlatform().size());

System.out.println(datasets[d].getName() + "\t" + platformId + "\t" + datasets[d].getPlatform() + "\t" + traitHashForPlatform.size());
for (int p = 0; p < probes.length; p++) {

MetaQTL4MetaTrait t = traitHashForPlatform.get(probes[p]);
int index = traitMap.get(t);

if (probes[p].equals("60437")) {
if (t != null) {
System.out.println(t.getMetaTraitId());
} else {
System.out.println("not found");
}
}

if (confineToTheseProbes == null || confineToTheseProbes.contains(probes[p])) {
MetaQTL4MetaTrait t = probeAnnotation.getTraitForPlatformId(platformId, probes[p]);
int index = traitMap.get(t);
probeIndex[index][d] = p;
}
}
}

System.out.println("");

TextFile out = new TextFile(outdir + "probeindex.txt", TextFile.W);

String header = "metaID";
for (int d = 0; d < datasets.length; d++) {
header += "\t" + datasets[d].getName() + "-pid\t" + datasets[d].getName() + "-probename";
}
out.writeln(header);
for (int p = 0; p < probeIndex.length; p++) {

String lnout = "" + traitList[p].getMetaTraitId();
for (int d = 0; d < datasets.length; d++) {
Integer pid = probeIndex[p][d];
String probeName = null;
if (pid != null) {
probeName = datasets[d].getProbeList()[pid];
}
lnout += "\t" + pid + "\t" + probeName;
}

out.writeln(lnout);
}

out.close();
}

private void addEQTL(QTL q) {
Expand Down Expand Up @@ -529,10 +600,10 @@ private void writeBuffer(String outdir, int permutation) throws IOException {
+ "Meta-Beta (SE)\t"
+ "Beta (SE)\t"
+ "FoldChange";

output.writeln(header);
// PValue SNPName SNPChr SNPChrPos ProbeName ProbeChr ProbeCenterChrPos CisTrans SNPType AlleleAssessed OverallZScore DatasetsWhereSNPProbePairIsAvailableAndPassesQC DatasetsZScores DatasetsNrSamples IncludedDatasetsMeanProbeExpression IncludedDatasetsProbeExpressionVariance HGNCName IncludedDatasetsCorrelationCoefficient Meta-Beta (SE) Beta (SE) FoldChange FDR

DecimalFormat format = new DecimalFormat("###.#######", new DecimalFormatSymbols(Locale.US));
DecimalFormat smallFormat = new DecimalFormat("0.#####E0", new DecimalFormatSymbols(Locale.US));
for (int i = 0; i < settings.getFinalEQTLBufferMaxLength(); i++) {
Expand Down Expand Up @@ -580,21 +651,28 @@ private void writeBuffer(String outdir, int permutation) throws IOException {
float[] datasetZScores = q.getDatasetZScores();
String[] dsBuilder = new String[datasets.length];
String[] dsNBuilder = new String[datasets.length];
String[] dsZBuilder = new String[datasets.length];

for (int d = 0; d < datasetZScores.length; d++) {

if (!Float.isNaN(datasetZScores[d])) {
String str = format.format(datasetZScores[d]);

dsBuilder[d] = settings.getDatasetnames().get(d);
dsNBuilder[d] = "" + q.getDatasetSampleSizes()[d];
dsZBuilder[d] = str;
} else {
dsBuilder[d] = "-";
dsNBuilder[d] = "-";
dsZBuilder[d] = "-";
}
}

sb.append("\t");
sb.append(Strings.concat(dsBuilder, Strings.semicolon));

sb.append("\t");
sb.append(Strings.concat(datasetZScores, format, Strings.semicolon));
sb.append(Strings.concat(dsZBuilder, Strings.semicolon));

sb.append("\t");
sb.append(Strings.concat(dsNBuilder, Strings.semicolon));
Expand All @@ -612,4 +690,11 @@ private void writeBuffer(String outdir, int permutation) throws IOException {
System.out.println(
"Done.");
}

private void clearResultsBuffer() {
Arrays.fill(finalEQTLs, null);
bufferHasOverFlown = false;
locationToStoreResult = 0;
maxSavedPvalue = -Double.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ public class BinaryMetaAnalysisDataset {
private final int platformId;
private RandomAccessFile raf;

public BinaryMetaAnalysisDataset(String dir, String prefix, int permutation, String platform, MetaQTL4TraitAnnotation probeAnnotation) throws IOException {
private String name = null;
private String platform = null;

public BinaryMetaAnalysisDataset(String dir, String name, String prefix, int permutation, String platform, MetaQTL4TraitAnnotation probeAnnotation) throws IOException {
dir = Gpio.formatAsDirectory(dir);
String matrix = dir;
String probeFile = dir;
String snpFile = dir;
this.platform = platform;
this.name = name;
this.probeAnnotation = probeAnnotation;
this.platformId = probeAnnotation.getPlatformId(platform);
String pref = "Dataset";
Expand Down Expand Up @@ -265,4 +270,12 @@ public void close() throws IOException {
raf.close();
}

public String getName() {
return name;
}

public String getPlatform() {
return platform;
}

}
Loading

0 comments on commit e22a739

Please sign in to comment.