| 1 | package Bio::Roary::Output::GroupMultifasta; | ||||||||||
| 2 | 2 | $Bio::Roary::Output::GroupMultifasta::VERSION = '3.13.0'; | |||||||||
| 3 | # ABSTRACT: Take in a group and create a multifasta file | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use Bio::SeqIO; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Bio::Roary::Exceptions; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Bio::Roary::AnalyseGroups; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 2 | has 'group_name' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 12 | 2 | has 'analyse_groups' => ( is => 'ro', isa => 'Bio::Roary::AnalyseGroups', required => 1 ); | |||||||||
| 13 | 2 | has 'output_filename_base' => ( is => 'ro', isa => 'Str', default => 'output_groups' ); | |||||||||
| 14 | 2 | has '_genes' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build__genes' ); | |||||||||
| 15 | 2 | has '_output_seq_io' => ( is => 'ro', lazy => 1, builder => '_build__output_seq_io' ); | |||||||||
| 16 | |||||||||||
| 17 | 12 | ▶ | sub _build__output_seq_io { | ||||||||
|
Subroutine
_build__output_seq_io: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 12 | my ($self) = @_; | |||||||||
| 19 | 12 | my $output_name = $self->output_filename_base . '_' . $self->group_name; | |||||||||
| 20 | 12 | $output_name =~ s!\W!_!g; | |||||||||
| 21 | 12 | $output_name .= '.fa'; | |||||||||
| 22 | 12 | return Bio::SeqIO->new( -file => ">" . $output_name, -format => 'Fasta' ); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 12 | ▶ | sub _build__genes { | ||||||||
|
Subroutine
_build__genes: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 12 | my ($self) = @_; | |||||||||
| 27 | 12 | return $self->analyse_groups->_groups_to_genes->{ $self->group_name }; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 24 | ▶ | sub _lookup_sequence { | ||||||||
|
Subroutine
_lookup_sequence: called CC=4 SCAR=14.3
| |||||||||||
| 31 | 24 | my ( $self, $gene, $filename ) = @_; | |||||||||
| 32 | 24 | ▶ | return undef if(! defined($filename)); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 24 | my $fasta_obj = Bio::SeqIO->new( -file => $filename, -format => 'Fasta' ); | |||||||||
| 34 | 24 | ▶ | while ( my $seq = $fasta_obj->next_seq() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 66 | ▶ | next unless ( $seq->display_id eq $gene ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 24 | return $seq; | |||||||||
| 37 | } | ||||||||||
| 38 | 0 | return undef; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 12 | ▶ | sub create_file { | ||||||||
|
Subroutine
create_file: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 42 | 12 | my ($self) = @_; | |||||||||
| 43 | 12 | for my $gene ( @{ $self->_genes } ) { | |||||||||
| 44 | 24 | my $seq = $self->_lookup_sequence( $gene, $self->analyse_groups->_genes_to_file->{$gene} ); | |||||||||
| 45 | 24 | ▶ | next unless ( defined($seq) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 24 | $self->_output_seq_io->write_seq($seq); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 12 | 1; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 53 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 54 | |||||||||||
| 55 | 2 | 1; | |||||||||
| 56 | |||||||||||
| 57 | __END__ | ||||||||||