line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::Gonzales::Feat::IO::BED; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
135025
|
use Mouse; |
|
1
|
|
|
|
|
28663
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
401
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
7
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
74
|
|
8
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
22
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.083'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
extends 'Bio::Gonzales::Feat::IO::Base'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'parent_handler' => ( is => 'rw' ); |
17
|
|
|
|
|
|
|
has 'track_name' => ( is => 'rw', default => 'unknown' ); |
18
|
|
|
|
|
|
|
has _wrote_sth_before => ( is => 'rw' ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub write_feat { |
21
|
57
|
|
|
57
|
0
|
273
|
my ( $self, @feats ) = @_; |
22
|
57
|
|
|
|
|
163
|
my $fh = $self->fh; |
23
|
|
|
|
|
|
|
|
24
|
57
|
100
|
|
|
|
162
|
$self->_write_header |
25
|
|
|
|
|
|
|
unless ( $self->_wrote_sth_before ); |
26
|
|
|
|
|
|
|
|
27
|
57
|
|
|
|
|
109
|
for my $f (@feats) { |
28
|
57
|
|
|
|
|
136
|
$self->_collect_feat($f); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
57
|
|
|
|
|
211
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _write_header { |
35
|
1
|
|
|
1
|
|
13
|
my ($self) = @_; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
5
|
my $fh = $self->fh; |
38
|
|
|
|
|
|
|
#get track name right |
39
|
1
|
|
|
|
|
4
|
my $track_name = $self->track_name; |
40
|
1
|
|
|
|
|
18
|
say $fh "track name=$track_name"; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
6
|
$self->_wrote_sth_before(1); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub write_collected_feats { |
46
|
0
|
|
|
0
|
0
|
0
|
confess 'this function is deprecated'; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
override 'close' => sub { |
50
|
|
|
|
|
|
|
my ($self) = @_; |
51
|
|
|
|
|
|
|
my $fh = $self->fh; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$self->_connect_feats; |
54
|
|
|
|
|
|
|
my $parents = $self->_find_parent_feats; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
for my $p (@$parents) { |
57
|
|
|
|
|
|
|
$self->parent_handler->($p) if ( $self->parent_handler ); |
58
|
|
|
|
|
|
|
print $fh _to_bed($p); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
super; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return; |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _to_bed { |
67
|
26
|
|
|
26
|
|
54
|
my ($f) = @_; |
68
|
|
|
|
|
|
|
|
69
|
26
|
|
|
|
|
37
|
my $strand; |
70
|
26
|
100
|
|
|
|
61
|
if ( $f->strand < 0 ) { $strand = '-'; } |
|
6
|
|
|
|
|
11
|
|
71
|
20
|
|
|
|
|
33
|
else { $strand = '+'; } |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#chr_id |
74
|
|
|
|
|
|
|
#scf_id |
75
|
|
|
|
|
|
|
#start |
76
|
|
|
|
|
|
|
#end |
77
|
|
|
|
|
|
|
#name |
78
|
|
|
|
|
|
|
#score // 0 |
79
|
|
|
|
|
|
|
#strand +- |
80
|
|
|
|
|
|
|
#start (thick) == start |
81
|
|
|
|
|
|
|
#end (thick) == end |
82
|
|
|
|
|
|
|
#rgb == 0 |
83
|
|
|
|
|
|
|
#block count |
84
|
|
|
|
|
|
|
#block sizes |
85
|
|
|
|
|
|
|
#block starts |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my @line |
88
|
26
|
|
100
|
|
|
54
|
= ( $f->scf_id, $f->start - 1, $f->end, $f->id, $f->score // 0, $strand, ( $f->start - 1 ), $f->end, 0 ); |
89
|
|
|
|
|
|
|
|
90
|
26
|
|
|
|
|
78
|
my @sf = $f->recurse_subfeats; |
91
|
26
|
100
|
|
|
|
61
|
if ( @sf > 0 ) { |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#my %sf = (map { $_->start . '_' . $_->end => $_ } @sf); |
94
|
|
|
|
|
|
|
|
95
|
5
|
50
|
|
|
|
16
|
@sf = sort { ( $a->start <=> $b->start ) || ( $b->end <=> $a->end ) } @sf; |
|
65
|
|
|
|
|
186
|
|
96
|
5
|
|
|
|
|
15
|
push @line, scalar @sf; |
97
|
|
|
|
|
|
|
|
98
|
5
|
|
|
|
|
10
|
push @line, join( ',', map { $_->end - $_->start + 1 } @sf ); |
|
34
|
|
|
|
|
95
|
|
99
|
5
|
|
|
|
|
14
|
push @line, join( ',', map { ( $_->start - $f->start ) } @sf ); |
|
34
|
|
|
|
|
92
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
26
|
|
|
|
|
148
|
return join( "\t", @line ), "\n"; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |