line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::Roary::BedFromGFFRole; |
2
|
|
|
|
|
|
|
$Bio::Roary::BedFromGFFRole::VERSION = '3.11.0'; |
3
|
|
|
|
|
|
|
# ABSTRACT: A role to create a bed file from a gff |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
3974
|
use Moose::Role; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
59
|
|
7
|
8
|
|
|
8
|
|
37983
|
use Bio::Tools::GFF; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
3166
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has '_tags_to_filter' => ( is => 'ro', isa => 'Str', default => '(CDS|ncRNA|tRNA|tmRNA|rRNA)' ); |
10
|
|
|
|
|
|
|
has 'min_gene_size_in_nucleotides' => ( is => 'ro', isa => 'Int', default => 120 ); |
11
|
|
|
|
|
|
|
has 'output_directory' => ( is => 'ro', isa => 'Str', default => '.' ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _bed_output_filename { |
14
|
6
|
|
|
6
|
|
19
|
my ($self) = @_; |
15
|
6
|
|
|
|
|
189
|
return join('/',($self->output_directory,join( '.', ( $self->output_filename, 'intermediate.bed' ) ))); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _create_bed_file_from_gff { |
19
|
3
|
|
|
3
|
|
11
|
my ($self) = @_; |
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
38
|
open( my $bed_fh, '>', $self->_bed_output_filename ); |
22
|
3
|
|
|
|
|
86
|
my $gffio = Bio::Tools::GFF->new( -file => $self->gff_file, -gff_version => 3 ); |
23
|
3
|
|
|
|
|
2412
|
while ( my $feature = $gffio->next_feature() ) { |
24
|
|
|
|
|
|
|
|
25
|
48
|
50
|
|
|
|
24020
|
next unless defined($feature); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Only interested in a few tags |
28
|
48
|
|
|
|
|
1242
|
my $tags_regex = $self->_tags_to_filter; |
29
|
48
|
50
|
|
|
|
102
|
next if !( $feature->primary_tag =~ /$tags_regex/ ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Must have an ID tag |
32
|
48
|
|
|
|
|
514
|
my $gene_id = $self->_get_feature_id($feature); |
33
|
48
|
50
|
|
|
|
70
|
next unless($gene_id); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#filter out small genes |
36
|
48
|
100
|
|
|
|
93
|
next if ( ( $feature->end - $feature->start ) < $self->min_gene_size_in_nucleotides ); |
37
|
|
|
|
|
|
|
|
38
|
45
|
100
|
|
|
|
97
|
my $strand = ($feature->strand > 0)? '+':'-' ; |
39
|
45
|
|
|
|
|
544
|
print {$bed_fh} join( "\t", ( $feature->seq_id, $feature->start -1, $feature->end, $gene_id, 1, $strand ) ) . "\n"; |
|
45
|
|
|
|
|
177
|
|
40
|
|
|
|
|
|
|
} |
41
|
3
|
|
|
|
|
18667
|
$gffio->close(); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _get_feature_id |
45
|
|
|
|
|
|
|
{ |
46
|
48
|
|
|
48
|
|
72
|
my ($self, $feature) = @_; |
47
|
48
|
|
|
|
|
58
|
my ( $gene_id, @junk ) ; |
48
|
48
|
50
|
|
|
|
85
|
if ( $feature->has_tag('ID') ) |
|
|
0
|
|
|
|
|
|
49
|
|
|
|
|
|
|
{ |
50
|
48
|
|
|
|
|
295
|
( $gene_id, @junk ) = $feature->get_tag_values('ID'); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif($feature->has_tag('locus_tag')) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
0
|
( $gene_id, @junk ) = $feature->get_tag_values('locus_tag'); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
|
|
0
|
return undef; |
59
|
|
|
|
|
|
|
} |
60
|
48
|
|
|
|
|
414
|
$gene_id =~ s!["']!!g; |
61
|
48
|
50
|
|
|
|
89
|
return undef if ( $gene_id eq "" ); |
62
|
48
|
|
|
|
|
82
|
return $gene_id ; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=pod |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=encoding UTF-8 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Bio::Roary::BedFromGFFRole - A role to create a bed file from a gff |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 VERSION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
version 3.11.0 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SYNOPSIS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
A role to create a bed file from a gff |
84
|
|
|
|
|
|
|
with 'Bio::Roary::BedFromGFFRole'; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Andrew J. Page <ap13@sanger.ac.uk> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This is free software, licensed under: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |