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.22'; |
7
|
3
|
|
|
3
|
|
20451
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
74
|
|
8
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
71
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
13
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
183
|
|
11
|
3
|
|
|
3
|
|
1935
|
use CracTools::Utils; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
2936
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
36
|
|
|
36
|
1
|
1772
|
my $class = shift; |
16
|
36
|
|
|
|
|
49
|
my $line = shift; |
17
|
36
|
|
|
|
|
42
|
my $format = shift; |
18
|
36
|
100
|
|
|
|
77
|
if(!defined $format) { |
19
|
34
|
|
|
|
|
42
|
$format = 'gff3'; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
36
|
|
|
|
|
106
|
my $self = bless {format => $format}, $class; |
23
|
|
|
|
|
|
|
|
24
|
36
|
50
|
|
|
|
88
|
if(defined $line) { |
25
|
36
|
|
|
|
|
72
|
$self->_init($line); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
36
|
|
|
|
|
101
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _init { |
32
|
36
|
|
|
36
|
|
57
|
my ($self,$line) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Split the line with TABS |
35
|
36
|
|
|
|
|
181
|
my ($chr,$source,$feature,$start,$end,$score,$strand,$phase,$attributes) = split("\t",$line); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Get the strand if 1/-1 format |
38
|
36
|
|
|
|
|
114
|
$strand = CracTools::Utils::convertStrand($strand); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# We do not want any "chr" string before the reference sequence value |
41
|
36
|
|
|
|
|
55
|
$chr =~ s/^chr//; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Loading the 8 first columns |
44
|
36
|
|
|
|
|
80
|
$self->{chr} = $chr; |
45
|
36
|
|
|
|
|
58
|
$self->{source} = $source; |
46
|
36
|
|
|
|
|
55
|
$self->{feature} = $feature; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Conversion to 0-based coordinate system |
49
|
36
|
|
|
|
|
81
|
$self->{start} = $start-1; |
50
|
36
|
|
|
|
|
62
|
$self->{end} = $end-1; |
51
|
|
|
|
|
|
|
|
52
|
36
|
|
|
|
|
55
|
$self->{score} = $score; |
53
|
36
|
|
|
|
|
83
|
$self->{strand} = $strand; |
54
|
36
|
|
|
|
|
67
|
$self->{phase} = $phase; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Loading attributes |
57
|
36
|
|
|
|
|
93
|
my @attributes_tab = split(";",$attributes); |
58
|
36
|
|
|
|
|
67
|
foreach my $attr (@attributes_tab) { |
59
|
110
|
|
|
|
|
109
|
my ($k,$v); |
60
|
110
|
100
|
66
|
|
|
414
|
if($self->{format} =~ /gff3/i || $self->{format} =~ /gff$/i) { |
|
|
50
|
|
|
|
|
|
61
|
108
|
|
|
|
|
395
|
($k,$v) = $attr =~ /(\S+)=(.*)/; |
62
|
|
|
|
|
|
|
} elsif ($self->{format} =~ /gtf/i){ |
63
|
2
|
|
|
|
|
10
|
($k,$v) = $attr =~ /(\S+)\s+"(.*)"/; |
64
|
|
|
|
|
|
|
}else{ |
65
|
0
|
|
|
|
|
0
|
croak "Missing format argument (gff3,gtf) in CracTools::GFF::Annotation constructor"; |
66
|
|
|
|
|
|
|
} |
67
|
110
|
50
|
33
|
|
|
456
|
if(defined $k && defined $v) { |
68
|
110
|
100
|
|
|
|
221
|
if($k eq "Parent") { |
69
|
32
|
|
|
|
|
70
|
my @parents = split(',',$v); |
70
|
32
|
|
|
|
|
64
|
$v = \@parents; |
71
|
|
|
|
|
|
|
} |
72
|
110
|
|
|
|
|
335
|
$self->{attributes}{$k} = $v; |
73
|
|
|
|
|
|
|
} #else { |
74
|
|
|
|
|
|
|
# carp("Error parsing attribute $attr"); |
75
|
|
|
|
|
|
|
#} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub chr { |
82
|
35
|
|
|
35
|
1
|
46
|
my $self = shift; |
83
|
35
|
|
|
|
|
44
|
my $chr = shift; |
84
|
35
|
50
|
|
|
|
79
|
if(defined $chr) { |
85
|
0
|
|
|
|
|
0
|
$self->{chr} = $chr; |
86
|
|
|
|
|
|
|
} |
87
|
35
|
|
|
|
|
109
|
return $self->{chr}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub source { |
92
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
93
|
1
|
|
|
|
|
2
|
my $source = shift; |
94
|
1
|
50
|
|
|
|
3
|
if(defined $source) { |
95
|
0
|
|
|
|
|
0
|
$self->{source} = $source; |
96
|
|
|
|
|
|
|
} |
97
|
1
|
|
|
|
|
5
|
return $self->{source}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub feature { |
102
|
227
|
|
|
227
|
1
|
280
|
my $self = shift; |
103
|
227
|
|
|
|
|
250
|
my $feature = shift; |
104
|
227
|
50
|
|
|
|
378
|
if(defined $feature) { |
105
|
0
|
|
|
|
|
0
|
$self->{feature} = $feature; |
106
|
|
|
|
|
|
|
} |
107
|
227
|
|
|
|
|
701
|
return $self->{feature}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub start { |
112
|
36
|
|
|
36
|
1
|
46
|
my $self = shift; |
113
|
36
|
|
|
|
|
42
|
my $start = shift; |
114
|
36
|
50
|
|
|
|
68
|
if(defined $start) { |
115
|
0
|
|
|
|
|
0
|
$self->{start} = $start; |
116
|
|
|
|
|
|
|
} |
117
|
36
|
|
|
|
|
94
|
return $self->{start}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub end { |
122
|
37
|
|
|
37
|
1
|
597
|
my $self = shift; |
123
|
37
|
|
|
|
|
45
|
my $end = shift; |
124
|
37
|
50
|
|
|
|
74
|
if(defined $end) { |
125
|
0
|
|
|
|
|
0
|
$self->{end} = $end; |
126
|
|
|
|
|
|
|
} |
127
|
37
|
|
|
|
|
94
|
return $self->{end}; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub score { |
132
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
133
|
1
|
|
|
|
|
2
|
my $score = shift; |
134
|
1
|
50
|
|
|
|
4
|
if(defined $score) { |
135
|
0
|
|
|
|
|
0
|
$self->{score} = $score; |
136
|
|
|
|
|
|
|
} |
137
|
1
|
|
|
|
|
3
|
return $self->{score}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub strand { |
142
|
35
|
|
|
35
|
1
|
42
|
my $self = shift; |
143
|
35
|
|
|
|
|
37
|
my $strand = shift; |
144
|
35
|
50
|
|
|
|
69
|
if(defined $strand) { |
145
|
0
|
|
|
|
|
0
|
$self->{strand} = $strand; |
146
|
|
|
|
|
|
|
} |
147
|
35
|
|
|
|
|
118
|
return $self->{strand}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub gffStrand { |
152
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
153
|
1
|
|
|
|
|
3
|
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
|
|
|
|
4
|
if(defined $phase) { |
161
|
0
|
|
|
|
|
0
|
$self->{phase} = $phase; |
162
|
|
|
|
|
|
|
} |
163
|
1
|
|
|
|
|
5
|
return $self->{phase}; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub parents { |
168
|
113
|
|
|
113
|
1
|
143
|
my $self = shift; |
169
|
113
|
100
|
|
|
|
197
|
if(defined $self->attribute('Parent')) { |
170
|
78
|
|
|
|
|
154
|
return $self->attribute('Parent'); |
171
|
|
|
|
|
|
|
} else { |
172
|
35
|
|
|
|
|
97
|
return []; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub attribute { |
178
|
255
|
|
|
255
|
1
|
643
|
my $self = shift; |
179
|
255
|
|
|
|
|
331
|
my $key = shift; |
180
|
255
|
|
|
|
|
272
|
my $value = shift; |
181
|
255
|
100
|
|
|
|
536
|
if(defined $value) { |
|
|
50
|
|
|
|
|
|
182
|
1
|
|
|
|
|
4
|
return $self->{attributes}{$key} = $value; |
183
|
|
|
|
|
|
|
} elsif(defined $key) { |
184
|
254
|
|
|
|
|
773
|
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__ |