-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathriboProPipe.sh
executable file
·1964 lines (1784 loc) · 74 KB
/
riboProPipe.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
###############################################################################
## The main bash script to run the ribosome profile pipeline. ##
## ##
## Version 0.9 ##
## Developer: Alexandra Bomane ##
## <[email protected]> ##
## Maintainer: Costas Bouyioukos ##
## email: [email protected] ##
## Developed in the PTER team at Paris Diderot and UMR7216, 2016-18 ##
## This program is a free software released under the GNU GPL v. 3 ##
###############################################################################
######################### Variables section ###########################
## Environment
# For debugging
# set -exv
# Allow to stop the program after an error, BUT doesn't display the error
# TODO Integrate parameter ANSWER_SPLICING_JUNCTIONS --> if YES let the STAR command line for mapping has it is ; if NO --> DON'T do splcing using --alignIntronMax 1 parameter of STAR
# Working directory
export WORKDIR=$(pwd)
# Default variables FIXME NO default parameters here ALL variables into the parameters file.
export ANSWER_REMOVE_POLYN_READS=NO
export ANSWER_REMOVE_PCR_DUPLICATES=NO
export ANSWER_RNASEQ_DATA=NO
export ANSWER_PSITE_CORRECTION=NO
export STOP_EXEC_PSITE_CORRECTION=YES
# Import configuration (.conf) file specified by the user: it overides default variables
source $1
# Error exit function FIXME it does not work as needed!
function error_exit {
PROGNAME=$(basename $@)
echo "${PROGNAME}: An error has occured at line: ${1}." 1>&2
exit 2
}
export -f error_exit
# TODO Check ANSWER_* variables
export WORKING_ANSWER_REMOVE_POLYN_READS=${ANSWER_REMOVE_POLYN_READS^^}
if [ ! $WORKING_ANSWER_REMOVE_POLYN_READS = NO ] && [ ! $WORKING_ANSWER_REMOVE_POLYN_READS = YES ]
then
echo "Check your ANSWER_REMOVE_POLYN_READS parameter. It must be YES or NO."
error_exit ${LINENO}
fi
export WORKING_ANSWER_DEMULTIPLEXING=${ANSWER_DEMULTIPLEXING^^}
if [ ! $WORKING_ANSWER_DEMULTIPLEXING = NO ] && [ ! $WORKING_ANSWER_DEMULTIPLEXING = YES ]
then
echo "Check your ANSWER_DEMULTIPLEXING parameter. It must be YES or NO."
error_exit ${LINENO}
fi
export WORKING_ANSWER_REMOVE_PCR_DUPLICATES=${ANSWER_REMOVE_PCR_DUPLICATES^^}
if [ ! $WORKING_ANSWER_REMOVE_PCR_DUPLICATES = NO ] && [ ! $WORKING_ANSWER_REMOVE_PCR_DUPLICATES = YES ]
then
echo "Check your ANSWER_REMOVE_PCR_DUPLICATES parameter. It must be YES or NO."
error_exit ${LINENO}
fi
export WORKING_ANSWER_RNASEQ_DATA=${ANSWER_RNASEQ_DATA^^}
if [ ! $WORKING_ANSWER_RNASEQ_DATA = NO ] && [ ! $WORKING_ANSWER_RNASEQ_DATA = YES ]
then
echo "Check your ANSWER_RNASEQ_DATA parameter. It must be YES or NO."
error_exit ${LINENO}
fi
if [ $WORKING_ANSWER_RNASEQ_DATA = YES ]
then
WORKING_ANSWER_PE_RNASEQ=${ANSWER_PE_RNASEQ^^}
if [ ! $WORKING_ANSWER_PE_RNASEQ = NO ] && [ ! $WORKING_ANSWER_PE_RNASEQ = YES ]
then
echo "Check your ANSWER_PE_RNASEQ parameter. It must be YES or NO."
error_exit ${LINENO}
elif [ -z $ANSWER_PE_RNASEQ ]
then
echo "ANSWER_PE_RNASEQ parameter is mandatory if you have RNA-seq data. It must be YES or NO."
error_exit ${LINENO}
fi
if [ ! $RNASEQ_LIBTYPE = "forwardstrand" ] && [ ! $RNASEQ_LIBTYPE = "unstranded" ] && [ ! $RNASEQ_LIBTYPE = "reversestrand" ]
then
echo "Check your RNASEQ_LIBTYPE parameter. It must be 'forwardstrand' (Read 1/single-end reads belongs to the forward strand) or 'unstranded' or 'reversestrand' (Read 1/single-end reads belongs to reverse strand)"
error_exit ${LINENO}
elif [ -z $RNASEQ_LIBTYPE ]
then
echo "RNASEQ_LIBTYPE parameter is mandatory if you have RNA-seq data. It must be 'forwardstrand' (Read 1/single-end reads belongs to the forward strand) or 'unstranded' or 'reversestrand' (Read 1/single-end reads belongs to the reverse strand)"
error_exit ${LINENO}
fi
fi
if [ "$WORKING_ANSWER_PE_RNASEQ" = YES ] && [ $RNASEQ_LIBTYPE = "reversestrand" ]
then
SALMON_LIBTYPE="ISR"
elif [ "$WORKING_ANSWER_PE_RNASEQ" = YES ] && [ $RNASEQ_LIBTYPE = "unstranded" ]
then
SALMON_LIBTYPE="IU"
elif [ "$WORKING_ANSWER_PE_RNASEQ" = YES ] && [ $RNASEQ_LIBTYPE = "forwardstrand" ]
then
SALMON_LIBTYPE="ISF"
elif [ "$WORKING_ANSWER_PE_RNASEQ" = NO ] && [ $RNASEQ_LIBTYPE = "reversestrand" ]
then
SALMON_LIBTYPE="SR"
elif [ "$WORKING_ANSWER_PE_RNASEQ" = NO ] && [ $RNASEQ_LIBTYPE = "unstranded" ]
then
SALMON_LIBTYPE="U"
elif [ "$WORKING_ANSWER_PE_RNASEQ" = NO ] && [ $RNASEQ_LIBTYPE = "forwardstrand" ]
then
SALMON_LIBTYPE="SF"
fi
#WORKING_ANSWER_KEEP_MULTIREAD=${ANSWER_KEEP_MULTIREAD^^} # TODO Multiread analysis to be removed
#if [ ! $WORKING_ANSWER_KEEP_MULTIREAD = NO ] && [ ! $WORKING_ANSWER_KEEP_MULTIREAD = YES ]
#then
# echo "Check your ANSWER_KEEP_MULTIREAD parameter. It must be YES or NO."
# error_exit "$LINENO: An error has occurred."
#fi
if [ ! "$DIFFERENTIAL_ANALYSIS_PACKAGE" = EDGER ] && [ ! $DIFFERENTIAL_ANALYSIS_PACKAGE = DESEQ2 ]
then
echo "Unavailable R package. Choose : EDGER or DESEQ2 (case sensitive)"
error_exit "$LINENO: An error has occurred."
fi
export WORKING_STOP_EXEC_PSITE_CORRECTION=${STOP_EXEC_PSITE_CORRECTION^^}
if [ ! "$WORKING_STOP_EXEC_PSITE_CORRECTION" = NO ] && [ ! $WORKING_STOP_EXEC_PSITE_CORRECTION = YES ]
then
echo "Check your STOP_EXEC_PSITE_CORRECTION parameter. It must be YES or NO."
error_exit ${LINENO}
fi
## Check mandatory parameters
if [ -z $PATH_TO_GENOME_INDEX ]
then
echo "Give your genome index path."
error_exit ${LINENO}
fi
if [ -z "$PATH_TO_rRNA_INDEX" ]
# TODO check if we really need to do that also.
then
echo "Give your rRNA index path."
error_exit ${LINENO}
fi
if [ -z $SAMPLE_ARRAY ]
then
echo "Give the samples array in $1 (eg : SAMPLE_ARRAY=(sample1 sample2 ...))."
error_exit ${LINENO}
fi
if [ -z $CONDITION_ARRAY ]
then
echo "Give the biological conditions array in $1 (eg : CONDITION_ARRAY=(sample1condition sample2condition ...))."
error_exit ${LINENO}
fi
if [ -z $ADAPTER_SEQUENCE_THREE_PRIME ]
then
echo "Give the 3' adapter sequence in $1 (eg : ADAPTER_SEQUENCE_THREE_PRIME=MYADAPTERSEQUENCETHREEPRIME)"
error_exit ${LINENO}
fi
export WORKING_SAMPLE_ARRAY=$(echo ${SAMPLE_ARRAY[*]})
export WORKING_ANSWER_DEMULTIPLEXING=${ANSWER_DEMULTIPLEXING^^}
if [ $WORKING_ANSWER_DEMULTIPLEXING = YES ]
then
if [ -z $SAMPLE_INDEX_ARRAY ]
then
echo "Give your sample index array in $1 (eg : SAMPLE_INDEX_ARRAY=(sample1index sample2index ...))."
error_exit ${LINENO}
fi
fi
export WORKING_ANSWER_RNASEQ_DATA=${ANSWER_RNASEQ_DATA^^}
if [ $WORKING_ANSWER_RNASEQ_DATA = NO ]
then
if [ -z $AUTHOR ]
then
$AUTHOR=UserName
fi
fi
if [ $WORKING_ANSWER_RNASEQ_DATA = NO ]
then
if [ -z $REFERENCE_CONDITION ]
then
echo "Give your reference (biological) condition in $1 (eg: REFERENCE_CONDITION=MYREFERENCECONDITION)"
error_exit ${LINENO}
fi
fi
if [ -z $PATH_TO_REFERENCE_GENOME_FILE ]
then
echo "Give the absolute path to your reference genome FASTA. in $1 (eg: PATH_TO_REFERENCE_GENOME_FILE=/path/to/my/ref/genome/mygenome.fasta)"
error_exit ${LINENO}
fi
if [ -z $PATH_TO_REFERENCE_TRANSCRIPTOME_FILE ]
then
echo "Give the absolute path to your reference transcriptome FASTA. in $1 (eg: PATH_TO_REFERENCE_TRANSCRIPTOME_FILE=/path/to/my/ref/transcriptome/mytranscriptome.fasta)"
error_exit ${LINENO}
fi
if [ -z $STRANDED ]
then
echo "Set the --stranded option of HTSeq-Count (For help : http://www-huber.embl.de/users/anders/HTSeq/doc/count.html)"
error_exit ${LINENO}
fi
if [ -z $PATH_TO_ANNOTATION_FILE ]
then
echo "Give the path to your GTF annotations."
error_exit ${LINENO}
fi
export WORKING_SAMPLE_INDEX_ARRAY=$(echo ${SAMPLE_INDEX_ARRAY[*]})
export SAMPLES=($(echo ${SAMPLE_ARRAY[@]%.fastq})) ## TODO No need because handling by GNU parallel (FIXME NO prtobably I made a wrong comment here.)
#WORKING_CONDITION_ARRAY=$(echo ${CONDITION_ARRAY[*]})
export WORKING_CONDITION_ARRAY=$(echo ${CONDITION_ARRAY[*]})
export SHELL=$(type -p bash)
export CONDITION_ARRAY_UNIQ=$(echo "${CONDITION_ARRAY[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
# Check arrays length
export NB_SAMPLE=$(echo ${#SAMPLE_ARRAY[@]})
if [ $WORKING_ANSWER_DEMULTIPLEXING = YES ]
then
NB_SAMPLE_INDEX=$(echo ${#SAMPLE_INDEX_ARRAY[@]})
if [ $NB_SAMPLE_INDEX -ne $NB_SAMPLE ]
then
echo "SAMPLE_INDEX_ARRAY and SAMPLE_ARRAY have different lengths. Check them."
error_exit ${LINENO}
fi
fi
if [ $WORKING_ANSWER_RNASEQ_DATA = YES ]
then
NB_CONDITION=$(echo ${#CONDITION_ARRAY[@]})
if [ $NB_CONDITION -ne $NB_SAMPLE ]
then
echo "CONDITION_ARRAY and SAMPLE_ARRAY have different lengths. Check them."
error_exit ${LINENO}
fi
fi
################### Scripts Section ###################################
# Main Bash script
export MAIN_SCRIPT_CANONICAL_PATH=$(readlink -f $0) ## basename $0
export CANONICAL_PATH=$(dirname $MAIN_SCRIPT_CANONICAL_PATH)
# Python and R scripts paths
export PYTHON_SCRIPTS_PATH="${CANONICAL_PATH}/PythonScripts/"
export R_SCRIPTS_PATH="${CANONICAL_PATH}/RScripts/"
#TODO probably there is NO NEED to have all these parameters as individual params. A call of the name of the script from the containing directory will be enough!
# TODO Dockerise EVERYTHING!
## Python scripts
export PYTHON_SCRIPT_DEMULTIPLEXING="run_demultiplexing.py"
export PYTHON_SCRIPT_REMOVE_PCR_DUP="rmDupPCR.py"
export PYTHON_SCRIPT_REMOVE_BAD_IQF="remove_bad_reads_Illumina_passing_filter.py"
export PYTHON_SCRIPT_READ_LENGTH_DISTRIBUTION="read_length_distribution.py"
export PYTHON_SCRIPT_SAM_FILTERING="sam_file_filter.py"
export PYTHON_SCRIPT_LONGEST_TRANSCRIPT="get_longest_transcripts_from_ensembl_gtf.py"
export PYTHON_SCRIPT_COUNT_CLUSTER="clusterCountings.py"
export PYTHON_SCRIPT_ADD_START_GTF="add_cds_start_to_gtf.py"
export PYTHON_SCRIPT_PSITE_AUTOCORRECTION="plastid_psite_offsets_autocorrection.py"
export PYTHON_SCRIPT_CDS_RANGE_GENERATOR="cds_range_generator.py"
## R scripts
export R_SCRIPT_BUILD_COUNTING_TABLE_RNASEQ="RNAseqCountDataMatrix.R"
export R_SCRIPT_BUILD_COUNTING_TABLE_RP="RPCountDataMatrix.R"
export R_SCRIPT_ANADIFF_BABEL="babel_RP_differentialAnalysis.R"
export R_SCRIPT_PERMT_TEST_BABEL="babel_RP_permutationTest.R"
export R_SCRIPT_ANADIFF_SARTOOLS_DESEQ2="script_DESeq2.R"
export R_SCRIPT_ANADIFF_SARTOOLS_EDGER="script_edgeR.R"
## Docker images
# TODO UPDATE ALL docker images and make them all available from Paris Epigenetics.
export WORKING_CHECK_DOCKER_IMAGES=${CHECK_DOCKER_IMAGES^^}
if [ ! $WORKING_CHECK_DOCKER_IMAGES = NO ]
then
if [ $WORKING_CHECK_DOCKER_IMAGES = YES ]
then
docker pull parisepigenetics/fastqc
docker pull parisepigenetics/cutadapt
docker pull parisepigenetics/multiqc
# docker pull genomicpariscentre/bowtie
docker pull parisepigenetics/star
docker pull genomicpariscentre/samtools
docker pull genomicpariscentre/gff3-ptools
docker pull genomicpariscentre/htseq
docker pull genomicpariscentre/babel
docker pull genomicpariscentre/sartools
docker pull genomicpariscentre/ribomap
# docker pull genomicpariscentre/bcbio-nextgen
docker pull parisepigenetics/bcbio-nextgen
docker pull parisepigenetics/plastid
# docker pull parisepigenetics/riboseqr TODO Integrate RiboSeqR
# docker pull parisepigenetics/umitools TODO Integrate Umitools
else
echo "Check your CHECK_DOCKER_IMAGES parameter. It must be YES or NO."
error_exit ${LINENO}
fi
fi
## Tools parameters
# Size selection: Cutadapt
export MIN_READ_LENGTH="25"
export MAX_READ_LENGTH="35"
export FILTER_MAX_N="2"
## Prepare samples step: Seqcluster
export MIN_COUNT="2"
export MIN_SIZE="25"
export MAX_SIZE="35"
export MIN_SHARED="2"
## Align to rRNA sequences: Bowtie 1
# TODO I do not know if we need to use yet another aligner to filter the rDNA. We can use just one (either STAR or hisat2) and then remove the rDNA from the annotaions.
# Bowtie 1 Options details : -q --> Fastq file as input ; --un --> write unaligned reads to another file (.fastq) ; -S --> write hits in SAM format
export BOWTIE_OPTIONS="-q -S --un"
## Align to reference genome: STAR
export MAX_ALLOWED_MISMATCHES="2" # alignment will be output only if it has no more mismatches than this value
export SEED_SEARCH_POINT="16" # defines the search start point through the read - the read is split into pieces no longer than this value
export FILTER_SCORE_MIN="0" # alignment will be output if its ratio of score to *read* length is higher than this value
export FILTER_MATCH_MIN="0.85" # alignment will be output if its ratio of number of matched bases to *read* length is higher than this value
export MAX_LOCI_ALLOWED="1000" # max number of loci anchors are allowed to map to
export MULTIMAP_SCORE_RANGE="0" # the score range below the maximum score for multimapping alignments
## Multi-mapped analysis
#TODO Multi-mapped analysis will be removed from the published version.
export MULTIMAP_N_MAX="500"
## P-site offsets analysis
export MIN_LENGTH_POFFSET="25"
export MAX_LENGTH_POFFSET="35"
export DEFAULT_POFFSET="0"
## Ribomap
export MIN_FPLEN="25"
export MAX_FPLEN="35"
## HTSeq-Count
export MODE_FOR_MULTIPLE_FEATURES_READS="union"
export FEATURE_TYPE="CDS"
export IDATTR="gene_id" ## Ok for Secluster-clustering step
export FILETYPE="bam"
## Manage output directories
if [ ! -e logFiles/ ]
then
mkdir -p logFiles/
fi
export LOGDIR=$(readlink -f logFiles/)/
if [ ! -e QC/ ]
then
mkdir -p QC/
fi
export QCDIR=$(readlink -f QC/)/
################### FUNCTIONS #########################################
#FIXME ALL I mean ALL the scripts we use will be dockerised (including Python and R scripts.)
# Run demultiplexing to get Fastq files
# $1 = SAMPLE $2 = ADAPTER
demultiplexing() {
echo "Demultiplexing of ${1}..."
WORKING_ANSWER_DEMULTIPLEXING=${ANSWER_DEMULTIPLEXING^^}
if [ $WORKING_ANSWER_DEMULTIPLEXING = YES ]
then
if [ -z $PATH_TO_RAW_UNDEMULTIPLEXED_FILE ]
then
echo "Give the path to your multiplexed FASTQ file."
error_exit ${LINENO}
fi
LOGFILE="${1}_demultiplexing.log"
OUTFILE="${1}_demultiplex.fastq"
if [ -s $OUTFILE ]
then
echo "Demultiplexing already done for ${1}"
return 0
else
$PYTHON_SCRIPTS_PATH$PYTHON_SCRIPT_DEMULTIPLEXING -i $PATH_TO_RAW_UNDEMULTIPLEXED_FILE -o $OUTFILE -a $2 > $LOGDIR$LOGFILE
if [ $? -ne 0 ]
then
echo "run_demultiplexing cannot run correctly ! Check your mutliplexed FASTQ path and your index adapter sequence."
error_exit ${LINENO}
fi
echo "Log file : $LOGFILE generated."
echo "End of demultiplexing."
fi
else
return 0
fi
}
# Run FastQC for quality control report of the raw sequences.
# $1 = directory output ; $2 = input
fastqc_quality_control() {
if [ "$(ls -1 $1)" ]
then
echo "Quality control already done"
return 0
else
mkdir -p $1
if [ $? -ne 0 ]
then
echo "$1 image cannot be created !"
error_exit ${LINENO}
fi
#echo "docker run --rm -u $(id -u):$(id -g) -v $WORKDIR:/home -w /home genomicpariscentre/fastqc -o $1 $2"
docker run --rm -u $(id -u):$(id -g) -v $WORKDIR:/home -w /home parisepigenetics/fastqc -o $1 $2
if [ $? -ne 0 ]
then
echo "FastQC cannot run correctly ! $@"
error_exit ${LINENO}
fi
echo "Finish FastQC."
fi
}
# Run FastQC for quality control of the demultiplexed files.
raw_quality_report() {
echo "Raw quality control for ${1}..."
WORKING_ANSWER_DEMULTIPLEXING=${ANSWER_DEMULTIPLEXING^^}
if [ $WORKING_ANSWER_DEMULTIPLEXING = YES ]
then
INPUT_RAW_FASTQ_PATH="${1}_demultiplex.fastq"
else
INPUT_RAW_FASTQ_PATH="${1}.fastq"
fi
DIR_RAW_FASTQ_REPORT="${1}_raw_fastqc_report"
if [ -s $INPUT_RAW_FASTQ_PATH ]
then
RAW_FASTQ_REPORT=$(basename $DIR_RAW_FASTQ_REPORT)
INPUT_RAW_FASTQ=$(basename $INPUT_RAW_FASTQ_PATH)
fastqc_quality_control $QCDIR$RAW_FASTQ_REPORT $INPUT_RAW_FASTQ
else
echo "$INPUT_RAW_FASTQ_PATH doesn't exist ! Check your SAMPLE_ARRAY."
error_exit ${LINENO}
fi
}
# Remove bad passing filter reads
removeBadIQF() {
echo "Remove bad IQF reads from ${1}..."
WORKING_ANSWER_DEMULTIPLEXING=${ANSWER_DEMULTIPLEXING^^}
if [ $WORKING_ANSWER_DEMULTIPLEXING = YES ]
then
INPUT_FASTQ="${1}_demultiplex.fastq"
else
INPUT_FASTQ="${1}.fastq"
fi
LOGFILE="${1}_rmIQF.log"
RM_BADIQF_OUTPUT="${1}_rmIQF.fastq"
if [ -s $RM_BADIQF_OUTPUT ]
then
echo "Illumina Quality Filtering already done for ${1}."
return 0
else
$PYTHON_SCRIPTS_PATH$PYTHON_SCRIPT_REMOVE_BAD_IQF $INPUT_FASTQ $RM_BADIQF_OUTPUT 2> $LOGDIR$LOGFILE
if [ $? -ne 0 ]
then
echo "Removing bad IQF cannot run correctly!"
error_exit "${LINENO}: An error has occurred."
fi
echo "Log file: $LOGFILE generated"
echo "End of removing bad IQF"
fi
}
# # Remove PCR duplicates --> % Amplification in log file
# # TODO Can be replaced by UMI-tools
# removePCRduplicates() {
# WORKING_ANSWER_REMOVE_PCR_DUPLICATES=${ANSWER_REMOVE_PCR_DUPLICATES^^}
# if [ $WORKING_ANSWER_REMOVE_PCR_DUPLICATES = "YES" ]
# then
# LOGFILE="$1_rmPCR.log"
# RM_PCRDUP_OUTPUT="$1_rmPCR.fastq"
# RM_PCRDUP_INPUT="$1_rmIQF.fastq"
# if [ -s $RM_PCRDUP_INPUT ]
# then
# if [ -s $RM_PCRDUP_OUTPUT ] && [ -s $LOGFILE ]
# then
# echo "Removal of PCR duplicates already done. (house script)"
# return 0
# else
# echo "Removing PCR duplicates :"
# awk '{ i=(NR-1) % 4; tab[i]=$0 ; if (i==3) { print tab[1]"\t"tab[0]"\t"tab[3]"\t"tab[2]} }' $RM_PCRDUP_INPUT | sort | $PYTHON_SCRIPTS_PATH$PYTHON_SCRIPT_REMOVE_PCR_DUP $RM_PCRDUP_OUTPUT > $LOGFILE
# if [ ! -s $RM_PCRDUP_OUTPUT ]
# then
# echo "Cannot run rmDupPCR correctly !"
# error_exit "$LINENO: An error has occurred."
# fi
# echo "Log file : $LOGFILE generated."
# echo "End of PCR duplicates removing."
# fi
# else
# echo "You need a file which was filtered on bad Illumina Qualitiy Filter (_rmIQF.fastq) !"
# error_exit "$LINENO: An error has occurred."
# fi
# else
# return 0
# fi
# }
# Run the 5' trimming
index_Adapter_trimming() {
echo "Index 5' adapter trimming..."
WORKING_ANSWER_REMOVE_PCR_DUPLICATES=${ANSWER_REMOVE_PCR_DUPLICATES^^}
WORKING_ANSWER_DEMULTIPLEXING=${ANSWER_DEMULTIPLEXING^^}
if [ $WORKING_ANSWER_DEMULTIPLEXING = YES ]
then
INDEX_TRIM_OUTPUT=$(basename "${1}_TrimIndex.fastq")
if [ $WORKING_ANSWER_REMOVE_PCR_DUPLICATES = YES ]
then
INDEX_TRIM_INPUT=$(basename "${1}_rmPCR.fastq")
else
INDEX_TRIM_INPUT=$(basename "${1}_rmIQF.fastq")
fi
INDEX_LENGTH=$(expr length $2)
LOGFILE="${1}_TrimIndex.log"
if [ -s $INDEX_TRIM_OUTPUT ]
then
echo "Index trimming already done for ${1}."
return 0
else
docker run --rm -u $(id -u):$(id -g) -v $TMPDIR:/tmp -v $WORKDIR:/home -w /home parisepigenetics/cutadapt bash -c "cutadapt -u $INDEX_LENGTH -o $INDEX_TRIM_OUTPUT $INDEX_TRIM_INPUT" > $LOGDIR$LOGFILE
if [ ! -s $INDEX_TRIM_OUTPUT ]
then
echo "Index adapter trimming cannot run correctly !"
error_exit "$LINENO: An error has occurred."
fi
echo "Log file : $LOGFILE generated."
echo "End of 5' index adapter trimming."
fi
else
echo "No demultiplexing, no need for 5' adapter trimming."
return 0
fi
}
# Sequencing adapter 3' trimming
threePrime_trimming() {
echo "Sequencing 3' adapter trimming..."
WORKING_ANSWER_DEMULTIPLEXING=${ANSWER_DEMULTIPLEXING^^}
WORKING_ANSWER_REMOVE_PCR_DUPLICATES=${ANSWER_REMOVE_PCR_DUPLICATES^^}
WORKING_ANSWER_REMOVE_POLYN_READS=${ANSWER_REMOVE_POLYN_READS^^}
if [ $WORKING_ANSWER_DEMULTIPLEXING = "YES" ]
then
THREEPRIME_TRIM_INPUT=$(basename "${1}_TrimIndex.fastq")
else
if [ $WORKING_ANSWER_REMOVE_PCR_DUPLICATES = "YES" ]
then
THREEPRIME_TRIM_INPUT=$(basename "${1}_rmPCR.fastq")
else
THREEPRIME_TRIM_INPUT=$(basename "${1}_rmIQF.fastq")
fi
fi
THREEPRIME_TRIM_OUTPUT=$(basename "${1}_ThreePrime_Trim.fastq")
LOGFILE=$(basename "${1}_ThreePrimeTrim.log")
if [ -s $THREEPRIME_TRIM_OUTPUT ]
then
echo "Three prime trimming already done for ${1}."
return 0
else
if [ $WORKING_ANSWER_REMOVE_POLYN_READS = "YES" ]
then
docker run --rm -u $(id -u):$(id -g) -v $WORKDIR:/home -w /home parisepigenetics/cutadapt bash -c "cutadapt -a $2 --discard-untrimmed --max-n $FILTER_MAX_N -o $THREEPRIME_TRIM_OUTPUT $THREEPRIME_TRIM_INPUT > $LOGDIR$LOGFILE"
else
docker run --rm -u $(id -u):$(id -g) -v $WORKDIR:/home -w /home parisepigenetics/cutadapt bash -c "cutadapt -a $2 --discard-untrimmed -o $THREEPRIME_TRIM_OUTPUT $THREEPRIME_TRIM_INPUT > $LOGDIR$LOGFILE"
fi
if [ $? -ne 0 ]
then
echo "Cutadapt 3' trimming cannot run correctly !"
error_exit "$LINENO: An error has occurred."
fi
echo "Log file: $LOGFILE generated."
echo "End of 3' trimming Cutadapt."
fi
}
# Perform size selection.
size_Selection() {
echo "Size selection with cutadapt..."
WORKING_ANSWER_DEMULTIPLEXING=${ANSWER_DEMULTIPLEXING^^}
WORKING_ANSWER_REMOVE_PCR_DUPLICATES=${ANSWER_REMOVE_PCR_DUPLICATES^^}
if [ $WORKING_ANSWER_DEMULTIPLEXING = "YES" ]
then
THREEPRIME_TRIM_INPUT="${1}_ThreePrime_Trim.fastq"
SIZE_SELECT_OUTPUT="${1}_SizeSelection.fastq"
LOGFILE="${1}_SizeSelection.log"
else
BASENAME=$(basename ${1} .f*q)
THREEPRIME_TRIM_INPUT="${BASENAME}_ThreePrime_Trim.fastq"
SIZE_SELECT_OUTPUT="${BASENAME}_SizeSelection.fastq"
LOGFILE="${BASENAME}_SizeSelection.log"
fi
if [ -s $THREEPRIME_TRIM_OUTPUT ]
then
echo "Size selection already done."
return 0
else
docker run --rm -u $(id -u):$(id -g) -v $WORKDIR:/home -w /home parisepigenetics/cutadapt bash -c "cutadapt -m $MIN_READ_LENGTH -M $MAX_READ_LENGTH -o $SIZE_SELECT_OUTPUT $THREEPRIME_TRIM_INPUT > $LOGDIR$LOGFILE"
if [ $? -ne 0 ]
then
echo "Cutadapt cannot run correctly !"
error_exit "$LINENO: An error has occurred."
fi
echo "Log file: $LOGFILE generated."
echo "End of size selection with Cutadapt."
fi
}
# Size selection quality control report
size_Selection_report() {
echo "Size selection quality control for ${1}..."
FASTQC_REPORT_DIR="${1}_sizeSelection_report/"
INPUT_FASTQ="${1}_SizeSelection.fastq"
if [ -s $INPUT_RAW_FASTQ ]
then
FASTQC_REPORT_DIR=$(basename $FASTQC_REPORT_DIR)
INPUT_FASTQ=$(basename $INPUT_FASTQ)
fastqc_quality_control $QCDIR$FASTQC_REPORT_DIR $INPUT_FASTQ
else
echo "$INPUT_FASTQ does not exist! Check your SAMPLE_ARRAY, and your Seze Selection process."
error_exit ${LINENO}
fi
}
# Run STAR to align reads to the reference genome
align_to_ref_genome() {
echo "Genome alignments with STAR..."
for sample in ${SAMPLE_ARRAY[*]}
do
echo "Start mapping ${sample} to reference genome..."
WORKING_ANSWER_DEMULTIPLEXING=${ANSWER_DEMULTIPLEXING^^}
if [ $WORKING_ANSWER_DEMULTIPLEXING = YES ]
then
DIR_ALIGN_STAR="${sample}_STARalignments/"
INPUT_ALIGN_GENOME="${sample}_SizeSelection.fastq"
else
BASENAME=$(basename $sample .fastq)
DIR_ALIGN_STAR="${BASENAME}_STARalignments/"
INPUT_ALIGN_GENOME="${BASENAME}_SizeSelection.fastq"
fi
if [ -e ${DIR_ALIGN_STAR} ]
then
if [ -s "${DIR_ALIGN_STAR}Log.final.out" ]
then
echo "Mapping already done for ${sample}."
continue
fi
else
mkdir -p $DIR_ALIGN_STAR
if [ $? -ne 0 ]
then
echo "Cannot create the directory !"
error_exit "$LINENO: An error has occurred."
fi
#TODO check optimal STAR alignment parameters.
#echo "docker run --rm -u $(id -u):$(id -g) -v $WORKDIR:/home -v $PATH_TO_GENOME_INDEX:/root -w /home parisepigenetics/star bash -c STAR --runThreadN $(nproc) --genomeDir /root --readFilesIn $INPUT_ALIGN_GENOME --outFileNamePrefix $DIR_ALIGN_STAR --limitBAMsortRAM 49000000 --outSAMunmapped Within --outFilterMultimapNmax 20 --outSAMprimaryFlag AllBestScore --twopassMode Basic --outSAMtype BAM SortedByCoordinate --quantMode TranscriptomeSAM GeneCounts --outStd Log --seedSearchStartLmaxOverLread 0.5 --winAnchorMultimapNmax 25 --outFilterScoreMinOverLread 0.5 --outFilterMatchNminOverLread 0.5"
docker run --rm -u $(id -u):$(id -g) -v $WORKDIR:/home -v $PATH_TO_GENOME_INDEX:/root -w /home parisepigenetics/star bash -c "STAR --runThreadN $(nproc) --genomeDir /root --readFilesIn $INPUT_ALIGN_GENOME --outFileNamePrefix $DIR_ALIGN_STAR --outSAMunmapped Within --outFilterMultimapNmax 20 --outSAMprimaryFlag AllBestScore --twopassMode Basic --outSAMtype BAM SortedByCoordinate --quantMode TranscriptomeSAM GeneCounts --outStd Log --seedSearchStartLmaxOverLread 0.5 --winAnchorMultimapNmax 25 --outFilterScoreMinOverLread 0.5 --outFilterMatchNminOverLread 0.5 --limitBAMsortRAM 48000000000 --quantTranscriptomeBan Singleend"
# OLD_CALL docker run --rm -u $(id -u):$(id -g) -v $WORKDIR:/home -v $PATH_TO_GENOME_INDEX:/root -w /home genomicpariscentre/star bash -c "STAR --runThreadN $(nproc) --genomeDir /root --readFilesIn $INPUT_ALIGN_GENOME --outFileNamePrefix $DIR_ALIGN_STAR --outSAMunmapped Within --outFilterMismatchNmax $MAX_ALLOWED_MISMATCHES --quantMode TranscriptomeSAM --seedSearchStartLmax $SEED_SEARCH_POINT --outFilterScoreMinOverLread $FILTER_SCORE_MIN --outFilterMatchNminOverLread $FILTER_MATCH_MIN --winAnchorMultimapNmax $MAX_LOCI_ALLOWED --outFilterMultimapScoreRange $MULTIMAP_SCORE_RANGE"
if [ ! -s "${DIR_ALIGN_STAR}ReadsPerGene.out.tab" ]
then
echo "STAR did not run correctly ! Check your files and directories."
error_exit "$LINENO: An error has occurred."
fi
echo "$DIR_ALIGN_STAR generated"
echo "End of mapping to reference genome."
fi
done
}
# Generate the MultiQC report.
multiqc_report(){
echo "Generating the MultiQC collective report..."
if [ -s multiqc_report.html ]
then
echo "MultiQC report exists."
return 0
else
docker run --rm -u $(id -u):$(id -g) -v $WORKDIR:/home -w /home parisepigenetics/multiqc bash -c "multiqc -f ."
fi
echo "MultiQC report fished."
}
# Performe the metagene analysis
#FIXME, we do not do this anymore, we use the longgest transcript.
metagene_analysis() {
WORKING_ANSWER_RNASEQ_DATA=${ANSWER_RNASEQ_DATA^^}
if [ $WORKING_ANSWER_RNASEQ_DATA = YES ]
then
echo "Metagene analysis :"
BASENAME_METAGENE="metagene_orfs"
LANDMARK="cds_start"
INPUT_ANNOTATION=$(basename $PATH_TO_ANNOTATION_FILE)
ANNOTATION_PREFIX=${INPUT_ANNOTATION:0:-4}
ANNOTATION_CDSLANDMARK="${ANNOTATION_PREFIX}_cdslandmark.gtf"
SORTED_ANNOTATION_CDSLANDMARK="${ANNOTATION_PREFIX}_cdslandmark_sorted.gtf"
if [ -s metagene_orfs_rois.txt ] && [ -s metagene_orfs_rois.bed ]
then
echo "Metagene analysis already done."
return 0
else
echo "Add CoDing Sequences landmark to annotations :"
$PYTHON_SCRIPTS_PATH$PYTHON_SCRIPT_ADD_START_GTF -i $PATH_TO_ANNOTATION_FILE -o $ANNOTATION_CDSLANDMARK
if [ $? -ne 0 ]
then
echo "Cannot add CDS landmarks correctly."
error_exit "$LINENO: An error has occurred."
fi
sort -T $TMPDIR -k1,1 -k4,4n $ANNOTATION_CDSLANDMARK > $SORTED_ANNOTATION_CDSLANDMARK
if [ $? -ne 0 ]
then
echo "Annotations file cannot be sorted."
error_exit "$LINENO: An error has occurred."
fi
docker run --rm -u $(id -u):$(id -g) -v $TMPDIR:/tmp -v $WORKDIR:/home -w /home -v "${WORKDIR}/${SORTED_ANNOTATION_CDSLANDMARK}:/run/${SORTED_ANNOTATION_CDSLANDMARK}" parisepigenetics/plastid:0.4.6 bash -c "metagene generate $BASENAME_METAGENE --landmark $LANDMARK --sorted --annotation_files /run/${SORTED_ANNOTATION_CDSLANDMARK}"
if [ $? -ne 0 ]
then
echo "Metagene analysis cannot run correctly."
error_exit "$LINENO: An error has occurred."
fi
gzip -9 $SORTED_ANNOTATION_CDSLANDMARK
if [ $? -ne 0 ]
then
echo "Cannot compress ${SORTED_ANNOTATION_CDSLANDMARK} correctly."
error_exit "$LINENO: An error has occurred."
fi
echo "End of metagene analysis."
# rm $ANNOTATION_CDS_EXON_START
rm $ANNOTATION_CDSLANDMARK
fi
else
return 0
fi
}
# Filter the SAM file to get conserve uniq reads
samFiltering() {
# WORKING_ANSWER_KEEP_MULTIREAD=${ANSWER_KEEP_MULTIREAD^^}
SAM_INPUT="$1_align_star/Aligned.out.sam"
FILTERED_SAM_UNIQUE_OUTPUT="$1_align_filtered.sam"
FILTERED_SAM_MULTI_OUTPUT="$1_align_multi.sam"
LOGFILE="$1_align_filtering.log"
echo "Starting of SAM file filtering :"
if [ -s $SAM_INPUT ]
then
if [ -s $FILTERED_SAM_UNIQUE_OUTPUT ]
then
echo "SAM file filering already done."
return 0
else
# if [ $WORKING_ANSWER_KEEP_MULTIREAD = YES ]
# then
grep -v '^@' $SAM_INPUT | awk '$2 != 4 {print $0}' | sort -k 1,1 -T $TMPDIR | $PYTHON_SCRIPTS_PATH$PYTHON_SCRIPT_SAM_FILTERING -i $SAM_INPUT -o $FILTERED_SAM_UNIQUE_OUTPUT -m $FILTERED_SAM_MULTI_OUTPUT > $LOGFILE
# else
# grep -v '^@' $SAM_INPUT | awk '$2 != 4 {print $0}' | sort -k 1,1 -T $TMPDIR | $PYTHON_SCRIPTS_PATH$PYTHON_SCRIPT_SAM_FILTERING -i $SAM_INPUT -o $FILTERED_SAM_UNIQUE_OUTPUT > $LOGFILE
# fi
if [ $? -ne 0 ]
then
echo "SAM file filtering cannot run correctly !"
error_exit "$LINENO: An error has occurred."
fi
echo "Log file : $LOGFILE generated."
echo "End of SAM file filtering."
fi
else
echo "You need a SAM file to launch this step !"
error_exit "$LINENO: An error has occurred."
fi
}
# Compute the reads length distribution after alignment to the reference genome and the SAM file filtering (uniquely mapped only)
mapped_to_genome_distrib_length() {
SAM_FILTERED_INPUT="$1_align_filtered.sam"
DISTR_LGT_PDF="$1_uniquely_mapped2genome_read_length_distribution.pdf"
if [ -s $DISTR_LGT_PDF ]
then
echo "Computing uniquely mapped to genome reads length distribution already done."
return 0
else
echo "Computing uniquely mapped to genome reads length distribution :"
grep -v '^@' $SAM_FILTERED_INPUT | awk '{print length($10)}' | $PYTHON_SCRIPTS_PATH$PYTHON_SCRIPT_READ_LENGTH_DISTRIBUTION $DISTR_LGT_PDF -e $SAM_FILTERED_INPUT
if [ ! -s $DISTR_LGT_PDF ]
then
echo "Cannot compute uniquely mapped to genome reads length distribution !"
error_exit "$LINENO: An error has occurred."
fi
echo "PDF file : $DISTR_LGT_PDF generated."
echo "End of computing uniquely mapped to genome reads length distribution."
fi
}
# Compute the multi-reads length distribution after alignment to reference genome
# TODO This can be written as a generic function for all the length distribution analysis
multimapped_to_genome_distrib_length() {
WORKING_ANSWER_KEEP_MULTIREAD=${ANSWER_KEEP_MULTIREAD^^}
if [ $WORKING_ANSWER_KEEP_MULTIREAD = YES ]
then
SAM_MULTIREAD_INPUT="$1_align_multi.sam"
DISTR_LGT_PDF="$1_multimapped_to_genome_read_length_distribution.pdf"
if [ -s $DISTR_LGT_PDF ]
then
echo "Computing multi-mapped to genome reads length distribution already done."
return 0
else
echo "Computing multi-mapped to genome reads length distribution :"
grep -v '^@' $SAM_MULTIREAD_INPUT | awk '{print length($10)}' | $PYTHON_SCRIPTS_PATH$PYTHON_SCRIPT_READ_LENGTH_DISTRIBUTION $DISTR_LGT_PDF -e $SAM_MULTIREAD_INPUT
if [ ! -s $DISTR_LGT_PDF ]
then
echo "Cannot compute multi-mapped to genome reads length distribution !"
error_exit "$LINENO: An error has occurred."
fi
fi
echo "PDF file : $DISTR_LGT_PDF generated."
echo "End of computing multi-mapped to genome reads length distribution."
else
return 0
fi
}
# Convert the filtered SAM file into a sorted BAM file which is indexed in BAI
sam_to_bam() {
FILTERED_SORTED_ALIGNMENT="$1_align_filtered.sorted" # Sorted alignment basename for BAM & BAI files
FILTERED_SAM="$1_align_filtered.sam"
if [ -s $FILTERED_SAM ]
then
if [ -s "${FILTERED_SORTED_ALIGNMENT}.bam" ]
then
return 0
else
echo "Starting of Samtools"
# SAM to BAM conversion + sorting of BAM file
docker run --rm -u $(id -u):$(id -g) -T $TMPDIR:/tmp -v $WORKDIR:/home -w /home genomicpariscentre/samtools bash -c "samtools view -Sb $FILTERED_SAM | samtools sort - $FILTERED_SORTED_ALIGNMENT"
# Index BAI
docker run --rm -u $(id -u):$(id -g) -T $TMPDIR:/tmp -v $WORKDIR:/home -w /home genomicpariscentre/samtools bash -c "samtools index "${FILTERED_SORTED_ALIGNMENT}.bam" "${FILTERED_SORTED_ALIGNMENT}.bai""
if [ ! -s "${FILTERED_SORTED_ALIGNMENT}.bam" ]
then
echo "Samtools cannot run correctly !"
error_exit "$LINENO: An error has occurred."
fi
echo "Sorted-indexed alignment : '${FILTERED_SORTED_ALIGNMENT}.bam' generated. You can use it in a genome browser (e.g IGV)"
echo "End of Samtools."
fi
else
echo "You need a filtered SAM file to launch this step !"
error_exit "$LINENO: An error has occurred."
fi
}
p_offset_analysis() {
WORKING_ANSWER_RNASEQ_DATA=${ANSWER_RNASEQ_DATA^^}
if [ $WORKING_ANSWER_RNASEQ_DATA = YES ]
then
echo "P-site offsets analysis :"
INPUT_METAGENE_ORF="metagene_orfs_rois.txt"
#BASENAME_RIBOPROFILE="$1_riboprofile"
# INPUT_COUNT_FILES=()
#METAGENE_PROFILE="${BASENAME_RIBOPROFILE}_metagene_profiles.txt"
#P_OFFSETS="${BASENAME_RIBOPROFILE}_p_offsets.txt"
#P_OFFSETS_CORRECTED="${BASENAME_RIBOPROFILE}_p_offsets_corrected.txt"
WORKING_ANSWER_DEMULTIPLEXING=${ANSWER_DEMULTIPLEXING^^}
if [ -s $INPUT_METAGENE_ORF ]
then
for cond in $CONDITION_ARRAY_UNIQ ## TODO Check if we can do it wuth GNU parallel. Problem is the passing of the arrays SAMPLE & CONDITIONS
do
echo "P-site offsets analysis for $cond condition :"
BASENAME_RIBOPROFILE="${cond}_riboprofile"
METAGENE_PROFILE="${BASENAME_RIBOPROFILE}_metagene_profiles.txt"
P_OFFSETS="${BASENAME_RIBOPROFILE}_p_offsets.txt"
WORKING_P_OFFSETS="${cond}_p_offsets.txt"
P_OFFSETS_CORRECTED="${cond}_p_offsets_corrected.txt"
INPUT_COUNT_FILES=()
if [ -s $WORKING_P_OFFSETS ] || [ -s $P_OFFSETS_CORRECTED ]
then
echo "P-site offsets analysis already done."
return 0
else
# CONDITION_ARRAY+=($2)
# SAMPLE_ARRAY+=($3)
# echo ${CONDITION_ARRAY[*]}
# echo ${SAMPLE_ARRAY[*]}
for index in ${!CONDITION_ARRAY[*]}
do
CURRENT_CONDITION=${CONDITION_ARRAY[$index]}
# echo $CURRENT_CONDITION
if [ $CURRENT_CONDITION = $cond ]
then
if [ $WORKING_ANSWER_DEMULTIPLEXING = "YES" ]
then
SAMPLE=${SAMPLE_ARRAY[$index]}
else
SAMPLE=$(basename ${SAMPLE_ARRAY[$index]} .fastq)
fi
INPUT_COUNT_FILES+=("${SAMPLE}_align_filtered.sorted.bam")
# echo $SAMPLE
fi
done
#echo ${INPUT_COUNT_FILES[*]}
docker run --rm -u $(id -u):$(id -g) -v $TMPDIR:/tmp -v $WORKDIR:/home -w /home parisepigenetics/plastid:0.4.6 bash -c "psite $INPUT_METAGENE_ORF $BASENAME_RIBOPROFILE --min_length $MIN_LENGTH_POFFSET --max_length $MAX_LENGTH_POFFSET --require_upstream --aggregate --count_files ${INPUT_COUNT_FILES[*]} --keep --default $DEFAULT_POFFSET"
if [ $? -ne 0 ]
then
echo "P-site offsets analysis cannot run correctly."
error_exit "$LINENO: An error has occurred."
fi
grep -v "##" $P_OFFSETS | grep -v "length" | grep -v "default" > $WORKING_P_OFFSETS
WORKING_ANSWER_PSITE_CORRECTION=${ANSWER_PSITE_CORRECTION^^}
if [ $WORKING_ANSWER_PSITE_CORRECTION = YES ]
then
$PYTHON_SCRIPTS_PATH$PYTHON_SCRIPT_PSITE_AUTOCORRECTION -i $WORKING_P_OFFSETS -m $METAGENE_PROFILE -o $P_OFFSETS_CORRECTED
if [ $? -ne 0 ]
then
echo "P-site offsets auto-correction cannot run correctly."
error_exit "$LINENO: An error has occurred."
fi
fi
echo "End of P-site offsets analysis."
echo "If you see a P-site offset of 0 or some odd p-offsets in $WORKING_P_OFFSETS and $P_OFFSETS_CORRECTED, you should correct them manually."
fi
done
WORKING_STOP_EXEC_PSITE_CORRECTION=${STOP_EXEC_PSITE_CORRECTION^^}
if [ $WORKING_STOP_EXEC_PSITE_CORRECTION = YES ]
then
echo "Execution stoped by STOP_EXEC_PSITE_CORRECTION parameter."
error_exit "$LINENO: An error has occurred."
fi
else
echo "You need $INPUT_METAGENE_ORF file to launch P-site offsets analysis."
error_exit "$LINENO: An error has occurred."
fi
else
return 0
fi
}
rna_seq_quantification() {
# The user MUST do transcriptome mapping of their RNA-seq data before (TODO, why it needs to be done like this!!!!)
WORKING_ANSWER_RNASEQ_DATA=${ANSWER_RNASEQ_DATA^^}
if [ $WORKING_ANSWER_RNASEQ_DATA = YES ]
then
echo "mRNA quantification :"
QUANTIFICATION_OUTPUT_DIR="$1_mRNA_quantification"
TRANSCRIPTOME_FASTA_FILE=$(basename $PATH_TO_REFERENCE_TRANSCRIPTOME_FILE)
RNA_BAM="$1_mRNA.transcriptome.mapping.bam"
#TRANSCRIPTOME_FASTA_DIR=$(dirname $PATH_TO_REFERENCE_TRANSCRIPTOME_FILE)
if [ -s "${QUANTIFICATION_OUTPUT_DIR}/quant.sf" ]
then
echo "mRNA quantification already done for $1."
return 0
else
if [ -s $RNA_BAM ]
then