forked from exsquire/gbrSnake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnakefile
More file actions
162 lines (153 loc) · 5.96 KB
/
Snakefile
File metadata and controls
162 lines (153 loc) · 5.96 KB
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
singularity: "gbrs.simg"
import os
import pandas as pd
from snakemake.utils import validate
##### load config and sample sheets #####
configfile: "config/config.yaml"
validate(config, schema="config/schemas/config.schema.yaml")
samples = pd.read_csv(config["samples"]).set_index("run", drop = False)
validate(samples, "config/schemas/samples.schema.yaml")
tags = list(set(samples.tag))
#For unique transprob files after pooling
tagSamples = samples.drop_duplicates(subset='tag')
##### Rules #############################
rule all:
input:
expand([
"bam/{run}/{run}.bam",
"emase/{run}/{run}.h5",
"output/emase_compress/{run}.h5c"],
run = samples.run.tolist()),
expand([
"output/pooled_emase/{tag}.pooled",
"output/multiway/{tag}/gbrs.quantified.multiway.genes.alignment_counts",
"output/multiway/{tag}/gbrs.quantified.multiway.genes.expected_read_counts",
"output/multiway/{tag}/gbrs.quantified.multiway.genes.tpm",
"output/multiway/{tag}/gbrs.quantified.multiway.isoforms.alignment_counts",
"output/multiway/{tag}/gbrs.quantified.multiway.isoforms.expected_read_counts",
"output/reconstruct/{tag}/gbrs.reconstructed.genoprobs.npz",
"output/reconstruct/{tag}/gbrs.reconstructed.genotypes.npz",
"output/reconstruct/{tag}/gbrs.reconstructed.genotypes.tsv",
"output/diploid/{tag}/gbrs.quantified.diploid.genes.alignment_counts",
"output/diploid/{tag}/gbrs.quantified.diploid.genes.expected_read_counts",
"output/diploid/{tag}/gbrs.quantified.diploid.genes.tpm",
"output/diploid/{tag}/gbrs.quantified.diploid.isoforms.alignment_counts",
"output/diploid/{tag}/gbrs.quantified.diploid.isoforms.expected_read_counts",
"output/diploid/{tag}/gbrs.quantified.diploid.isoforms.tpm"],
tag = tags)
rule align_fastq:
input:
"input/{run}.fastq.gz"
output:
temp("bam/{run}/{run}.bam")
priority: 5
resources:
load = 1
shell:
"set +o pipefail; "
"export PATH=/opt/conda/envs/gbrs/bin:$PATH; "
"bowtie -q -a --best --strata --sam -v 3 /usr/share/gbrs/R84-REL1505/transcripts "
"{input} | samtools view -bS - > {output}"
rule bam_to_emase:
input:
"bam/{run}/{run}.bam"
output:
temp("emase/{run}/{run}.h5")
priority: 6
shell:
"set +o pipefail; "
"export PATH=/opt/conda/envs/gbrs/bin:$PATH; "
"gbrs bam2emase -i {input} -m /usr/share/gbrs/R84-REL1505/ref.transcripts.info "
"-s A,B,C,D,E,F,G,H -o {output}"
rule compress_emase:
input:
"emase/{run}/{run}.h5"
output:
"output/emase_compress/{run}.h5c"
priority: 7
shell:
"set +o pipefail; "
". /opt/conda/etc/profile.d/conda.sh; "
"conda activate gbrs; "
"gbrs compress -i {input} -o {output}"
rule pool_emase:
input:
lambda wildcards: list("output/emase_compress/"+samples.run.loc[(samples.tag == wildcards.tag)]+".h5c")
output:
"output/pooled_emase/{tag}.pooled"
priority: 4
params:
pool=lambda wildcards, input: ",".join(input)
shell:
"set +o pipefail; "
". /opt/conda/etc/profile.d/conda.sh; "
"conda activate gbrs; "
"gbrs compress -i {params.pool} -o {output}"
rule quantify_multiway:
input:
emase = "output/pooled_emase/{tag}.pooled"
output:
"output/multiway/{tag}/gbrs.quantified.multiway.genes.alignment_counts",
"output/multiway/{tag}/gbrs.quantified.multiway.genes.expected_read_counts",
"output/multiway/{tag}/gbrs.quantified.multiway.genes.tpm",
"output/multiway/{tag}/gbrs.quantified.multiway.isoforms.alignment_counts",
"output/multiway/{tag}/gbrs.quantified.multiway.isoforms.expected_read_counts",
"output/multiway/{tag}/gbrs.quantified.multiway.isoforms.tpm"
priority: 3
params:
g2tRef = "/usr/share/gbrs/R84-REL1505/ref.gene2transcripts.tsv",
hybTarg = "/usr/share/gbrs/R84-REL1505/gbrs.hybridized.targets.info",
method = "2"
shell:
"set +o pipefail; "
". /opt/conda/etc/profile.d/conda.sh; "
"conda activate gbrs; "
"gbrs quantify -i {input.emase} -g {params.g2tRef} "
"-L {params.hybTarg} -M {params.method} "
"--report-alignment-counts; "
"mv gbrs.quantified.multiway* output/multiway/{wildcards.tag}/"
rule reconstruct_genome:
input:
counts = "output/multiway/{tag}/gbrs.quantified.multiway.genes.tpm"
output:
"output/reconstruct/{tag}/gbrs.reconstructed.genoprobs.npz",
"output/reconstruct/{tag}/gbrs.reconstructed.genotypes.npz",
"output/reconstruct/{tag}/gbrs.reconstructed.genotypes.tsv"
priority: 2
params:
transprob = lambda wildcards: tagSamples.loc[(tagSamples.tag == wildcards.tag),"transprob"].item(),
avecs = "/usr/share/gbrs/R84-REL1505/avecs.npz",
genPos = "/usr/share/gbrs/R84-REL1505/ref.gene_pos.ordered.npz"
shell:
"set +o pipefail; "
". /opt/conda/etc/profile.d/conda.sh; "
"conda activate gbrs; "
"echo {wildcards.tag} {input.counts} {params.transprob} > "
"gbrs.reconstructed.transprob.log; "
"gbrs reconstruct -e {input.counts} -t /usr/share/gbrs/R84-REL1505/{params.transprob} "
"-x {params.avecs} "
"-g {params.genPos}; "
"mv gbrs.reconstructed* output/reconstruct/{wildcards.tag}/"
rule quantify_diploid:
input:
emase = "output/pooled_emase/{tag}.pooled",
geno = "output/reconstruct/{tag}/gbrs.reconstructed.genotypes.tsv"
output:
"output/diploid/{tag}/gbrs.quantified.diploid.genes.alignment_counts",
"output/diploid/{tag}/gbrs.quantified.diploid.genes.expected_read_counts",
"output/diploid/{tag}/gbrs.quantified.diploid.genes.tpm",
"output/diploid/{tag}/gbrs.quantified.diploid.isoforms.alignment_counts",
"output/diploid/{tag}/gbrs.quantified.diploid.isoforms.expected_read_counts",
"output/diploid/{tag}/gbrs.quantified.diploid.isoforms.tpm"
priority: 1
params:
g2tRef = "/usr/share/gbrs/R84-REL1505/ref.gene2transcripts.tsv",
hybTarg = "/usr/share/gbrs/R84-REL1505/gbrs.hybridized.targets.info",
method = "2"
shell:
"set +o pipefail; "
". /opt/conda/etc/profile.d/conda.sh; "
"conda activate gbrs; "
"gbrs quantify -i {input.emase} -G {input.geno} -g {params.g2tRef} "
"-L {params.hybTarg} -M {params.method} --report-alignment-counts; "
"mv gbrs.quantified.diploid* output/diploid/{wildcards.tag}/"