forked from bmc-CompBio/snakemake_SRA_RNASEQ_PE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
116 lines (100 loc) · 3.43 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
#
configfile: "config.yaml"
import pandas as pd
sample_table = pd.read_table(config["runtable"], sep=",")
samples = list(sample_table['Sample Name'].unique())
# everything that need network connection for
localrules: prefetch, get_index_files
rule all:
input:
expand("{SRS}_out/{SRS}_rsem.genes.results", SRS=samples)
rule STAR:
input:
files1=lambda wildcards: expand("raw/{sample}_1.fastq.gz",
sample=list(sample_table[sample_table['Sample Name']==wildcards.SRS].Run)),
files2=lambda wildcards: expand("raw/{sample}_2.fastq.gz",
sample=list(sample_table[sample_table['Sample Name']==wildcards.SRS].Run)),
index="star_index/Genome"
output:
temp("{SRS}_out/{SRS}.Aligned.toTranscriptome.out.bam"),
temp("{SRS}_out/{SRS}.Aligned.out.bam"),
threads: 16
params:
files1=lambda wildcards: ",".join(expand("raw/{sample}_1.fastq.gz",
sample=list(sample_table[sample_table['Sample Name']==wildcards.SRS].Run))),
files2=lambda wildcards: ",".join(expand("raw/{sample}_2.fastq.gz",
sample=list(sample_table[sample_table['Sample Name']==wildcards.SRS].Run))),
quantMode="TranscriptomeSAM GeneCounts",
outSAMtype="BAM Unsorted",
limitBAMsortRAM="40000000000",
readFilesCommand="gunzip -c",
SRS=lambda wildcards: wildcards.SRS
shell:
"""
STAR --genomeDir star_index \
--sjdbGTFfile genome.gtf \
--runThreadN {threads} \
--readFilesCommand {params.readFilesCommand} \
--quantMode {params.quantMode} --outSAMtype {params.outSAMtype} \
--limitBAMsortRAM {params.limitBAMsortRAM} \
--readFilesIn {params.files1} {params.files2} \
--outFileNamePrefix {params.SRS}_out/{params.SRS}.
"""
rule RSEM:
input:
"{SRS}_out/{SRS}.Aligned.toTranscriptome.out.bam",
index="star_index/Genome"
output:
"{SRS}_out/{SRS}_rsem.genes.results",
temp("{SRS}_out/{SRS}_rsem.transcript.bam"),
threads: 16
params:
SRS=lambda wildcards: wildcards.SRS
shell:
"""
rsem-calculate-expression --bam --paired-end --strandedness none -p {threads} {params.SRS}_out/{params.SRS}.Aligned.toTranscriptome.out.bam star_index/genome {params.SRS}_out/{params.SRS}_rsem
"""
rule fastq_dump:
input:
"sra/{SRR}.sra"
output:
"raw/{SRR}_1.fastq.gz",
"raw/{SRR}_2.fastq.gz"
shell:
"""
fastq-dump --split-3 --gzip {input} --outdir raw
"""
rule prefetch:
output:
"sra/{SRR}.sra"
shell:
"prefetch -O sra {wildcards.SRR}"
rule star_index:
input:
fasta="genome.fa",
gtf="genome.gtf"
output:
"star_index/Genome",
"star_index/genome.transcripts.fa",
"star_index/chrNameLength.txt"
threads: 30
shell:
"""
rsem-prepare-reference --gtf {input.gtf} --star -p {threads} {input.fasta} star_index/genome
"""
rule get_index_files:
params:
genomeLocation=config['genomeFTP'],
gtfLocation=config['gtfFTP']
output:
"genome.fa",
"genome.gtf"
shell:
"""
wget -O genome.fa.gz {params.genomeLocation}
gunzip genome.fa.gz
wget -O genome.gtf.gz {params.gtfLocation}
gunzip genome.gtf.gz
"""
onsuccess:
shell("rm *.out")