| 1 | package Bio::Roary::GroupLabels; | ||||||||||
| 2 | 3 | $Bio::Roary::GroupLabels::VERSION = '3.13.0'; | |||||||||
| 3 | # ABSTRACT: Add labels to the groups | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use Bio::Roary::Exceptions; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 3 | has 'groups_filename' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 10 | 3 | has 'output_filename' => ( is => 'ro', isa => 'Str', default => 'labelled_groups_file' ); | |||||||||
| 11 | |||||||||||
| 12 | 3 | has '_input_fh' => ( is => 'ro', lazy => 1, builder => '_build__input_fh' ); | |||||||||
| 13 | 3 | has '_output_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_fh' ); | |||||||||
| 14 | 3 | has '_group_default_prefix' => ( is => 'ro', isa => 'Str', default => 'group_' ); | |||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | sub _build__input_fh { | ||||||||
|
Subroutine
_build__input_fh: called CC=2 SCAR=7.1
| |||||||||||
| 17 | 1 | my ($self) = @_; | |||||||||
| 18 | 1 | ▶ | open( my $fh, $self->groups_filename ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | or Bio::Roary::Exceptions::FileNotFound->throw( error => "Group file not found:" . $self->groups_filename ); | ||||||||||
| 20 | 1 | return $fh; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | sub _build__output_fh { | ||||||||
|
Subroutine
_build__output_fh: called CC=2 SCAR=7.1
| |||||||||||
| 24 | 1 | my ($self) = @_; | |||||||||
| 25 | 1 | ▶ | open( my $fh, '>', $self->output_filename ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | or Bio::Roary::Exceptions::CouldntWriteToFile->throw( | ||||||||||
| 27 | error => "Couldnt write output file:" . $self->output_filename ); | ||||||||||
| 28 | 1 | return $fh; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 1 | ▶ | sub add_labels { | ||||||||
|
Subroutine
add_labels: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 32 | 1 | my ($self) = @_; | |||||||||
| 33 | |||||||||||
| 34 | 1 | my $counter = 1; | |||||||||
| 35 | 1 | my $in_fh = $self->_input_fh; | |||||||||
| 36 | 1 | ▶ | while (<$in_fh>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 6 | my $line = $_; | |||||||||
| 38 | 6 | ▶ | next if ( $line eq "" ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 6 | print { $self->_output_fh } $self->_group_default_prefix . $counter . ": " . $line; | |||||||||
| 40 | 6 | $counter++; | |||||||||
| 41 | } | ||||||||||
| 42 | 1 | close( $self->_input_fh ); | |||||||||
| 43 | 1 | close( $self->_output_fh ); | |||||||||
| 44 | 1 | return 1; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 3 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 48 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||
| 49 | |||||||||||
| 50 | 3 | 1; | |||||||||
| 51 | |||||||||||
| 52 | __END__ | ||||||||||