| 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
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 386 | ▶ | next unless defined($feature); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 34 | |||||||||||||||
| 35 | #filter out small genes | ||||||||||||||
| 36 | 254 | ▶ | next if ( ( $feature->end - $feature->start ) < $self->min_gene_size_in_nucleotides ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | |||||||||||||||
| 38 | 254 | ▶ | my $strand = ($feature->strand > 0)? '+':'-' ; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 62 | 254 | return $gene_id ; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 28 | 1; | |||||||||||||
| 66 | |||||||||||||||
| 67 | __END__ | ||||||||||||||