| 1 | package Bio::AssemblyImprovement::PrepareForSubmission::RenameContigs; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Update the names of the contigs so that the assembly can be submitted to a database like EMBL | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use File::Temp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Bio::SeqIO; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use File::Copy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 2 | has 'input_assembly' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 12 | 2 | has 'base_contig_name' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 13 | |||||||||||
| 14 | 2 | has '_input_fh' => ( is => 'ro', lazy => 1, builder => '_build__input_fh' ); | |||||||||
| 15 | 2 | has '_output_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_fh' ); | |||||||||
| 16 | |||||||||||
| 17 | 2 | has '_temp_output_file_obj' => ( is => 'ro', lazy => 1, builder => '_build__temp_output_file_obj' ); | |||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | sub _build__temp_output_file_obj { | ||||||||
|
Subroutine
_build__temp_output_file_obj: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | my ($self) = @_; | |||||||||
| 21 | 1 | File::Temp->new(); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | sub _build__input_fh { | ||||||||
|
Subroutine
_build__input_fh: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 1 | my ($self) = @_; | |||||||||
| 26 | 1 | Bio::SeqIO->new( -file => $self->input_assembly, -format => 'Fasta' ); | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | sub _build__output_fh { | ||||||||
|
Subroutine
_build__output_fh: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 1 | my ($self) = @_; | |||||||||
| 31 | 1 | Bio::SeqIO->new( -file => "+>" . $self->_temp_output_filename, -format => 'Fasta' ); | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 2 | ▶ | sub _temp_output_filename { | ||||||||
|
Subroutine
_temp_output_filename: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 2 | my ($self) = @_; | |||||||||
| 36 | 2 | $self->_temp_output_file_obj->filename; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 7 | ▶ | sub _generate_contig_name { | ||||||||
|
Subroutine
_generate_contig_name: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 7 | my ( $self, $counter ) = @_; | |||||||||
| 41 | 7 | my $normalised_basename = $self->base_contig_name ; | |||||||||
| 42 | 7 | $normalised_basename =~ s![^\w\.]!_!gi; | |||||||||
| 43 | 7 | return join( '.', ( $normalised_basename, $counter ) ); | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 1 | ▶ | sub _create_temp_outputfile { | ||||||||
|
Subroutine
_create_temp_outputfile: called CC=2 SCAR=6.9
| |||||||||||
| 47 | 1 | my ($self) = @_; | |||||||||
| 48 | 1 | my $seq_counter = 1; | |||||||||
| 49 | 1 | ▶ | while ( my $input_seq = $self->_input_fh->next_seq() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 3 | $self->_output_fh->write_seq( | |||||||||
| 51 | Bio::Seq->new( -display_id => $self->_generate_contig_name($seq_counter), -seq => $input_seq->seq ) ); | ||||||||||
| 52 | 3 | $seq_counter++; | |||||||||
| 53 | } | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | ▶ | sub run { | ||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | 1 | my ($self) = @_; | |||||||||
| 58 | 1 | $self->_create_temp_outputfile; | |||||||||
| 59 | 1 | move($self->_temp_output_filename, $self->input_assembly); | |||||||||
| 60 | 1 | return $self; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 65 | 2 | 1; | |||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||