forked from saketkc/rna-seq-snakemake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile.kallisto.sra
155 lines (133 loc) · 3.94 KB
/
Snakefile.kallisto.sra
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
from itertools import chain, combinations
from os.path import join
import glob
import re
from collections import defaultdict
import os
from os.path import join
import glob
import numpy as np
import pandas as pd
import os
import errno
def mkdir_p(path):
"""Python version mkdir -p
Parameters
----------
path : str
"""
if path:
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
include:
config['config_path']
workdir: OUT_DIR
mkdir_p(join(OUT_DIR, 'slurm-logs'))
ALL_SRA_FILES = glob.glob('{}/**/*.sra'.format(RAWDATA_DIR), recursive=True)
SRX_ID = defaultdict(list)
for sample in ALL_SRA_FILES:
srx, srr = sample.replace('{}'.format(RAWDATA_DIR),'').lstrip('/').rstrip('/').split('/')
SRX_ID[srx].append(srr.replace('.sra', ''))
SRR_ID = list(SRX_ID.values())
SRX_SAMPLES = list(SRX_ID.keys())
ALL_SRR = [item for sublist in SRR_ID for item in sublist]
def merge_fastq_input(wildcards):
return ['sratofastq/{}.fastq.gz'.format(srr) for srr in SRX_ID[wildcards.sample]]
def sra_to_fastq_input(wildcards):
srr_id = wildcards.sample
for srx_id in list(SRX_ID.keys()):
value = SRX_ID[srx_id]
if srr_id in list(value):
return ancient(str(join(RAWDATA_DIR, srx_id, srr_id+'.sra')))
print("WRONG encodeterend: {}".format(srr_id))
def get_wrapper(wrapper_name):
path = os.path.dirname(os.path.abspath(os.path.realpath(workflow.snakefile)))
return 'file://' + os.path.join(path,
'wrappers',
wrapper_name + '.py')
rule all:
input:
CDNA_IDX,
CDS_IDX,
expand('counts_cdna/{sample}/abundance.tsv', sample=SRX_SAMPLES),
expand('counts_cds/{sample}/abundance.tsv', sample=SRX_SAMPLES)
rule sra_to_fastq:
input: sra_to_fastq_input
benchmark: 'benchmarks/sra_to_fastq/{sample}.txt'
output: 'sratofastq/{sample}.fastq.gz'
params:
prefix_sra='sratofastq/{sample}.sra.fastq',
prefix='sratofastq/{sample}.fastq',
temp_dir='/tmp/{sample}_sratofastq',
shell:
r'''
fastq-dump --split-3 \
-O sratofastq {input} \
&& gzip {params.prefix}
'''
"""
rule sra_to_fastq:
input: sra_to_fastq_input
benchmark: 'benchmarks/sra_to_fastq/{sample}.txt'
output: 'sratofastq/{sample}.fastq.gz'
params:
prefix_sra='sratofastq/{sample}.sra.fastq',
prefix='sratofastq/{sample}.fastq',
temp_dir='/tmp/{sample}_sratofastq',
threads: 16
shell:
r'''
parallel-fastq-dump --threads 16 --outdir sratofastq/ --gzip -s {input}
'''
"""
rule merge_fastq:
input:
all_fastq = expand('sratofastq/{srr}.fastq.gz', srr=ALL_SRR),
dynamic_input = merge_fastq_input
benchmark: 'benchmarks/merge_fastq/{sample}.txt'
output: temp('fastq_merged/{sample}.fastq.gz')
wrapper:
get_wrapper('merge_fastq_wrapper')
rule quantify_cdna:
input:
R1='fastq_merged/{sample}.fastq.gz',
output:
'counts_cdna/{sample}/abundance.tsv',
params:
index=CDNA_IDX,
outdir='counts_cdna/{sample}'
threads: 16 ## hardcoded below
shell:
r'''
kallisto quant \
--index={params.index} \
--threads={threads}\
-l 200 \
-s 30 \
--output-dir={params.outdir} \
--single \
-b 100 <(zcat {input.R1})'''
rule quantify_cds:
input:
R1='fastq_merged/{sample}.fastq.gz',
output:
'counts_cds/{sample}/abundance.tsv',
params:
index=CDS_IDX,
outdir='counts_cds/{sample}'
threads: 16 ## hardcoded below
shell:
r'''
kallisto quant \
--index={params.index} \
--threads={threads}\
-l 200 \
-s 30 \
--output-dir={params.outdir} \
--single \
-b 100 <(zcat {input.R1})'''