forked from liulab-dfci/RIMA_pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RIMA.snakefile
162 lines (144 loc) · 6.49 KB
/
RIMA.snakefile
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python
#----------------main snakefile to run RIMA-------------------------#
import os
import sys
import subprocess
import pandas as pd
import yaml
from string import Template
#from snakemake_files.scripts.utils import getTargetInfo
def getRuns(config):
ret = {}
#LEN: Weird, but using pandas to handle the comments in the file
#KEY: need skipinitialspace to make it fault tolerant to spaces!
metadata = pd.read_csv(config['metasheet'], index_col=0, sep=',', comment='#', skipinitialspace=True)
f = metadata.to_csv().split() #make it resemble an actual file with lines
#SKIP the hdr
for l in f[1:]:
tmp = l.strip().split(",")
#print(tmp)
ret[tmp[0]] = tmp[1:]
#print(ret)
config['runs'] = ret
return config
def addCondaPaths_Config(config):
"""ADDS the python2 paths to config"""
conda_root = subprocess.check_output('conda info --root',shell=True).decode('utf-8').strip()
conda_path = os.path.join(conda_root, 'pkgs')
current_path = os.getcwd()
config['conda_root'] = conda_root
config['rnaseq_root'] = "%s/envs/rnaseq_new" % conda_root
config['stat_root'] = "%s/envs/stat_perl_r" % conda_root
config['centrifuge_root']= "%s/envs/centrifuge_env" % conda_root
config['rseqc_root']= "%s/envs/rseqc_env" % conda_root
config['vep_root']= "%s/envs/vep_env" % conda_root
config['prada_root']= "%s/envs/prada_env" % conda_root
def addExecPaths(config):
conda_root = subprocess.check_output('conda info --root',shell=True).decode('utf-8').strip()
conda_path = os.path.join(conda_root, 'pkgs')
current_path = os.getcwd()
#NEED the following when invoking python2 (to set proper PYTHONPATH)
if not "pvacseq_path" in config or not config["pvacseq_path"]:
config["pvacseq_path"] = os.path.join(conda_root, 'envs', 'pvacseq', 'bin')
if not "trust4_path" in config or not config["trust4_path"]:
config["trust4_path"] = os.path.join(current_path,'TRUST4')
if not "arcasHLA_path" in config or not config["arcasHLA_path"]:
config["arcasHLA_path"] = os.path.join(current_path,'arcasHLA')
if not "prada_path" in config or not config["prada_path"]:
config["prada_path"] = os.path.join(current_path,'prada')
return config
def loadRef(config):
f = open(config['ref'])
ref_info = yaml.safe_load(f)
f.close()
#print(ref_info[config['assembly']])
for (k,v) in ref_info[config['assembly']].items():
#NO CLOBBERING what is user-defined!
if k not in config:
config[k] = v
def load_config(config_file):
#load the main config file including parameters which are not change a lot
with open(config_file, 'r') as stream:
try:
return yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
def load_execution(execution_file):
#load the main config file including parameters which are not change a lot
with open(execution_file, 'r') as stream:
try:
return yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
#--------- CONFIG set up ---------------
config = load_config('config.yaml')
execution = load_execution('execution.yaml')
addCondaPaths_Config(config)
loadRef(config)
addExecPaths(config)
#------------------------------------------------------------------------------
# TARGETS
#------------------------------------------------------------------------------
def all_targets(wildcards):
ls = []
if execution["preprocess_individual"]:
ls.extend(preprocess_individual_targets(wildcards))
if execution["preprocess_cohort"]:
ls.extend(preprocess_cohort_targets(wildcards))
if execution["differential_expression_cohort"]:
ls.extend(diffexpr_targets(wildcards))
if execution["immune_infiltration_cohort"]:
ls.extend(immune_infiltration_targets(wildcards))
if execution["mutation_individual"]:
ls.extend(mutation_individual_targets(wildcards))
if execution["mutation_cohort"]:
ls.extend(mutation_cohort_targets(wildcards))
if execution["immune_response_individual"]:
ls.extend(immune_response_individual_targets(wildcards))
if execution["immune_response_cohort"]:
ls.extend(immune_response_cohort_targets(wildcards))
if execution["immune_repertoire_individual"]:
ls.extend(immune_repertoire_individual_targets(wildcards))
if execution["immune_repertoire_cohort"]:
ls.extend(immune_repertoire_cohort_targets(wildcards))
if execution["neoantigen_individual"]:
ls.extend(neoantigen_individual_targets(wildcards))
if execution["neoantigen_cohort"]:
ls.extend(neoantigen_cohort_targets(wildcards))
if execution["microbiome_individual"]:
ls.extend(microbiome_individual_targets(wildcards))
if execution["microbiome_cohort"]:
ls.extend(microbiome_cohort_targets(wildcards))
return ls
rule target:
input:
all_targets
message: "Compiling all outputs"
if execution["preprocess_individual"]:
include: "./modules/preprocess/preprocess_individual.snakefile"
if execution["preprocess_cohort"]:
include: "./modules/preprocess/preprocess_cohort.snakefile"
if execution["differential_expression_cohort"]:
include: "./modules/differential_expression/differential_expression_cohort.snakefile"
if execution["immune_infiltration_cohort"]:
include: "./modules/immune_infiltration/immune_infiltration_cohort.snakefile"
if execution["mutation_individual"]:
include: "./modules/mutation/mutation_individual.snakefile"
if execution["mutation_cohort"]:
include: "./modules/mutation/mutation_cohort.snakefile"
if execution["immune_response_individual"]:
include: "./modules/immune_response/immune_response_individual.snakefile"
if execution["immune_response_cohort"]:
include: "./modules/immune_response/immune_response_cohort.snakefile"
if execution["immune_repertoire_individual"]:
include: "./modules/immune_repertoire/immune_repertoire_individual.snakefile"
if execution["immune_repertoire_cohort"]:
include: "./modules/immune_repertoire/immune_repertoire_cohort.snakefile"
if execution["neoantigen_individual"]:
include: "./modules/neoantigen/neoantigen_individual.snakefile"
if execution["neoantigen_cohort"]:
include: "./modules/neoantigen/neoantigen_cohort.snakefile"
if execution["microbiome_individual"]:
include: "./modules/microbiome/microbiome_individual.snakefile"
if execution["microbiome_cohort"]:
include: "./modules/microbiome/microbiome_cohort.snakefile"