« lib/Bio/AssemblyImprovement/Scaffold/Descaffold.pm
↑ Summary
lib/Bio/AssemblyImprovement/Scaffold/SSpace/PreprocessInputFiles.pm »
| 1 | package Bio::AssemblyImprovement::Util::FastaTools; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Utilities for sequences in a FASTA file | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use Bio::SeqIO; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use Cwd 'abs_path'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | with 'Bio::AssemblyImprovement::Util::UnzipFileIfNeededRole'; | |||||||||
| 11 | 3 | with 'Bio::AssemblyImprovement::Scaffold::SSpace::TempDirectoryRole'; | |||||||||
| 12 | |||||||||||
| 13 | 3 | has 'input_filename' => ( is => 'ro', isa => 'Str' , required => 1 ); | |||||||||
| 14 | 3 | has 'output_filename' => ( is => 'rw', isa => 'Str' , lazy => 1, builder => '_build_output_filename' ); | |||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | sub _build_output_filename { | ||||||||
|
Subroutine
_build_output_filename: not called CC=1 SCAR=6.9
| |||||||||||
| 18 | 0 | my ($self) = @_; | |||||||||
| 19 | 0 | return join('/', ($self->_temp_directory, '_filter_by_length.fa')); | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | # Throw away small contigs, but not if the overall size of the genome drops too low | ||||||||||
| 24 | 6 | ▶ | sub remove_small_contigs { | ||||||||
|
Subroutine
remove_small_contigs: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 25 | 6 | my ($self, $minimum_contig_size_in_assembly, $minimum_perc_to_turn_off_filtering) = @_; | |||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | 6 | my $fasta_file = $self->_gunzip_file_if_needed($self->input_filename); | |||||||||
| 29 | 6 | my $fasta_obj = Bio::SeqIO->new(-file => $fasta_file, -format => 'Fasta'); | |||||||||
| 30 | 6 | my $out_fasta_obj = Bio::SeqIO->new(-file => "+>".$self->output_filename , -format => 'Fasta'); | |||||||||
| 31 | |||||||||||
| 32 | 6 | my $sequence_length = 0; | |||||||||
| 33 | 6 | my $bases_kept = 0; | |||||||||
| 34 | 6 | ▶ | while(my $seq = $fasta_obj->next_seq()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 21 | $sequence_length += $seq->length(); | |||||||||
| 36 | 21 | ▶ | next if($seq->length < $minimum_contig_size_in_assembly); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 17 | $out_fasta_obj->write_seq($seq); | |||||||||
| 38 | 17 | $bases_kept += $seq->length(); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 6 | ▶ | if(($bases_kept /$sequence_length) *100 < $minimum_perc_to_turn_off_filtering) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 1 | $self->output_filename($self->input_filename); | |||||||||
| 43 | 1 | return $self; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 5 | return $self; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | 3 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||
| 52 | 3 | 1; | |||||||||
| 53 | |||||||||||
| 54 | __END__ | ||||||||||