forked from lh3/readfq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readfq.pl
57 lines (54 loc) · 1.08 KB
/
readfq.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
#!/usr/bin/env perl
use strict;
use warnings;
sub readfq {
my ($fh, $aux) = @_;
@$aux = [undef, 0] if (!defined(@$aux));
return if ($aux->[1]);
if (!defined($aux->[0])) {
while (<$fh>) {
chomp;
if (substr($_, 0, 1) eq '>' || substr($_, 0, 1) eq '@') {
$aux->[0] = $_;
last;
}
}
if (!defined($aux->[0])) {
$aux->[1] = 1;
return;
}
}
my $name = /^.(\S+)/? $1 : '';
my $seq = '';
my $c;
$aux->[0] = undef;
while (<$fh>) {
chomp;
$c = substr($_, 0, 1);
last if ($c eq '>' || $c eq '@' || $c eq '+');
$seq .= $_;
}
$aux->[0] = $_;
$aux->[1] = 1 if (!defined($aux->[0]));
return ($name, $seq) if ($c ne '+');
my $qual = '';
while (<$fh>) {
chomp;
$qual .= $_;
if (length($qual) >= length($seq)) {
$aux->[0] = undef;
return ($name, $seq, $qual);
}
}
$aux->[1] = 1;
return ($name, $seq);
}
my @aux = undef;
my ($name, $seq, $qual);
my ($n, $slen, $qlen) = (0, 0, 0);
while (($name, $seq, $qual) = readfq(\*STDIN, \@aux)) {
++$n;
$slen += length($seq);
$qlen += length($qual) if ($qual);
}
print join("\t", $n, $slen, $qlen), "\n";