line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CracTools::GFF::Annotation; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$CracTools::GFF::Annotation::DIST = 'CracTools'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Parse GFF lines. |
6
|
|
|
|
|
|
|
$CracTools::GFF::Annotation::VERSION = '1.25'; |
7
|
2
|
|
|
2
|
|
14044
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
45
|
|
8
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
37
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
6
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
103
|
|
11
|
2
|
|
|
2
|
|
841
|
use CracTools::Utils; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1291
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
33
|
|
|
33
|
1
|
1420
|
my $class = shift; |
16
|
33
|
|
|
|
|
27
|
my $line = shift; |
17
|
33
|
|
|
|
|
26
|
my $format = shift; |
18
|
33
|
100
|
|
|
|
86
|
if(!defined $format) { |
19
|
31
|
|
|
|
|
28
|
$format = 'gff3'; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
33
|
|
|
|
|
50
|
my $self = bless {format => $format}, $class; |
23
|
|
|
|
|
|
|
|
24
|
33
|
50
|
|
|
|
49
|
if(defined $line) { |
25
|
33
|
|
|
|
|
46
|
$self->_init($line); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
33
|
|
|
|
|
52
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _init { |
32
|
33
|
|
|
33
|
|
28
|
my ($self,$line) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Split the line with TABS |
35
|
33
|
|
|
|
|
109
|
my ($chr,$source,$feature,$start,$end,$score,$strand,$phase,$attributes) = split("\t",$line); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Get the strand if 1/-1 format |
38
|
33
|
|
|
|
|
54
|
$strand = CracTools::Utils::convertStrand($strand); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# We do not want any "chr" string before the reference sequence value |
41
|
33
|
|
|
|
|
32
|
$chr =~ s/^chr//; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Loading the 8 first columns |
44
|
33
|
|
|
|
|
37
|
$self->{chr} = $chr; |
45
|
33
|
|
|
|
|
26
|
$self->{source} = $source; |
46
|
33
|
|
|
|
|
28
|
$self->{feature} = $feature; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Conversion to 0-based coordinate system |
49
|
33
|
|
|
|
|
47
|
$self->{start} = $start-1; |
50
|
33
|
|
|
|
|
35
|
$self->{end} = $end-1; |
51
|
|
|
|
|
|
|
|
52
|
33
|
|
|
|
|
22
|
$self->{score} = $score; |
53
|
33
|
|
|
|
|
45
|
$self->{strand} = $strand; |
54
|
33
|
|
|
|
|
33
|
$self->{phase} = $phase; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Loading attributes |
57
|
33
|
|
|
|
|
51
|
my @attributes_tab = split(";",$attributes); |
58
|
33
|
|
|
|
|
38
|
foreach my $attr (@attributes_tab) { |
59
|
104
|
|
|
|
|
58
|
my ($k,$v); |
60
|
104
|
100
|
66
|
|
|
248
|
if($self->{format} =~ /gff3/i || $self->{format} =~ /gff$/i) { |
|
|
50
|
|
|
|
|
|
61
|
102
|
|
|
|
|
240
|
($k,$v) = $attr =~ /(\S+)=(.*)/; |
62
|
|
|
|
|
|
|
} elsif ($self->{format} =~ /gtf/i){ |
63
|
2
|
|
|
|
|
9
|
($k,$v) = $attr =~ /(\S+)\s+"(.*)"/; |
64
|
|
|
|
|
|
|
}else{ |
65
|
0
|
|
|
|
|
0
|
croak "Missing format argument (gff3,gtf) in CracTools::GFF::Annotation constructor"; |
66
|
|
|
|
|
|
|
} |
67
|
104
|
50
|
33
|
|
|
296
|
if(defined $k && defined $v) { |
68
|
104
|
100
|
|
|
|
122
|
if($k eq "Parent") { |
69
|
29
|
|
|
|
|
71
|
my @parents = split(',',$v); |
70
|
29
|
|
|
|
|
35
|
$v = \@parents; |
71
|
|
|
|
|
|
|
} |
72
|
104
|
|
|
|
|
176
|
$self->{attributes}{$k} = $v; |
73
|
|
|
|
|
|
|
} #else { |
74
|
|
|
|
|
|
|
# carp("Error parsing attribute $attr"); |
75
|
|
|
|
|
|
|
#} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub chr { |
82
|
32
|
|
|
32
|
1
|
36
|
my $self = shift; |
83
|
32
|
|
|
|
|
22
|
my $chr = shift; |
84
|
32
|
50
|
|
|
|
43
|
if(defined $chr) { |
85
|
0
|
|
|
|
|
0
|
$self->{chr} = $chr; |
86
|
|
|
|
|
|
|
} |
87
|
32
|
|
|
|
|
52
|
return $self->{chr}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub source { |
92
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
93
|
1
|
|
|
|
|
7
|
my $source = shift; |
94
|
1
|
50
|
|
|
|
4
|
if(defined $source) { |
95
|
0
|
|
|
|
|
0
|
$self->{source} = $source; |
96
|
|
|
|
|
|
|
} |
97
|
1
|
|
|
|
|
4
|
return $self->{source}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub feature { |
102
|
227
|
|
|
227
|
1
|
128
|
my $self = shift; |
103
|
227
|
|
|
|
|
134
|
my $feature = shift; |
104
|
227
|
50
|
|
|
|
232
|
if(defined $feature) { |
105
|
0
|
|
|
|
|
0
|
$self->{feature} = $feature; |
106
|
|
|
|
|
|
|
} |
107
|
227
|
|
|
|
|
413
|
return $self->{feature}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub start { |
112
|
33
|
|
|
33
|
1
|
37
|
my $self = shift; |
113
|
33
|
|
|
|
|
22
|
my $start = shift; |
114
|
33
|
50
|
|
|
|
41
|
if(defined $start) { |
115
|
0
|
|
|
|
|
0
|
$self->{start} = $start; |
116
|
|
|
|
|
|
|
} |
117
|
33
|
|
|
|
|
49
|
return $self->{start}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub end { |
122
|
34
|
|
|
34
|
1
|
299
|
my $self = shift; |
123
|
34
|
|
|
|
|
19
|
my $end = shift; |
124
|
34
|
50
|
|
|
|
40
|
if(defined $end) { |
125
|
0
|
|
|
|
|
0
|
$self->{end} = $end; |
126
|
|
|
|
|
|
|
} |
127
|
34
|
|
|
|
|
49
|
return $self->{end}; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub score { |
132
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
133
|
1
|
|
|
|
|
2
|
my $score = shift; |
134
|
1
|
50
|
|
|
|
3
|
if(defined $score) { |
135
|
0
|
|
|
|
|
0
|
$self->{score} = $score; |
136
|
|
|
|
|
|
|
} |
137
|
1
|
|
|
|
|
3
|
return $self->{score}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub strand { |
142
|
32
|
|
|
32
|
1
|
21
|
my $self = shift; |
143
|
32
|
|
|
|
|
19
|
my $strand = shift; |
144
|
32
|
50
|
|
|
|
38
|
if(defined $strand) { |
145
|
0
|
|
|
|
|
0
|
$self->{strand} = $strand; |
146
|
|
|
|
|
|
|
} |
147
|
32
|
|
|
|
|
83
|
return $self->{strand}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub gffStrand { |
152
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
153
|
1
|
|
|
|
|
2
|
return CracTools::Utils::convertStrand($self->{strand}); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub phase { |
158
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
159
|
1
|
|
|
|
|
1
|
my $phase = shift; |
160
|
1
|
50
|
|
|
|
3
|
if(defined $phase) { |
161
|
0
|
|
|
|
|
0
|
$self->{phase} = $phase; |
162
|
|
|
|
|
|
|
} |
163
|
1
|
|
|
|
|
4
|
return $self->{phase}; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub parents { |
168
|
113
|
|
|
113
|
1
|
71
|
my $self = shift; |
169
|
113
|
100
|
|
|
|
103
|
if(defined $self->attribute('Parent')) { |
170
|
78
|
|
|
|
|
75
|
return $self->attribute('Parent'); |
171
|
|
|
|
|
|
|
} else { |
172
|
35
|
|
|
|
|
49
|
return []; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub attribute { |
178
|
257
|
|
|
257
|
1
|
408
|
my $self = shift; |
179
|
257
|
|
|
|
|
153
|
my $key = shift; |
180
|
257
|
|
|
|
|
129
|
my $value = shift; |
181
|
257
|
100
|
|
|
|
304
|
if(defined $value) { |
|
|
50
|
|
|
|
|
|
182
|
1
|
|
|
|
|
3
|
return $self->{attributes}{$key} = $value; |
183
|
|
|
|
|
|
|
} elsif(defined $key) { |
184
|
256
|
|
|
|
|
431
|
return $self->{attributes}{$key}; |
185
|
|
|
|
|
|
|
} else { |
186
|
0
|
|
|
|
|
|
return undef; |
187
|
|
|
|
|
|
|
#croak ("Missing attribute key to retreive attribute value"); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
__END__ |