File Coverage

lib/Bio/Roary/BedFromGFFRole.pm
Criterion Covered Total %
statement 29 31 93.5
branch 9 16 56.2
condition n/a
subroutine 5 5 100.0
pod n/a
total 43 52 82.6


line stmt bran cond sub pod time code
1             package Bio::Roary::BedFromGFFRole;
2             $Bio::Roary::BedFromGFFRole::VERSION = '3.10.1';
3             # ABSTRACT: A role to create a bed file from a gff
4              
5              
6 8     8   5090 use Moose::Role;
  8         58  
  8         70  
7 8     8   49129 use Bio::Tools::GFF;
  8         24  
  8         4129  
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   24 my ($self) = @_;
15 6         351 return join('/',($self->output_directory,join( '.', ( $self->output_filename, 'intermediate.bed' ) )));
16             }
17              
18             sub _create_bed_file_from_gff {
19 3     3   14 my ($self) = @_;
20              
21 3         44 open( my $bed_fh, '>', $self->_bed_output_filename );
22 3         131 my $gffio = Bio::Tools::GFF->new( -file => $self->gff_file, -gff_version => 3 );
23 3         3736 while ( my $feature = $gffio->next_feature() ) {
24              
25 48 50       42057 next unless defined($feature);
26              
27             # Only interested in a few tags
28 48         2280 my $tags_regex = $self->_tags_to_filter;
29 48 50       237 next if !( $feature->primary_tag =~ /$tags_regex/ );
30              
31             # Must have an ID tag
32 48         896 my $gene_id = $self->_get_feature_id($feature);
33 48 50       183 next unless($gene_id);
34              
35             #filter out small genes
36 48 100       147 next if ( ( $feature->end - $feature->start ) < $self->min_gene_size_in_nucleotides );
37              
38 45 100       205 my $strand = ($feature->strand > 0)? '+':'-' ;
39 45         1095 print {$bed_fh} join( "\t", ( $feature->seq_id, $feature->start -1, $feature->end, $gene_id, 1, $strand ) ) . "\n";
  45         187  
40             }
41 3         33549 $gffio->close();
42             }
43              
44             sub _get_feature_id
45             {
46 48     48   107 my ($self, $feature) = @_;
47 48         143 my ( $gene_id, @junk ) ;
48 48 50       224 if ( $feature->has_tag('ID') )
    0          
49             {
50 48         440 ( $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         706 $gene_id =~ s!["']!!g;
61 48 50       129 return undef if ( $gene_id eq "" );
62 48         121 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.10.1
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