lib/Bio/Roary/ChunkFastaFile.pm

filter: Statementstmt 100% 51 / 51 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 100% 67 / 67 CC 3 SCAR 3.6
CC
3
Cov
100%
_build_sequence_file_names
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« lib/Bio/Roary/Output/EMBLHeaderCommon.pm ↑ Summary lib/Bio/Roary/Output/CoreGeneAlignmentCoordinatesEMBL.pm »
1 package Bio::Roary::ChunkFastaFile;
2 4 $Bio::Roary::ChunkFastaFile::VERSION = '3.13.0';
3 # ABSTRACT: Take in a FASTA file and chunk it up into smaller pieces.
4  
5  
6 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Bio::Roary::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 has 'fasta_file' => ( is => 'ro', isa => 'Str', required => 1 );
13 4 has 'target_chunk_size' => ( is => 'ro', isa => 'Int', default => 200000 );
14 4 has 'sequence_file_names' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build_sequence_file_names' );
15 has '_working_directory' =>
16 5 ▶ ( is => 'ro', isa => 'File::Temp::Dir', default => sub { File::Temp->newdir( DIR => getcwd, CLEANUP => 1 ); } );
Subroutine __ANON__: called CC=1 SCAR=0.0
17 4 has '_working_directory_name' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build__working_directory_name' );
18 4 has '_input_seqio' => ( is => 'ro', isa => 'Bio::SeqIO', lazy => 1, builder => '_build__input_seqio' );
19  
20 5 ▶sub _build__working_directory_name {
Subroutine _build__working_directory_name: called CC=1 SCAR=0.0
21 5 my ($self) = @_;
22 5 return $self->_working_directory->dirname();
23 }
24  
25 5 ▶sub _build__input_seqio {
Subroutine _build__input_seqio: called CC=1 SCAR=0.0
26 5 my ($self) = @_;
27 5 return Bio::SeqIO->new( -file => $self->fasta_file, -format => 'Fasta' );
28 }
29  
30 20 ▶sub _create_next_chunk_file_name {
Subroutine _create_next_chunk_file_name: called CC=1 SCAR=0.0
31 20 my ( $self, $chunk_number ) = @_;
32 20 return join( '/', ( $self->_working_directory_name, $chunk_number . '.seq' ) );
33 }
34  
35 10 ▶sub _create_next_chunk_seqio {
Subroutine _create_next_chunk_seqio: called CC=1 SCAR=0.0
36 10 my ( $self, $chunk_number ) = @_;
37 10 return Bio::SeqIO->new( -file => ">".$self->_create_next_chunk_file_name($chunk_number), -format => 'Fasta' );
38 }
39  
40 5 ▶sub _build_sequence_file_names {
Subroutine _build_sequence_file_names: called CC=3 SCAR=11.0
41 5 my ($self) = @_;
42 5 my @sequence_file_names;
43 5 my $chunk_number = 0;
44 5 my $current_chunk_length = 0;
45 5 my $current_chunk_seqio = $self->_create_next_chunk_seqio($chunk_number);
46 5 push( @sequence_file_names, $self->_create_next_chunk_file_name($chunk_number) );
47  
48 5 ▶ while ( my $input_seq = $self->_input_seqio->next_seq() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $input_seq = $self->_input_seqio->next_seq) 30 5 35
49 30 ▶ if ( $current_chunk_length > $self->target_chunk_size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_chunk_length > $self->target_chunk_size) 5 25 30
50  
51 # next chunk
52 5 $chunk_number++;
53 5 $current_chunk_length = 0;
54 5 $current_chunk_seqio = $self->_create_next_chunk_seqio($chunk_number);
55 5 push( @sequence_file_names, $self->_create_next_chunk_file_name($chunk_number) );
56 }
57 30 $current_chunk_seqio->write_seq($input_seq);
58 30 $current_chunk_length += $input_seq->length();
59 }
60 5 return \@sequence_file_names;
61 }
62  
63 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 4 __PACKAGE__->meta->make_immutable;
65  
66 4 1;
67  
68 __END__
« lib/Bio/Roary/Output/EMBLHeaderCommon.pm ↑ Summary lib/Bio/Roary/Output/CoreGeneAlignmentCoordinatesEMBL.pm »