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.4.6'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
####################################################################### |
33
|
|
|
|
|
|
|
####################### Load External modules ##################### |
34
|
|
|
|
|
|
|
####################################################################### |
35
|
1
|
|
|
1
|
|
3707
|
use Modern::Perl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
36
|
1
|
|
|
1
|
|
168
|
use autodie; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
15
|
|
37
|
1
|
|
|
1
|
|
3921
|
use Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
15
|
|
38
|
1
|
|
|
1
|
|
6616
|
use namespace::autoclean; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
13
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
####################################################################### |
42
|
|
|
|
|
|
|
######################### Load GenOO modules ###################### |
43
|
|
|
|
|
|
|
####################################################################### |
44
|
1
|
|
|
1
|
|
91
|
use GenOO::Data::File::FASTQ::Record; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
455
|
|
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
|
737
|
my ($self) = @_; |
84
|
|
|
|
|
|
|
|
85
|
43
|
|
|
|
|
1236
|
my $filehandle = $self->_filehandle; |
86
|
43
|
|
|
|
|
788
|
while (my $line = $filehandle->getline) { |
87
|
42
|
50
|
|
|
|
1283
|
if ($line =~ /^\@/) { |
88
|
42
|
|
|
|
|
73
|
my $id = substr($line,1); chomp($id); |
|
42
|
|
|
|
|
55
|
|
89
|
42
|
|
|
|
|
658
|
my $seq = $filehandle->getline; chomp($seq); |
|
42
|
|
|
|
|
763
|
|
90
|
42
|
|
|
|
|
657
|
$filehandle->getline; #unused line |
91
|
42
|
|
|
|
|
1419
|
my $quality = $filehandle->getline; chomp($quality); |
|
42
|
|
|
|
|
787
|
|
92
|
|
|
|
|
|
|
|
93
|
42
|
|
|
|
|
1683
|
$self->_inc_records_read_count; |
94
|
42
|
|
|
|
|
86
|
return $self->_create_record($id, $seq, $quality); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
1
|
|
|
|
|
69
|
return undef; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
####################################################################### |
101
|
|
|
|
|
|
|
####################### Private Methods ############################ |
102
|
|
|
|
|
|
|
####################################################################### |
103
|
|
|
|
|
|
|
sub _open_filehandle { |
104
|
2
|
|
|
2
|
|
7
|
my ($self) = @_; |
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
3
|
my $read_mode; |
107
|
|
|
|
|
|
|
my $HANDLE; |
108
|
2
|
50
|
|
|
|
54
|
if (!defined $self->file) { |
|
|
50
|
|
|
|
|
|
109
|
0
|
|
|
|
|
0
|
open ($HANDLE, '<-', $self->file); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif ($self->file =~ /\.gz$/) { |
112
|
2
|
50
|
|
|
|
45
|
die 'Cannot open file ' . $self->file . "\n" if ! -e $self->file; |
113
|
2
|
|
|
|
|
56
|
open($HANDLE, 'gzip -dc ' . $self->file . ' |'); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
else { |
116
|
0
|
|
|
|
|
0
|
open ($HANDLE, '<', $self->file); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
2
|
|
|
|
|
9670
|
return $HANDLE; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _create_record { |
123
|
42
|
|
|
42
|
|
56
|
my ($self, $id, $seq, $quality) = @_; |
124
|
|
|
|
|
|
|
|
125
|
42
|
|
|
|
|
1319
|
return GenOO::Data::File::FASTQ::Record->new( |
126
|
|
|
|
|
|
|
name => $id, |
127
|
|
|
|
|
|
|
sequence => $seq, |
128
|
|
|
|
|
|
|
quality => $quality, |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
####################################################################### |
133
|
|
|
|
|
|
|
############################ Finalize ############################# |
134
|
|
|
|
|
|
|
####################################################################### |
135
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |