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