forked from gringer/bioinfscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fastx-qualHist.pl
executable file
·70 lines (61 loc) · 1.44 KB
/
fastx-qualHist.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
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long qw(:config auto_help pass_through);
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
my $idFileName = "";
my $quiet = 0;
my $base = 33;
GetOptions("idfile=s" => \$idFileName, "quiet!" => \$quiet,
"base" => \$base ) or
die("Error in command line arguments");
# unknown commands are treated as identifiers
my @files = ();
while(@ARGV){
my $arg = shift(@ARGV);
if(-f $arg){
push(@files, $arg);
}
}
@ARGV = @files;
my %qualCounts = ();
my $baseCount = 0;
my $inQual = 0; # false
my $seqID = "";
my $qualID = "";
my $seq = "";
my $qual = "";
while(<>){
chomp;
chomp;
if(!$inQual){
if(/^(>|@)((.+?)( .*?\s*)?)$/){
my $newSeqID = $2;
my $newShortID = $3;
$seq = "";
$qual = "";
$seqID = $newSeqID;
} elsif(/^\+(.*)$/) {
$inQual = 1; # true
$qualID = $1;
} else {
$seq .= $_;
}
} else {
grep {$qualCounts{$_}++} split(//,$_);
$baseCount += length($_);
$qual .= $_;
if(length($qual) >= length($seq)){
$inQual = 0; # false
}
}
}
my $cumCount = 0;
foreach my $qualChar (sort(keys(%qualCounts))){
$cumCount += $qualCounts{$qualChar};
printf("%s [%2d]: %6d (%6.2f%% / %6.2f%% )\n",
$qualChar, ord($qualChar) - $base,
$qualCounts{$qualChar}, $qualCounts{$qualChar} * 100 / $baseCount,
$cumCount * 100 / $baseCount);
}
printf("Total sequence length: %d\n", $baseCount);