forked from plantgenomicslab/RNASeq_CSSI
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSnakefile
executable file
·174 lines (143 loc) · 7.19 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
import sys
import os
import pandas as pd
SAMPLE_FILE = pd.read_table('samples.tsv', sep="\s+", dtype=str).set_index("sample", drop=False) # enforce str in index
SAMPLE_LIST = SAMPLE_FILE["sample"].values.tolist()
THREADS = 16
configfile: "./config.json"
os.makedirs("output/cluster/logs/", exist_ok=True)
for path in SAMPLE_LIST:
os.makedirs("output/" + path + "/stat/", exist_ok=True)
os.makedirs("output/" + path + "/RAW/", exist_ok=True)
###################
##CHECK reference file, if there's no reference, please check fasta file and gff file. If the fasta and GFF is there, need to create with below commands
#chrLength_test = os.path.exists('chrLength.txt')
#chrNameLength_test = os.path.exists('chrNameLength.txt')
#chrName_test = os.path.exists('chrName.txt')
#exonGTI_test = os.path.exists('exonGeTrInfo.tab')
#exonInfo_test = os.path.exists('exonInfo.tab')
REF_FILES = ['chrNameLength.txt', 'chrName.txt', 'exonGeTrInfo.tab', 'exonInfo.tab', 'geneInfo.tab',
'Genome', 'genomeParameters.txt', 'SA', 'SAindex', 'sjdbInfo.txt', 'sjdbList.fromGTF.out.tab',
'sjdbList.out.tab', 'transcriptInfo.tab']
missing_files = 0
os.makedirs('ref', exist_ok=True)
#for ref in REF_FILES:
# if not os.path.exists('ref/' + ref):
# missing_files = 1
#if missing_files:
# os.system('curl -L https://www.arabidopsis.org/download_files/Genes/TAIR10_genome_release/TAIR10_gff3/TAIR10_GFF3_genes.gff > ref/TAIR10_GFF3_genes.gff; curl -L https://www.arabidopsis.org/download_files/Genes/TAIR10_genome_release/TAIR10_chromosome_files/TAIR10_chr_all.fas > ref/TAIR10_chr_all.fas')
#https://www.arabidopsis.org/download_files/Genes/TAIR10_genome_release/TAIR10_gff3/TAIR10_GFF3_genes.gff
#https://www.arabidopsis.org/download_files/Genes/TAIR10_genome_release/TAIR10_chromosome_files/TAIR10_chr_all.fas
##REF = 'reference/'
##We will use this at mapping step
#os.system("gffread ref/TAIR10_GFF3_genes.gff -T -o ref/TAIR10.gtf")
#FASTA_LINES = open('ref/TAIR10_chr_all.fas', 'r').readlines()
#FASTA_OUTPUT = open('ref/TAIR10_chr_all.fas.fixed', 'w')
#chr_count = 0
#for row in FASTA_LINES:
# if row[0] == '>':
# FASTA_OUTPUT.write('>Chr' + row[1].upper() + '\n')
# else:
# FASTA_OUTPUT.write(row)
#FASTA_OUTPUT.close()
##need to create refrence folder
#os.system("STAR --runThreadN 6 --genomeDir ./reference/ --genomeFastaFiles ref/TAIR10_chr_all.fas.fixed --sjdbGTFfile ref/TAIR10.gtf --runMode genomeGenerate --sjdbOverhang 99 --genomeSAindexNbases 10")
###################
#os.makedirs("output/cluster/logs/", exist_ok=True)
#for path in SAMPLE_LIST:
# os.makedirs("output/" + path + "/stat/", exist_ok=True)
# os.makedirs("output/" + path + "/RAW/", exist_ok=True)
rule all:
input:
"output/Final_analysis/diffExpr.P1e-3_C1.matrix",
"output/featureCount.cnt_for_tpm.tpm.tab",
expand("output/{rundeg_input}", rundeg_input = config["rundeg-output"]),
#"output/featureCount.cnt.fixed",
expand("output/{sample}/{sample}Aligned.sortedByCoord.out.bam", sample = SAMPLE_LIST),
#expand("output/{sample}/{rundeg_input}", sample = SAMPLE_LIST, rundeg_input = config["rundeg-output"])
expand("output/{sample}/TRIM/{sample}_pass_2_val_2.fq.gz", sample = SAMPLE_LIST),
expand("output/{sample}/TRIM/{sample}_pass_1_val_1.fq.gz", sample = SAMPLE_LIST)
################
### please implement
rule fastqdump:
message: "-~- Downloading fastq files... -~-"
output:
fwd="output/{sample}/RAW/{sample}_pass_1.fastq.gz",
rev="output/{sample}/RAW/{sample}_pass_2.fastq.gz"
shell:
"fastq-dump --outdir output/{wildcards.sample}/RAW/ --gzip --skip-technical --readids --read-filter pass --dumpbase --split-3 --clip {wildcards.sample}"
################
rule trimming:
message: "-~- Trimming fastq files... -~-"
input:
fwd="output/{sample}/RAW/{sample}_pass_1.fastq.gz",
rev="output/{sample}/RAW/{sample}_pass_2.fastq.gz"
output:
fwd="output/{sample}/TRIM/{sample}_pass_1_val_1.fq.gz",
rev="output/{sample}/TRIM/{sample}_pass_2_val_2.fq.gz"
threads: THREADS
run:
shell('mkdir -p output/{wildcards.sample}/TRIM')
shell('trim_galore \
--paired \
--three_prime_clip_R1 10 \
--three_prime_clip_R2 10 \
--cores {threads} \
--max_n 50 \
--gzip \
-o output/{wildcards.sample}/TRIM/ \
{input.fwd} \
{input.rev}')
#module = ['LSC', 'IRA', 'IRB', 'SSC']
rule mapping:
threads: THREADS
input:
fwd="output/{sample}/TRIM/{sample}_pass_1_val_1.fq.gz",
rev="output/{sample}/TRIM/{sample}_pass_2_val_2.fq.gz"
output:
file = "output/{sample}/{sample}Aligned.sortedByCoord.out.bam"
message: "STAR mapping"
run:
#shell('mkdir -p output/{wildcards.sample}/')
shell('STAR --runMode alignReads --runThreadN 10 --readFilesCommand zcat --outFilterMultimapNmax 10 --alignIntronMin 30 --alignIntronMax 55000 --genomeDir ./reference --readFilesIn {input.fwd},{input.rev} --outSAMtype BAM SortedByCoordinate --outFileNamePrefix output/{wildcards.sample}/{wildcards.sample}')
##################
rule readscount:
input:
bam = expand("output/{sample}/{sample}Aligned.sortedByCoord.out.bam", sample = SAMPLE_LIST)
output:
ftcount = "output/featureCount.cnt.fixed"
shell:
"featureCounts -p -Q 10 -M --fraction -s 0 -T 16 -o output/featureCount.cnt -a ./ref/TAIR10.gtf {input.bam}; python src/fix_featCnt_header.py output/featureCount.cnt"
### EXAMPLE
#Cont_1Aligned.sortedByCoord.out.bam Cont_2Aligned.sortedByCoord.out.bam Cont_3Aligned.sortedByCoord.out.bam Hours2_1Aligned.sortedByCoord.out.bam Hours2_2Aligned.sortedByCoord.out.bam Hours2_3Aligned.sortedByCoord.out.bam Hours4_1Aligned.sortedByCoord.out.bam Hours4_2Aligned.sortedByCoord.out.bam Hours4_3Aligned.sortedByCoord.out.bam Hours6_1Aligned.sortedByCoord.out.bam Hours6_2Aligned.sortedByCoord.out.bam Hours6_3Aligned.sortedByCoord.out.bam Hours8_1Aligned.sortedByCoord.out.bam Hours8_3Aligned.sortedByCoord.out.bam
###############
###############
rule rundeg:
input:
ftcount = "output/featureCount.cnt.fixed"
output:
rd_out = directory(expand("output/{rundeg_input}", rundeg_input = config["rundeg-output"]))
shell:
"run_DE_analysis.pl -m output/featureCount.cnt.fixed --method DESeq2 --samples_file ./samplefile --output {output.rd_out} --contrasts ./contrasts"
##############
###############
rule TPM:
input:
ftcount = "output/featureCount.cnt.fixed"
output:
ft_tab = "output/featureCount.cnt_for_tpm.tpm.tab"
shell:
"cut -f 1,6- {input.ftcount} | egrep -v '#' >> output/featureCount.cnt_for_tpm; python tpm_raw_exp_calculator.py -count output/featureCount.cnt_for_tpm"
##############
##############
rule diffexpr:
## Need to go to output folder
input:
tmp_tab = "output/featureCount.cnt_for_tpm.tpm.tab"
output:
analyze = "output/Final_analysis/diffExpr.P1e-3_C1.matrix"
params:
rundeg_file = expand("output/{rundeg_input}", rundeg_input = config["rundeg-output"])
shell:
"cd {params.rundeg_file}; analyze_diff_expr.pl --matrix ../featureCount.cnt_for_tpm.tpm.tab -P 1e-3 -C 1 --max_genes_clust 40000; mkdir -p ../Final_analysis/; mv diffExpr.P1e-3_C1* ../Final_analysis/; mv *.subset ../Final_analysis; mv *.samples ../Final_analysis; mv *.matrix ../Final_analysis; cd ../.."
#############