forked from single-cell-genetics/limix_qtl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakemake.smk.py
137 lines (119 loc) · 4.26 KB
/
Snakemake.smk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import glob
import os
from subprocess import run
import pandas as pd
import re
from os.path import join
shell.prefix("set -euo pipefail;")
def _multi_arg_start(flag, files):
flag += " "
return " ".join(flag + f for f in files)
def _multi_arg_end(flag, files):
flag = " "+flag
return " ".join(f + flag for f in files)
def _multi_arg_both_ends(flag1, flag2, files):
flag1 += " "
flag2 = " "+flag2
return " ".join(flag1 + f + flag2 for f in files)
def flatenChunk(chunk):
return chunk.replace(":", "_").replace("-", "_")
def extendChunk(chunk):
relChunk = chunk.pop()
chunkSplitted = relChunk.split("_")
return chunkSplitted[0]+":"+chunkSplitted[1]+"-"+chunkSplitted[2]
## Variables ##
##Files, these are populated now with the test examples and we use here plink genotypes.
chunkFile = './Chunks.txt' ##Not provided in the repo, instructions can be found on the repo wiki.
genotypeFile = '/limix_qtl/Limix_QTL/test_data/Genotypes/Geuvadis' ##Genotype without file extension. Please update flag in the runner to reflect --plink or --bgen
kinshipFile = '/limix_qtl/Limix_QTL/test_data/Genotypes/Geuvadis_chr1_kinship'
annotationFile = '/limix_qtl/Limix_QTL/test_data/Expression/Geuvadis_CEU_Annot.txt'
phenotypeFile = '/limix_qtl/Limix_QTL/test_data/Expression/Geuvadis_CEU_YRI_Expr.txt'
covariateFile = '/limix_qtl/Limix_QTL/test_data/Expression/Geuvadis_CEU_YRI_covariates.txt'
randomEffFile = '' #no second random effect in this example
sampleMappingFile = '/limix_qtl/Limix_QTL/test_data/Expression/Geuvadis_CEU_Annot.txt'
outputFolder = './OutGeuvadis/'
##Settings
numberOfPermutations = '1000'
minorAlleleFrequency = '0.1'
windowSize = '1000000'
hwequilibrium = '0.000001'
FDR = '0.05'
## End Variables ##
finalQTLRun = outputFolder+'qtl_results_all.txt'
topQTL = outputFolder+'top_qtl_results_all.txt'
with open(chunkFile,'r') as f:
chunks = [x.strip() for x in f.readlines()]
qtlOutput = []
for chunk in chunks:
#print(chunk)
processedChunk = flatenChunk(chunk)
#print(processedChunk)
processedChunk=expand(outputFolder+'{chunk}.finished',chunk=processedChunk )
#print(processedChunk)
qtlOutput.append(processedChunk)
## flatten these lists
qtlOutput = [filename for elem in qtlOutput for filename in elem]
rule all:
input:
qtlOutput,finalQTLRun,topQTL
rule run_qtl_mapping:
input:
af = annotationFile,
pf = phenotypeFile,
cf = covariateFile,
kf = kinshipFile,
smf = sampleMappingFile
output:
outputFolder + '{chunk}.finished'
params:
gen=genotypeFile,
od = outputFolder,
np = numberOfPermutations,
maf = minorAlleleFrequency,
hwe = hwequilibrium,
w = windowSize,
run:
chunkFull = extendChunk({wildcards.chunk})
shell(
" singularity exec --bind ~ ~/limix.simg python /limix_qtl/Limix_QTL/run_QTL_analysis.py "
" --bgen {params.gen} "
" -af {input.af} "
" -pf {input.pf} "
" -cf {input.cf} "
" -od {params.od} "
" -rf {input.kf} "
" --sample_mapping_file {input.smf} "
" -gr {chunkFull} "
" -np {params.np} "
" -maf {params.maf} "
" -hwe {params.hwe} "
" -w {params.w} "
" -c -gm gaussnorm -bs 500 -rs 0.95 ")
shell("touch {output}")
rule aggregate_qtl_results:
input:
IF = outputFolder,
OF = outputFolder,
finalFiles = qtlOutput
output:
finalQTLRun
run:
shell(
" singularity exec --bind ~ ~/limix.simg python /limix_qtl/Limix_QTL/post-processing_QTL/minimal_postprocess.py "
" -id {input.IF} "
" -od {input.OF} "
" -sfo ")
rule top_feature:
input:
IF = outputFolder,
OF = outputFolder,
finalFile = finalQTLRun
output:
topQTL
run:
shell(
" singularity exec --bind ~ ~/limix.simg python /limix_qtl/Limix_QTL/post-processing_QTL/minimal_postprocess.py "
"-id {input.IF} "
"-od {input.OF} "
"-tfb "
"-sfo ")