-
Notifications
You must be signed in to change notification settings - Fork 0
/
pamlinc.sh
executable file
·1082 lines (1002 loc) · 66.3 KB
/
pamlinc.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#Chosen Obih
#Script to process Illuminaa RNA-Seq data for the annotation of modified RNAs, lincRNAs and quantification of transcript abundance
usage() {
echo ""
echo "Usage : sh $0"
echo ""
cat <<'EOF'
######################################### COMMAND LINE OPTIONS #############################
-g <reference genome fasta file>
-a <reference genome annotation>
-i </path/to/genome indexes>
-l library type #note that this is a lower case L
-1 <reads_1> Ends with R1 and is in the same order as reverse reads
-2 <reads_2> Ends with R2, must be present, and is in the same order as forward reads
-u <single_reads> Do not use single reads along with paired end reads
-o </path/to/ pipeline output folder>
-S SRA ID number
-p number of threads
-q transcript abundance quantification
-M select aligner of choice ("tophat2" or "star"), include double quotation on the command line. Must select tophat2 if you want to run HAMR
-t select adapter trimmer of choice ("trimmomatic" or "fastp"), include double quotation on the command line.
-c sjdbOverhang, value is dependent on the read length of your fastq files, value=(read length minus 1)
-f genomeSAindexNbases, default=14 but it should be scaled down for small genomes. Value=min(14, log2(GenomeLength)/2 - 1)
-y type of reads (single end or paired end) #denoted as "SE" or "PE", include double quotation on command line
-d reads_mismatches (% reads mismatches to allow. Required for tophat2)
-m activates HAMR for RNA modification annotation
-A minimum base calling quality score. All low-quality bases will be removed from HAMR analysis, default=30
-B minimum read coverage of a genomic position for it to be analyzed in HAMR, default=10
-F expected percentage of mismatches based solely on sequencing error,default=0.01
-G maximum p-value cutoff. All sites with P-value greater than this value will be filtered out during HAMR analysis, default=1
-H maximum FDR cutoff, default=0.05
-I minimum percentage of reads that must match the reference nucleotide. All sites with reference read nucleotide proportion less than this value will be filtered out during HAMR analysis, default=0.05
-e activates evolinc_i for lincRNA identification
-E run evolinc_i with mandatory files or both mandatory and optional files. Denoted as "M" or "MO", include double quotation on the command line. Default is "M"
-T </path/to/transposable Elements file> (optional file for evolinc_i)
-C </path/to/CAGE RNA file> (optional file for evolinc_i)
-D </path/to/known lincRNA file> (optional file for evolinc_i)
-k feature type #Feature type (Default is exon)
-r gene attribute (Default is gene_id)
-n strandedness (Default is 0 (unstranded), 1 (stranded), 2 (reversely stranded)
-h help message
################################################# END ########################################
EOF
exit 0
}
num_threads=4
referencegenome=0
referenceannotation=0
evolinc_i=0
evolinc_option="M"
transcript_abun_quant=0
HAMR=0
min_read_qual=30
min_read_cov=10
seq_error_rate=0.01
max_p=1
max_fdr=0.05
ref_percent=0.05
while getopts ":g:a:A:i:l:1:2:u:o:S:p:d:k:c:f:r:M:t:n:A:B:F:G:H:I:E:hqeTCDmy:" opt; do
case $opt in
g)
referencegenome=$OPTARG
;;
a)
referenceannotation=$OPTARG
;;
i)
index_folder=$OPTARG
;;
l)
lib_type=$OPTARG
;;
1)
left_reads+=("$OPTARG")
;;
2)
right_reads=("$OPTARG")
;;
u)
single_reads+=("$OPTARG")
;;
o)
pipeline_output=$OPTARG
;;
S)
sra_id=$OPTARG
;;
p)
num_threads=$OPTARG
;;
d)
reads_mismatches=$OPTARG
;;
q)
transcript_abun_quant=$OPTARG
;;
m)
HAMR=$OPTARG
;;
A)
min_read_qual=$OPTARG
;;
B)
min_read_cov=$OPTARG
;;
F)
seq_error_rate=$OPTARG
;;
G)
max_p=$OPTARG
;;
H)
max_fdr=$OPTARG
;;
I)
ref_percent=$OPTARG
;;
e)
evolinc_i=$OPTARG
;;
E)
evolinc_option=$OPTARG
;;
T)
blast_file=$OPTARG
;;
C)
cage_file=$OPTARG
;;
D)
known_linc=$OPTARG
;;
M)
aligner=$OPTARG
;;
t)
adapter_trimmer=$OPTARG
;;
c)
sjdbOverhang=$OPTARG
;;
f)
genomeSAindexNbases=$OPTARG
;;
k)
feature_type=$OPTARG
;;
r)
gene_attribute=$OPTARG
;;
n)
strandedness=$OPTARG
;;
y)
seq_type=$OPTARG
;;
h)
usage
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
echo "Pipeline Starts"
date
start_time=$(date +%s)
# Create the output directory
if [ ! -d "$pipeline_output" ]; then
mkdir $pipeline_output
elif [ -d "$pipeline_ouput" ]; then
rm -r $pipeline_output; mkdir $pipeline_output
fi
###################################################################################################################
# # Check reference genome annotation file type and convert to .gtf if .gff3 file was supplied by user
###################################################################################################################
#extract the basename of input reference genome
gname=$(basename "$referencegenome" | cut -d. -f1)
if (grep -q -E 'transcript_id | gene_id' $referenceannotation); then
echo "$referenceannotation is in .gtf format"
else
gffread $referenceannotation -T -o "$gname".gtf
referenceannotation="$gname".gtf
fi
###################################################################################################################
# # pipeline house keeping - move output files into user input directory; delete some intermediate output files
###################################################################################################################
house_keeping()
{
mkdir intermediate_files
if [ -e "./$gname.gtf" ]; then
rm "$gname".gtf
fi
if [ "$adapter_trimmer" == "trimmomatic" ]; then
mkdir trimmomatic_output
if [ "$seq_type" == "SE" ]; then
mv *_trimmed.* trimmomatic_output
else
mv *_1P.* *_1U.* *_2P.* *_2U.* trimmomatic_output
fi
mv trimmomatic_output intermediate_files
elif [ "$adapter_trimmer" == "fastp" ]; then
mkdir fastp_output
if [ "$seq_type" == "SE" ]; then
mv *_fastp.* *_trimmed.* fastp_output
else
mv *_fastp.* *_trimmed_* fastp_output
fi
mv fastp_output intermediate_files
fi
if [ "$sra_id" !=0 ]; then
mkdir SRA_raw_files
mv *$sra_id* SRA_raw_files && mv SRA_raw_files intermediate_files
fi
if [ ! -z "$index_folder" ]; then
if [ "$aligner" == "tophat2" ]; then
mv *.bt2 "$index_folder"
elif [ "$aligner" == "star" ]; then
mv star_index "$index_folder"
rm *.tab *.out
fi
elif [ -z "$index_folder" ]; then
if [ "$aligner" == "tophat2" ]; then
mkdir index_folder
mv *.bt2 index_folder && mv index_folder intermediate_files
elif [ "$aligner" == "star" ]; then
mkdir index_folder && mv star_index index_folder
mv index_folder intermediate_files
rm *.tab *.out
fi
fi
if [ "$transcript_abun_quant" != 0 ]; then
mkdir transcript_abund_quant && mv *_featurecount.txt* transcript_abund_quant
mv transcript_abund_quant "$pipeline_output"
fi
if [ "$evolinc_i" != 0 ]; then
rm *.loci *.stats *.tracking
mv *_lincRNA* "$pipeline_output"
mv *.gtf intermediate_files
fi
if [ "$HAMR" != 0 ]; then
mv *_HAMR* "$pipeline_output"
mv *.bai intermediate_files
rm "$gname".dict
fi
if [ "$aligner" == "$tophat" != 0 ]; then
mkdir mapped_files
mv *_tophat* mapped_files
mv mapped_files intermediate_files
elif [ "$aligner" == "$tophat" != 0 ]; then
mkdir mapped_files
mv
mv mapped_files intermediate_files
fi
if [ -e "./$gname.fa.fai" ]; then
rm "$gname".fa.fai
fi
mv *.sam intermediate_files
mv *.bam intermediate_files
mv intermediate_files "$pipeline_output"
echo "##############################"
echo "Pipeline Executed"
echo "##############################"
date
end_time=$(date +%s)
execution_time=$((end_time - start_time))
echo "Pipeline Executiion Time: $execution_time seconds"
}
##################################################################################################################
# # Transcript abundance quantification
###################################################################################################################
tophat_mapping_transcript_quantification()
{
if [ "$transcript_abun_quant" != 0 ]; then
echo "###########################################################################"
echo "Running featureCounts"
echo "###########################################################################"
if [ "$evolinc_i" != 0 ]; then
if [ "$seq_type" == "PE" ]; then
featureCounts -T $num_threads -a ${filename3}_lincRNA/${filename3}.lincRNA.updated.gtf -o ${filename3}_featurecount.txt ${filename3}_merged.bam
elif [ "$seq_type" == "SE" ]; then
featureCounts -T $num_threads -s $strandedness -a ${filename}_lincRNA/${filename}.lincRNA.updated.gtf -o ${filename}_featurecount.txt ${filename}_sorted.bam
fi
elif [ "$evolinc_i" = 0 ]; then
if [ "$seq_type" == "PE" ]; then
featureCounts -T $num_threads -a $referenceannotation -o ${filename3}_featurecount.txt ${filename3}_merged.bam
elif [ "$seq_type" == "SE" ]; then
featureCounts -T $num_threads -s $strandedness -a $referenceannotation -o ${filename}_featurecount.txt ${filename}_sorted.bam
fi
fi
fi
}
star_mapping_transcript_quantification()
{
if [ "$transcript_abun_quant" != 0 ]; then
echo "###########################################################################"
echo "Running featureCounts"
echo "###########################################################################"
if [ "$evolinc_i" != 0 ]; then
if [ "$seq_type" == "PE" ]; then
featureCounts -T $num_threads -a ${filename3}_lincRNA/${filename3}.lincRNA.updated.gtf -o ${filename3}_featurecount.txt ${filename3}_Aligned.sortedByCoord.out.bam
elif [ "$seq_type" == "SE" ]; then
featureCounts -T $num_threads -s $strandedness -a ${filename}_lincRNA/${filename}.lincRNA.updated.gtf -o ${filename}_featurecount.txt ${filename}_Aligned.sortedByCoord.out.bam
fi
elif [ "$evolinc_i" = 0 ]; then
if [ "$seq_type" == "PE" ]; then
featureCounts -T $num_threads -a $referenceannotation -o ${filename3}_featurecount.txt ${filename3}_Aligned.sortedByCoord.out.bam
elif [ "$seq_type" == "SE" ]; then
featureCounts -T $num_threads -s $strandedness -a $referenceannotation -o ${filename}_featurecount.txt ${filename}_Aligned.sortedByCoord.out.bam
fi
fi
fi
}
sra_id_transcript_quantification()
{
if [ "$transcript_abun_quant" != 0 ]; then
echo "###########################################################################"
echo "Running featureCounts"
echo "###########################################################################"
if [ "$evolinc_i" != 0 ]; then
if [ "$seq_type" == "PE" ]; then
featureCounts -T $num_threads -a ${sra_id}_lincRNA/${sra_id}.lincRNA.updated.gtf -o ${sra_id}_featurecount.txt ${sra_id}_merged.bam
elif [ "$seq_type" == "SE" ]; then
featureCounts -T $num_threads -s $strandedness -a ${sra_id}_lincRNA/${sra_id}.lincRNA.updated.gtf -o ${sra_id}_featurecount.txt ${sra_id}_sorted.bam
fi
elif [ "$evolinc_i" = 0 ]; then
if [ "$seq_type" == "PE" ]; then
featureCounts -T $num_threads -a $referenceannotation -o ${sra_id}_featurecount.txt ${sra_id}_merged.bam
elif [ "$seq_type" == "SE" ]; then
featureCounts -T $num_threads -s $strandedness -a $referenceannotation -o ${sra_id}_featurecount.txt ${sra_id}_sorted.bam
fi
fi
fi
}
##################################################################################################################
# # lincRNA identification
###################################################################################################################
tophat_mapping_lincRNA_annotation()
{
if [ "$evolinc_i" != 0 ]; then
echo "#########################################################################################"
echo "Pre-processing uniquely mapped reads before running evolinc_i for lincRNA identification"
echo "#########################################################################################"
if [ "$seq_type" == "PE" ]; then
if [ "$lib_type" == fr-secondstrand ]; then
stringtie ${filename3}_merged.bam -o ${filename3}_merged.gtf -G $referenceannotation -p $num_threads --fr
cuffcompare ${filename3}_merged.gtf -r $referenceannotation -s $referencegenome -T -o ${filename3}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${filename3}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename3}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${filename3}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename3}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
elif [ "$lib_type" == fr-firststrand ]; then
stringtie ${filename3}_merged.bam -o ${filename3}_merged.gtf -G $referenceannotation -p $num_threads --rf
cuffcompare ${filename3}_merged.gtf -r $referenceannotation -s $referencegenome -T -o ${filename3}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${filename3}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename3}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${filename3}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename3}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
fi
elif [ "$seq_type" == "SE" ]; then
if [ "$lib_type" == fr-secondstrand ]; then
stringtie ${filename}_sorted.bam -o ${filename}.gtf -G $referenceannotation -p $num_threads --fr
cuffcompare ${filename}.gtf -r $referenceannotation -s $referencegenome -T -o ${filename}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${filename}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${filename}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
elif [ "$lib_type" == fr-firststrand ]; then
stringtie ${filename}_sorted.bam -o ${filename}.gtf -G $referenceannotation -p $num_threads --rf
cuffcompare ${filename}.gtf -r $referenceannotation -s $referencegenome -T -o ${filename}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${filename}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${filename}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
fi
fi
fi
}
star_mapping_lincRNA_annotation()
{
if [ "$evolinc_i" != 0 ]; then
echo "#########################################################################################"
echo "Pre-processing uniquely mapped reads before running evolinc_i for lincRNA identification"
echo "#########################################################################################"
if [ "$seq_type" == "PE" ]; then
if [ "$lib_type" == fr-secondstrand ]; then
stringtie ${filename3}_Aligned.sortedByCoord.out.bam -o ${filename3}.gtf -G $referenceannotation -p $num_threads --fr
cuffcompare ${filename3}.gtf -r $referenceannotation -s $referencegenome -T -o ${filename3}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${filename3}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename3}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${filename3}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename3}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
elif [ "$lib_type" == fr-firststrand ]; then
stringtie ${filename3}_Aligned.sortedByCoord.out.bam -o ${filename3}.gtf -G $referenceannotation -p $num_threads --rf
cuffcompare ${filename3}.gtf -r $referenceannotation -s $referencegenome -T -o ${filename3}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${filename3}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename3}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${filename3}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename3}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
fi
elif [ "$seq_type" == "SE" ]; then
if [ "$lib_type" == fr-secondstrand ]; then
stringtie ${filename}_Aligned.sortedByCoord.out.bam -o ${filename}.gtf -G $referenceannotation -p $num_threads --fr
cuffcompare ${filename}.gtf -r $referenceannotation -s $referencegenome -T -o ${filename}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${filename}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${filename}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
elif [ "$lib_type" == fr-firststrand ]; then
stringtie ${filename}_Aligned.sortedByCoord.out.bam -o ${filename}.gtf -G $referenceannotation -p $num_threads --rf
cuffcompare ${filename}.gtf -r $referenceannotation -s $referencegenome -T -o ${filename}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${filename}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${filename}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${filename}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
fi
fi
fi
}
sra_id_lincRNA_annotation()
{
if [ "$evolinc_i" != 0 ]; then
echo "#########################################################################################"
echo "Pre-processing uniquely mapped reads before running evolinc_i for lincRNA identification"
echo "#########################################################################################"
if [ "$seq_type" == "PE" ]; then
if [ "$lib_type" == fr-secondstrand ]; then
stringtie ${sra_id}_merged.bam -o ${sra_id}_merged.gtf -G $referenceannotation -p $num_threads --fr
cuffcompare ${sra_id}_merged.gtf -r $referenceannotation -s $referencegenome -T -o ${sra_id}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${sra_id}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${sra_id}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${sra_id}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${sra_id}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
elif [ "$lib_type" == fr-firststrand ]; then
stringtie ${sra_id}_merged.bam -o ${sra_id}_merged.gtf -G $referenceannotation -p $num_threads --rf
cuffcompare ${sra_id}_merged.gtf -r $referenceannotation -s $referencegenome -T -o ${sra_id}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${sra_id}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${sra_id}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${sra_id}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${sra_id}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
fi
elif [ "$seq_type" == "SE" ]; then
if [ "$lib_type" == fr-secondstrand ]; then
stringtie ${sra_id}_sorted.bam -o ${sra_id}.gtf -G $referenceannotation -p $num_threads --fr
cuffcompare ${sra_id}.gtf -r $referenceannotation -s $referencegenome -T -o ${sra_id}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${sra_id}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${sra_id}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${sra_id}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${sra_id}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
elif [ "$lib_type" == fr-firststrand ]; then
stringtie ${sra_id}_sorted.bam -o ${sra_id}.gtf -G $referenceannotation -p $num_threads --rf
cuffcompare ${sra_id}.gtf -r $referenceannotation -s $referencegenome -T -o ${sra_id}
if [ "$evolinc_option" == "M" ]; then
evolinc-part-I.sh -c ${sra_id}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${sra_id}_lincRNA
elif [ "$evolinc_option" == "MO" ]; then
evolinc-part-I.sh -c ${sra_id}.combined.gtf -g $referencegenome -u $referenceannotation -r $referenceannotation -n $num_threads -o ${sra_id}_lincRNA -b $blast_file -t $cage_file -x $known_linc
fi
fi
fi
fi
}
############################################################################################################################################################################################################################
# # Trimm, Map, Grep unique reads, Resolve spliced alignment and annotate RNA mods
############################################################################################################################################################################################################################
# Paired end reads
paired_fq_gz()
{
filename=$(basename "$f" ".fq.gz")
filename2=${filename/_R1/_R2}
filename3=$(echo $filename | sed 's/_R1//')
if [ "$seq_type" == "PE" ]; then
echo "###############################"
echo "Trimming paired-end input reads"
echo "###############################"
fi
if [ "$adapter_trimmer" == "trimmomatic" ]; then
trimmomatic PE -threads $num_threads ${filename}.fq.gz ${filename2}.fq.gz ${filename3}_1P.fq.gz ${filename3}_1U.fq.gz ${filename3}_2P.fq.gz ${filename3}_2U.fq.gz ILLUMINACLIP:$ADAPTERPATH/TruSeq3-PE.fa:2:30:10:2 LEADING:3 TRAILING:3 MINLEN:36
elif [ "$adapter_trimmer" == "fastp" ]; then
fastp -w $num_threads -i ${filename}.fq.gz -I ${filename2}.fq.gz -o ${filename3}_trimmed_R1.fq.gz -O ${filename3}_trimmed_R2.fq.gz -j ${filename3}_fastp.json -h ${filename3}_fastp.html
fi
if [ "$aligner" == "tophat2" ]; then
echo "###################################"
echo "Running tophat2 in paired-end mode"
echo "###################################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_fwd_tophat -G $referenceannotation $fbname ${filename3}_1P.fq.gz,${filename3}_1U.fq.gz
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_rev_tophat -G $referenceannotation $fbname ${filename3}_2P.fq.gz
elif [ "$adapter_trimmer" == "fastp" ]; then
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_fwd_tophat -G $referenceannotation $fbname ${filename3}_trimmed_R1.fq.gz
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_rev_tophat -G $referenceannotation $fbname ${filename3}_trimmed_R2.fq.gz
fi
echo "####################################################"
echo "Pre-processing mapped .BAM file before running HAMR"
echo "####################################################"
#Convert .bam to .sam, grep unique reads, sort reads and merge forward and reverse reads
samtools view -h -@ $num_threads -o ${filename3}_fwd.sam ${filename3}_fwd_tophat/accepted_hits.bam
samtools view -h -@ $num_threads -o ${filename3}_rev.sam ${filename3}_rev_tophat/accepted_hits.bam
grep -P '^\@|NH:i:1$' ${filename3}_fwd.sam > ${filename3}_fwd_unique.sam
grep -P '^\@|NH:i:1$' ${filename3}_rev.sam > ${filename3}_rev_unique.sam
samtools view -bSh -@ $num_threads ${filename3}_fwd_unique.sam > ${filename3}_fwd_unique.bam
samtools view -bSh -@ $num_threads ${filename3}_rev_unique.sam > ${filename3}_rev_unique.bam
samtools sort -@ $num_threads ${filename3}_fwd_unique.bam > ${filename3}_fwd_sorted.bam
samtools sort -@ $num_threads ${filename3}_rev_unique.bam > ${filename3}_rev_sorted.bam
samtools merge -f ${filename3}_merged.bam ${filename3}_fwd_sorted.bam ${filename3}_rev_sorted.bam
if [ "$HAMR" != 0 ]; then
echo "######################################################"
echo "Resolving spliced alignments"
echo "######################################################"
picard AddOrReplaceReadGroups I=${filename3}_merged.bam O=${filename3}_RG.bam ID=${filename3} LB=D4 PL=illumina PU=HWUSI-EAS1814:28:2 SM=${filename3}
picard ReorderSam I=${filename3}_RG.bam O=${filename3}_RGO.bam R=$referencegenome
samtools index ${filename3}_RGO.bam ${filename3}_RGO.bam.bai
gatk --java-options "-Xmx8g" SplitNCigarReads -R $referencegenome -I ${filename3}_RGO.bam -O ${filename3}_resolvedalig.bam -OBI false
echo "######################################################"
echo "Running HAMR"
echo "######################################################"
python /HAMR/hamr.py -fe ${filename3}_resolvedalig.bam $referencegenome $HAMR_MODELS_PATH/euk_trna_mods.Rdata ${filename3}_HAMR ${filename3} $min_read_qual $min_read_cov $seq_error_rate H4 $max_p $max_fdr $ref_percent
fi
tophat_mapping_lincRNA_annotation
tophat_mapping_transcript_quantification
fi
if [ "$aligner" == "star" ]; then
echo "###################################"
echo "Running STAR in paired-end mode"
echo "###################################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --readFilesCommand zcat --genomeDir ./star_index --outFileNamePrefix ${filename3}_ --readFilesIn ${filename3}_1P.fq.gz ${filename3}_2P.fq.gz
elif [ "$adapter_trimmer" == "fastp" ]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --readFilesCommand zcat --genomeDir ./star_index --outFileNamePrefix ${filename3}_ --readFilesIn ${filename3}_trimmed_R1.fq.gz ${filename3}_trimmed_R2.fq.gz
fi
star_mapping_lincRNA_annotation
star_mapping_transcript_quantification
fi
house_keeping
}
paired_fastq_gz()
{
filename=$(basename "$f" ".fastq.gz")
filename2=${filename/_R1/_R2}
filename3=$(echo $filename | sed 's/_R1//')
if [ "$seq_type" == "PE" ]; then
echo "###############################"
echo "Trimming paired-end input reads"
echo "###############################"
fi
if [ "$adapter_trimmer" == "trimmomatic" ]; then
trimmomatic PE -threads $num_threads ${filename}.fastq.gz ${filename2}.fastq.gz ${filename3}_1P.fastq.gz ${filename3}_1U.fastq.gz ${filename3}_2P.fastq.gz ${filename3}_2U.fastq.gz ILLUMINACLIP:$ADAPTERPATH/TruSeq3-PE.fa:2:30:10:2 LEADING:3 TRAILING:3 MINLEN:36
elif [ "$adapter_trimmer" == "fastp" ]; then
fastp -w $num_threads -i ${filename}.fastq.gz -I ${filename2}.fastq.gz -o ${filename3}_trimmed_R1.fastq.gz -O ${filename3}_trimmed_R2.fastq.gz -j ${filename3}_fastp.json -h ${filename3}_fastp.html
fi
if [ "$aligner" == "tophat2" ]; then
echo "###################################"
echo "Running tophat2 in paired-end mode"
echo "###################################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_fwd_tophat -G $referenceannotation $fbname ${filename3}_1P.fastq.gz,${filename3}_1U.fastq.gz
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_rev_tophat -G $referenceannotation $fbname ${filename3}_2P.fastq.gz
elif [ "$adapter_trimmer" == "fastp" ]; then
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_fwd_tophat -G $referenceannotation $fbname ${filename3}_trimmed_R1.fastq.gz
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_rev_tophat -G $referenceannotation $fbname ${filename3}_trimmed_R2.fastq.gz
fi
echo "####################################################"
echo "Pre-processing mapped .BAM file before running HAMR"
echo "####################################################"
#Convert .bam to .sam, grep unique reads, sort reads and merge forward and reverse reads
samtools view -h -@ $num_threads -o ${filename3}_fwd.sam ${filename3}_fwd_tophat/accepted_hits.bam
samtools view -h -@ $num_threads -o ${filename3}_rev.sam ${filename3}_rev_tophat/accepted_hits.bam
grep -P '^\@|NH:i:1$' ${filename3}_fwd.sam > ${filename3}_fwd_unique.sam
grep -P '^\@|NH:i:1$' ${filename3}_rev.sam > ${filename3}_rev_unique.sam
samtools view -bSh -@ $num_threads ${filename3}_fwd_unique.sam > ${filename3}_fwd_unique.bam
samtools view -bSh -@ $num_threads ${filename3}_rev_unique.sam > ${filename3}_rev_unique.bam
samtools sort -@ $num_threads ${filename3}_fwd_unique.bam > ${filename3}_fwd_sorted.bam
samtools sort -@ $num_threads ${filename3}_rev_unique.bam > ${filename3}_rev_sorted.bam
samtools merge -f ${filename3}_merged.bam ${filename3}_fwd_sorted.bam ${filename3}_rev_sorted.bam
if [ "$HAMR" != 0 ]; then
echo "######################################################"
echo "Resolving spliced alignments"
echo "######################################################"
picard AddOrReplaceReadGroups I=${filename3}_merged.bam O=${filename3}_RG.bam ID=${filename3} LB=D4 PL=illumina PU=HWUSI-EAS1814:28:2 SM=${filename3}
picard ReorderSam I=${filename3}_RG.bam O=${filename3}_RGO.bam R=$referencegenome
samtools index ${filename3}_RGO.bam ${filename3}_RGO.bam.bai
gatk --java-options "-Xmx8g" SplitNCigarReads -R $referencegenome -I ${filename3}_RGO.bam -O ${filename3}_resolvedalig.bam -OBI false
echo "######################################################"
echo "Running HAMR"
echo "######################################################"
python /HAMR/hamr.py -fe ${filename3}_resolvedalig.bam $referencegenome $HAMR_MODELS_PATH/euk_trna_mods.Rdata ${filename3}_HAMR ${filename3} $min_read_qual $min_read_cov $seq_error_rate H4 $max_p $max_fdr $ref_percent
fi
tophat_mapping_lincRNA_annotation
tophat_mapping_transcript_quantification
fi
if [ "$aligner" == "star" ]; then
echo "###################################"
echo "Running STAR in paired-end mode"
echo "###################################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --readFilesCommand zcat --genomeDir ./star_index --outFileNamePrefix ${filename3}_ --readFilesIn ${filename3}_1P.fastq.gz ${filename3}_2P.fastq.gz
elif [ "$adapter_trimmer" == "fastp" ]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --readFilesCommand zcat --genomeDir ./star_index --outFileNamePrefix ${filename3}_ --readFilesIn ${filename3}_trimmed_R1.fastq.gz ${filename3}_trimmed_R2.fastq.gz
fi
star_mapping_lincRNA_annotation
star_mapping_transcript_quantification
fi
house_keeping
}
paired_fq()
{
filename=$(basename "$f" ".fq")
filename2=${filename/_R1/_R2}
filename3=$(echo $filename | sed 's/_R1//')
if [ "$seq_type" == "PE" ]; then
echo "###############################"
echo "Trimming paired-end input reads"
echo "###############################"
fi
if [ "$adapter_trimmer" == "trimmomatic" ]; then
trimmomatic PE -threads $num_threads ${filename}.fq ${filename2}.fq ${filename3}_1P.fq ${filename3}_1U.fq ${filename3}_2P.fq ${filename3}_2U.fq ILLUMINACLIP:$ADAPTERPATH/TruSeq3-PE.fa:2:30:10:2 LEADING:3 TRAILING:3 MINLEN:36
elif [ "$adapter_trimmer" == "fastp" ]; then
fastp -w $num_threads -i ${filename}.fq -I ${filename2}.fq -o ${filename3}_trimmed_R1.fq -O ${filename3}_trimmed_R2.fq -j ${filename3}_fastp.json -h ${filename3}_fastp.html
fi
if [ "$aligner" == "tophat2" ]; then
echo "###################################"
echo "Running tophat2 in paired-end mode"
echo "###################################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_fwd_tophat -G $referenceannotation $fbname ${filename3}_1P.fq,${filename3}_1U.fq
tophat2-p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_rev_tophat -G $referenceannotation $fbname ${filename3}_2P.fq
elif [ "$adapter_trimmer" == "fastp" ]; then
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_fwd_tophat -G $referenceannotation $fbname ${filename3}_trimmed_R1.fq
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_rev_tophat -G $referenceannotation $fbname ${filename3}_trimmed_R2.fq
fi
echo "####################################################"
echo "Pre-processing mapped .BAM file before running HAMR"
echo "####################################################"
#Convert .bam to .sam, grep unique reads, sort reads and merge forward and reverse reads
samtools view -h -@ $num_threads -o ${filename3}_fwd.sam ${filename3}_fwd_tophat/accepted_hits.bam
samtools view -h -@ $num_threads -o ${filename3}_rev.sam ${filename3}_rev_tophat/accepted_hits.bam
grep -P '^\@|NH:i:1$' ${filename3}_fwd.sam > ${filename3}_fwd_unique.sam
grep -P '^\@|NH:i:1$' ${filename3}_rev.sam > ${filename3}_rev_unique.sam
samtools view -bSh -@ $num_threads ${filename3}_fwd_unique.sam > ${filename3}_fwd_unique.bam
samtools view -bSh -@ $num_threads ${filename3}_rev_unique.sam > ${filename3}_rev_unique.bam
samtools sort -@ $num_threads ${filename3}_fwd_unique.bam > ${filename3}_fwd_sorted.bam
samtools sort -@ $num_threads ${filename3}_rev_unique.bam > ${filename3}_rev_sorted.bam
samtools merge -f ${filename3}_merged.bam ${filename3}_fwd_sorted.bam ${filename3}_rev_sorted.bam
if [ "$HAMR" != 0 ]; then
echo "######################################################"
echo "Resolving spliced alignments"
echo "######################################################"
picard AddOrReplaceReadGroups I=${filename3}_merged.bam O=${filename3}_RG.bam ID=${filename3} LB=D4 PL=illumina PU=HWUSI-EAS1814:28:2 SM=${filename3}
picard ReorderSam I=${filename3}_RG.bam O=${filename3}_RGO.bam R=$referencegenome
samtools index ${filename3}_RGO.bam ${filename3}_RGO.bam.bai
gatk --java-options "-Xmx8g" SplitNCigarReads -R $referencegenome -I ${filename3}_RGO.bam -O ${filename3}_resolvedalig.bam -OBI false
echo "######################################################"
echo "Running HAMR"
echo "######################################################"
python /HAMR/hamr.py -fe ${filename3}_resolvedalig.bam $referencegenome $HAMR_MODELS_PATH/euk_trna_mods.Rdata ${filename3}_HAMR ${filename3} $min_read_qual $min_read_cov $seq_error_rate H4 $max_p $max_fdr $ref_percent
fi
tophat_mapping_lincRNA_annotation
tophat_mapping_transcript_quantification
fi
if [ "$aligner" == "star" ]; then
echo "###################################"
echo "Running STAR in paired-end mode"
echo "###################################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --readFilesCommand zcat --genomeDir ./star_index --outFileNamePrefix ${filename3}_ --readFilesIn ${filename3}_1P.fq ${filename3}_2P.fq
elif [ "$adapter_trimmer" == "fastp" ]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --readFilesCommand zcat --genomeDir ./star_index --outFileNamePrefix ${filename3}_ --readFilesIn ${filename3}_trimmed_R1.fq ${filename3}_trimmed_R2.fq
fi
star_mapping_lincRNA_annotation
star_mapping_transcript_quantification
fi
house_keeping
}
paired_fastq()
{
filename=$(basename "$f" ".fastq")
filename2=${filename/_R1/_R2}
filename3=$(echo $filename | sed 's/_R1//')
if [ "$seq_type" == "PE" ]; then
echo "###############################"
echo "Trimming paired-end input reads"
echo "###############################"
fi
if [ "$adapter_trimmer" == "trimmomatic" ]; then
trimmomatic PE -threads $num_threads ${filename}.fastq ${filename2}.fastq ${filename3}_1P.fastq ${filename3}_1U.fastq ${filename3}_2P.fastq ${filename3}_2U.fastq ILLUMINACLIP:$ADAPTERPATH/TruSeq3-PE.fa:2:30:10:2 LEADING:3 TRAILING:3 MINLEN:36
elif [ "$adapter_trimmer" == "fastp" ]; then
fastp -w $num_threads -i ${filename}.fastq -I ${filename2}.fastq -o ${filename3}_trimmed_R1.fastq -O ${filename3}_trimmed_R2.fastq -j ${filename3}_fastp.json -h ${filename3}_fastp.html
fi
if [ "$aligner" == "tophat2" ]; then
echo "###################################"
echo "Running tophat2 in paired-end mode"
echo "###################################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_fwd_tophat -G $referenceannotation $fbname ${filename3}_1P.fastq,${filename3}_1U.fastq
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_rev_tophat -G $referenceannotation $fbname ${filename3}_2P.fastq
elif [ "$adapter_trimmer" == "fastp" ]; then
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_fwd_tophat -G $referenceannotation $fbname ${filename3}_trimmed_R1.fastq
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename3}_rev_tophat -G $referenceannotation $fbname ${filename3}_trimmed_R2.fastq
fi
echo "####################################################"
echo "Pre-processing mapped .BAM file before running HAMR"
echo "####################################################"
#Convert .bam to .sam, grep unique reads, sort reads and merge forward and reverse reads
samtools view -h -@ $num_threads -o ${filename3}_fwd.sam ${filename3}_fwd_tophat/accepted_hits.bam
samtools view -h -@ $num_threads -o ${filename3}_rev.sam ${filename3}_rev_tophat/accepted_hits.bam
grep -P '^\@|NH:i:1$' ${filename3}_fwd.sam > ${filename3}_fwd_unique.sam
grep -P '^\@|NH:i:1$' ${filename3}_rev.sam > ${filename3}_rev_unique.sam
samtools view -bSh -@ $num_threads ${filename3}_fwd_unique.sam > ${filename3}_fwd_unique.bam
samtools view -bSh -@ $num_threads ${filename3}_rev_unique.sam > ${filename3}_rev_unique.bam
samtools sort -@ $num_threads ${filename3}_fwd_unique.bam > ${filename3}_fwd_sorted.bam
samtools sort -@ $num_threads ${filename3}_rev_unique.bam > ${filename3}_rev_sorted.bam
samtools merge -f ${filename3}_merged.bam ${filename3}_fwd_sorted.bam ${filename3}_rev_sorted.bam
if [ "$HAMR" != 0 ]; then
echo "######################################################"
echo "Resolving spliced alignments"
echo "######################################################"
picard AddOrReplaceReadGroups I=${filename3}_merged.bam O=${filename3}_RG.bam ID=${filename3} LB=D4 PL=illumina PU=HWUSI-EAS1814:28:2 SM=${filename3}
picard ReorderSam I=${filename3}_RG.bam O=${filename3}_RGO.bam R=$referencegenome
samtools index ${filename3}_RGO.bam ${filename3}_RGO.bam.bai
gatk --java-options "-Xmx8g" SplitNCigarReads -R $referencegenome -I ${filename3}_RGO.bam -O ${filename3}_resolvedalig.bam -OBI false
echo "######################################################"
echo "Running HAMR"
echo "######################################################"
python /HAMR/hamr.py -fe ${filename3}_resolvedalig.bam $referencegenome $HAMR_MODELS_PATH/euk_trna_mods.Rdata ${filename3}_HAMR ${filename3} $min_read_qual $min_read_cov $seq_error_rate H4 $max_p $max_fdr $ref_percent
fi
tophat_mapping_lincRNA_annotation
tophat_mapping_transcript_quantification
fi
if [ "$aligner" == "star" ]; then
echo "###################################"
echo "Running STAR in paired-end mode"
echo "###################################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --readFilesCommand zcat --genomeDir ./star_index --outFileNamePrefix ${filename3}_ --readFilesIn ${filename3}_1P.fastq ${filename3}_2P.fastq
elif [ "$adapter_trimmer" == "fastp" ]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --readFilesCommand zcat --genomeDir ./star_index --outFileNamePrefix ${filename3}_ --readFilesIn ${filename3}_trimmed_R1.fastq ${filename3}_trimmed_R2.fastq
fi
star_mapping_lincRNA_annotation
star_mapping_transcript_quantification
fi
house_keeping
}
single_end()
{
extension=$(echo "$f" | sed -r 's/.*(fq|fq.gz|fastq|fastq.gz)$/\1/')
filename=$(basename "$f" ".$extension")
echo "##############################"
echo "Trimming single-end input read"
echo "##############################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
trimmomatic SE -threads $num_threads ${filename}.${extension} ${filename}_trimmed.${extension} ILLUMINACLIP:$ADAPTERPATH/TruSeq3-SE.fa:2:30:10:2 LEADING:3 TRAILING:3 MINLEN:36
elif [ "$adapter_trimmer" == "fastp" ]; then
fastp -w $num_threads -i ${filename}.${extension} -o ${filename}_trimmed.${extension} -j ${filename}_fastp.json -h ${filename}_fastp.html
fi
if [ "$aligner" == "tophat2" ]; then
echo "###################################"
echo "Running tophat2 in single-end mode"
echo "###################################"
echo "tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename}_tophat -G $referenceannotation $fbname ${filename}_trimmed.${extension}"
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${filename}_tophat -G $referenceannotation $fbname ${filename}_trimmed.${extension}
echo "####################################################"
echo "Pre-processing mapped .BAM file before running HAMR"
echo "####################################################"
#Convert .bam to .sam, grep unique reads, sort reads
samtools view -h -@ $num_threads -o ${filename}.sam ${filename}_tophat/accepted_hits.bam
grep -P '^\@|NH:i:1$' ${filename}.sam > ${filename}_unique.sam
samtools view -bSh -@ $num_threads ${filename}_unique.sam > ${filename}_unique.bam
samtools sort -@ $num_threads ${filename}_unique.bam > ${filename}_sorted.bam
if [ "$HAMR" != 0 ]; then
echo "######################################################"
echo "Resolving spliced alignments"
echo "######################################################"
picard AddOrReplaceReadGroups I=${filename}_sorted.bam O=${filename}_RG.bam ID=${filename} LB=D4 PL=illumina PU=HWUSI-EAS1814:28:2 SM=${filename}
picard ReorderSam I=${filename}_RG.bam O=${filename}_RGO.bam R=$referencegenome
samtools index ${filename}_RGO.bam ${filename}_RGO.bam.bai
gatk --java-options "-Xmx8g" SplitNCigarReads -R $referencegenome -I ${filename}_RGO.bam -O ${filename}_resolvedalig.bam -OBI false
echo "######################################################"
echo "Running HAMR"
echo "######################################################"
python /HAMR/hamr.py -fe ${filename}_resolvedalig.bam $referencegenome $HAMR_MODELS_PATH/euk_trna_mods.Rdata ${filename}_HAMR ${filename} $min_read_qual $min_read_cov $seq_error_rate H4 $max_p $max_fdr $ref_percent
fi
tophat_mapping_lincRNA_annotation
tophat_mapping_transcript_quantification
elif [ "$aligner" == "star" ]; then
if [[ "$extension" =~ "fq.gz" ]]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --readFilesCommand zcat --genomeDir star_index --outFileNamePrefix ${filename}_ --readFilesIn ${filename}_trimmed.${extension}
elif [[ "$extension" =~ "fastq.gz" ]]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --readFilesCommand zcat --genomeDir star_index --outFileNamePrefix ${filename}_ --readFilesIn ${filename}_trimmed.${extension}
elif [[ "$extension" =~ "fq" ]]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --genomeDir star_index --outFileNamePrefix ${filename}_ --readFilesIn ${filename}_trimmed.${extension}
elif [[ "$extension" =~ "fastq" ]]; then
STAR --runMode alignReads --outSAMtype BAM SortedByCoordinate --genomeDir star_index --outFileNamePrefix ${filename}_ --readFilesIn ${filename}_trimmed.${extension}
fi
star_mapping_lincRNA_annotation
star_mapping_transcript_quantification
fi
house_keeping
}
#############################################################################################################################################################################################################################
# Check if user supplied index folder which contains either bowtie2, star indexes or both. Build the indexes if not supplied
#############################################################################################################################################################################################################################
if [ "$HAMR" != 0 ]; then
echo "samtools dict $referencegenome -o $gname.dict"
samtools dict $referencegenome -o "$gname".dict
echo "samtools faidx $referencegenome"
samtools faidx $referencegenome
fi
if [ "$aligner" == "tophat2" ]; then
if [ ! -z "$index_folder" ]; then
for i in $index_folder/*.bt2; do
mv -f $i .
fbname=$(basename "$i" .bt2 | cut -d. -f1)
done
elif [ ! -z "$referencegenome" ] && [ -z "$index_folder" ]; then
echo "##########################################"
echo "Building reference genome index for TopHat2"
echo "##########################################"
echo "bowtie2-build --threads -f $referencegenome $gname"
bowtie2-build -f $referencegenome "$gname"
echo "fbname=$(basename "$gname" .bt2 | cut -d. -f1)"
fbname=$(basename "$gname" .bt2 | cut -d. -f1)
fi
elif [ "$aligner" == "star" ]; then
if [ ! -z "$index_folder" ]; then
mv -f $index_folder/star_index/ .
elif [ ! -z "$referencegenome" ] && [ -z "$index_folder" ]; then
echo "########################################"
echo "Building reference genome index for STAR"
echo "########################################"
STAR --runThreadN $num_threads --runMode genomeGenerate --genomeDir star_index --genomeFastaFiles $referencegenome --sjdbGTFfile $referenceannotation --sjdbOverhang $sjdbOverhang --genomeSAindexNbases $genomeSAindexNbases
fi
fi
#############################################################################################################################################################################################################################
# # Check that the input fastq files has the appropriate extension and then trim reads, align the reads to the reference genome, quantify transcript abundance, identify RNA Mods. and LincRNAs
#############################################################################################################################################################################################################################
if [ ! -z "$left_reads" ] && [ ! -z "$right_reads" ]; then
numb=$(ls "${left_reads[@]}" | wc -l)
for f in "${left_reads[@]}"; do
extension=$(echo "$f" | sed -r 's/.*(fq|fq.gz|fastq|fastq.gz)$/\1/')
if [[ "$extension" =~ "fq.gz" ]]; then
paired_fq_gz
elif [[ "$extension" =~ "fastq.gz" ]]; then
paired_fastq_gz
elif [[ "$extension" =~ "fq" ]]; then
echo "gzip" "$f"
paired_fq
elif [[ "$extension" =~ "fastq" ]]; then
echo "gzip" "$f"
paired_fastq
elif [ "$extension" != "fastq" ] || [ "$extension" != "fq" ] || [ "$extension" != "fastq.gz" ] || [ "$extension" != "fq.gz" ]; then
echo "The extension" "$extension" "is not supported. Only .fq, .fq.gz, .fastq, .fastq.gz are only supported" 1>&2
exit 64
fi
done
#single end reads
elif [ ! -z "$single_reads" ]; then
numb=$(ls "${single_reads[@]}" | wc -l)
for f in "${single_reads[@]}"; do
if [ ! -d "$pipeline_output" ]; then
mkdir $pipeline_output
fi
single_end
done
elif [ ! -z "$sra_id" ]; then
if [ "$seq_type" == "PE" ]; then
echo "######################"
echo "Downloading SRA data"
echo "######################"
prefetch $sra_id
fasterq-dump -e $num_threads $sra_id
echo "###############################"
echo "Trimming paired-end input reads"
echo "###############################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
trimmomatic PE -threads $num_threads ${sra_id}_1.fastq ${sra_id}_2.fastq ${sra_id}_1P.fastq.gz ${sra_id}_1U.fastq.gz ${sra_id}_2P.fastq.gz ${sra_id}_2U.fastq.gz ILLUMINACLIP:$ADAPTERPATH/TruSeq3-PE.fa:2:30:10 LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:36
elif [ "$adapter_trimmer" == "fastp" ]; then
fastp -w $num_threads -i ${sra_id}_1.fastq -I ${sra_id}_2.fastq -o ${sra_id}_trimmed_R1.fastq.gz -O ${sra_id}_trimmed_R2.fastq.gz -j ${sra_id}_fastp.json -h ${sra_id}_fastp.html
fi
if [ "$aligner" == "tophat2" ]; then
echo "###################################"
echo "Running tophat2 in paired-end mode"
echo "###################################"
if [ "$adapter_trimmer" == "trimmomatic" ]; then
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${sra_id}_fwd_tophat -G $referenceannotation $fbname ${sra_id}_1P.fastq.gz,${sra_id}_1U.fastq.gz
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${sra_id}_rev_tophat -G $referenceannotation $fbname ${sra_id}_2P.fastq.gz
elif [ "$adapter_trimmer" == "fastp" ]; then
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${sra_id}_fwd_tophat -G $referenceannotation $fbname ${sra_id}_trimmed_R1.fastq.gz
tophat -p $num_threads --library-type $lib_type --read-mismatches $reads_mismatches --read-edit-dist $reads_mismatches --max-multihits 10 --b2-very-sensitive --transcriptome-max-hits 10 --no-coverage-search --output-dir ${sra_id}_rev_tophat -G $referenceannotation $fbname ${sra_id}_trimmed_R2.fastq.gz
fi
echo "####################################################"
echo "Pre-processing mapped .BAM file before running HAMR"
echo "####################################################"
#Convert .bam to .sam, grep unique reads, sort reads and merge forward and reverse reads
samtools view -h -@ $num_threads -o ${sra_id}_fwd.sam ${sra_id}_fwd_tophat/accepted_hits.bam
samtools view -h -@ $num_threads -o ${sra_id}_rev.sam ${sra_id}_rev_tophat/accepted_hits.bam
grep -P '^\@|NH:i:1$' ${sra_id}_fwd.sam > ${sra_id}_fwd_unique.sam
grep -P '^\@|NH:i:1$' ${sra_id}_rev.sam > ${sra_id}_rev_unique.sam
samtools view -bSh -@ $num_threads ${sra_id}_fwd_unique.sam > ${sra_id}_fwd_unique.bam
samtools view -bSh -@ $num_threads ${sra_id}_rev_unique.sam > ${sra_id}_rev_unique.bam
samtools sort -@ $num_threads ${sra_id}_fwd_unique.bam > ${sra_id}_fwd_sorted.bam
samtools sort -@ $num_threads ${sra_id}_rev_unique.bam > ${sra_id}_rev_sorted.bam
samtools merge -f ${sra_id}_merged.bam ${sra_id}_fwd_sorted.bam ${sra_id}_rev_sorted.bam
if [ "$HAMR" != 0 ]; then
echo "######################################################"
echo "Resolving spliced alignments"
echo "######################################################"
picard AddOrReplaceReadGroups I=${sra_id}_merged.bam O=${sra_id}_RG.bam ID=${sra_id} LB=D4 PL=illumina PU=HWUSI-EAS1814:28:2 SM=${sra_id}
picard ReorderSam I=${sra_id}_RG.bam O=${sra_id}_RGO.bam R=$referencegenome
samtools index ${sra_id}_RGO.bam ${sra_id}_RGO.bam.bai
gatk --java-options "-Xmx8g" SplitNCigarReads -R $referencegenome -I ${sra_id}_RGO.bam -O ${sra_id}_resolvedalig.bam -OBI false
echo "######################################################"
echo "Running HAMR"
echo "######################################################"