line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# POD documentation - main docs before the code |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
GenOO::Data::File::FASTQ - Object implementing methods for accessing fastq formatted files |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Object that manages a fastq file. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# To initialize |
12
|
|
|
|
|
|
|
my $file = GenOO::Data::File::FASTQ->new( |
13
|
|
|
|
|
|
|
file => undef, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This object offers methods to read a fastq file entry by entry |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 EXAMPLES |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Read one entry |
23
|
|
|
|
|
|
|
my $entry = $fastq_parser->next_record(); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Let the code begin... |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package GenOO::Data::File::FASTQ; |
30
|
|
|
|
|
|
|
$GenOO::Data::File::FASTQ::VERSION = '1.5.2'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
####################################################################### |
33
|
|
|
|
|
|
|
####################### Load External modules ##################### |
34
|
|
|
|
|
|
|
####################################################################### |
35
|
1
|
|
|
1
|
|
5632
|
use Modern::Perl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
36
|
1
|
|
|
1
|
|
190
|
use autodie; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
37
|
1
|
|
|
1
|
|
5807
|
use Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
13
|
|
38
|
1
|
|
|
1
|
|
7961
|
use namespace::autoclean; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
11
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
####################################################################### |
42
|
|
|
|
|
|
|
######################### Load GenOO modules ###################### |
43
|
|
|
|
|
|
|
####################################################################### |
44
|
1
|
|
|
1
|
|
116
|
use GenOO::Data::File::FASTQ::Record; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
706
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
####################################################################### |
48
|
|
|
|
|
|
|
####################### Interface attributes ###################### |
49
|
|
|
|
|
|
|
####################################################################### |
50
|
|
|
|
|
|
|
has 'file' => ( |
51
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
52
|
|
|
|
|
|
|
is => 'rw', |
53
|
|
|
|
|
|
|
required => 1 |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has 'records_read_count' => ( |
57
|
|
|
|
|
|
|
traits => ['Counter'], |
58
|
|
|
|
|
|
|
is => 'ro', |
59
|
|
|
|
|
|
|
isa => 'Num', |
60
|
|
|
|
|
|
|
default => 0, |
61
|
|
|
|
|
|
|
handles => { |
62
|
|
|
|
|
|
|
_inc_records_read_count => 'inc', |
63
|
|
|
|
|
|
|
_reset_records_read_count => 'reset', |
64
|
|
|
|
|
|
|
}, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
####################################################################### |
69
|
|
|
|
|
|
|
######################## Private attributes ####################### |
70
|
|
|
|
|
|
|
####################################################################### |
71
|
|
|
|
|
|
|
has '_filehandle' => ( |
72
|
|
|
|
|
|
|
is => 'ro', |
73
|
|
|
|
|
|
|
builder => '_open_filehandle', |
74
|
|
|
|
|
|
|
init_arg => undef, |
75
|
|
|
|
|
|
|
lazy => 1, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
####################################################################### |
80
|
|
|
|
|
|
|
######################## Interface Methods ######################## |
81
|
|
|
|
|
|
|
####################################################################### |
82
|
|
|
|
|
|
|
sub next_record { |
83
|
43
|
|
|
43
|
0
|
1483
|
my ($self) = @_; |
84
|
|
|
|
|
|
|
|
85
|
43
|
|
|
|
|
1151
|
my $filehandle = $self->_filehandle; |
86
|
43
|
|
|
|
|
779
|
while (my $line = $filehandle->getline) { |
87
|
42
|
50
|
|
|
|
1461
|
if ($line =~ /^\@/) { |
88
|
42
|
|
|
|
|
116
|
my $id = substr($line,1); |
89
|
42
|
|
|
|
|
92
|
chomp($id); |
90
|
42
|
|
|
|
|
88
|
$id =~ s/\r//g; |
91
|
42
|
|
|
|
|
759
|
my $seq = $filehandle->getline; |
92
|
42
|
|
|
|
|
956
|
chomp($seq); |
93
|
42
|
|
|
|
|
89
|
$seq =~ s/\r//g; |
94
|
42
|
|
|
|
|
683
|
$filehandle->getline; #unused line |
95
|
42
|
|
|
|
|
1446
|
my $quality = $filehandle->getline; |
96
|
42
|
|
|
|
|
910
|
chomp($quality); |
97
|
42
|
|
|
|
|
77
|
$quality =~ s/\r//g; |
98
|
|
|
|
|
|
|
|
99
|
42
|
|
|
|
|
1587
|
$self->_inc_records_read_count; |
100
|
42
|
|
|
|
|
113
|
return $self->_create_record($id, $seq, $quality); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
1
|
|
|
|
|
52
|
return undef; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
####################################################################### |
107
|
|
|
|
|
|
|
####################### Private Methods ############################ |
108
|
|
|
|
|
|
|
####################################################################### |
109
|
|
|
|
|
|
|
sub _open_filehandle { |
110
|
2
|
|
|
2
|
|
4
|
my ($self) = @_; |
111
|
|
|
|
|
|
|
|
112
|
2
|
|
|
|
|
4
|
my $read_mode; |
113
|
|
|
|
|
|
|
my $HANDLE; |
114
|
2
|
50
|
|
|
|
53
|
if (!defined $self->file) { |
|
|
50
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
open ($HANDLE, '<-', $self->file); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
elsif ($self->file =~ /\.gz$/) { |
118
|
2
|
50
|
|
|
|
54
|
die 'Cannot open file ' . $self->file . "\n" if ! -e $self->file; |
119
|
2
|
|
|
|
|
65
|
open($HANDLE, 'gzip -dc ' . $self->file . ' |'); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
0
|
|
|
|
|
0
|
open ($HANDLE, '<', $self->file); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
2
|
|
|
|
|
16320
|
return $HANDLE; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _create_record { |
129
|
42
|
|
|
42
|
|
98
|
my ($self, $id, $seq, $quality) = @_; |
130
|
|
|
|
|
|
|
|
131
|
42
|
|
|
|
|
1247
|
return GenOO::Data::File::FASTQ::Record->new( |
132
|
|
|
|
|
|
|
name => $id, |
133
|
|
|
|
|
|
|
sequence => $seq, |
134
|
|
|
|
|
|
|
quality => $quality, |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
####################################################################### |
139
|
|
|
|
|
|
|
############################ Finalize ############################# |
140
|
|
|
|
|
|
|
####################################################################### |
141
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |