« lib/Bio/AssemblyImprovement/Scaffold/SSpace/Iterative.pm
↑ Summary
lib/Bio/AssemblyImprovement/PrepareForSubmission/RenameContigs.pm »
| 1 | package Bio::AssemblyImprovement::Assemble::SGA::Main; | ||||||||||
| 2 | # ABSTRACT: Run SGA preprocess and error correction steps | ||||||||||
| 3 | |||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use Cwd; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use Cwd 'abs_path'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use File::Copy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use File::Basename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 2 | ▶ | use Bio::AssemblyImprovement::Assemble::SGA::PreprocessReads; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use Bio::AssemblyImprovement::Assemble::SGA::IndexAndCorrectReads; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | with 'Bio::AssemblyImprovement::Scaffold::SSpace::TempDirectoryRole'; | |||||||||
| 15 | 2 | with 'Bio::AssemblyImprovement::Util::ZipFileRole'; | |||||||||
| 16 | |||||||||||
| 17 | 2 | has 'input_files' => ( is => 'ro', isa => 'ArrayRef' , required => 1); | |||||||||
| 18 | |||||||||||
| 19 | # Parameters for preprocessing | ||||||||||
| 20 | 2 | has 'min_length' => ( is => 'ro', isa => 'Num', default => 51); | |||||||||
| 21 | 2 | has 'quality_trim' => ( is => 'ro', isa => 'Num', default => 3); | |||||||||
| 22 | 2 | has 'pe_mode' => ( is => 'ro', isa => 'Num', default => 2); #We set default to 2 as the pipeline will almost always send in an interleaved fastq file | |||||||||
| 23 | |||||||||||
| 24 | # Parameters for indexing and correction | ||||||||||
| 25 | 2 | has 'algorithm' => ( is => 'ro', isa => 'Str', default => 'ropebwt'); # BWT construction algorithm: sais or ropebwt | |||||||||
| 26 | 2 | has 'threads' => ( is => 'ro', isa => 'Num', default => 1); # Use this many threads for computation | |||||||||
| 27 | 2 | has 'kmer_threshold' => ( is => 'ro', isa => 'Num', default=> 5); # Attempt to correct kmers that are seen less than this many times | |||||||||
| 28 | 2 | has 'kmer_length' => ( is => 'ro', isa => 'Num', default=> 41); | |||||||||
| 29 | 2 | has 'output_filename' => ( is => 'rw', isa => 'Str', default => '_sga_error_corrected.fastq.gz' ); #We always zip the results | |||||||||
| 30 | 2 | has 'output_directory' => ( is => 'rw', isa => 'Str', lazy => 1, builder => '_build_output_directory' ); # Default to cwd | |||||||||
| 31 | 2 | has 'sga_exec' => ( is => 'rw', isa => 'Str', required => 1 ); | |||||||||
| 32 | 2 | has 'debug' => ( is => 'ro', isa => 'Bool', default => 0); | |||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | sub _build_output_directory{ | ||||||||
|
Subroutine
_build_output_directory: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 1 | my ($self) = @_; | |||||||||
| 36 | 1 | return getcwd(); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 4 | ▶ | sub _final_results_file { | ||||||||
|
Subroutine
_final_results_file: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 4 | my ($self) = @_; | |||||||||
| 41 | 4 | return $self->output_directory.'/'.$self->output_filename; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | # Intermediate preprocessed file | ||||||||||
| 45 | 4 | ▶ | sub _intermediate_file { | ||||||||
|
Subroutine
_intermediate_file: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 4 | my ($self) = @_; | |||||||||
| 47 | 4 | return $self->_temp_directory.'/_sga_preprocessed.fastq'; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 1 | ▶ | sub run { | ||||||||
|
Subroutine
run: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 51 | 1 | my ($self) = @_; | |||||||||
| 52 | 1 | my $original_cwd = getcwd(); | |||||||||
| 53 | 1 | $self->output_directory; # Essentially setting output directory to cwd | |||||||||
| 54 | |||||||||||
| 55 | # Do all the intermediate steps in a temporary directory (which will be cleaned up when object out of scope) | ||||||||||
| 56 | 1 | chdir( $self->_temp_directory ); # Default to temporary directory if alternative not provided | |||||||||
| 57 | |||||||||||
| 58 | 1 | my $stdout_of_program = ''; | |||||||||
| 59 | 1 | ▶ | $stdout_of_program = "> /dev/null 2>&1" if($self->debug == 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | |||||||||||
| 61 | # SGA preprocess | ||||||||||
| 62 | 1 | my $sga_preprocessor = Bio::AssemblyImprovement::Assemble::SGA::PreprocessReads->new( | |||||||||
| 63 | input_files => $self->input_files, | ||||||||||
| 64 | pe_mode => $self->pe_mode, | ||||||||||
| 65 | min_length => $self->min_length, | ||||||||||
| 66 | pe_mode => $self->pe_mode, | ||||||||||
| 67 | quality_trim => $self->quality_trim, | ||||||||||
| 68 | output_directory => $self->output_directory, | ||||||||||
| 69 | sga_exec => $self->sga_exec, | ||||||||||
| 70 | debug => $self->debug, | ||||||||||
| 71 | ); | ||||||||||
| 72 | |||||||||||
| 73 | 1 | $sga_preprocessor->run(); | |||||||||
| 74 | |||||||||||
| 75 | # Move preprocessed file to this temporary directory | ||||||||||
| 76 | 1 | move ( $sga_preprocessor->_output_filename(), $self->_intermediate_file ); | |||||||||
| 77 | |||||||||||
| 78 | # SGA error correction (on the results from above) | ||||||||||
| 79 | 1 | my $sga_error_corrector = Bio::AssemblyImprovement::Assemble::SGA::IndexAndCorrectReads->new( | |||||||||
| 80 | input_filename => $self->_intermediate_file, | ||||||||||
| 81 | algorithm => $self->algorithm, | ||||||||||
| 82 | threads => $self->threads, | ||||||||||
| 83 | kmer_threshold => $self->kmer_threshold, | ||||||||||
| 84 | kmer_length => $self->kmer_length, | ||||||||||
| 85 | sga_exec => $self->sga_exec, | ||||||||||
| 86 | debug => $self->debug, | ||||||||||
| 87 | ); | ||||||||||
| 88 | |||||||||||
| 89 | 1 | $sga_error_corrector->run(); | |||||||||
| 90 | |||||||||||
| 91 | 1 | chdir($original_cwd); | |||||||||
| 92 | |||||||||||
| 93 | 1 | my $zipped_results = $self->_zip_file( $sga_error_corrector->_output_filename , $self->output_directory ); | |||||||||
| 94 | 1 | move ( $zipped_results, $self->_final_results_file); | |||||||||
| 95 | |||||||||||
| 96 | 1 | return $self; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | |||||||||||
| 100 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 101 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 102 | 2 | 1; | |||||||||
| 103 | |||||||||||
| 104 | __END__ | ||||||||||