Seq/Stream/FASTQ.pm

filter: Statementstmt 100% 45 / 45 Branchbran 75.0% 12 / 16 Conditioncond 60.0% 6 / 10 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 84.5% 71 / 84 CC 13 SCAR 20.4
CC
13
Cov
89%
next_seq
11.4
_init
3.0
BEGIN
1.0
CRAP 7.7
« Seq/Stream.pm ↑ Summary Seq/Stream/FASTA.pm »
1 package BioX::Seq::Stream::FASTQ;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use parent qw/BioX::Seq::Stream/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 ▶sub _check_type {
Subroutine _check_type: called CC=1 SCAR=0.0
9  
10 15 my ($class,$self) = @_;
11 15 return substr($self->{buffer},0,1) eq '@';
12  
13 }
14  
15 3 ▶sub _init {
Subroutine _init: called CC=3 SCAR=11.0
16  
17 3 my ($self) = @_;
18  
19 # First two bytes should not contain line ending chars
20 die "Missing ID in initial header (check file format)\n"
21 3 ▶ if ($self->{buffer} =~ /[\r\n]/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"buffer"} =~ /[\r\n]/ 0 3 3
22 3 my $fh = $self->{fh};
23 3 $self->{buffer} .= <$fh>;
24  
25 # detect line endings for text files based on first line
26 # (other solutions, such as using the :crlf layer or s///
27 # instead of chomp may be marginally more robust but slow
28 # things down too much)
29 3 ▶ if ($self->{buffer} =~ /([\r\n]{1,2})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'buffer'} =~ /([\r\n]{1,2})$/) { } 2 1 3
30 2 $self->{rec_sep} = $1;
31 }
32 else {
33 1 die "Failed to detect line endings\n";
34 }
35  
36 2 return;
37
38 }
39  
40 4 ▶sub next_seq {
Subroutine next_seq: called CC=11 SCAR=24.3
Pod documented
41
42 4 my ($self) = @_;
43 4 my $fh = $self->{fh};
44  
45 4 local $/ = $self->{rec_sep};
46  
47 4 ▶ my $line = $self->{buffer} // <$fh>;
Condition66%2/3
$self->{"buffer"} // readline $fh
l!l&&r!l&&!r
220
MC/DC0%0/2
$self->{"buffer"} // readline $fh
$self->{"buffer"} readline $fh
Truth table66%2/3
A // B
A= $self->{"buffer"}B= readline $fh
ABresult
1X1
011
000
48 4 ▶ return if (! defined $line);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 4 4
49 4 chomp $line;
50  
51 4 my ($id, $desc) = ($line =~ /^\@(\S+)\s*(.+)?$/);
52 4 ▶ die "Bad FASTQ ID line\n" if (! defined $id);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 4 4
53  
54 # seq and qual can be multiline (although rare)
55 # qual is tricky since it can contain '@' but we compare to the
56 # sequence length to know when to stop parsing (must be equal lengths)
57 4 ▶ my $seq = <$fh> // die "Bad or missing FASTQ sequence";
Condition50%1/2
readline $fh // die("Bad or missing FASTQ sequence")
l!l
40
MC/DC0%0/1
readline $fh // die("Bad or missing FASTQ sequence")
readline $fh
Truth table50%1/2
A
A= readline $fh
Aresult
11
00
58 4 chomp $seq;
59  
60 SEQ:
61 4 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 5 0 5
62 5 chomp $line;
63 5 ▶ last SEQ if ($line =~ /^\+/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\+/ 4 1 5
64 1 $seq .= $line;
65 }
66  
67 4 my $seq_len = length $seq;
68  
69 4 ▶ QUAL:
Condition50%1/2
readline $fh // die("Bad or missing FASTQ format")
l!l
40
MC/DC0%0/1
readline $fh // die("Bad or missing FASTQ format")
readline $fh
Truth table50%1/2
A
A= readline $fh
Aresult
11
00
70 my $qual = <$fh> // die "Bad or missing FASTQ format";
71 4 chomp $qual;
72  
73 4 ▶ while ( (length($qual) < $seq_len) && defined (my $line = <$fh>) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $qual < $seq_len and defined(my $line = readline $fh)) 2 4 6
Condition66%2/3
length $qual < $seq_len and defined(my $line = readline $fh)
!ll&&!rl&&r
402
MC/DC50%1/2
length $qual < $seq_len and defined(my $line = readline $fh)
length $qual < $seq_len defined(my $line = readline $fh)
Truth table66%2/3
A and B
A= length $qual < $seq_lenB= defined(my $line = readline $fh)
ABresult
0X0
100
111
74 2 chomp $line;
75 2 $qual .= $line;
76 }
77 4 ▶ die "Bad FASTQ quality length" if ($seq_len != length($qual));
Branch: 1 branch
BranchTrueFalseTotal
if $seq_len != length $qual 1 3 4
78  
79 3 $self->{buffer} = undef;
80  
81 3 my $obj = BioX::Seq->new($seq, $id, $desc, $qual);
82 3 $obj->{_input_format} = 'fastq';
83 3 return $obj;
84  
85 }
86  
87 2 1;
88  
89 __END__
« Seq/Stream.pm ↑ Summary Seq/Stream/FASTA.pm »