lib/Bio/Roary/BedFromGFFRole.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 72.2% 13 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 89.8% 53 / 59 CC 10 SCAR 16.0
CC
10
Cov
89%
_create_bed_file_from_gff
7.1
_get_feature_id
4.1
BEGIN
1.0
CRAP 4.9
« lib/Bio/Roary/GeneNamesFromGFF.pm ↑ Summary lib/Bio/Roary/FilterFullClusters.pm »
1 package Bio::Roary::BedFromGFFRole;
2 28 $Bio::Roary::BedFromGFFRole::VERSION = '3.13.0';
3 # ABSTRACT: A role to create a bed file from a gff
4  
5  
6 28 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 28 ▶use Bio::Tools::GFF;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 28 has '_tags_to_filter' => ( is => 'ro', isa => 'Str', default => 'CDS' );
10 28 has 'min_gene_size_in_nucleotides' => ( is => 'ro', isa => 'Int', default => 18 );
11 28 has 'output_directory' => ( is => 'ro', isa => 'Str', default => '.' );
12  
13 66 ▶sub _bed_output_filename {
Subroutine _bed_output_filename: called CC=1 SCAR=0.0
14 66 my ($self) = @_;
15 66 return join('/',($self->output_directory,join( '.', ( $self->output_filename, 'intermediate.bed' ) )));
16 }
17  
18 23 ▶sub _create_bed_file_from_gff {
Subroutine _create_bed_file_from_gff: called CC=7 SCAR=19.6
19 23 my ($self) = @_;
20  
21 23 open( my $bed_fh, '>', $self->_bed_output_filename );
22 23 my $gffio = Bio::Tools::GFF->new( -file => $self->gff_file, -gff_version => 3 );
23 23 ▶ while ( my $feature = $gffio->next_feature() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $feature = $gffio->next_feature) 386 23 409
24  
25 386 ▶ next unless defined($feature);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $feature 0 386 386
26  
27 # Only interested in a few tags
28 386 my $tags_regex = $self->_tags_to_filter;
29 386 ▶ next if !( $feature->primary_tag =~ /$tags_regex/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $feature->primary_tag =~ /$tags_regex/ 132 254 386
30  
31 # Must have an ID tag
32 254 my $gene_id = $self->_get_feature_id($feature);
33 254 ▶ next unless($gene_id);
Branch: 1 branch
BranchTrueFalseTotal
unless $gene_id 0 254 254
34  
35 #filter out small genes
36 254 ▶ next if ( ( $feature->end - $feature->start ) < $self->min_gene_size_in_nucleotides );
Branch: 1 branch
BranchTrueFalseTotal
if $feature->end - $feature->start < $self->min_gene_size_in_nucleotides 0 254 254
37  
38 254 ▶ my $strand = ($feature->strand > 0)? '+':'-' ;
Branch: 1 branch
BranchTrueFalseTotal
$feature->strand > 0 ? : 155 99 254
39 254 print {$bed_fh} join( "\t", ( $feature->seq_id, $feature->start -1, $feature->end, $gene_id, 1, $strand ) ) . "\n";
40 }
41 23 $gffio->close();
42 }
43  
44 sub _get_feature_id
45 254 ▶{
Subroutine _get_feature_id: called CC=4 SCAR=14.2
46 254 my ($self, $feature) = @_;
47 254 my ( $gene_id, @junk ) ;
48 254 ▶ if ( $feature->has_tag('ID') )
Branch: 2 branches
BranchTrueFalseTotal
if ($feature->has_tag('ID')) { } 212 42 254
elsif ($feature->has_tag('locus_tag')) { } 42 0 42
49 {
50 212 ( $gene_id, @junk ) = $feature->get_tag_values('ID');
51 }
52 elsif($feature->has_tag('locus_tag'))
53 {
54 42 ( $gene_id, @junk ) = $feature->get_tag_values('locus_tag');
55 }
56 else
57 {
58 0 return undef;
59 }
60 254 $gene_id =~ s!["']!!g;
61 254 ▶ return undef if ( $gene_id eq "" );
Branch: 1 branch
BranchTrueFalseTotal
if $gene_id eq "" 0 254 254
62 254 return $gene_id ;
63 }
64  
65 28 1;
66  
67 __END__
« lib/Bio/Roary/GeneNamesFromGFF.pm ↑ Summary lib/Bio/Roary/FilterFullClusters.pm »