| 1 | package Bio::Roary::Output::CoreGeneAlignmentCoordinatesEMBL; | ||||||||||
| 2 | 2 | $Bio::Roary::Output::CoreGeneAlignmentCoordinatesEMBL::VERSION = '3.13.0'; | |||||||||
| 3 | # ABSTRACT: Create an embl file for the header with locations of where genes are in the multifasta alignment of core genes | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use Bio::Roary::Exceptions; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use File::Basename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | with 'Bio::Roary::Output::EMBLHeaderCommon'; | |||||||||
| 10 | |||||||||||
| 11 | 2 | has 'output_filename' => ( is => 'ro', isa => 'Str', default => 'core_alignment_header.embl' ); | |||||||||
| 12 | 2 | has 'multifasta_files' => ( is => 'ro', isa => 'ArrayRef', required => 1 ); | |||||||||
| 13 | 2 | has 'gene_lengths' => ( is => 'ro', isa => 'HashRef', required => 1 ); | |||||||||
| 14 | 2 | has '_current_coordinate' => ( is => 'rw', isa => 'Int', default => 1 ); | |||||||||
| 15 | 2 | has '_output_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_fh' ); | |||||||||
| 16 | |||||||||||
| 17 | 3 | ▶ | sub _build__output_fh { | ||||||||
|
Subroutine
_build__output_fh: called CC=2 SCAR=7.1
| |||||||||||
| 18 | 3 | my ($self) = @_; | |||||||||
| 19 | 3 | ▶ | open( my $fh, '>', $self->output_filename ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | or Bio::Roary::Exceptions::CouldntWriteToFile->throw( error => "Couldnt write output file:" . $self->output_filename ); | ||||||||||
| 21 | 3 | return $fh; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 12 | ▶ | sub _gene_name_from_filename { | ||||||||
|
Subroutine
_gene_name_from_filename: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 12 | my ( $self, $filename ) = @_; | |||||||||
| 26 | 12 | my $gene_name = basename($filename); | |||||||||
| 27 | 12 | $gene_name =~ s!\.aln!!; | |||||||||
| 28 | 12 | $gene_name =~ s!\.fa!!; | |||||||||
| 29 | 12 | return $gene_name; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 8 | ▶ | sub _header_block { | ||||||||
|
Subroutine
_header_block: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 8 | my ( $self, $gene_filename ) = @_; | |||||||||
| 34 | 8 | my $gene_name = $self->_gene_name_from_filename($gene_filename); | |||||||||
| 35 | 8 | my $gene_length = $self->gene_lengths->{$gene_filename}; | |||||||||
| 36 | 8 | my $end_coordinate = $self->_current_coordinate + $gene_length - 1; | |||||||||
| 37 | 8 | my $annotation_type = $self->_annotation_type($gene_name); | |||||||||
| 38 | |||||||||||
| 39 | 8 | my $tab_file_entry = join( '', ( 'FT', $annotation_type, $self->_current_coordinate, '..', $end_coordinate, "\n" ) ); | |||||||||
| 40 | 8 | $tab_file_entry .= "FT /label=$gene_name\n"; | |||||||||
| 41 | 8 | $tab_file_entry .= "FT /locus_tag=$gene_name\n"; | |||||||||
| 42 | |||||||||||
| 43 | 8 | $self->_current_coordinate( $end_coordinate + 1 ); | |||||||||
| 44 | 8 | return $tab_file_entry; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 3 | ▶ | sub create_file { | ||||||||
|
Subroutine
create_file: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 48 | 3 | my ($self) = @_; | |||||||||
| 49 | 3 | print { $self->_output_fh } $self->_header_top; | |||||||||
| 50 | 3 | for my $filename ( @{ $self->multifasta_files } ) { | |||||||||
| 51 | 8 | print { $self->_output_fh } $self->_header_block($filename); | |||||||||
| 52 | } | ||||||||||
| 53 | 3 | print { $self->_output_fh } $self->_header_bottom; | |||||||||
| 54 | 3 | close( $self->_output_fh ); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 58 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 59 | |||||||||||
| 60 | 2 | 1; | |||||||||
| 61 | |||||||||||
| 62 | __END__ | ||||||||||