-
Notifications
You must be signed in to change notification settings - Fork 2
/
LeTRS.pl
1972 lines (1754 loc) · 129 KB
/
LeTRS.pl
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
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use Bio::SeqIO;
use File::Basename;
use List::Compare;
use List::Util qw(sum);
use List::Uniq ':all';
my $selfpath=dirname(__FILE__);
my %options;
my @standard_options =("help|h!",
"version|v!",
"mode=s",
"bam=s",
"fq=s",
"primer_bed=s",
"pool=s",
"ref=s",
"t|thread=s",
"o=s",
"Rtch=s",
"adjleader=s",
"adjTRS=s",
"poscutoff=s",
"covcutoff=s",
"covcutoffidp=s",
"extractfasta!",
"TRSLindependent!",
"noguide!",
"ployALoc=s",
);
GetOptions( \%options, @standard_options );
###################### parameters setting ######################
# if no arguments supplied print the usage and exit
if ((keys (%options))==0) {
print "please use -h to get help\n";
exit;
}
# If the -help option is set, print the usage and exit
if ($options{'help'}) {
print "\nUsage example\:
perl LeTRS.pl -t 16 -extractfasta -pool 0 -Rtch cDNA -mode nanopore -fq example.fastq.gz -primer_bed path_to_primer_V3.bed -o LeTRS_output
perl LeTRS.pl -t 16 -extractfasta -Rtch RNA -mode nanopore -fq example.fastq.gz -o LeTRS_output
perl LeTRS.pl -t 16 -extractfasta -pool 1 -Rtch cDNA -mode nanopore -fq example.fastq.gz -primer_bed path_to_custom_primer.bed -o LeTRS_output -ref reference_folder
perl LeTRS.pl -t 16 -extractfasta -pool 1 -mode illumina -fq #1.fastq.gz:#2.fastq.gz -primer_bed path_to_primer_V3.bed -o LeTRS_output
perl LeTRS.pl -t 16 -extractfasta -mode illumina -bam example.bam -o LeTRS_output
Required options:
-mode \"nanopore\" or \"illumina\" of the input fastq file.
-Rtch \"RNA\" (direct RNA) or \"cDNA\" (amplicon cDNA) to indicate the sequencing library for \"nanopore\" mode.
-fq fastq file (paired reads can be provide as \"#1.fastq.gz:#2.fastq.gz\").
-primer_bed amplicon primer bed file is required for \"nanopore cDNA\" and \"illumina\" modes.
-pool INT amplicon primer pool is required for \"nanopore cDNA\" and \"illumina\" modes, 0 indicates all pools.
Optional options:
-bam custom bam can also be provided if the \"-fq\" dosen't exist.
-ref custom sars-cov-2 or other coronavirus reference folder.
-extractfasta to extract the reads contain the identified leader-TRS junctions in fasta format.
-TRSLindependent to find the reads with sgmRNAs with non-canonical leaders.
-noguide this option turns off the known leader-TRS guided alignment.
-t/-thread number of threads, 1 by default.
-o output path, \"./\" by default.
-adjleader INT leader junction boundary tolerance, +-10 nts by default.
-adjTRS INT TRS junction boundary tolerance, -20 nts to 1 nt ahead the ATG of knonwn orfs by default.
-poscutoff INT postion of leader end cutoff for the novel leader-TRS identification, 80 by default.
-covcutoff INT coverge cutoff for the novel leader-TRS identification, 5 reads/read pairs by default.
-covcutoffidp INT coverge cutoff for the sgmRNAs with non-canonical leaders, 5 reads/read pairs by default.
-ployALoc INT The position of the first A in ployA tail on the virus genome, auto detection by default.
-v/-version Print version information.
-h/-help Print help message.\n\n";
exit;
}
if ($options{'version'}) {
print "v2.2.1\n";
exit;
}
my $chackbam; my $chackfa;
# Compulsory items
if (!exists $options{'mode'}) {
print "mode is requeired\n";
exit;
}
if (exists ($options{'bam'})) {
$chackbam=1;
}elsif (!exists ($options{'bam'})){
$chackbam=0;}
if (exists ($options{'fq'})) {
$chackfa=1;
}elsif (!exists ($options{'fq'})){
$chackfa=0;
}
if ($chackbam==0 and $chackfa==0) {
print "fa or bam is requeired\n";
exit;
}elsif ($chackbam==1 and $chackfa==0) {
print "it is running with bam\n";
}elsif ($chackbam==0 and $chackfa==1) {
print "it is running with fa\n";
}elsif ($chackbam==1 and $chackfa==1) {
print "please only provide one of bam and fa\n";
}
my $pathtoreference;
if (!exists ($options{'ref'})) {
$pathtoreference="$selfpath/references-sars-cov-2";
}elsif(exists ($options{'ref'})) {
$pathtoreference="$options{'ref'}";
}
my $thread;
if (!exists ($options{'t'})) {
$thread=1;
}elsif (exists ($options{'t'})) {
$thread= $options{'t'};
}
print "thread: $thread\n";
my $outputpath;
if (!exists ($options{'o'})) {
$outputpath= "\./";
}elsif (exists ($options{'o'})) {
$outputpath= $options{'o'};
mkdir "$outputpath";
}
print "path: $outputpath\n";
my $polyapostion;
my $polyapostion5;
if (!exists ($options{'ployALoc'})) {
my $inputfilename="$pathtoreference/genome.fasta";
my $in = Bio::SeqIO->new(-file => "$inputfilename", -format => 'Fasta');
while ( my $seq = $in->next_seq() ) {
my $wholegenomeseq= $seq->seq;
my $wholegenomelength= $seq->length;
my @eachwholegenomeseq=split(//,$wholegenomeseq);
my $stepseq=0;
for (;;) {
$stepseq--;
last if ($eachwholegenomeseq[$stepseq] ne "A");
}
$wholegenomelength=$wholegenomelength+$stepseq+2;
if ($stepseq == -1) {
print "please add ployA sequences in your reference genome";
exit;
}else {
$polyapostion=$wholegenomelength;
$polyapostion5=$polyapostion+4;
print "the position of the first A in ployA tail is $polyapostion on the virus genome.\n";
}
}
}elsif (exists ($options{'ployALoc'})) {
$polyapostion= $options{'ployALoc'};
$polyapostion5=$polyapostion+4;
print "the position of the first A in ployA tail is $polyapostion on the virus genome.\n";
}
###################### parsing ######################
my $leaderadjectnumber;
if (!exists ($options{'adjleader'})) {
if ($options{'mode'} eq "nanopore") {
$leaderadjectnumber= "10";
}elsif ($options{'mode'} eq "illumina") {
$leaderadjectnumber= "10";
}
}elsif (exists ($options{'adjleader'})) {
$leaderadjectnumber= $options{'adjleader'};
}
print "junction site at leader adject number: \+\-$leaderadjectnumber\n";
my $orfadjectnumber;
if (!exists ($options{'adjorf'})) {
if ($options{'mode'} eq "nanopore") {
$orfadjectnumber= "20";
}elsif ($options{'mode'} eq "illumina") {
$orfadjectnumber= "20";
}
}elsif (exists ($options{'adjorf'})) {
$orfadjectnumber= $options{'adjorf'};
}
print "junction site at orf adject number: \-$orfadjectnumber\n";
my $cutoff;
if (!exists ($options{'covcutoff'})) {
$cutoff= "5";
}elsif (exists ($options{'covcutoff'})) {
$cutoff= $options{'covcutoff'};
}
print "novel junction covervage cutoff: $cutoff\n";
my $cutoffidp;
if (exists ($options{'TRSLindependent'})) {
if (!exists ($options{'covcutoffidp'})) {
$cutoffidp= "5";
}elsif (exists ($options{'covcutoffidp'})) {
$cutoffidp= $options{'covcutoffidp'};
}
print "non-canonical junction covervage cutoff: $cutoff\n";
}
my $cutoffpos=80;
if (!exists ($options{'poscutoff'})) {
$cutoffpos= "80";
}elsif (exists ($options{'poscutoff'})) {
$cutoffpos= $options{'poscutoff'};
}
print "novel junction of genome position of leader end cutoff: $cutoff\n";
###################### script running ######################
if ($options{'mode'} eq "nanopore") {
print "it is nanopore mode now\n";
if ($chackbam==0 and $chackfa==1) {
if (!exists ($options{'Rtch'})) {
print "please indicate the minion seq model: RNA or cDNA in --Rtch\n";
exit;
}
if ($options{'Rtch'} eq "cDNA" && !exists ($options{'primer_bed'})) {
print "please provide a primer bed file\n";
exit;
}
if ($options{'Rtch'} eq "cDNA" && !exists ($options{'pool'})) {
print "please select primer pool\n";
exit;
}
if ($options{'Rtch'} eq "RNA") {
&mappingnanopore;
print "looking for the leader-TRS\n";
&tabfix;
&RNAbamparse;
&getcoverage;
&parseresult;
}else {
&mappingnanopore;
print "looking for the leader-TRS\n";
&tabfix;
&getprimerbed;
&bamparse;
&getcoveragecDNA;
&parseresult;
}
}elsif($chackbam==1 and $chackfa==0) {
if (exists ($options{'primer_bed'})) {
print "\"-primer_bed\" is not functional with \"-bam\"\n";
exit;
}
if (exists ($options{'pool'})) {
print "\"-pool\" is not functional with \"-bam\"\n";
exit;
}
$options{'Rtch'}=0;
&bamnanopore;
print "looking for the leader-TRS\n";
&tabfix;
&bamparse;
&getcoverage;
&parseresult;
}
}elsif ($options{'mode'} eq "illumina") {
print "it is illumina mode now\n";
if ($chackbam==0 and $chackfa==1 and $options{'fq'}=~/\:/) {
if (exists ($options{'Rtch'})) {
print "--Rtch is not functional in illumina mode\n";
exit;
}
$options{'Rtch'}=0;
if (!exists ($options{'primer_bed'})) {
print "please provide a primer bed file\n";
exit;
}
if (!exists ($options{'pool'})) {
print "please select primer pool\n";
exit;
}
&mappingillumina;
print "looking for the leader-TRS\n";
&tabfix;
&getprimerbed;
&bamparseillumina;
&getcoverageillumina;
&parseresult;
}elsif ($chackbam==0 and $chackfa==1 and $options{'fq'}!~/\:/) {
if (exists ($options{'Rtch'})) {
print "--Rtch is not functional in illumina mode\n";
exit;
}
$options{'Rtch'}=0;
if (!exists ($options{'primer_bed'})) {
print "please provide a primer bed file\n";
exit;
}
if (!exists ($options{'pool'})) {
print "please select primer pool\n";
exit;
}
&mappingillumina;
print "looking for the leader-TRS\n";
&tabfix;
&getprimerbed;
&bamparse;
&getcoveragecDNA;
&parseresult;
}elsif($chackbam==1 and $chackfa==0) {
if (exists ($options{'primer_bed'})) {
print "\"-primer_bed\" is not functional with \"-bam\"\n";
exit;
}
if (exists ($options{'pool'})) {
print "\"-pool\" is not functional with \"-bam\"\n";
exit;
}
$options{'Rtch'}=0;
&bamillumina;
print "looking for the leader-TRS\n";
&tabfix;
&bamparse;
&getcoverage;
&parseresult;
}
}else {
print "please select illumina or nanopore mode to run\n";
}
###################### Mapping SUBS ######################
sub mappingnanopore {
my $lable="alignment";
mkdir "$outputpath/$lable\_output";
if ($options{'Rtch'} eq "cDNA" and exists($options{'noguide'})) {
print "minion seq model: cDNA\n";
system ("minimap2 -ax splice -t $thread $pathtoreference/genome.fasta $options{'fq'} | samtools view -@ $thread -q 10 -F 2308 -Sb | samtools sort -@ $thread -o $outputpath/$lable\_output/$lable\.sorted.bam");
}elsif ($options{'Rtch'} eq "cDNA") {
print "minion seq model: cDNA\n";
system ("minimap2 -ax splice --junc-bed $pathtoreference/genome.bed -t $thread $pathtoreference/genome.fasta $options{'fq'} | samtools view -@ $thread -q 10 -F 2308 -Sb | samtools sort -@ $thread -o $outputpath/$lable\_output/$lable\.sorted.bam");
}elsif ($options{'Rtch'} eq "RNA" and exists($options{'noguide'})) {
print "minion seq model: RNA\n";
system ("minimap2 -ax splice -uf -k14 -t $thread $pathtoreference/genome.fasta $options{'fq'} | samtools view -@ $thread -q 10 -F 2320 -Sb | samtools sort -@ $thread -o $outputpath/$lable\_output/$lable\.sorted.bam");
}elsif ($options{'Rtch'} eq "RNA") {
print "minion seq model: RNA\n";
system ("minimap2 -ax splice -uf -k14 --junc-bed $pathtoreference/genome.bed -t $thread $pathtoreference/genome.fasta $options{'fq'} | samtools view -@ $thread -q 10 -F 2320 -Sb | samtools sort -@ $thread -o $outputpath/$lable\_output/$lable\.sorted.bam");
}elsif ($options{'Rtch'} ne "cDNA" and $options{'Rtch'} ne "RNA") {
print "please indicate the minion seq model: RNA or cDNA in --Rtch\n";
exit;
}
system ("samtools index $outputpath/$lable\_output/$lable\.sorted.bam");
system ("portcullis prep -t $thread -o $outputpath/$lable\_output/$lable\_portcullis_out $pathtoreference/genome.fasta $outputpath/$lable\_output/$lable\.sorted.bam");
system ("portcullis junc --intron_gff --exon_gff -t $thread --orientation SE -o $outputpath/$lable\_output/$lable\_portcullis_out $outputpath/$lable\_output/$lable\_portcullis_out");
}
sub bamnanopore {
my $lable="alignment";
mkdir "$outputpath/$lable\_output";
system ("samtools view -@ $thread -b -q 10 -F 2308 $options{'bam'} | samtools sort -@ $thread -o $outputpath/$lable\_output/$lable\.sorted.bam");
system ("portcullis prep -t $thread -o $outputpath/$lable\_output/$lable\_portcullis_out $pathtoreference/genome.fasta $outputpath/$lable\_output/$lable\.sorted.bam");
system ("portcullis junc --intron_gff --exon_gff -t $thread --orientation SE -o $outputpath/$lable\_output/$lable\_portcullis_out $outputpath/$lable\_output/$lable\_portcullis_out");
}
sub mappingillumina {
my $lable="alignment";
mkdir "$outputpath/$lable\_output";
my @fasta; my $inputread1; my $inputread2;
if ($options{'fq'}=~/\:/) {
@fasta=split(/\:/, $options{'fq'});
print "the \"illumina\" mode is running with paired end reads\n";
print "$fasta[0]\n";
print "$fasta[1]\n";
$inputread1=$fasta[0];
$inputread2=$fasta[1];
}else{
print "the \"illumina\" mode is running with single end reads\n";
print "$options{'fq'}\n";
$inputread1=$options{'fq'};
}
my $indexfileExist = -e "$pathtoreference/genome.1.ht2";
if ($indexfileExist) {
print "the hisat2-build has done\n";
} else {
system ("hisat2-build -f $pathtoreference/genome.fasta $pathtoreference/genome");
}
if (exists($options{'noguide'})) {
system ("hisat2 -p $thread -q -t -x $pathtoreference/genome -1 $fasta[0] -2 $fasta[1] -S $outputpath/$lable\_output/$lable\.sam --summary-file $outputpath/$lable\_output/$lable\.mapping.summary");
}else{
if ($options{'fq'}=~/\:/) {
system ("hisat2 -p $thread -q -t -x $pathtoreference/genome --known-splicesite-infile $pathtoreference/genome_splicesites.txt -1 $inputread1 -2 $inputread2 -S $outputpath/$lable\_output/$lable\.sam --summary-file $outputpath/$lable\_output/$lable\.mapping.summary");
}else{
system ("hisat2 -p $thread -q -t -x $pathtoreference/genome --known-splicesite-infile $pathtoreference/genome_splicesites.txt -U $inputread1 -S $outputpath/$lable\_output/$lable\.sam --summary-file $outputpath/$lable\_output/$lable\.mapping.summary");
}
}
if ($options{'fq'}=~/\:/) {
system ("samtools view -@ $thread -q 10 -F 2316 -Sb $outputpath/$lable\_output/$lable\.sam | samtools sort -@ $thread -o $outputpath/$lable\_output/$lable\.sorted.bam");
}else{
system ("samtools view -@ $thread -q 10 -F 2308 -Sb $outputpath/$lable\_output/$lable\.sam | samtools sort -@ $thread -o $outputpath/$lable\_output/$lable\.sorted.bam");
}
system ("samtools index $outputpath/$lable\_output/$lable\.sorted.bam");
system ("portcullis prep -t $thread -o $outputpath/$lable\_output/$lable\_portcullis_out $pathtoreference/genome.fasta $outputpath/$lable\_output/$lable\.sorted.bam");
system ("portcullis junc --intron_gff --exon_gff -t $thread -o $outputpath/$lable\_output/$lable\_portcullis_out $outputpath/$lable\_output/$lable\_portcullis_out");
}
sub bamillumina {
my $lable="alignment";
mkdir "$outputpath/$lable\_output";
system ("samtools view -@ $thread -b -q 10 -F 2308 $options{'bam'} | samtools sort -@ $thread -o $outputpath/$lable\_output/$lable\.sorted.bam");
system ("portcullis prep -t $thread -o $outputpath/$lable\_output/$lable\_portcullis_out $pathtoreference/genome.fasta $outputpath/$lable\_output/$lable\.sorted.bam");
system ("portcullis junc --intron_gff --exon_gff -t $thread -o $outputpath/$lable\_output/$lable\_portcullis_out $outputpath/$lable\_output/$lable\_portcullis_out");
}
sub tabfix {
open(TAB, "$outputpath/alignment_output/alignment_portcullis_out.junctions.tab");
open(TABR, ">$outputpath/alignment_output/alignment_portcullis_out.junctions_fixed.tab");
while (<TAB>) {
unless (/^\n/){
if (/^index\trefid/) {
print TABR;
}else{
my @splittab=split(/\t/,$_,10);
my $endfix=$splittab[5]+2;
my $leftfix=$splittab[7]+1;
my $rightfix=$splittab[8]+1;
print TABR "$splittab[0]\t$splittab[1]\t$splittab[2]\t$splittab[3]\t$splittab[4]\t$endfix\t$splittab[6]\t$leftfix\t$rightfix\t$splittab[9]";
}
}
}
close TAB; close TABR;
unlink ("$outputpath/alignment_output/alignment_portcullis_out.junctions.tab");
rename ("$outputpath/alignment_output/alignment_portcullis_out.junctions_fixed.tab", "$outputpath/alignment_output/alignment_portcullis_out.junctions.tab" );
}
my $poollable;
sub getprimerbed {
open(PRIMERBED, "$options{'primer_bed'}") or die "can't find primer bed file";
open(PRIMERBEDNEW, ">$outputpath/alignment_output/selected_primer_pool.bed");
while (<PRIMERBED>) {
if ($options{'pool'}==0) {
print PRIMERBEDNEW;
$poollable="both pools";
}else{
$poollable="pool $options{'pool'}";
my @eachprimerbedpool=split(/\t/);
if ($eachprimerbedpool[4] == $options{'pool'}) {
print PRIMERBEDNEW;
}
}
}
close PRIMERBED; close PRIMERBEDNEW;
}
sub bamparse {
my $inputbam;
$inputbam="$outputpath/alignment_output/alignment.sorted.bam";
system ("samtools view -@ $thread $inputbam > $outputpath/alignment_output/alignment.sorted.splice.tmp");
open(BAMEXTRACT, "$outputpath/alignment_output/alignment.sorted.splice.tmp");
open(BAMEXTRACTR, ">$outputpath/alignment_output/alignment.sorted.splice.tab");
print BAMEXTRACTR "#ID\tnumberN\tleft\tstart\tend\tright\tjunctionlength\tCIGAR\tread\n";
my @bamextracts=<BAMEXTRACT>;
foreach (@bamextracts) {
my @eachcols=split(/\t/);
my @eachCIGAR=split(/(?<=[A-Z])/,$eachcols[5]);
my $numberN=grep(/N/,@eachCIGAR);
my $start=0; my $end=0; my $right=0; my $junctionlength=0;
if ($numberN >0) {
my ($idx) = grep { $eachCIGAR[$_] =~/N/ } 0 .. $#eachCIGAR;
#print $idx;
my $fragment1=0;
for (my $n=0;$n<$idx;$n++) {
unless($eachCIGAR[$n]=~/I|S/) {
$eachCIGAR[$n]=~s/[A-Z]//;
$fragment1=$fragment1+$eachCIGAR[$n];
}
}
$start=$eachcols[3]+$fragment1-1;
$eachCIGAR[$idx]=~s/N//;
$end=$start+$eachCIGAR[$idx]+1;
my $fragment2=0;
for (my $n=$idx+1;$n<$#eachCIGAR+1;$n++) {
unless($eachCIGAR[$n]=~/I|S/) {
$eachCIGAR[$n]=~s/[A-Z]//;
$fragment2=$fragment2+$eachCIGAR[$n];
}
}
$right=$end+$fragment2-1;
$junctionlength=$eachCIGAR[$idx];
}else{
$start=0; $end=0;$junctionlength=0;
my $fragment=0;
for (my $n=0;$n<$#eachCIGAR+1;$n++) {
unless($eachCIGAR[$n]=~/I|S/) {
$eachCIGAR[$n]=~s/[A-Z]//;
$fragment=$fragment+$eachCIGAR[$n];
}
$right=$eachcols[3]+$fragment-1;
}
}
print BAMEXTRACTR "$eachcols[1]\_\_$eachcols[0]\t$numberN\t$eachcols[3]\t$start\t$end\t$right\t$junctionlength\t$eachcols[5]\t$eachcols[9]\n";
}
close BAMEXTRACT; close BAMEXTRACTR;
#unlink ("$outputpath/alignment_output/alignment.sorted.splice.tmp");
}
sub RNAbamparse {
my $inputbam;
$inputbam="$outputpath/alignment_output/alignment.sorted.bam";
system ("samtools view -@ $thread $inputbam | awk '(\$6 ~ /N/)' > $outputpath/alignment_output/alignment.sorted.splice.tmp");
open(BAMEXTRACT, "$outputpath/alignment_output/alignment.sorted.splice.tmp");
open(BAMEXTRACTR, ">$outputpath/alignment_output/alignment.sorted.splice.tab");
print BAMEXTRACTR "#ID\tnumberN\tleft\tstart\tend\tright\tjunctionlength\tCIGAR\tread\n";
my @bamextracts=<BAMEXTRACT>;
foreach (@bamextracts) {
my @eachcols=split(/\t/);
my @eachCIGAR=split(/(?<=[A-Z])/,$eachcols[5]);
my $numberN=grep(/N/,@eachCIGAR);
my ($idx) = grep { $eachCIGAR[$_] =~/N/ } 0 .. $#eachCIGAR;
#print $idx;
my $fragment1=0;
for (my $n=0;$n<$idx;$n++) {
unless($eachCIGAR[$n]=~/I|S/) {
$eachCIGAR[$n]=~s/[A-Z]//;
$fragment1=$fragment1+$eachCIGAR[$n];
}
}
my $start=$eachcols[3]+$fragment1-1;
$eachCIGAR[$idx]=~s/N//;
my $end=$start+$eachCIGAR[$idx]+1;
my $fragment2=0;
for (my $n=$idx+1;$n<$#eachCIGAR+1;$n++) {
unless($eachCIGAR[$n]=~/I|S/) {
$eachCIGAR[$n]=~s/[A-Z]//;
$fragment2=$fragment2+$eachCIGAR[$n];
}
}
my $right=$end+$fragment2-1;
print BAMEXTRACTR "$eachcols[1]\_\_$eachcols[0]\t$numberN\t$eachcols[3]\t$start\t$end\t$right\t$eachCIGAR[$idx]\t$eachcols[5]\t$eachcols[9]\n";
}
close BAMEXTRACT; close BAMEXTRACTR;
unlink ("$outputpath/alignment_output/alignment.sorted.splice.tmp");
}
sub bamparseillumina {
my $inputbam;
$inputbam="$outputpath/alignment_output/alignment.sorted.bam";
system ("samtools view -@ $thread $inputbam > $outputpath/alignment_output/alignment.sorted.splice.tmp");
open(BAMEXTRACT, "$outputpath/alignment_output/alignment.sorted.splice.tmp");
open(BAMEXTRACTR, ">$outputpath/alignment_output/alignment.sorted.splice.tab");
print BAMEXTRACTR "#ID1\tnumberN1\tleft1\tstart1\tend1\tright1\tjunctionlength1\tCIGAR1\tread1\t#ID2\tnumberN2\tleft2\tstart2\tend2\tright2\tjunctionlength2\tCIGAR2\tread2\n";
my %hashbamextracts=();
my @bamextracts=<BAMEXTRACT>;
foreach (@bamextracts) {
chomp;
my @eachbamextracts=split(/\t/);
my @eachCIGAR=split(/(?<=[A-Z])/,$eachbamextracts[5]);
my $numberN=grep(/N/,@eachCIGAR);
#if ($numberN == 0 or $numberN == 1) {
my @groupbamextracts=("$eachbamextracts[0]","$eachbamextracts[1]","$eachbamextracts[3]","$eachbamextracts[5]","$eachbamextracts[9]");
push (@{$hashbamextracts{$eachbamextracts[0]}}, [@groupbamextracts]);
#}
}
for my $keybamextracts (keys %hashbamextracts) {
#print "$keybamextracts => ";
if ($#{$hashbamextracts{$keybamextracts}} == 1) {
my @numgroups;
if ($hashbamextracts{$keybamextracts}[0][2] <= $hashbamextracts{$keybamextracts}[1][2]) {
@numgroups=("0","1");
}
if ($hashbamextracts{$keybamextracts}[0][2] > $hashbamextracts{$keybamextracts}[1][2]) {
@numgroups=("1","0");
}
my @eachCIGARgroup1=split(/(?<=[A-Z])/,$hashbamextracts{$keybamextracts}[0][3]);
my @eachCIGARgroup2=split(/(?<=[A-Z])/,$hashbamextracts{$keybamextracts}[1][3]);
my $numberNgroup1=grep(/N/,@eachCIGARgroup1);
my $numberNgroup2=grep(/N/,@eachCIGARgroup2);
#if ($numberNgroup1 > 0 or $numberNgroup2 > 0) {
my @numberNew=();
foreach my $numgroup(@numgroups) {
#print "$hashbamextracts{$keybamextracts}[$numgroup][1]\__$hashbamextracts{$keybamextracts}[$numgroup][0]", "\n";
my @eachCIGAR=split(/(?<=[A-Z])/,$hashbamextracts{$keybamextracts}[$numgroup][3]);
my $numberN=grep(/N/,@eachCIGAR);
if ($numberN > 0) {
my ($idx) = grep { $eachCIGAR[$_] =~/N/ } 0 .. $#eachCIGAR;
#print $idx;
my $fragment1=0;
for (my $n=0;$n<$idx;$n++) {
unless($eachCIGAR[$n]=~/I|S/) {
$eachCIGAR[$n]=~s/[A-Z]//;
$fragment1=$fragment1+$eachCIGAR[$n];
}
}
my $start=$hashbamextracts{$keybamextracts}[$numgroup][2]+$fragment1-1;
$eachCIGAR[$idx]=~s/N//;
my $end=$start+$eachCIGAR[$idx]+1;
my $fragment2=0;
for (my $n=$idx+1;$n<$#eachCIGAR+1;$n++) {
unless($eachCIGAR[$n]=~/I|S/) {
$eachCIGAR[$n]=~s/[A-Z]//;
$fragment2=$fragment2+$eachCIGAR[$n];
}
}
my $right=$end+$fragment2-1;
print BAMEXTRACTR "$hashbamextracts{$keybamextracts}[$numgroup][1]\_\_$hashbamextracts{$keybamextracts}[$numgroup][0]\t$numberN\t$hashbamextracts{$keybamextracts}[$numgroup][2]\t$start\t$end\t$right\t$eachCIGAR[$idx]\t$hashbamextracts{$keybamextracts}[$numgroup][3]\t$hashbamextracts{$keybamextracts}[$numgroup][4]\t";
}
if ($numberN == 0) {
my $fragment0=0;
for (my $n=0;$n<$#eachCIGAR+1;$n++) {
unless($eachCIGAR[$n]=~/I|S/) {
$eachCIGAR[$n]=~s/[A-Z]//;
$fragment0=$fragment0+$eachCIGAR[$n];
}
}
my $right=$hashbamextracts{$keybamextracts}[$numgroup][2]+$fragment0-1;
print BAMEXTRACTR "$hashbamextracts{$keybamextracts}[$numgroup][1]\_\_$hashbamextracts{$keybamextracts}[$numgroup][0]\t$numberN\t$hashbamextracts{$keybamextracts}[$numgroup][2]\t\-\t\-\t$right\t\-\t$hashbamextracts{$keybamextracts}[$numgroup][3]\t$hashbamextracts{$keybamextracts}[$numgroup][4]\t";
}
push (@numberNew,$numberN);
}
if ($numberNew[0] == 0 and $numberNew[1] == 1 or $numberNew[0] == 1 and $numberNew[1] == 0 or $numberNew[0] == 1 and $numberNew[1] == 1) {
print BAMEXTRACTR "yes\n";
}else {
print BAMEXTRACTR "no\n";
}
#}
}
}
close BAMEXTRACT; close BAMEXTRACTR;
unlink ("$outputpath/alignment_output/alignment.sorted.splice.tmp");
}
my $totalmappedread=0;
my $numleftprimersonly;
my $numrightprimersonly;
my $numbothprimers;
my $numatleastprimers;
sub getcoverage {
my @mappedcoverage;
open my $getmappedcoverage, "-|", "samtools flagstat $outputpath/alignment_output/alignment.sorted.bam";
while (<$getmappedcoverage>) {
if (/mapped \(/) {
@mappedcoverage=split(/ /);
$totalmappedread=$mappedcoverage[0];
print "number of total mapped read: $totalmappedread\n";
}
}
close $getmappedcoverage;
}
sub getcoveragecDNA {
my %hashcoverage1;
open(BAMEXTRACTR, "$outputpath/alignment_output/alignment.sorted.splice.tab");
while (<BAMEXTRACTR>) {
unless (/^\#/) {
$totalmappedread++;
my @eachasspscoverage=split(/\t/);
#if ($eachassps[1] eq 1) {
my @eachcoverage=($eachasspscoverage[0],$eachasspscoverage[2],$eachasspscoverage[5]);
push (@{$hashcoverage1{"$eachasspscoverage[3]\t$eachasspscoverage[4]"}}, [@eachcoverage]);
#}
}
}
close BAMEXTRACTR;
my @clusterleftprimeridscov=(); my @clusterrightprimeridscov=();
for my $key (keys %hashcoverage1){
open(PRIMERBED, "$outputpath/alignment_output/selected_primer_pool.bed") or die "can't find primer bed file";
while (<PRIMERBED>) {
chomp;
my @eachprimerbedcov=split(/\t/);
if ($eachprimerbedcov[3]=~/_LEFT/) {
my @leftprimeridscov=grep(grep($_>=$eachprimerbedcov[1] && $_<=$eachprimerbedcov[2]-10, @$_[1]), @{$hashcoverage1{$key}});
for (my $n=0; $n<$#leftprimeridscov+1; $n++) {
push (@clusterleftprimeridscov,"$leftprimeridscov[$n][0]\_$eachprimerbedcov[4]");
}
}
if ($eachprimerbedcov[3]=~/_RIGHT/) {
my @rightprimeridscov=grep(grep($_>=$eachprimerbedcov[1]+10 && $_<=$eachprimerbedcov[2], @$_[2]), @{$hashcoverage1{$key}});
for (my $n=0; $n<$#rightprimeridscov+1; $n++) {
push (@clusterrightprimeridscov,"$rightprimeridscov[$n][0]\_$eachprimerbedcov[4]");
}
}
}
close PRIMERBED;
}
my $insect = List::Compare->new(\@clusterleftprimeridscov, \@clusterrightprimeridscov);
my @insectboth = $insect->get_intersection;
my @clusterleftprimeridscovuniq=uniq(@clusterleftprimeridscov);
my @clusterrightprimeridscovuniq=uniq(@clusterrightprimeridscov);
$numbothprimers=$#insectboth+1;
$numleftprimersonly=$#clusterleftprimeridscovuniq+1-$numbothprimers;
$numrightprimersonly=$#clusterrightprimeridscovuniq+1-$numbothprimers;
$numatleastprimers=$numleftprimersonly+$numrightprimersonly+$numbothprimers;
print "Total mapped read/read pairs in both pools\: ",$totalmappedread,"\n";
print "Total reads/read pairs with left primer only in $poollable\: ",$numleftprimersonly,"\n";
print "Total reads/read pairs with right primer only in $poollable\: ",$numrightprimersonly,"\n";
print "Total reads/read pairs with both primers in $poollable\: ",$numbothprimers,"\n";
print "Total reads/read pairs with at least one primer in $poollable\: ",$numatleastprimers,"\n";
}
sub getcoverageillumina {
my %hashcoverage1; my %hashcoverage2;
open(BAMEXTRACTR, "$outputpath/alignment_output/alignment.sorted.splice.tab");
while (<BAMEXTRACTR>) {
unless (/^\#/) {
$totalmappedread++;
my @eachasspscoverage=split(/\t/);
#if ($eachassps[1] eq 1) {
my @eachcoverage1=($eachasspscoverage[0],$eachasspscoverage[2],$eachasspscoverage[5],$eachasspscoverage[9],$eachasspscoverage[11],$eachasspscoverage[14]);
push (@{$hashcoverage1{"$eachasspscoverage[3]\t$eachasspscoverage[4]"}}, [@eachcoverage1]);
my @eachcoverage2=($eachasspscoverage[0],$eachasspscoverage[2],$eachasspscoverage[5],$eachasspscoverage[9],$eachasspscoverage[11],$eachasspscoverage[14]);
push (@{$hashcoverage2{"$eachasspscoverage[12]\t$eachasspscoverage[13]"}}, [@eachcoverage2]);
#}
}
}
close BAMEXTRACTR;
my @clusterleftprimeridscov=(); my @clusterrightprimeridscov=();
for my $key (keys %hashcoverage1){
open(PRIMERBED, "$outputpath/alignment_output/selected_primer_pool.bed") or die "can't find primer bed file";
while (<PRIMERBED>) {
chomp;
my @eachprimerbedcov=split(/\t/);
if ($eachprimerbedcov[3]=~/_LEFT/) {
my @leftprimeridscov1=grep(grep($_>=$eachprimerbedcov[1] && $_<=$eachprimerbedcov[2]-10, @$_[1]), @{$hashcoverage1{$key}});
for (my $n=0; $n<$#leftprimeridscov1+1; $n++) {
push (@clusterleftprimeridscov,"$leftprimeridscov1[$n][0]\_$leftprimeridscov1[$n][3]\_$eachprimerbedcov[4]");
}
}
if ($eachprimerbedcov[3]=~/_RIGHT/) {
my @rightprimeridscov1=grep(grep($_>=$eachprimerbedcov[1]+10 && $_<=$eachprimerbedcov[2], @$_[5]), @{$hashcoverage1{$key}});
for (my $n=0; $n<$#rightprimeridscov1+1; $n++) {
push (@clusterrightprimeridscov,"$rightprimeridscov1[$n][0]\_$rightprimeridscov1[$n][3]\_$eachprimerbedcov[4]");
}
}
}
close PRIMERBED;
}
for my $key (keys %hashcoverage2){
open(PRIMERBED, "$outputpath/alignment_output/selected_primer_pool.bed") or die "can't find primer bed file";
while (<PRIMERBED>) {
chomp;
my @eachprimerbedcov=split(/\t/);
if ($eachprimerbedcov[3]=~/_LEFT/) {
my @leftprimeridscov2=grep(grep($_>=$eachprimerbedcov[1] && $_<=$eachprimerbedcov[2]-10, @$_[1]), @{$hashcoverage2{$key}});
for (my $n=0; $n<$#leftprimeridscov2+1; $n++) {
push (@clusterleftprimeridscov,"$leftprimeridscov2[$n][0]\_$leftprimeridscov2[$n][3]\_$eachprimerbedcov[4]");
}
}
if ($eachprimerbedcov[3]=~/_RIGHT/) {
my @rightprimeridscov2=grep(grep($_>=$eachprimerbedcov[1]+10 && $_<=$eachprimerbedcov[2], @$_[5]), @{$hashcoverage2{$key}});
for (my $n=0; $n<$#rightprimeridscov2+1; $n++) {
push (@clusterrightprimeridscov,"$rightprimeridscov2[$n][0]\_$rightprimeridscov2[$n][3]\_$eachprimerbedcov[4]");
}
}
}
close PRIMERBED;
}
my $insect = List::Compare->new(\@clusterleftprimeridscov, \@clusterrightprimeridscov);
my @insectboth = $insect->get_intersection;
my @clusterleftprimeridscovuniq=uniq(@clusterleftprimeridscov);
my @clusterrightprimeridscovuniq=uniq(@clusterrightprimeridscov);
$numbothprimers=$#insectboth+1;
$numleftprimersonly=$#clusterleftprimeridscovuniq+1-$numbothprimers;
$numrightprimersonly=$#clusterrightprimeridscovuniq+1-$numbothprimers;
$numatleastprimers=$numleftprimersonly+$numrightprimersonly+$numbothprimers;
print "Total mapped read/read pairs in both pools\: ",$totalmappedread,"\n";
print "Total reads/read pairs with left primer only in $poollable\: ",$numleftprimersonly,"\n";
print "Total reads/read pairs with right primer only in $poollable\: ",$numrightprimersonly,"\n";
print "Total reads/read pairs with both primers in $poollable\: ",$numbothprimers,"\n";
print "Total reads/read pairs with at least one primer in $poollable\: ",$numatleastprimers,"\n";
}
my $atgporstionnovel;
my %junctionhash;
sub parseresult {
mkdir "$outputpath/results";
open (NOVELDETAILS, ">$outputpath/results/novel_junction_details.tab");
print NOVELDETAILS "subgenome\tleader_end\tTRS_start\tACGAAC\tATG_postion\tknown_ATG\t20_leader_seq\tTRS_seq\tfirst_orf_aa\n";
#if ($options{'TRSLindependent'}) {
# open (NOVELDETAILSIND, ">$outputpath/results/TRS_L_independent_junction_details.tab");
# print NOVELDETAILSIND "subgenome\tfusion_satrt\tfusion_end\tATG_postion\tfirst_orf_aa\n";
#}
open (KNOWNJUNCATIONSDETAILS, ">$outputpath/results/known_junction_details.tab");
print KNOWNJUNCATIONSDETAILS "subgenome\tpeak_leader_end\tpeak_TRS_start\tACGAAC\tATG_postion\t20_leader_seq\tTRS_seq\tfirst_orf_aa\n";
open (NOVEL, ">$outputpath/results/novel_junction.tab");
print NOVEL "subgenome\tleader_end\tTRS_start\tnb_count\tnormalized_count\n";
open (KNOWNJUNCATIONS, ">$outputpath/results/known_junction.tab");
print KNOWNJUNCATIONS "subgenome\tref_leader_end\tpeak_leader_end\tref_TRS_start\tpeak_TRS_start\tpeak_count\tpeak_normalized_count\tcluster_count\tcluster_normalized_count\n";
open (JBED, "$pathtoreference/junction.bed") or die "can't find reference files";
my @junctions=<JBED>;
close JBED;
my %hashtab; my %hashtabr; my %hashtabnoncanonical; #%hashtab for unkonwn junctions, %hashtabr for known junctions.
my @allindexcollection;
my @allindexcollectionextra;
open(TAB, "$outputpath/alignment_output/alignment_portcullis_out.junctions.tab");
while (<TAB>) {
unless (/^index\trefid/ or /^\n/){
my @eachtabs=split(/\t/,$_);
if ($eachtabs[4]<$cutoffpos && $eachtabs[20]>$cutoff) {
$hashtab{$eachtabs[0]}="$eachtabs[0]\t$eachtabs[4]\t$eachtabs[5]\t$eachtabs[20]";
push (@allindexcollection,"$eachtabs[0]");
}
if (exists $options{'TRSLindependent'}) {
if ($eachtabs[4]>=$cutoffpos && $eachtabs[20]>$cutoffidp) {
push (@allindexcollectionextra,"$eachtabs[0]");
$hashtabnoncanonical{$eachtabs[0]}="$eachtabs[0]\t$eachtabs[4]\t$eachtabs[5]\t$eachtabs[20]";
}
}
#if ($eachtabs[4]<266) {
$hashtabr{$eachtabs[0]}="$eachtabs[0]\t$eachtabs[4]\t$eachtabs[5]\t$eachtabs[20]";
#}
}
}
close TAB;
open(BAMEXTRACTR, "$outputpath/alignment_output/alignment.sorted.splice.tab");
my %hashassp; my %hashasspleftright; my %hashassfa; my %hashillumina; my %hashasspleftright1; my %hashasspleftright2; #%hashassp for right site; %hashasspleftright for left and right site; %hashassfa for fasta extaction;
while (<BAMEXTRACTR>) {
chomp;
my @eachassps=split(/\t/);
if ($options{'mode'} eq "illumina" && !exists $options{'bam'} && $options{'fq'}=~/\:/) {
if ($eachassps[-1] eq "yes") {
my @eachleftright1=($eachassps[0],$eachassps[2],$eachassps[5],$eachassps[9],$eachassps[11],$eachassps[14]);
push (@{$hashasspleftright1{"$eachassps[3]\t$eachassps[4]"}}, [@eachleftright1]);
my @eachleftright2=($eachassps[0],$eachassps[2],$eachassps[5],$eachassps[9],$eachassps[11],$eachassps[14]);
push (@{$hashasspleftright2{"$eachassps[12]\t$eachassps[13]"}}, [@eachleftright2]);
push (@{$hashassfa{"$eachassps[3]\t$eachassps[4]"}}, "$eachassps[0]\t$eachassps[2]\t$eachassps[5]\t$eachassps[8]");
push (@{$hashassfa{"$eachassps[12]\t$eachassps[13]"}}, "$eachassps[9]\t$eachassps[11]\t$eachassps[14]\t$eachassps[17]");
my @spliteachasspsone0=split(/\_\_/,$eachassps[0]);
my @spliteachasspstwo0=split(/\_\_/,$eachassps[9]);
push (@{$hashillumina{"$eachassps[3]\t$eachassps[4]"}}, "$spliteachasspsone0[1]");
push (@{$hashillumina{"$eachassps[12]\t$eachassps[13]"}}, "$spliteachasspstwo0[1]");
}
}else {
if ($eachassps[1] eq 1) {
push (@{$hashassp{"$eachassps[3]\t$eachassps[4]"}}, "$eachassps[5]");
my @eachleftright=($eachassps[0],$eachassps[2],$eachassps[5]);
push (@{$hashasspleftright{"$eachassps[3]\t$eachassps[4]"}}, [@eachleftright]);
push (@{$hashassfa{"$eachassps[3]\t$eachassps[4]"}}, "$eachassps[0]\t$eachassps[2]\t$eachassps[5]\t$eachassps[8]");
}
}
}
close BAMEXTRACTR;
my @indexcollections;
foreach my $junction (@junctions) {
chomp $junction;
my @junctionsites=split(/\t/,$junction);
$junctionhash{$junctionsites[3]}=$junctionsites[0];
my %hashcluster=();
my %hashleftrightprimerscluster=();
my %hashleftrightprimerspeak=();
my @clustercounts=(); #for the normal counts collection
my @clusterployAcounts1=(); #for the ployA >= 1 counts collection
my @clusterployAcounts5=(); #for the ployA >= 5 counts collection
my @clusterleftprimerids=(); #for the left primer ids collection
my @clusterrightprimerids=(); #for the right primer ids collection
my @clustercountsillumina=(); #to count all mapped reads in illumina
#my @clusterATGsite=(); #for the ATGids collection
#####cluster count of junction
open(TAB, "$outputpath/alignment_output/alignment_portcullis_out.junctions.tab");
while (<TAB>) {
my @eachtabs=split(/\t/);
unless (/^index\trefid/ or /^\n/){
my $adjectlederup=$junctionsites[1]+$leaderadjectnumber;
my $adjectlederdown=$junctionsites[1]-$leaderadjectnumber;
my $adjectorfup=$junctionsites[3];
my $adjectorfdown=$junctionsites[2]-$orfadjectnumber;
if ($eachtabs[4] < $adjectlederup && $eachtabs[4] > $adjectlederdown && $eachtabs[5] < $adjectorfup && $eachtabs[5] > $adjectorfdown) {
push (@indexcollections,$eachtabs[0]);
push (@clustercounts,$eachtabs[20]); #cluster uniqe junction count.
$hashcluster{$eachtabs[0]}=$eachtabs[20];
if ($options{'Rtch'} eq "RNA" && !exists $options{'bam'}) {
my $countployAcounts1=grep($_>=$polyapostion, @{$hashassp{"$eachtabs[4]\t$eachtabs[5]"}});
push (@clusterployAcounts1,$countployAcounts1); # to get ployA >= 1 by the sart and end postions in the cluster.
my $countployAcounts5=grep($_>=$polyapostion5, @{$hashassp{"$eachtabs[4]\t$eachtabs[5]"}});
push (@clusterployAcounts5,$countployAcounts5); # to get ployA >= 5 by the sart and end postions in the cluster.
#my $clusterATGsiteid=grep($_>$adjectorfup+1, @{$hashassp{"$eachtabs[4]\t$eachtabs[5]"}});
#push (@clusterATGsite,$clusterATGsiteid);
}
if ($options{'Rtch'} eq "cDNA" && !exists $options{'bam'}) {
#my $countployAcounts1=grep($_>=$polyapostion, @{$hashassp{"$eachtabs[4]\t$eachtabs[5]"}});
#push (@clusterployAcounts1,$countployAcounts1); # to get ployA >= 1 by the sart and end postions in the cluster.
#my $countployAcounts5=grep($_>=$polyapostion5, @{$hashassp{"$eachtabs[4]\t$eachtabs[5]"}});
#push (@clusterployAcounts5,$countployAcounts5); # to get ployA >=5 by the sart and end postions in the cluster.
#my $clusterATGsiteid=grep($_>$adjectorfup+1, @{$hashassp{"$eachtabs[4]\t$eachtabs[5]"}});
#push (@clusterATGsite,$clusterATGsiteid);
open(PRIMERBED, "$outputpath/alignment_output/selected_primer_pool.bed") or die "can't find primer bed file";
while (<PRIMERBED>) {
chomp;
my @eachprimerbed=split(/\t/);
if ($eachprimerbed[1] < $eachtabs[4] && $eachprimerbed[3]=~/_LEFT/) {
my @leftprimerids=grep(grep($_>=$eachprimerbed[1] && $_<=$eachprimerbed[2]-10, @$_[1]), @{$hashasspleftright{"$eachtabs[4]\t$eachtabs[5]"}});
for (my $n=0; $n<$#leftprimerids+1; $n++) {
push (@clusterleftprimerids,"$leftprimerids[$n][0]");
}
}
if ($eachprimerbed[2] > $eachtabs[5] && $eachprimerbed[3]=~/_RIGHT/) {
my @rightprimerids=grep(grep($_>=$eachprimerbed[1]+10 && $_<=$eachprimerbed[2], @$_[2]), @{$hashasspleftright{"$eachtabs[4]\t$eachtabs[5]"}});
for (my $n=0; $n<$#rightprimerids+1; $n++) {
push (@clusterrightprimerids,"$rightprimerids[$n][0]");
}
}
}
close PRIMERBED;
}
if ($options{'mode'} eq "illumina" && !exists $options{'bam'} && $options{'fq'}!~/\:/) {
#my $countployAcounts1=grep($_>=$polyapostion, @{$hashassp{"$eachtabs[4]\t$eachtabs[5]"}});
#push (@clusterployAcounts1,$countployAcounts1); # to get ployA >= 1 by the sart and end postions in the cluster.
#my $countployAcounts5=grep($_>=$polyapostion5, @{$hashassp{"$eachtabs[4]\t$eachtabs[5]"}});
#push (@clusterployAcounts5,$countployAcounts5); # to get ployA >=5 by the sart and end postions in the cluster.
#my $clusterATGsiteid=grep($_>$adjectorfup+1, @{$hashassp{"$eachtabs[4]\t$eachtabs[5]"}});
#push (@clusterATGsite,$clusterATGsiteid);
open(PRIMERBED, "$outputpath/alignment_output/selected_primer_pool.bed") or die "can't find primer bed file";
while (<PRIMERBED>) {
chomp;
my @eachprimerbed=split(/\t/);
if ($eachprimerbed[1] < $eachtabs[4] && $eachprimerbed[3]=~/_LEFT/) {
my @leftprimerids=grep(grep($_>=$eachprimerbed[1] && $_<=$eachprimerbed[2]-10, @$_[1]), @{$hashasspleftright{"$eachtabs[4]\t$eachtabs[5]"}});
for (my $n=0; $n<$#leftprimerids+1; $n++) {
push (@clusterleftprimerids,"$leftprimerids[$n][0]");
}
}
if ($eachprimerbed[2] > $eachtabs[5] && $eachprimerbed[3]=~/_RIGHT/) {
my @rightprimerids=grep(grep($_>=$eachprimerbed[1]+10 && $_<=$eachprimerbed[2], @$_[2]), @{$hashasspleftright{"$eachtabs[4]\t$eachtabs[5]"}});
for (my $n=0; $n<$#rightprimerids+1; $n++) {
push (@clusterrightprimerids,"$rightprimerids[$n][0]");
}
}
}
close PRIMERBED;
}
if ($options{'mode'} eq "illumina" && !exists $options{'bam'} && $options{'fq'}=~/\:/) {
#my $clusterATGsiteid=grep($_>$adjectorfup+1, @{$hashassp{"$eachtabs[4]\t$eachtabs[5]"}});
#push (@clusterATGsite,$clusterATGsiteid);
if (defined $hashillumina{"$eachtabs[4]\t$eachtabs[5]"}) {
push (@clustercountsillumina, @{$hashillumina{"$eachtabs[4]\t$eachtabs[5]"}});
}
open(PRIMERBED, "$outputpath/alignment_output/selected_primer_pool.bed") or die "can't find primer bed file";
while (<PRIMERBED>) {