-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlncRNA.Snakemake
237 lines (190 loc) · 8.61 KB
/
lncRNA.Snakemake
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
234
235
236
#run snakemake
#
#snakemake -d `pwd` -s `pwd`/lncRNA.Snakemake --stats snakemake.stats -j 100 --cluster 'qsub {params.cluster}'
###############################
##### long non-coding RNA #####
###############################
#Create a directory "lncRNA" and copy all nessesary files (output from genomeAnnotation.Snakemake) to this directory.
#Create a subdirectory "DIFF" and copy the mapped sam-files to this directory.
#Create a directory "BLAST" and copy the Uniprotdatabase to this directory.
# EXAMPLE:
### genome: claImm.fasta, genome-Annotation: claImm.Annot.gff3
### pasa-assembly: claImm.pasa_assemblies.gff3, claImm.assemblies.fasta, claImm.PASAhints.gff
### transdecoder: claImm.assemblies.fasta.transdecoder.genome.gff3
### mapped-files: SAMPLE.mapped.sam
### BLAST db: UniProt90pSaccharomyceta.fasta
#necessary programs:
#~/bin/rmenterdb.pl
#perl mergealign.pl
#IntersectBed
#getAnnoFasta.pl
#cpat
#blast
#pfam
#featureCounts
#diff.R
#################################
# #
# Variables setup #
# #
#################################
#################################
#ENVIRONMENT #
#################################
#HOME=os.environ['HOME']
WORKDIR="/media/ckustor/work/lncRNA/snakemaketest"
#COMPUTEDIR=os.environ['GLOBAL']
#################################
#THREADS #
#################################
THREADS=4
##################################
#FILES #
##################################
ID="claImm"
GENOME=ID+".fasta"
ANNOT=ID+".Annot.gff3"
PASA=ID+".pasa_assemblies.gff3"
PASAFASTA=ID+".assemblies.fasta"
BLAST="UniProt90pSaccharomyceta.fasta"
PFAM="/home/ckustor/bin/PfamScan/db/"
SAMS=WORKDIR+"/DIFF/{SAMPLES}.sam"
SAMPLES,=glob_wildcards(SAMS);
SAMPLES=sorted(SAMPLES)
#Which rules are run locally # depends on which computer the pipeline is running
localrules: intersect, preparefiles, cpat, pfam, blast, lncRNA, countreads, diff
##################################
## #
## ALL #
## #
##################################
rule all:
input: "DIFF/diff.ok"
#################################################################################
# #
# DIFFERENTIAL EXPRESSION #
# #
#################################################################################
########################
#### DIFF ####
########################
rule diff:
input: "DIFF/all.counts"
output: "DIFF/diff.ok"
params:
threads: THREADS
shell:"""
cd DIFF
Rscript {WORKDIR}/limma.R -c {WORKDIR}/{input}
touch {WORKDIR}/{output}
"""
########################
#### COUNT READS ####
########################
rule countreads:
input: sam=expand(WORKDIR+"/DIFF/{samples}.sam", samples=SAMPLES), annot=ID+".lncRNA.gff3"
output: "DIFF/all.counts"
params:
threads: THREADS
shell: """
cd DIFF
cat {WORKDIR}/{input.annot} | sed -r 's/cDNA_match/exon/' | sed -r 's#ID=#gene_id "#' | sed -r 's/;.+/";/g' > lncRNA.gtf
featureCounts -s 1 -T {threads} -a lncRNA.gtf -o counts {input.sam}
cat counts | grep -vP "^#" | sed -r 's#{WORKDIR}/DIFF/##g' | cut -f 1,7- > {WORKDIR}/{output}
"""
#################################################################################
# #
# DATABASE SEARCH #
# #
#################################################################################
########################
#### lncRNA ####
########################
rule lncRNA: ids="CPAT/cpat.results", blast="BLAST/blast.coding.candidates", pfam="PFAM/"+ID+".pfam.coding.candidates"
input: lnc=ID+"lncRNA.gff3"
output:
threads: THREADS
params:
shell:"""
cat {WORKDIR}/{input.blast} {WORKDIR}/{input.pfam} | sort -u > coding.candidates
cut -f 1 {WORKDIR}/{input.ids} > id.cpat.results
cat id.cpat.results | perl -lane 'my $count=`grep -cw $F[0] coding.candidates`; chomp($count); if($count==0){{print $F[0]}};' | sort -u | fgrep -w -f {WORKDIR}/{PASA} > {WORKDIR}/{output.lnc}
"""
########################
#### BLAST ####
########################
rule blast:
input: cpat="CPAT/"+ID+".cpat.fasta"
output: blast="BLAST/blast.coding.candidates"
threads: THREADS
params:
shell:"""
cd BLAST
formatdb -i {BLAST} -p T -n uniprot90S
blastx -query {WORKDIR}/{input.cpat} -db uniprot90S -num_threads {threads} -outfmt 7 -out blast.out
cat blast.out | perl -lane 'if($F[7]>$F[6] && $F[10]<0.001){{print;}}' | cut -f 1 | sort -u | sed -r 's/asmbl/>asmbl/' > {WORKDIR}/{output.blast}
"""
########################
#### PFAM ####
########################
rule pfam:
input: "/CPAT/"+ID+".cpat.fasta"
output: "PFAM/"+ID+".pfam.coding.candidates"
params:
threads: THREADS
shell: """
mkdir PFAM
cd PFAM
pfam_scan.pl -fasta {WORKDIR}/{input} -dir {PFAM} -cpu {threads} -outfile pfam.out
cat pfam.out | grep -v '#' | perl -lane 'if($F[2]>$F[1] && $F[12]<0.001){{print;}}' | cut -f 1 | sort -u | sed -r 's/asmbl/>asmbl/' > {WORKDIR}/{output}
"""
#################################################################################
# #
# CPAT #
# #
#################################################################################
rule cpat:
input: gene="noOverlap.fasta", fa="assemblies.fa", nonc="nonconding.fasta", coding="codingseq.fasta"
output: fasta="CPAT/"+ID+".cpat.fasta", results="CPAT/cpat.results"
params:
threads: THREADS
shell:"""
mkdir -p CPAT
cd CPAT
make_hexamer_tab.py -c {WORKDIR}/{input.coding} -n {WORKDIR}/{input.nonc} > hexamer.tab
make_logitModel.py -c {WORKDIR}/{input.coding} -n {WORKDIR}/{input.nonc} -x hexamer.tab -o {ID}
cpat.py -d {ID}.logit.RData -x hexamer.tab -g {WORKDIR}/{input.gene} -o {ID}.cpat
cat {ID}.cpat | perl -lane 'if($F[1]>=1000 && $F[5]<0.01){{print;}}' | sort -k 2,2gr | sed -r 's/ASMBL/asmbl/' > {WORKDIR}/{output.results}
parallel -j {threads} 'grep -P "{{}}$" {WORKDIR}/{input.fa} -A 1 ' ::: `cat {WORKDIR}/{output.results} | cut -f 1` > {WORKDIR}/{output.fasta}
"""
rule preparefiles:
input: fa="assemblies.fa", intron=ID+"introns.gff"
output: coding="codingseq.fasta", nonc="nonconding.fasta"
params:
threads: THREADS
shell:"""
getAnnoFasta.pl {ANNOT} --seqfile {GENOME}
cat {ID}.Annot3.cdsexons | sed -r 's/.cds[0-9]//g' | perl -lane 'BEGIN{{my $previousId="";}} if($F[0]=~/>/){{if($F[0] eq $previousId){{next;}}else{{$previousId=$F[0]; print "\n",$F[0]}}}}else{{printf $F[0]}}' > {output.coding}
cat {input.intron} | sed -r 's/;src=E//g' > introns.gff
parallel -j {threads} 'grep -P "{{}}$" assemblies.fa -A 1 ' ::: `cat introns.gff | cut -f 9 | sed -r 's/.+Target=([^$]+)/\\1/' | sort -u` > {output.nonc}
"""
#################################################################################
# #
# INTERSECT #
# #
#################################################################################
rule intersect:
input: ID+".assemblies.fasta.transdecoder.genome.gff3"
output: fasta="noOverlap.fasta", fa="assemblies.fa"
params:
threads: THREADS
shell:"""
perl ./mergealign.pl < {PASA} > merged.gff
cat merged.gff | cut -f 1-9 > {ID}.pasa_assemblies.mergedCoordinates.gff3
intersectBed -v -s -a {ID}.pasa_assemblies.mergedCoordinates.gff3 -b {ANNOT} > no.gff3
intersectBed -v -s -a no.gff3 -b {input} > noOverlap.gff
perl ~/bin/rmenterdb.pl < {PASAFASTA} > {output.fa}
parallel -j {threads} 'grep -P "{{}}$" assemblies.fa -A 1 ' ::: `cat noOverlap.gff | cut -f 9 | sed -r 's/.+Target=([^$]+)/\\1/' | sort -u` > {output.fasta}
"""
#rule clean:
# shell: " "