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.1'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
####################################################################### |
33
|
|
|
|
|
|
|
####################### Load External modules ##################### |
34
|
|
|
|
|
|
|
####################################################################### |
35
|
1
|
|
|
1
|
|
5958
|
use Modern::Perl; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
16
|
|
36
|
1
|
|
|
1
|
|
227
|
use autodie; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
37
|
1
|
|
|
1
|
|
5356
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
38
|
1
|
|
|
1
|
|
8394
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
####################################################################### |
42
|
|
|
|
|
|
|
######################### Load GenOO modules ###################### |
43
|
|
|
|
|
|
|
####################################################################### |
44
|
1
|
|
|
1
|
|
122
|
use GenOO::Data::File::FASTQ::Record; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
744
|
|
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
|
1349
|
my ($self) = @_; |
84
|
|
|
|
|
|
|
|
85
|
43
|
|
|
|
|
1714
|
my $filehandle = $self->_filehandle; |
86
|
43
|
|
|
|
|
1207
|
while (my $line = $filehandle->getline) { |
87
|
42
|
50
|
|
|
|
2097
|
if ($line =~ /^\@/) { |
88
|
42
|
|
|
|
|
131
|
my $id = substr($line,1); |
89
|
42
|
|
|
|
|
136
|
chomp($id); |
90
|
42
|
|
|
|
|
77
|
$id =~ s/\r//g; |
91
|
42
|
|
|
|
|
1337
|
my $seq = $filehandle->getline; |
92
|
42
|
|
|
|
|
1686
|
chomp($seq); |
93
|
42
|
|
|
|
|
83
|
$seq =~ s/\r//g; |
94
|
42
|
|
|
|
|
1200
|
$filehandle->getline; #unused line |
95
|
42
|
|
|
|
|
2429
|
my $quality = $filehandle->getline; |
96
|
42
|
|
|
|
|
1194
|
chomp($quality); |
97
|
42
|
|
|
|
|
71
|
$quality =~ s/\r//g; |
98
|
|
|
|
|
|
|
|
99
|
42
|
|
|
|
|
2370
|
$self->_inc_records_read_count; |
100
|
42
|
|
|
|
|
126
|
return $self->_create_record($id, $seq, $quality); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
1
|
|
|
|
|
54
|
return undef; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
####################################################################### |
107
|
|
|
|
|
|
|
####################### Private Methods ############################ |
108
|
|
|
|
|
|
|
####################################################################### |
109
|
|
|
|
|
|
|
sub _open_filehandle { |
110
|
2
|
|
|
2
|
|
5
|
my ($self) = @_; |
111
|
|
|
|
|
|
|
|
112
|
2
|
|
|
|
|
5
|
my $read_mode; |
113
|
|
|
|
|
|
|
my $HANDLE; |
114
|
2
|
50
|
|
|
|
92
|
if (!defined $self->file) { |
|
|
50
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
open ($HANDLE, '<-', $self->file); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
elsif ($self->file =~ /\.gz$/) { |
118
|
2
|
50
|
|
|
|
77
|
die 'Cannot open file ' . $self->file . "\n" if ! -e $self->file; |
119
|
2
|
|
|
|
|
83
|
open($HANDLE, 'gzip -dc ' . $self->file . ' |'); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
0
|
|
|
|
|
0
|
open ($HANDLE, '<', $self->file); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
2
|
|
|
|
|
22063
|
return $HANDLE; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _create_record { |
129
|
42
|
|
|
42
|
|
276
|
my ($self, $id, $seq, $quality) = @_; |
130
|
|
|
|
|
|
|
|
131
|
42
|
|
|
|
|
1856
|
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; |