File Coverage

lib/Bio/Roary/Output/CoreGeneAlignmentCoordinatesEMBL.pm
Criterion Covered Total %
statement 40 40 100.0
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 49 51 96.0


line stmt bran cond sub pod time code
1             package Bio::Roary::Output::CoreGeneAlignmentCoordinatesEMBL;
2             $Bio::Roary::Output::CoreGeneAlignmentCoordinatesEMBL::VERSION = '3.10.2';
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     2   81885 use Moose;
  2         371693  
  2         11  
7 2     2   12280 use Bio::Roary::Exceptions;
  2         4  
  2         44  
8 2     2   9 use File::Basename;
  2         4  
  2         890  
9             with 'Bio::Roary::Output::EMBLHeaderCommon';
10              
11             has 'output_filename' => ( is => 'ro', isa => 'Str', default => 'core_alignment_header.embl' );
12             has 'multifasta_files' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
13             has 'gene_lengths' => ( is => 'ro', isa => 'HashRef', required => 1 );
14             has '_current_coordinate' => ( is => 'rw', isa => 'Int', default => 1 );
15             has '_output_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_fh' );
16              
17             sub _build__output_fh {
18 3     3   8 my ($self) = @_;
19 3 50       112 open( my $fh, '>', $self->output_filename )
20             or Bio::Roary::Exceptions::CouldntWriteToFile->throw( error => "Couldnt write output file:" . $self->output_filename );
21 3         138 return $fh;
22             }
23              
24             sub _gene_name_from_filename {
25 12     12   26 my ( $self, $filename ) = @_;
26 12         372 my $gene_name = basename($filename);
27 12         40 $gene_name =~ s!\.aln!!;
28 12         29 $gene_name =~ s!\.fa!!;
29 12         34 return $gene_name;
30             }
31              
32             sub _header_block {
33 8     8   20 my ( $self, $gene_filename ) = @_;
34 8         17 my $gene_name = $self->_gene_name_from_filename($gene_filename);
35 8         215 my $gene_length = $self->gene_lengths->{$gene_filename};
36 8         242 my $end_coordinate = $self->_current_coordinate + $gene_length - 1;
37 8         27 my $annotation_type = $self->_annotation_type($gene_name);
38              
39 8         217 my $tab_file_entry = join( '', ( 'FT', $annotation_type, $self->_current_coordinate, '..', $end_coordinate, "\n" ) );
40 8         27 $tab_file_entry .= "FT /label=$gene_name\n";
41 8         19 $tab_file_entry .= "FT /locus_tag=$gene_name\n";
42              
43 8         241 $self->_current_coordinate( $end_coordinate + 1 );
44 8         31 return $tab_file_entry;
45             }
46              
47             sub create_file {
48 3     3 0 10 my ($self) = @_;
49 3         5 print { $self->_output_fh } $self->_header_top;
  3         110  
50 3         10 for my $filename ( @{ $self->multifasta_files } ) {
  3         98  
51 8         11 print { $self->_output_fh } $self->_header_block($filename);
  8         215  
52             }
53 3         6 print { $self->_output_fh } $self->_header_bottom;
  3         92  
54 3         93 close( $self->_output_fh );
55             }
56              
57 2     2   15 no Moose;
  2         3  
  2         14  
58             __PACKAGE__->meta->make_immutable;
59              
60             1;
61              
62             __END__
63              
64             =pod
65              
66             =encoding UTF-8
67              
68             =head1 NAME
69              
70             Bio::Roary::Output::CoreGeneAlignmentCoordinatesEMBL - Create an embl file for the header with locations of where genes are in the multifasta alignment of core genes
71              
72             =head1 VERSION
73              
74             version 3.10.2
75              
76             =head1 SYNOPSIS
77              
78             Create an embl file for the header with locations of where genes are in the multifasta alignment of core genes
79             use Bio::Roary::Output::CoreGeneAlignmentCoordinatesEMBL;
80              
81             my $obj = Bio::Roary::Output::CoreGeneAlignmentCoordinatesEMBL->new(
82             output_filename => 'core_alignment_header.embl',
83             multifasta_files => [
84             't/data/multifasta_files/1.aln', 't/data/multifasta_files/outof_order.aln',
85             't/data/multifasta_files/2.aln', 't/data/multifasta_files/3.aln'
86             ],
87             gene_lengths => {
88             't/data/multifasta_files/1.aln' => 1,
89             't/data/multifasta_files/outof_order.aln' => 10,
90             't/data/multifasta_files/2.aln' => 100,
91             't/data/multifasta_files/3.aln' => 1000
92             },
93             );
94             $obj->create_file;
95              
96             =head1 AUTHOR
97              
98             Andrew J. Page <ap13@sanger.ac.uk>
99              
100             =head1 COPYRIGHT AND LICENSE
101              
102             This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.
103              
104             This is free software, licensed under:
105              
106             The GNU General Public License, Version 3, June 2007
107              
108             =cut