-
Notifications
You must be signed in to change notification settings - Fork 2
/
splice_pipeline.w.exon.skipping.no.DTU_multiorg.sh
335 lines (281 loc) · 11.2 KB
/
splice_pipeline.w.exon.skipping.no.DTU_multiorg.sh
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/bin/bash
#SBATCH --job-name=sicelore
#SBATCH --mem=300G
#SBATCH --cpus-per-task=12
#SBATCH --ntasks=1
#SBATCH --partition=bigmem
#SBATCH --output=stdout_%j.log
#SBATCH --error=stderror_%j.log
source /etc/profile.d/modules.sh
module load java/1.9
module load samtools
module load racon
PATH=$PATH:/gpfs/commons/home/ahawkins/spoa/build/bin/
PATH=$PATH:/gpfs/commons/home/gmullokandov/software/minimap2-2.17_x64-linux/minimap2
echo $PATH
##### input arguments/ requirements
## working directory must contain a folder labeled input_files
## within input_files folder there are folders
## 1.ONT_fastq -starts out empty but unzipped fastq is copied here
## 2.short_read_files - contains barcodes.tsv (must be unzipped) and possorted_genome_bam.bam and possorted_genome_bam.bam.bai from cellranger outs folder
workdir=$1 #working directory where all output files will be
fastq=$2 #full path to fastq
fastqdir=$3
sample_name=$4
run_files=$5 ##location where all scripts are located
#genotype_info=$6
#pattern=$7
#nperm=$8
#barcodes=$8 #full path to barcodes file
echo $sample_name
##moved simple checks (i.e. directory permissions, etc.) to the beginning
##so that basic mistakes are caught before complex computation
{
cd $workdir
} || {
echo "invalid directory: $workdir"
exit
}
if [ ! -d output_files ]
then
{
mkdir output_files
echo "output_files folder created"
} || {
echo "unable to create output_files folder. Check permissions"
exit
}
else
echo "output_files folder exists"
fi
cd ./output_files
if [ ! -d logs ]
then
{
mkdir logs
echo "logs folder created"
} || {
echo "unable to create logs folder. Check permissions"
exit
}
else
echo "output_files/logs folder exists"
fi
if [ ! -d sicelore_outputs ]
then
{
mkdir sicelore_outputs
echo "sicelore_outputs folder created"
} || {
echo "unable to create sicelore_outputs folder. Check permissions"
exit
}
else
echo "sicelore_outputs folder exists"
fi
cd ./sicelore_outputs
if [ ! -d temp ]
then
{
mkdir temp
echo "temp folder created"
} || {
echo "unable to create temp folder. Check permissions"
exit
}
else
echo "sicelore_outputs/temp folder exists"
fi
if [ ! -d "$workdir"/input_files/2.short_read_files/10X_parsing_files ]
then
{
mkdir "$workdir"/input_files/2.short_read_files/10X_parsing_files
echo "10X_parsing_files folder created"
} || {
echo "unable to create 10X_parsing_files folder. Check permissions"
exit
}
else
echo "10X_parsing_files folder exists"
fi
if [ -f "$workdir"/input_files/2.short_read_files/barcodes.tsv ]
then
barcodes=$workdir/input_files/2.short_read_files/barcodes.tsv
else
echo "file missing: folder 2.short_read_files needs an unzipped barcodes.tsv file"
exit
fi
if [ -f "$workdir"/input_files/2.short_read_files/possorted_genome_bam.bam ]
then
bam="$workdir"/input_files/2.short_read_files/possorted_genome_bam.bam
else
echo "file missing: folder 2.short_read_files needs a file possorted_genome_bam.bam"
exit
fi
{
cd $fastqdir
} || {
echo "invalid directory: $fastqdir"
exit
}
##check if the fastq file already exists. If it does, don't unzip it again
##and proceed to next step. This is useful, if the pipeline crashes later
##and needs to be rerun
if [ ! -f "$sample_name".fastq ]
then
{
gunzip -c $fastq > "$sample_name".fastq
} || {
echo "invalid fastq: $fastq"
exit
}
else
echo "fastq already exists in original folder. running analysis on existing fastq"
fi
if [ ! -f "$workdir"/input_files/1.ONT_fastq/"$sample_name".fastq ]
then
{
cp "$sample_name".fastq "$workdir"/input_files/1.ONT_fastq
} || {
echo "unable to copy fastq file to: $workdir/input_files/1.ONT_fastq"
exit
}
else
echo "fastq already exists in destination folder. running analysis on existing fastq"
fi
##polyA scanning, if completed will create a file polyADone.txt. This checks
##if the file exists and skips the step if it does. That way, if the pipeline
##is run multiple times, it can skip the polyA scanning step
if [ ! -f "$workdir"/output_files/sicelore_outputs/polyADone.txt ]
then
{
echo "scanning polyA"
java -jar /gpfs/commons/home/ahawkins/sicelore/Jar/NanoporeReadScanner-0.5.jar -i "$workdir"/input_files/1.ONT_fastq/"$sample_name".fastq -o "$workdir"/output_files/sicelore_outputs
echo "polyA scan done" > "$workdir"/output_files/sicelore_outputs/polyADone.txt
} || {
echo "polyA scan failed"
exit
}
else
echo "polyA scan previously completed. running analyis with existing files"
fi
##10x parsing , if completed will create a file parsing10x.txt. This checks
##if the file exists and skips the step if it does. That way, if the pipeline
##is run multiple times, it can skip the 10x parsing step
##split this out so that it runs after parallel to other tasks
if [ ! -f "$workdir"/input_files/2.short_read_files/"$sample_name"_parsed_for_Nanopore.obj ]
then
echo "parsing 10X object"
parsedobj="$workdir"/input_files/2.short_read_files/"$sample_name"_parsed_for_Nanopore.obj
## ----- Parse for cell barcodes and UMIs ------------------
##set this as a separate job so other tasks can run simultaneously
cd "$workdir"/input_files/2.short_read_files/10X_parsing_files
cat > "$sample_name"_10X_parsing.sh <<EOF
#!/bin/bash
#SBATCH --job-name=10x_parsing
#SBATCH --mem-per-cpu=100G
#SBATCH --partition=pe2
#SBATCH --output=stderror_%j.log
#SBATCH --error=stderror_%j.log
#SBATCH --ntasks=5
module load java/1.9
java -Xmx500g -jar /gpfs/commons/home/ahawkins/sicelore/Jar/IlluminaParser-1.0.jar --inFileIllumina $bam --tsv $barcodes --outFile $parsedobj --cellBCflag CB --umiFlag UB --geneFlag GN
EOF
sbatch --job-name="$sample_name"_10X_parsing "$sample_name"_10X_parsing.sh
else
parsedobj="$workdir"/input_files/2.short_read_files/"$sample_name"_parsed_for_Nanopore.obj
echo "10x object parsing previously completed. running analyis with existing files"
fi
##fastq splitting
##fastp outputs a file fastp.json. If this file exists in the folder,
##it has already run, and can be skipped
cd $workdir/output_files/sicelore_outputs
if [ ! -f "$workdir"/output_files/sicelore_outputs/fastp.json ]
then
if [ -f "$workdir"/output_files/sicelore_outputs/passed/"$sample_name"FWD.fastq ]
then
polyAfastq="$workdir"/output_files/sicelore_outputs/passed/"$sample_name"FWD.fastq ## make sure this includes workdir/passed/fastqnameFWD.fastq in name
else
echo "no passed sicelore outputs"
exit
fi
echo "splitting fastq files"
{
/gpfs/commons/home/pchamely/software/fastp -i $polyAfastq -Q -A --thread 1 --split_prefix_digits=3 --out1=sub.fastq --split=100
echo "fastq files split"
} || {
echo "fastq file splitting failed"
exit
}
else
echo "fastq file previously split. running analysis on previous files"
fi
if [ ! -d "$workdir"/output_files/sicelore_outputs/err_and_out ]
then
{
mkdir err_and_out
echo "err_and_out folder created"
} || {
echo "unable to create err_and_out folder. Check permissions"
exit
}
else
echo "err_and_out folder exists"
fi
sicelore_jobids=()
## step 3: Alignment, UMI, and CB matching for all files
## perform this step only for non-empty files
## do not repeat it, if it was completed previously
jobs=$(seq -w 1 100)
for i in ${jobs[@]};
do
if [ -f "$workdir"/output_files/sicelore_outputs/"$i".sub.fastq ]
then
if [ ! -f "$workdir"/output_files/sicelore_outputs/"$i".sub.GEUS10xAttributes.bam ]
then
filename="$workdir"/output_files/sicelore_outputs/"$i".sub.fastq
size=$(stat -c %s $filename)
if (( $size>0 ))
then
cat > "$sample_name"_"$i"_sicelore_2.sh <<EOF
#!/bin/bash
#SBATCH --job-name=Sicelore_2
#SBATCH --mem=300G
#SBATCH --partition=bigmem,pe2
#SBATCH --output=err_and_out/"$i"_stdout_%j.log
#SBATCH --error=err_and_out/"$i"_stderror_%j.log
#SBATCH --cpus-per-task=5
source /etc/profile.d/modules.sh
module load samtools
module load bedtools
module load java/1.9
sample_name=$4
parsedobj="$1"/input_files/2.short_read_files/"$sample_name"_parsed_for_Nanopore.obj
/gpfs/commons/home/gmullokandov/software/minimap2-2.17_x64-linux/minimap2 -ax splice -uf --MD --secondary=no --sam-hit-only -t 20 --junc-bed /gpfs/commons/home/pchamely/SequencingData/CH_dataset_02_27_20/ONT-GEX-CH305/smart_seq_alljunctions.bed /gpfs/commons/home/gmullokandov/software/ref_genome/GRCh38.p12.mmi "$i".sub.fastq > "$i".sub.sam
samtools view -Sb "$i".sub.sam -o "$i".sub.unsorted.bam
samtools sort "$i".sub.unsorted.bam -o "$i".sub.bam
samtools index "$i".sub.bam
java -jar -Xmx100g /gpfs/commons/home/ahawkins/sicelore/Jar/Sicelore-1.0.jar AddGeneNameTag I="$i".sub.bam O="$i".sub.GE.bam REFFLAT=/gpfs/commons/home/gmullokandov/software/ref_genome/gencode.v31.refFlat GENETAG=GE ALLOW_MULTI_GENE_READS=true USE_STRAND_INFO=true VALIDATION_STRINGENCY=SILENT
samtools index "$i".sub.GE.bam
java -jar -Xmx100g /gpfs/commons/home/ahawkins/sicelore/Jar/Sicelore-1.0.jar AddBamReadSequenceTag I="$i".sub.GE.bam O="$i".sub.GEUS.bam FASTQ="$i".sub.fastq
samtools index "$i".sub.GEUS.bam
java -jar -Xmx300g /gpfs/commons/home/ahawkins/sicelore/Jar/NanoporeBC_UMI_finder-1.0.jar -i "$i".sub.GEUS.bam -o "$i".sub.GEUS10xAttributes.bam -k $parsedobj --maxUMIfalseMatchPercent 2 --maxBCfalseMatchPercent 5 --ncpu 5 --logFile "$i".sub_NanoporeBC_UMI_finder.log
EOF
sicelore_jobids+=($(sbatch --job-name="$sample_name" "$sample_name"_"$i"_sicelore_2.sh))
fi
else
echo "analysis previously run on $i.sub.fastq. Using previous outputs"
fi
fi
done
### after this is complete then merge files and run second script to merge
## step 4: Merge all files and generate consensus sequences
#sbatch /gpfs/commons/groups/landau_lab/ahawkins/MDS_ONT_splice/ONT_processing_pipeline/sicelore_scripts/2.sicelore_part2/sicelore_part2.sh "$workdir"/output_files/sicelore_outputs $sample_name $workdir/output_files/sicelore_outputs/temp
sic_part2=($(sbatch --dependency=singleton --job-name="$sample_name" "$run_files"/sicelore_scripts/sicelore_part2.sh "$workdir"/output_files/sicelore_outputs $sample_name $workdir/output_files/sicelore_outputs/temp))
cd $workdir
## step 5: Junction calling and annotation
#sbatch --job-name="$sample_name" "$run_files"/leafcutter_scripts/junc_calling_pipeline.sh "$workdir"/output_files "$workdir"/output_files/sicelore_outputs/"$sample_name"_consensus.sorted.tags.GE.bam $sample_name "$run_files"/bin
junc_calling=($(sbatch --dependency=singleton --job-name="$sample_name" "$run_files"/leafcutter_scripts/junc_calling_pipeline.w.exon.skip.sh "$workdir"/output_files "$workdir"/output_files/sicelore_outputs/"$sample_name"_consensus.sorted.tags.GE.bam $sample_name "$run_files"/bin))
## step 6: Differential transcript usage (with permutations within cell types)
#diff_transcript=($(sbatch --dependency=singleton --job-name="$sample_name" "$run_files"/diff_transcript_usage_scripts/diff_transcript_pipeline.sh "$workdir"/output_files $run_files "$workdir"/output_files/leafcutter_outputs/"$sample_name"_output/"$sample_name"_all.introns.info.w.primary.annotations.txt "$workdir"/output_files/leafcutter_outputs/"$sample_name"_output/"$sample_name"_perind_numbers.counts.txt $genotype_info $pattern $sample_name $nperm))
'