-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathFaQCs.pl
executable file
·2590 lines (2420 loc) · 100 KB
/
FaQCs.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/env perl
###### Required ########################################################
# 1. Parallel::ForkManager module from CPAN #
# 2. String::Approx module from CPAN #
# 3. R for ploting #
# 4. Jellyfish for kmer counting #
# (http://www.cbcb.umd.edu/software/jellyfish/) #
###########################################################################
###### Inputs #########################################################
# 1. Fastq files either paired-end or unpaired reads or both #
# Can input multiple library fastq files but only output #
# concatenate trimmed fastq files #
# 2. Output directory #
# 3. Other options #
###########################################################################
###### Output #########################################################
# 1. Two Paired-ends files if input paired-end reads #
# 2. One unpaired reads file #
# 3. trimming statistical text file #
# 4. quality report pdf file #
###########################################################################
###### Functions ####################################################
# 1. trim bidirection. 2. add -min_L flag #
# 3. phredScore= ord(Q)-$ascii for diffent quality #
# encoding and conversion #
# 4. -n "N" base filter 5. Low complexity filter #
# 6. multi-threads (required Parallel::ForkManager) #
# 7. output ascii conversion 8. stats report #
# 9. input paired end reads 10. average read quality filter #
# 11. Trim artifact 12. replace N #
# AUTHOR: CHIEN-CHI LO #
# Copyright (c) 2013 LANS, LLC All rights reserved #
# All right reserved. This program is free software; you can redistribute #
# it and/or modify it under the same terms as Perl itself. #
# #
# LAST REVISED: Aug 2014 #
###########################################################################
use strict;
use File::Basename;
use Getopt::Long;
use Data::Dumper;
use FindBin qw($Bin);
use lib ("$Bin/../lib","$Bin/lib");
use Parallel::ForkManager;
use String::Approx;
my $version=1.34;
my $debug=0;
sub Usage {
my $msg=shift;
my $short_usage = "perl $0 [options] [-u unpaired.fastq] -p reads1.fastq reads2.fastq -d out_directory";
($msg)?
print "\n $msg\n\n $short_usage\n\n Option -h to see full usage \n\n" :
print <<"END";
Usage: $short_usage
Version $version
Input File: (can use more than once)
-u <Files> Unpaired reads
-p <Files> Paired reads in two files and separate by space
Trim:
-mode "HARD" or "BWA" or "BWA_plus" (default BWA_plus)
BWA trim is NOT A HARD cutoff! (see bwa's bwa_trim_read() function in bwaseqio.c)
-q <INT> Targets # as quality level (default 5) for trimming
-5end <INT> Cut # bp from 5 end before quality trimming/filtering
-3end <INT> Cut # bp from 3 end before quality trimming/filtering
-adapter <bool> Trim reads with illumina adapter/primers (default: no)
-rate <FLOAT> Mismatch ratio of adapters' length (default: 0.2, allow 20% mismatches)
-artifactFile <File> additional artifact (adapters/primers/contaminations) reference file in fasta format
Filters:
-min_L <INT> Trimmed read should have to be at least this minimum length (default:50)
-avg_q <NUM> Average quality cutoff (default:0, no filtering)
-n <INT> Trimmed read has more than this number of continuous base "N" will be discarded.
(default: 2, "NN")
-lc <FLOAT> Low complexity filter ratio, Maximum fraction of mono-/di-nucleotide sequence (default: 0.85)
-phiX <bool> Filter phiX reads (slow)
Q_Format:
-ascii Encoding type: 33 or 64 or autoCheck (default)
Type of ASCII encoding: 33 (standard) or 64 (illumina 1.3+)
-out_ascii Output encoding. (default: 33)
Output:
-prefix <TEXT> Output file prefix. (default: QC)
-stats <File> Statistical numbers output file (default: prefix.stats.txt)
-d <PATH> Output directory.
Options:
-t <INT > # of CPUs to run the script (default:2 )
-split_size <INT> Split the input file into several sub files by sequence number (default: 1000000)
-qc_only <bool> no Filters, no Trimming, report numbers.
-kmer_rarefaction <bool>
Turn on the kmer calculation. Turn on will slow down ~10 times. (default:Calculation is off.)
(meaningless if -subset is too small)
-m <INT> kmer for rarefaction curve (range:[2,31], default 31)
-subset <INT> Use this nubmer x split_size for qc_only and kmer_rarefaction
(default: 10, 10x1000000 SE reads, 20x1000000 PE reads)
-discard <bool> Output discarded reads to prefix.discard.fastq (default: 0, not output)
-substitute <bool> Replace "N" in the trimmed reads with random base A,T,C ,or G (default: 0, off)
-trim_only <bool> No quality report. Output trimmed reads only.
-5trim_off <bool> Turn off trimming from 5'end.
-debug <bool> keep intermediate files
END
exit(1);
}
# magic number of quality score
my $highest_illumina_score=41;
my $lowest_illumina_score=0;
# Options Variable initialization
my $thread=2;
my $opt_q=5;
my $opt_min_L=50;
my $opt_avg_cutoff=0;
my $trim_5_end=0;
my $trim_3_end=0;
my $ascii;
my $trim_5_end_off;
my $mode="BWA_plus";
my $N_num_cutoff=2;
my $replace_N;
my $out_offset=33;
my $low_complexity_cutoff_ratio=0.85;
my $subfile_size=1000000;
#my $subfile_size=100000;
my $kmer_rarefaction_on=0;
my $kmer=31;
my $prefix="QC";
my $plots_file;
my $stats_output;
my $trimmed_reads1_fastq_file;
my $trimmed_reads2_fastq_file;
my $trimmed_unpaired_fastq_file;
my $trimmed_discard_fastq_file;
my @paired_files;
my @unpaired_files;
my $outDir;
my $output_discard;
my $qc_only=0;
my $trim_only=0;
my $stringent_cutoff=0;
my $filter_adapter=0;
my $filter_phiX=0;
my $filterAdapterMismatchRate=0.2;
my $artifactFile;
my $subsample_num=10;
## not used yet for shihai's algorithm
my $minicut=4;
my $lowperc=0;
my $upperc=0.2;
my $discperc=0.35;
my $cutlimit1=0.3;
my $cutlimit2=0.3;
# Options
GetOptions("q=i" => \$opt_q,
"min_L=i" => \$opt_min_L,
"avg_q=f" => \$opt_avg_cutoff,
"5end=i" => \$trim_5_end,
"3end=i" => \$trim_3_end,
"mode=s" => \$mode,
"p=s{,}" => \@paired_files,
"u=s{,}" => \@unpaired_files,
"ascii=i" => \$ascii,
"5trim_off" => \$trim_5_end_off,
"n=i" => \$N_num_cutoff,
'stringent_q=i'=> \$stringent_cutoff,
"lc=f" => \$low_complexity_cutoff_ratio,
"out_ascii=i" => \$out_offset,
"t|threads=i" => \$thread,
'kmer_rarefaction' => \$kmer_rarefaction_on,
'm=i' => \$kmer,
'split_size=i' => \$subfile_size,
'prefix=s' => \$prefix,
'd=s' => \$outDir,
'stats=s' => \$stats_output,
'discard' => \$output_discard,
'substitute' => \$replace_N,
'qc_only' => \$qc_only,
'trim_only' => \$trim_only,
'subset=i' => \$subsample_num,
'debug' => \$debug,
'adapter' => \$filter_adapter,
'phiX' => \$filter_phiX,
'rate=f' => \$filterAdapterMismatchRate,
'artifactFile=s' => \$artifactFile,
'R1=s' => \$trimmed_reads1_fastq_file, # for galaxy impelementation
'R2=s' => \$trimmed_reads2_fastq_file, # for galaxy impelementation
'Ru=s' => \$trimmed_unpaired_fastq_file, # for galaxy impelementation
'Rd=s' => \$trimmed_discard_fastq_file, # for galaxy impelementation
'QRpdf=s' => \$plots_file, # for galaxy impelementation
"version" => sub{print "Version: $version\n";exit;},
"help|?" => sub{Usage()} );
#### Input check ####
Usage("Missing input files.") unless @unpaired_files or @paired_files;
&checkDependedPrograms;
my @make_paired_paired_files;
my %file;
if (@paired_files)
{
if (scalar(@paired_files) % 2) { Usage("Please check paired data input are even file numbers\n") ;}
map { if(is_file_empty($_)){ Usage("Please check paired data input at flag -p.\n $_ doesn't not exist or empty."); $file{basename($_)}=1;} } @paired_files;
#make pair in a new array 'read1_1 read1_2', 'read2_1 read2_2' ...
for(my$i=0;$i<=$#paired_files;$i=$i+2)
{
if (&is_paired($paired_files[$i], $paired_files[$i+1]))
{
push @make_paired_paired_files, "$paired_files[$i] $paired_files[$i+1]";
}
else
{
print ("The seqeucne names of the paired end reads in $paired_files[$i],$paired_files[$i+1] are not matching.\nWill use them as single end reads\n");
push @unpaired_files, $paired_files[$i],$paired_files[$i+1];
delete $file{basename($paired_files[$i])};
delete $file{basename($paired_files[$i+1])};
}
}
}
if (@unpaired_files)
{
map { if(is_file_empty($_))
{
Usage("Please check unpaired data input at flag -u.\n $_ doesn't not exist or empty.");
}
if ($file{basename($_)})
{
Usage("The single end file, $_,has been used in the paired end data.")
}
} @unpaired_files;
}
Usage("Missing output directory at flag -d ") unless $outDir;
#########################
if ($mode =~ /hard/i)
{
print "Hard trimming is used. \n" if (!$qc_only);
$mode="hard";
}
elsif ($mode =~ /BWA_plus/i)
{
print "Bwa extension trimming algorithm is used. \n" if (!$qc_only);
$mode="BWA_plus";
}
elsif ($mode =~ /BWA/i)
{
print "Bwa trimming algorithm is used. \n" if (!$qc_only);
$mode="BWA";
}
else # default
{
print "Not recognized mode $mode. Bwa extension trimming algorithm is used. \n" if (!$qc_only);
$mode="BWA_plus";
}
###### Output file initialization #####
# temp files for plotting
my $quality_matrix="$outDir/$prefix.quality.matrix";
my $avg_quality_histogram="$outDir/$prefix.for_qual_histogram.txt";
my $base_matrix="$outDir/$prefix.base.matrix";
my $nuc_composition_file="$outDir/$prefix.base_content.txt";
my $length_histogram="$outDir/$prefix.length_count.txt";
my $qa_quality_matrix="$outDir/qa.$prefix.quality.matrix";
my $qa_avg_quality_histogram="$outDir/qa.$prefix.for_qual_histogram.txt";
my $qa_base_matrix="$outDir/qa.$prefix.base.matrix";
my $qa_nuc_composition_file="$outDir/qa.$prefix.base_content.txt";
my $qa_length_histogram="$outDir/qa.$prefix.length_count.txt";
my $fastq_count="$outDir/fastqCount.txt";
# output files
$trimmed_discard_fastq_file="$outDir/$prefix.discard.fastq" if (!$trimmed_discard_fastq_file);
$plots_file="$outDir/${prefix}_qc_report.pdf" if (!$plots_file);
$trimmed_unpaired_fastq_file="$outDir/$prefix.unpaired.trimmed.fastq" if (!$trimmed_unpaired_fastq_file);
$trimmed_reads1_fastq_file="$outDir/$prefix.1.trimmed.fastq" if (!$trimmed_reads1_fastq_file);
$trimmed_reads2_fastq_file="$outDir/$prefix.2.trimmed.fastq" if (!$trimmed_reads2_fastq_file);
$stats_output="$outDir/$prefix.stats.txt" if (!$stats_output);
# temp files for kmer counting plot
my $kmer_rarefaction_file="$outDir/$prefix.Kmercount.txt"; #
my $kmer_files="$outDir/$prefix.KmerFiles.txt"; #
my $kmer_histogram_file="$outDir/$prefix.kmerH.txt"; #
#######################################
###### Output check ################
if (! -e $outDir)
{
mkdir $outDir;
}
if (-e $trimmed_reads1_fastq_file)
{
print "The output $trimmed_reads1_fastq_file file exists and will be overwritten.\n";
system ("rm $trimmed_reads1_fastq_file");
}
if (-e $trimmed_reads2_fastq_file)
{
print "The output $trimmed_reads2_fastq_file file exists and will be overwritten.\n";
system ("rm $trimmed_reads2_fastq_file");
}
if (-e $trimmed_unpaired_fastq_file)
{
print "The output $trimmed_unpaired_fastq_file file exists and will be overwritten.\n";
system ("rm $trimmed_unpaired_fastq_file");
}
if (-e $plots_file)
{
print "The output $plots_file file exists and will be overwritten.\n";
system ("rm $plots_file");
}
if (-e $trimmed_discard_fastq_file)
{
print "The output $trimmed_discard_fastq_file file exists and will be overwritten.\n";
system ("rm $trimmed_discard_fastq_file");
}
system ("rm $kmer_files") if (-e $kmer_files);
#######################################
if ($qc_only)
{
# set all Filters to pass
# $opt_q=0;
# $opt_min_L=0;
# $opt_avg_cutoff=0;
#$N_num_cutoff=1000;
#$low_complexity_cutoff_ratio=1;
}
my $orig_opt_q = $opt_q;
my ( $total_count,$total_count_1, $total_count_2, $total_len_1,$total_len_2, $total_len);
my ( $total_num, $trimmed_num,$total_raw_seq_len, $total_trimmed_seq_len);
my ( $trim_seq_len_std, $trim_seq_len_avg, $max, $min, $median);
my ( $paired_seq_num, $total_paired_bases )=(0,0);
my ( @split_files, @split_files_2);
my ( $readsFilterByLen, $basesFilterByLen ) = (0,0);
my ( $readsTrimByQual, $basesTrimByQual ) = (0,0);
my ( $readsFilterByNN, $basesFilterByNN ) = (0,0);
my ( $readsFilterByPhiX, $basesFilterByPhiX ) = (0,0);
my ( $readsTrimByAdapter, $basesTrimByAdapter ) = (0,0);
my ( $readsFilterByAvgQ, $basesFilterByAvgQ ) = (0,0);
my ( $readsFilterByLowComplexity, $basesFilterByLowComplexity ) = (0,0);
$N_num_cutoff=1 if (!$N_num_cutoff);
my (%position, %qa_position);
my (%AverageQ, %qa_AverageQ);
my (%base_position,%qa_base_position);
my (%base_content, %qa_base_content);
my (%len_hash, %qa_len_hash);
my (%filter_stats, %qa_filter_stats);
my %EachAdapter;
my %EachReplaceN;
my ( $i_file_name, $i_path, $i_suffix );
my ($phiX_id,$phiX_seq) = &read_phiX174 if ($filter_phiX);
$filter_adapter=1 if ($artifactFile);
open(my $fastqCount_fh, ">$fastq_count") or die "Cannot write $fastq_count\n";
foreach my $input (@unpaired_files,@make_paired_paired_files){
print "Processing $input file\n";
#print $STATS_fh "Processing $input file\n";
my ($reads1_file,$reads2_file) = split /\s+/,$input;
# check file
if(&is_file_empty($reads1_file)<0) { die "The file $reads1_file doesn't exist or empty.\n";}
if(&is_file_empty($reads2_file)<0 and $reads2_file) { die "The file $reads2_file doesn't exist or empty.\n";}
# check quality offset
if (! $ascii){$ascii = &checkQualityFormat($reads1_file)}
# check NextSeq platform
if( &is_NextSeq($reads1_file) and $opt_q < 16){
$opt_q = 16;
warn "The input looks like NextSeq data and the quality level (-q) is adjusted to 16 for trimming.\n";
}else{ $opt_q = $orig_opt_q;}
#split
($total_count_1,$total_len_1,@split_files) = &split_fastq($reads1_file,$outDir,$subfile_size);
printf $fastqCount_fh ("%s\t%d\t%d\t%.2f\n",basename($reads1_file),$total_count_1,$total_len_1,$total_len_1/$total_count_1);
if ($reads2_file)
{
($total_count_2,$total_len_2,@split_files_2) = &split_fastq($reads2_file,$outDir,$subfile_size);
printf $fastqCount_fh ("%s\t%d\t%d\t%.2f\n",basename($reads2_file),$total_count_2,$total_len_2,$total_len_2/$total_count_2);
}
$total_count += $total_count_1 + $total_count_2;
$total_len += $total_len_1 + $total_len_2;
my $random_num_ref = &random_subsample(scalar(@split_files),$subsample_num);
$subsample_num -= scalar(@split_files);
$subsample_num -= scalar(@split_files) if ($reads2_file);
my $pm = new Parallel::ForkManager($thread);
# data structure retrieval and handling from multi-threading
# $pm->run_on_start(
# sub { my ($pid,$ident)=@_;
# #print "** $ident started, pid: $pid\n";
# }
# );
$pm -> run_on_finish ( # called BEFORE the first call to start()
sub {
my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $nums_ref) = @_;
print qq|child process $ident, exit on singal $exit_signal| if ($exit_signal);
print qq|core dump from child process $pid! on $ident\n| if ($core_dump);
# retrieve data structure from child
if (defined($nums_ref)) { # children are not forced to send anything
my $random_sub_raw_ref;
$random_sub_raw_ref=$nums_ref->{random_sub_raw} if ( $random_num_ref->{$ident} and !$qc_only);
my ($total_score, $avg_score);
$total_num += $nums_ref->{raw_seq_num};
$trimmed_num += $nums_ref->{trim_seq_num};
$total_raw_seq_len += $nums_ref->{total_raw_seq_len};
$total_trimmed_seq_len += $nums_ref->{total_trim_seq_len};
my $processed_num= $nums_ref->{raw_seq_num};
$trim_seq_len_std = $nums_ref->{trim_seq_len_std};
$trim_seq_len_avg = $nums_ref->{trim_seq_len_avg};
$max = $nums_ref->{max};
$min = $nums_ref->{min};
$median = $nums_ref->{median};
$paired_seq_num += $nums_ref->{paired_seq_num};
$total_paired_bases += $nums_ref->{total_paired_bases};
my %filter;
if ($nums_ref->{filter})
{
%filter=%{$nums_ref->{filter}};
map {$filter_stats{$_}->{basesNum} += $filter{$_}->{basesNum};
$filter_stats{$_}->{readsNum} += $filter{$_}->{readsNum};
} keys %filter;
}
if ($replace_N)
{
my %tmp_ReplaceN;
%tmp_ReplaceN = %{$nums_ref->{replaceN}} if ($nums_ref->{replaceN});
map {
$EachReplaceN{$_} += $tmp_ReplaceN{$_};
} keys %tmp_ReplaceN;
}
if ($filter_adapter)
{
my %tmp_Adapters;
%tmp_Adapters= %{$nums_ref->{adapter}} if ($nums_ref->{adapter});
map {
$EachAdapter{$_}->{readsNum} += $tmp_Adapters{$_}->{readsNum};
$EachAdapter{$_}->{basesNum} += $tmp_Adapters{$_}->{basesNum};
} keys %tmp_Adapters;
}
if ($nums_ref->{ReadAvgQ})
{
my %temp_avgQ = %{$nums_ref->{ReadAvgQ}};
map {$AverageQ{$_}->{bases} += $temp_avgQ{$_}->{basesNum};
$AverageQ{$_}->{reads} += $temp_avgQ{$_}->{readsNum};
} keys %temp_avgQ;
}
my %temp_position= %{$nums_ref->{qual}} if ($nums_ref->{qual});
my %temp_base_position= %{$nums_ref->{base}} if ($nums_ref->{base});
my %qa_temp_position= %{$random_sub_raw_ref->{qual}} if ($random_sub_raw_ref);
my %qa_temp_base_position= %{$random_sub_raw_ref->{base}} if ($random_sub_raw_ref);
for my $score ($lowest_illumina_score..$highest_illumina_score)
{
if ($nums_ref->{qual})
{
foreach my $pos (keys (%temp_position))
{
$position{$pos}->{$score} += $temp_position{$pos}->{$score};
$total_score += $score * $temp_position{$pos}->{$score};
}
}
if ($random_sub_raw_ref)
{
foreach my $pos (keys (%qa_temp_position))
{
$qa_position{$pos}->{$score} += $qa_temp_position{$pos}->{$score};
}
}
}
for my $nuc ("A","T","C","G","N")
{
if ($nums_ref->{base})
{
foreach my $pos (keys (%temp_base_position))
{
$base_position{$pos}->{$nuc} += $temp_base_position{$pos}->{$nuc};
}
}
if ($random_sub_raw_ref)
{
foreach my $pos (keys (%qa_temp_base_position))
{
$qa_base_position{$pos}->{$nuc} += $qa_temp_base_position{$pos}->{$nuc};
}
}
}
my %tmp_base_content = %{$nums_ref->{Base_content}} if ($nums_ref->{Base_content});
my %qa_tmp_base_content = %{$random_sub_raw_ref->{Base_content}} if ($random_sub_raw_ref);
for my $nuc ("A","T","C","G","N","GC")
{
while (my ($key, $value)= each %{$tmp_base_content{$nuc}})
{
$base_content{$nuc}->{$key} += $value if ($nums_ref->{Base_content});
}
if ($random_sub_raw_ref)
{
while (my ($key, $value)= each %{$qa_tmp_base_content{$nuc}})
{
$qa_base_content{$nuc}->{$key} += $value;
}
}
}
if ($nums_ref->{ReadLen})
{
while (my ($key, $value)= each %{$nums_ref->{ReadLen}} )
{
$len_hash{$key} += $value;
}
}
if ( $random_num_ref->{$ident}){
open (KMEROUT, ">>$kmer_files") or die "$!\n";
if ($qc_only)
{
print KMEROUT $nums_ref->{file_name_1},"\t",$nums_ref->{raw_seq_num_1},"\n";
print KMEROUT $nums_ref->{file_name_2},"\t" if ($nums_ref->{file_name_2});
print KMEROUT $nums_ref->{raw_seq_num_2},"\n" if ($nums_ref->{file_name_2});
}
else
{
print KMEROUT $nums_ref->{trim_file_name_1},"\t",$nums_ref->{trim_seq_num_1},"\n";
print KMEROUT $nums_ref->{trim_file_name_2},"\t" if ($nums_ref->{trim_file_name_2});
print KMEROUT $nums_ref->{trim_seq_num_2},"\n" if ($nums_ref->{trim_file_name_2});
}
close KMEROUT;
if ($random_sub_raw_ref)
{
while (my ($key, $value)= each %{$random_sub_raw_ref->{ReadLen}} )
{
$qa_len_hash{$key} += $value;
}
my %qa_temp_avgQ = %{$random_sub_raw_ref->{ReadAvgQ}};
map {$qa_AverageQ{$_}->{bases} += $qa_temp_avgQ{$_}->{basesNum};
$qa_AverageQ{$_}->{reads} += $qa_temp_avgQ{$_}->{readsNum};
} keys %qa_temp_avgQ;
if ($random_sub_raw_ref->{filter})
{
%filter=%{$random_sub_raw_ref->{filter}};
map {$qa_filter_stats{$_}->{basesNum} += $filter{$_}->{basesNum};
$qa_filter_stats{$_}->{readsNum} += $filter{$_}->{readsNum};
} keys %filter;
}
}
# print Dumper($random_sub_raw_ref),"\n";
}
#print $STATS_fh " Processed $total_num/$total_count\n";
print "Processed $total_num/$total_count\n";
if ( $nums_ref->{total_trim_seq_len} )
{
if (!$trim_only)
{
printf (" Post Trimming Length(Mean, Std, Median, Max, Min) of %d reads with Overall quality %.2f\n",$nums_ref->{trim_seq_num}, $total_score/$nums_ref->{total_trim_seq_len});
}
else
{
printf (" Post Trimming Length(Mean, Std, Median, Max, Min) of %d reads\n",$nums_ref->{trim_seq_num});
}
printf (" (%.2f, %.2f, %.1f, %d, %d)\n",$trim_seq_len_avg,$trim_seq_len_std,$median,$max,$min);
#unlink $split_files[$ident];
#unlink $split_files_2[$ident] if ($split_files_2[$ident]);
}
else
{
print "All reads are trimmed/filtered\n";
}
} else { # problems occuring during storage or retrieval will throw a warning
print qq|No message received from child process $pid! on $ident\n|;
}
}
);
foreach my $i(0..$#split_files)
{
next if ($qc_only and ! $random_num_ref->{$i});
$pm->start($i) and next;
my $hash_ref = &qc_process($split_files[$i],$split_files_2[$i],$random_num_ref->{$i});
&run_kmercount($hash_ref,$kmer,1) if ( $random_num_ref->{$i} and $kmer_rarefaction_on );
&run_kmercount($hash_ref,$kmer,2) if ( $random_num_ref->{$i} and $kmer_rarefaction_on and $split_files_2[$i]);
$pm->finish(0, $hash_ref);
}
$pm->wait_all_children;
# clean up
foreach my $i(0..$#split_files)
{
unlink $split_files[$i];
unlink $split_files_2[$i] if ($split_files_2[$i]);
}
} #end foreach $input
close $fastqCount_fh;
# concatenate each thread's trimmed reads and files clean up.
if (! $qc_only)
{
if (@unpaired_files)
{
foreach my $input (@unpaired_files){
( $i_file_name, $i_path, $i_suffix ) = fileparse( "$input", qr/\.[^.]*/ );
( $i_file_name, $i_path, $i_suffix ) = fileparse( "$i_file_name", qr/\.[^.]*/ ) if ($i_suffix =~ /gz$/);
if (system("cat $outDir/${i_file_name}_?????_trim.fastq >> $trimmed_unpaired_fastq_file")) { die "cat failed: $!" }
`rm $outDir/${i_file_name}_?????_trim.fastq`;
if ($output_discard){
if (system("cat $outDir/${i_file_name}_?????_trim_discard.fastq >> $trimmed_discard_fastq_file")) { die "cat failed: $!" }
`rm $outDir/${i_file_name}_?????_trim_discard.fastq`;
}
}
}
if (@make_paired_paired_files)
{
foreach my $input (@make_paired_paired_files){
my ($reads1_file,$reads2_file) = split /\s+/,$input;
( $i_file_name, $i_path, $i_suffix ) = fileparse( "$reads1_file", qr/\.[^.]*/ );
( $i_file_name, $i_path, $i_suffix ) = fileparse( "$i_file_name", qr/\.[^.]*/ ) if ($i_suffix =~ /gz$/);
if (system("cat $outDir/${i_file_name}_?????_trim.fastq >> $trimmed_reads1_fastq_file")) { die "cat failed: $!" }
`rm $outDir/${i_file_name}_?????_trim.fastq`;
if ($output_discard){
if (system("cat $outDir/${i_file_name}_?????_trim_discard.fastq >> $trimmed_discard_fastq_file")) { die "cat failed: $!" }
`rm $outDir/${i_file_name}_?????_trim_discard.fastq`;
}
( $i_file_name, $i_path, $i_suffix ) = fileparse( "$reads2_file", qr/\.[^.]*/ );
( $i_file_name, $i_path, $i_suffix ) = fileparse( "$i_file_name", qr/\.[^.]*/ ) if ($i_suffix =~ /gz$/);
if (system("cat $outDir/${i_file_name}_?????_trim.fastq >> $trimmed_reads2_fastq_file")) { die "cat failed: $!" }
`rm $outDir/${i_file_name}_?????_trim.fastq`;
if (system("cat $outDir/${i_file_name}_?????_trim_unpaired.fastq >> $trimmed_unpaired_fastq_file")) { die "cat failed: $!" }
`rm $outDir/${i_file_name}_?????_trim_unpaired.fastq`;
}
}
&print_quality_report_files($qa_quality_matrix,$qa_avg_quality_histogram,$qa_base_matrix,$qa_nuc_composition_file,$qa_length_histogram,\%qa_position,\%qa_AverageQ,\%qa_base_position,\%qa_base_content,\%qa_len_hash) if (!$trim_only);
}
&Kmer_rarefaction() if ($kmer_rarefaction_on);
&print_quality_report_files($quality_matrix,$avg_quality_histogram,$base_matrix,$nuc_composition_file,$length_histogram,\%position,\%AverageQ,\%base_position,\%base_content,\%len_hash) if (!$trim_only);
&print_final_stats();
&plot_by_R() if (!$trim_only);
unless ($debug){
unlink $nuc_composition_file;
unlink $quality_matrix;
unlink $base_matrix;
unlink $avg_quality_histogram;
unlink $length_histogram;
unlink $qa_nuc_composition_file;
unlink $qa_quality_matrix;
unlink $qa_base_matrix;
unlink $qa_avg_quality_histogram;
unlink $qa_length_histogram;
unlink $kmer_files;
if ($kmer_rarefaction_on)
{
# unlink $kmer_rarefaction_file;
# unlink $kmer_histogram_file;
}
}
# END MAIN
exit(0);
sub build_initial_quality_matrix # not used yet
{
my $fastqFile=shift;
open (my $fh, "$fastqFile") or die "$fastqFile $!";
my %basequal;
my $total_reads=0;
while(<$fh>)
{
last if ($total_reads>2000000);
my $name=$_;
my $seq=<$fh>;
$seq =~ s/\n//g;
while ($seq !~ /\+/)
{
$seq .= <$fh>;
$seq =~ s/\n//g;
}
my $q_id_pos=index($seq,"+");
$seq = substr($seq, 0, $q_id_pos);
my $seq_len = length $seq;
my $qual_seq=<$fh>;
$qual_seq =~ s/\n//g;
my $qual_seq_len = length $qual_seq;
while ( $qual_seq_len < $seq_len )
{
last if ( $qual_seq_len == $seq_len);
$qual_seq .= <$fh>;
$qual_seq =~ s/\n//g;
$qual_seq_len = length $qual_seq;
}
my @qual_seq=split //, $qual_seq;
if (rand() <=0.2) {
$total_reads++;
for my $pos(0..$#qual_seq)
{
push @{$basequal{$pos}}, ord($qual_seq[$pos])-$ascii;
}
}
}
close $fh;
@{$basequal{$_}}= sort {$a <=> $b} @{$basequal{$_}} foreach (keys %basequal);
return \%basequal;
}
sub run_kmercount
{
my $hash_ref =shift;
my $kmer =shift;
my $mate = shift;
my $file= ($qc_only)?$hash_ref->{"file_name_$mate"}:$hash_ref->{"trim_file_name_$mate"};
my $cmd = "jellyfish count -C -s 512M -c 3 -m $kmer -o $file$prefix $file";
if (system($cmd)){
die "$!\n";
}
}
sub Kmer_rarefaction {
my $old_merge;
my $count=0;
my $new_merge="$outDir/${prefix}tmpKmerMerge${$}$count";
my (@kmercount,$distinct_kmer,$total_kmer);
#opendir (DIR, $outDir);
#my @files=grep { /${prefix}_0/ } readdir(DIR);
#closedir DIR;
open (KMER, ">$kmer_rarefaction_file") or die "$!\n";
open (FILES, "$kmer_files") or die "$!\n";
while (<FILES>)
#for my $i(0..$#files)
{
chomp;
#my $subset_kmer_file="$outDir/$files[$i]";
my ($subset_kmer_file, $seq_num) = split /\t/, $_;
# jellyfish v1 output xxxx_0 count result. jellyfish 2 doesn't not
$subset_kmer_file = ( -e "$subset_kmer_file${prefix}_0")?"$subset_kmer_file${prefix}_0":"$subset_kmer_file$prefix";
#my ($subset_file_name) = $subset_kmer_file =~ /(\S+)${prefix}_0/;
#$sequence_num += $subfile_size_hash{$subset_file_name};
if ($count==0)
{
@kmercount=`jellyfish stats $subset_kmer_file | grep -A 1 'Distinct' | awk '{print \$2}'`;
($distinct_kmer) = $kmercount[0] =~ /(\d+)/;
($total_kmer) = $kmercount[1] =~ /(\d+)/;
print KMER $seq_num . "\t". $distinct_kmer. "\t". $total_kmer."\n";
$old_merge=$subset_kmer_file;
$count++;
}
else
{
`jellyfish merge -o $new_merge $old_merge $subset_kmer_file `;
@kmercount=`jellyfish stats $new_merge | grep -A 1 'Distinct' | awk '{print \$2}'`;
($distinct_kmer) = $kmercount[0] =~ /(\d+)/;
($total_kmer) = $kmercount[1] =~ /(\d+)/;
unlink $old_merge;
unlink $subset_kmer_file;
$old_merge=$new_merge;
$new_merge="$outDir/${prefix}tmpKmerMerge${$}$count";
print KMER $seq_num . "\t". $distinct_kmer. "\t". $total_kmer."\n";
$count++;
}
}
close FILES;
close KMER;
`jellyfish histo -o $kmer_histogram_file $old_merge`;
unlink $old_merge;
}
sub print_final_stats{
open (my $fh, ">$stats_output") or die "$!\t$stats_output\n";
$readsFilterByLen = $filter_stats{len}->{readsNum};
$basesFilterByLen = $filter_stats{len}->{basesNum};
$readsTrimByQual = $filter_stats{qualTrim}->{readsNum};
$basesTrimByQual = $filter_stats{qualTrim}->{basesNum};
$readsFilterByNN = $filter_stats{NN}->{readsNum};
$basesFilterByNN = $filter_stats{NN}->{basesNum};
$readsFilterByPhiX = $filter_stats{phiX}->{readsNum};
$basesFilterByPhiX = $filter_stats{phiX}->{basesNum};
$readsTrimByAdapter = $filter_stats{adapter}->{readsNum};
$basesTrimByAdapter = $filter_stats{adapter}->{basesNum};
$readsFilterByAvgQ = $filter_stats{AvgQ}->{readsNum};
$basesFilterByAvgQ = $filter_stats{AvgQ}->{basesNum};
$readsFilterByLowComplexity = $filter_stats{lowComplexity}->{readsNum};
$basesFilterByLowComplexity = $filter_stats{lowComplexity}->{basesNum};
# stats
if ($qc_only)
{
print $fh "\n";
print $fh "Reads #: $total_count\n";
print $fh "Total bases: $total_len\n";
printf $fh ("Reads Length: %.2f\n",$total_len/$total_count);
print $fh "Processed $total_num reads for quality check only\n";
printf $fh (" Reads length < %d bp: %d (%.2f %%)\n", $opt_min_L, $readsFilterByLen , ($readsFilterByLen)/$total_num*100);
printf $fh (" Reads have %d continuous base \"N\": %d (%.2f %%)\n", $N_num_cutoff, $readsFilterByNN , ($readsFilterByNN)/$total_num*100);
printf $fh (" Low complexity Reads (>%.2f%% mono/di-nucleotides): %d (%.2f %%)\n", $low_complexity_cutoff_ratio*100, $readsFilterByLowComplexity , ($readsFilterByLowComplexity)/$total_num*100);
printf $fh (" Reads < average quality %.1f: %d (%.2f %%)\n", $opt_avg_cutoff, $readsFilterByAvgQ , ($readsFilterByAvgQ)/$total_num*100);
printf $fh (" Reads hits to phiX sequence: %d (%.2f %%)\n", $readsFilterByPhiX , ($readsFilterByPhiX)/$total_num*100) if ($filter_phiX);
if ($filter_adapter)
{
printf $fh (" Reads with Adapters/Primers: %d (%.2f %%)\n", $readsTrimByAdapter , ($readsTrimByAdapter)/$total_num*100);
foreach my $adapter_id (keys %EachAdapter)
{
my $affect_reads = $EachAdapter{$adapter_id}->{readsNum};
my $affect_bases = $EachAdapter{$adapter_id}->{basesNum};
printf $fh (" %s %d reads (%.2f %%) %d bases (%.2f %%)\n", $adapter_id, $affect_reads, $affect_reads/$total_num*100,$affect_bases, $affect_bases/$total_raw_seq_len*100);
}
}
}
else
{
# print $fh "\nQC process\n";
print $fh "Before Trimming\n";
print $fh "Reads #: $total_num\n";
print $fh "Total bases: $total_raw_seq_len\n";
printf $fh ("Reads Length: %.2f\n",$total_raw_seq_len/$total_num);
print $fh "\nAfter Trimming\n";
printf $fh ("Reads #: %d (%.2f %%)\n",$trimmed_num, $trimmed_num/$total_num*100);
printf $fh ("Total bases: %d (%.2f %%)\n",$total_trimmed_seq_len,$total_trimmed_seq_len/$total_raw_seq_len*100);
if ($trimmed_num)
{
printf $fh ("Mean Reads Length: %.2f\n",$total_trimmed_seq_len/$trimmed_num);
}
else
{
printf $fh "Mean Reads Length: 0\n";
}
if (@make_paired_paired_files){
printf $fh (" Paired Reads #: %d (%.2f %%)\n",$paired_seq_num, $paired_seq_num/$trimmed_num*100);
printf $fh (" Paired total bases: %d (%.2f %%)\n",$total_paired_bases,$total_paired_bases/$total_trimmed_seq_len*100);
printf $fh (" Unpaired Reads #: %d (%.2f %%)\n", $trimmed_num - $paired_seq_num, ($trimmed_num - $paired_seq_num)/$trimmed_num*100);
printf $fh (" Unpaired total bases: %d (%.2f %%)\n", $total_trimmed_seq_len - $total_paired_bases , ($total_trimmed_seq_len - $total_paired_bases)/$total_trimmed_seq_len*100);
}
printf $fh ("\nDiscarded reads #: %d (%.2f %%)\n", $total_num - $trimmed_num , ($total_num - $trimmed_num)/$total_num*100);
printf $fh ("Trimmed bases: %d (%.2f %%)\n", $total_raw_seq_len - $total_trimmed_seq_len, ($total_raw_seq_len - $total_trimmed_seq_len)/$total_raw_seq_len*100);
printf $fh (" Reads Filtered by length cutoff (%d bp): %d (%.2f %%)\n", $opt_min_L, $readsFilterByLen , ($readsFilterByLen)/$total_num*100);
printf $fh (" Bases Filtered by length cutoff: %d (%.2f %%)\n", $basesFilterByLen , ($basesFilterByLen)/$total_raw_seq_len*100);
printf $fh (" Reads Filtered by continuous base \"N\" (%d): %d (%.2f %%)\n", $N_num_cutoff, $readsFilterByNN , ($readsFilterByNN)/$total_num*100);
printf $fh (" Bases Filtered by continuous base \"N\": %d (%.2f %%)\n", $basesFilterByNN , ($basesFilterByNN)/$total_raw_seq_len*100);
printf $fh (" Reads Filtered by low complexity ratio (%.1f): %d (%.2f %%)\n", $low_complexity_cutoff_ratio, $readsFilterByLowComplexity , ($readsFilterByLowComplexity)/$total_num*100);
printf $fh (" Bases Filtered by low complexity ratio: %d (%.2f %%)\n", $basesFilterByLowComplexity , ($basesFilterByLowComplexity)/$total_raw_seq_len*100);
if ($opt_avg_cutoff>0)
{
printf $fh (" Reads Filtered by avg quality (%.1f): %d (%.2f %%)\n", $opt_avg_cutoff, $readsFilterByAvgQ , ($readsFilterByAvgQ)/$total_num*100);
printf $fh (" Bases Filtered by avg quality: %d (%.2f %%)\n", $basesFilterByAvgQ , ($basesFilterByAvgQ)/$total_raw_seq_len*100);
}
if ($filter_phiX)
{
printf $fh (" Reads Filtered by phiX sequence: %d (%.2f %%)\n", $readsFilterByPhiX , ($readsFilterByPhiX)/$total_num*100);
printf $fh (" Bases Filtered by phiX sequence: %d (%.2f %%)\n", $basesFilterByPhiX , ($basesFilterByPhiX)/$total_raw_seq_len*100);
}
printf $fh (" Reads Trimmed by quality (%.1f): %d (%.2f %%)\n", $opt_q, $readsTrimByQual , ($readsTrimByQual)/$total_num*100);
printf $fh (" Bases Trimmed by quality: %d (%.2f %%)\n", $basesTrimByQual , ($basesTrimByQual)/$total_raw_seq_len*100);
if ($trim_5_end)
{
printf $fh (" Reads Trimmed with %d bp from 5' end\n", $trim_5_end);
}
if ($trim_3_end)
{
printf $fh (" Reads Trimmed with %d bp from 3' end\n", $trim_3_end);
}
if ($filter_adapter){
printf $fh (" Reads Trimmed with Adapters/Primers: %d (%.2f %%)\n", $readsTrimByAdapter , ($readsTrimByAdapter)/$total_num*100);
printf $fh (" Bases Trimmed with Adapters/Primers: %d (%.2f %%)\n", $basesTrimByAdapter , ($basesTrimByAdapter)/$total_raw_seq_len*100);
foreach my $adapter_id (keys %EachAdapter)
{
my $affect_reads = $EachAdapter{$adapter_id}->{readsNum};
my $affect_bases = $EachAdapter{$adapter_id}->{basesNum};
printf $fh (" %s %d reads (%.2f %%) %d bases (%.2f %%)\n", $adapter_id, $affect_reads, $affect_reads/$total_num*100,$affect_bases, $affect_bases/$total_raw_seq_len*100);
}
}
if ($replace_N)
{
printf $fh ("\nN base random substitution: A %d, T %d, C %d, G %d\n",$EachReplaceN{A},$EachReplaceN{T},$EachReplaceN{C},$EachReplaceN{G});
}
} # end qc only
return (0);
}
sub plot_by_R
{
open (R,">$outDir/tmp$$.R");
print R <<RSCRIPT;
if(file.exists(\"$qa_length_histogram\")){
pdf(file = \"$plots_file\",width=15,height=7)
}else{
pdf(file = \"$plots_file\",width=10,height=8)
}
def.par <- par(no.readonly = TRUE) # get default parameters
#Summary
par(family="mono")
SummaryStats<-readLines("$stats_output")
plot(0:1,0:1,type=\'n\',xlab=\"\",ylab=\"\",xaxt=\'n\',yaxt=\'n\',bty=\'n\')
if ($qc_only){
for (i in 1:length(SummaryStats)){
text(0.05,1-0.04*(i-1),SummaryStats[i],adj=0,font=2,cex=1)
}
}else{
if ($paired_seq_num > 0) {
adjust <-14
abline(h=0.73,lty=2)
}else{
adjust<-11
abline(h=0.85,lty=2)
}
for (i in 1:length(SummaryStats)){
if (i>5 && i<adjust){
text(0.45,1-0.035*(i-6),SummaryStats[i],adj=0,font=2,cex=0.9)
}else if(i >=adjust){
text(0.05,1-0.035*(i-6),SummaryStats[i],adj=0,font=2,cex=0.9)
}else{
text(0.05,1-0.035*(i-1),SummaryStats[i],adj=0,font=2,cex=0.9)
}
}
}
#title(paste(\"$prefix\",\"QC report\"),sub = 'DOE Joint Genome Institute/Los Alamos National Laboratory', adj = 0.5, col.sub='darkblue',font.sub=2,cex.sub=0.8)
title("QC stats")
par(def.par)#- reset to default
#lenght histogram
length_histogram <- function(length_count_file, xlab,ylab){
lengthfile<-read.table(file=length_count_file)
lengthList<-as.numeric(lengthfile\$V1)
lengthCount<-as.numeric(lengthfile\$V2)
lenAvg<-sum(lengthList * lengthCount)/sum(lengthCount)
lenStd<-sqrt(sum(((lengthList - lenAvg)**2)*lengthCount)/sum(lengthCount))
lenMax<-max(lengthList[lengthCount>0])
lenMin<-min(lengthList[lengthCount>0])
totalReads<-sum(lengthCount)
barplot(lengthCount/1000000,names.arg=lengthList,xlab=xlab,ylab=ylab,cex.names=0.8)
legend.txt<-c(paste("Mean",sprintf ("%.2f",lenAvg),"±",sprintf ("%.2f",lenStd)),paste("Max",lenMax),paste("Min",lenMin))
legend('topleft',legend.txt,bty='n')
if (totalReads< $trimmed_num){
mtext(side=3,paste(\"(Sampling\",formatC(totalReads/1000000,digits=3),\"M Reads)\"),adj=0)
}
return(totalReads)
}
if(file.exists(\"$qa_length_histogram\")){
par(mfrow=c(1,2),mar=c(5,6,4,2))
qa.readsCount<-length_histogram(\"$qa_length_histogram\","Input Length","Count (millions)")
readsCount<-length_histogram(\"$length_histogram\","Trimmed Length","")
}else{
readsCount<-length_histogram(\"$length_histogram\","Length","Count (millions)")
}
par(def.par)#- reset to default
title("Reads Length Histogram")
#readGC plot
readGC_plot <- function(base_content_file, totalReads, fig_x_start,fig_x_end,xlab,ylab,new){
baseP<-read.table(file=base_content_file)
Apercent<-baseP\$V2[which(baseP\$V1=="A")]
ApercentCount<-baseP\$V3[which(baseP\$V1=="A")]
Tpercent<-baseP\$V2[which(baseP\$V1=="T")]
TpercentCount<-baseP\$V3[which(baseP\$V1=="T")]
Cpercent<-baseP\$V2[which(baseP\$V1=="C")]
CpercentCount<-baseP\$V3[which(baseP\$V1=="C")]
Gpercent<-baseP\$V2[which(baseP\$V1=="G")]