-
Notifications
You must be signed in to change notification settings - Fork 1
/
Snakefile
233 lines (216 loc) · 5.96 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# Read in data
import pandas as pd
samples_table = pd.read_csv("samples.csv").set_index("sample",drop=False)
# Definitions for rule all
gex_table = samples_table[samples_table.sample_gex == True]
SAMPLES_GEX = gex_table.loc[:,"sample"].values.tolist()
citeseq_table = samples_table[samples_table.sample_citeseq == True]
SAMPLES_CITESEQ = citeseq_table.loc[:,"sample"].values.tolist()
vdj_table = samples_table[samples_table.sample_vdj == True]
vdj_library_table = vdj_table[~vdj_table['fastq_vdj'].astype(str).str.contains("False")]
vdj_no_library_table = vdj_table[vdj_table['fastq_vdj'].astype(str).str.contains("False")]
SAMPLES_VDJ_library = vdj_library_table.loc[:,"sample"].values.tolist()
SAMPLES_VDJ_no_library = vdj_no_library_table.loc[:,"sample"].values.tolist()
SAMPLES_VDJ_no_library = [s + "_TCR" for s in SAMPLES_VDJ_no_library]
velocyto_table = samples_table[samples_table.sample_velocity == True]
SAMPLES_VELO = velocyto_table.loc[:,"sample"].values.tolist()
arcas_table = samples_table[samples_table.sample_arcas == True]
SAMPLES_ARCAS = arcas_table.loc[:,"sample"].values.tolist()
# Define local rule
localrules:
all
# Rule to define output directories
rule all:
input:
expand("cellranger/{final_gex}",final_gex=SAMPLES_GEX),
expand("citeseq/{final_citeseq}",final_citeseq=SAMPLES_CITESEQ),
expand("vdj_cellranger/{final_vdj}",final_vdj=SAMPLES_VDJ_library),
expand("vdj_trust4/{final_vdj}",final_vdj=SAMPLES_VDJ_no_library),
expand("velocyto/{final_velocity}",final_velocity=SAMPLES_VELO),
expand("arcas/{final_arcas}/genotype/",final_arcas=SAMPLES_ARCAS)
# Function to read in gex fastq paths from samples_table
def get_gex_input(wildcards):
return gex_table.loc[wildcards.sample,"fastq_gex"]
# Cellranger count rule
rule count:
input:
get_gex_input
output:
directory("cellranger/{sample}/")
threads:
8
resources:
runtime="03-00:00:00",
mem_mb=128000
shell:
"""
module load cellranger/7.0.1
"""
"""
mkdir -p cellranger
cd cellranger
cellranger count --id={wildcards.sample} \
--transcriptome=/ix/tbruno/arc85/00_INBOX/cellranger_ref_230418/GRCh38 \
--fastqs={input} \
--sample={wildcards.sample} \
--localcores=8 \
--localmem=128 \
--include-introns=false
"""
# Function to read in citeseq fastq paths from samples_table
def get_citeseq_input(wildcards):
return citeseq_table.loc[wildcards.sample,"fastq_citeseq"]
# CITEseq count rule
rule citeseq:
input:
fastq=get_citeseq_input,
barcodes="cellranger/{sample}/"
output:
directory("citeseq/{sample}")
threads:
4
resources:
runtime="12:00:00",
mem_mb=40000
shell:
"""
module load gcc/8.2.0 r/3.6.0
"""
"""
find {input.fastq} -name "*_R1_*" | xargs cat > {input.fastq}/r1_merged_fastq.gz
find {input.fastq} -name "*_R2_*" | xargs cat > {input.fastq}/r2_merged_fastq.gz
"""
"""
Rscript cell_barcode_id.R {input.barcodes}/outs/filtered_feature_bc_matrix {wildcards.sample}
EXPECTED_CELLS=$(wc -l {wildcards.sample}_whitelist.csv | cut -d' ' -f 1)
"""
"""
module purge
module load cite-seq-count/1.4.3
"""
"""
CITE-seq-Count -R1 {input.fastq}/r1_merged_fastq.gz \
-R2 {input.fastq}/r2_merged_fastq.gz \
-t citeseq_totalseqC_10tags_human_murine.csv \
-cbf 1 -cbl 16 -umif 17 -umil 26 \
-trim 10 \
-o {output} \
-cells $EXPECTED_CELLS \
-wl {wildcards.sample}_whitelist.csv \
-T 4
"""
# Function to define vdj samples with libraries
def get_vdj_library_input(wildcards):
return vdj_library_table.loc[wildcards.sample,"fastq_vdj"]
# VDJ with cellranger with VDJ library
rule vdj_lib:
input:
get_vdj_library_input
output:
directory("vdj_cellranger/{sample}")
threads:
4
resources:
runtime="01-00:00:00",
mem_mb=60000
shell:
"""
module load cellranger/7.0.1
"""
"""
mkdir -p vdj_cellranger
cd vdj_cellranger
cellranger vdj --id={wildcards.sample} \
--fastqs={input} \
--reference=/ix/tbruno/arc85/00_INBOX/cellranger_ref_230418/vdj_reference/refdata-cellranger-vdj-GRCh38-alts-ensembl-7.1.0 \
--sample={wildcards.sample} \
--localcores=4 \
--localmem=59
"""
# VDJ with TRUST without VDJ library
rule vdj_no_lib:
input:
"cellranger/{sample}"
output:
directory("vdj_trust4/{sample}_TCR")
threads:
1
resources:
runtime="12:00:00",
mem_mb=16000
shell:
"""
/zfs1/tbruno/arc85/TRUST4/run-trust4 \
-f /zfs1/tbruno/arc85/TRUST4/hg38_bcrtcr.fa \
--ref /zfs1/tbruno/arc85/TRUST4/human_IMGT+C.fa \
-b {input}/outs/possorted_genome_bam.bam \
--barcode CB \
--od {output} \
-t 1
"""
# Velocyto rule
rule velocity:
input:
"cellranger/{sample}"
output:
directory("velocyto/{sample}")
threads:
4
resources:
runtime="12:00:00",
mem_mb=64000
shell:
"""
module load gcc/8.2.0
module load samtools/1.9
module load velocyto/0.17
"""
"""
velocyto run10x -m /zfs1/tbruno/arc85/00_INBOX/18071_for_velocity/mat/grch38_repeat_mask.gtf \
{input} \
/bgfs/genomics/refs/CellRanger/refdata-cellranger-GRCh38-3.0.0/genes/genes.gtf
mkdir -p velocyto/{wildcards.sample}
mv cellranger/{wildcards.sample}/velocyto velocyto/{wildcards.sample}
"""
# ARCAS extract rule
rule arcas_extract:
input:
"cellranger/{sample}"
output:
directory("arcas/{sample}/fastq/")
threads:
4
resources:
runtime="02:00:00",
mem_mb=64000
shell:
"""
mkdir -p {output}
module load singularity/3.9.6
singularity exec --bind {input}:/mnt \
--bind /ihome/tbruno/arc85/arcasHLA:/home/arcasHLA \
--bind {output}:/out \
--bind .:/script \
/ihome/tbruno/arc85/arcashla.sif /bin/bash /script/arcas_extract.sh
"""
# ARCAS align rule
rule arcas_align:
input:
"arcas/{sample}/fastq"
output:
directory("arcas/{sample}/genotype/")
threads:
4
resources:
runtime="02:00:00",
mem_mb=64000
shell:
"""
mkdir -p {output}
module load singularity/3.9.6
singularity exec --bind {input}:/mnt \
--bind /ihome/tbruno/arc85/arcasHLA:/home/arcasHLA \
--bind {output}:/out \
--bind .:/script \
/ihome/tbruno/arc85/arcashla.sif /bin/bash /script/arcas_align.sh
"""