-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSnakefile
executable file
·82 lines (65 loc) · 3.28 KB
/
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
import yaml
import os
configfile: 'snakemake.yml'
CBSx_SIGNATURES = config["CBSx_SIGNATURES"]
MIXTURES = config["MIXTURES"]
INPUT_FOLDER = config["INPUT_FOLDER"]
OUTPUT_FOLDER = config["OUTPUT_FOLDER"]
CIBERSORTx_OUTPUT_FOLDER = OUTPUT_FOLDER + "/cibersortx"
credentials_given = False
# Check if the credentials file exists
if os.path.exists(config["CREDENTIALS_FILE"]):
credentials_given = True
credentials_yml = None
with open(config["CREDENTIALS_FILE"]) as f:
credentials_yml = yaml.safe_load(f)
MAIL = credentials_yml["MAIL"]
TOKEN = credentials_yml["TOKEN"]
else:
print(f"The credentials file CREDENTIALS_FILE does not exist.")
rule cibersortx:
input:
signature = INPUT_FOLDER + "/{signature}.txt" if credentials_given else "",
mixture = INPUT_FOLDER + "/{mixture}.txt" if credentials_given else ""
output:
CIBERSORTx_OUTPUT_FOLDER + "/{signature}___CIBERSORTx_fractions___{mixture}/CIBERSORTx_Results.txt" if credentials_given else ""
run:
if credentials_given:
shell("Rscript scripts/run_cibersort_local_container.R --signature_file {input.signature} --expression_file {input.mixture} --mail " + MAIL + " --token " + TOKEN + " --output_folder " + CIBERSORTx_OUTPUT_FOLDER)
rule curate_cibersortx_results:
input:
CIBERSORTx_OUTPUT_FOLDER + "/{signature}___CIBERSORTx_fractions___{mixture}/CIBERSORTx_Results.txt" if credentials_given else "",
output:
CIBERSORTx_OUTPUT_FOLDER + "/{signature}___CIBERSORTx_fractions___{mixture}/CIBERSORTx_Results_curated.txt" if credentials_given else "",
run:
if credentials_given:
shell("Rscript scripts/curate_cibersortx_results.R --cibersortx_results_file {input} --signature {wildcards.signature} --output_file {output}")
rule deconvolutions:
input:
mixture = INPUT_FOLDER + "/{mixture}.txt"
output:
OUTPUT_FOLDER + "/deconvolutions/deconvolutions_{mixture}.txt"
shell:
"Rscript scripts/deconvolution/deconvolution.R --expression_file {input.mixture} --output_file {output}"
rule all_deconvolutions_one_table:
input:
OUTPUT_FOLDER + "/deconvolutions/deconvolutions_{mixture}.txt",
expand(CIBERSORTx_OUTPUT_FOLDER + "/{signature}___CIBERSORTx_fractions___{{mixture}}/CIBERSORTx_Results_curated.txt", signature=CBSx_SIGNATURES) if credentials_given else []
output:
OUTPUT_FOLDER + "/all_deconvolutions/all_deconvolutions_{mixture}.txt"
run:
shell("Rscript scripts/merge_all_deconvolutions.R --deconvolution_files {input} --output_file {output}")
real_user = os.environ["SUDO_USER"]
rule fix_root_permissions:
input:
expand(OUTPUT_FOLDER + "/all_deconvolutions/all_deconvolutions_{mixture}.txt", mixture = MIXTURES),
output:
OUTPUT_FOLDER + "/.fixed_permissions"
shell:
"touch {output} && chown -R " + real_user + " " + OUTPUT_FOLDER
rule all:
input:
expand(expand(CIBERSORTx_OUTPUT_FOLDER + "/{signature}___CIBERSORTx_fractions___{{mixture}}/CIBERSORTx_Results_curated.txt", signature=CBSx_SIGNATURES), mixture = MIXTURES) if credentials_given else [],
OUTPUT_FOLDER + "/.fixed_permissions",
expand(OUTPUT_FOLDER + "/deconvolutions/deconvolutions_{mixture}.txt", mixture = MIXTURES) if credentials_given else [],
expand(OUTPUT_FOLDER + "/all_deconvolutions/all_deconvolutions_{mixture}.txt", mixture = MIXTURES) if credentials_given else [],