« lib/Bio/AssemblyImprovement/IvaQC/Main.pm
↑ Summary
lib/Bio/AssemblyImprovement/AdapterRemoval/Trimmomatic/Main.pm »
| 1 | package Bio::AssemblyImprovement::DigitalNormalisation::Khmer::Main; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Perform digital normalisation on sequencing reads | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||
|
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 Cwd; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use File::Basename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use File::Copy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use Bio::AssemblyImprovement::Util::FastqTools; | ||||||||
|
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_file' => ( is => 'ro', isa => 'Str' , required => 1); | |||||||||
| 18 | 2 | has 'desired_coverage' => ( is => 'ro', isa => 'Num', default => 2 ); | |||||||||
| 19 | 2 | has 'kmer_size' => ( is => 'ro', isa => 'Num', default => 31); | |||||||||
| 20 | 2 | has 'number_of_hashes' => ( is => 'ro', isa => 'Num', default => 4); | |||||||||
| 21 | 2 | has 'min_hash_size' => ( is => 'ro', isa => 'Str', default => '2.5e8'); | |||||||||
| 22 | 2 | has 'paired' => ( is => 'ro', isa => 'Bool', default => 1); # The pipeline will almost always be sending paired data | |||||||||
| 23 | 2 | has 'output_filename' => ( is => 'rw', isa => 'Str', default => 'digitally_normalised.fastq.gz' ); | |||||||||
| 24 | 2 | has 'output_directory' => ( is => 'rw', isa => 'Str', lazy => 1, builder => '_build_output_directory' ); # Default to cwd | |||||||||
| 25 | 2 | has 'khmer_exec' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 26 | 2 | has 'python_exec' => ( is => 'ro', isa => 'Str', default => 'python-2.7'); | |||||||||
| 27 | 2 | has 'debug' => ( is => 'ro', isa => 'Bool', default => 0); | |||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | sub _build_output_directory{ | ||||||||
|
Subroutine
_build_output_directory: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 1 | my ($self) = @_; | |||||||||
| 32 | 1 | return getcwd(); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub _final_results_file { | ||||||||
|
Subroutine
_final_results_file: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | 0 | my ($self) = @_; | |||||||||
| 37 | 0 | return $self->output_directory.'/'.$self->output_filename; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 1 | ▶ | sub _default_output_filename { | ||||||||
|
Subroutine
_default_output_filename: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 1 | my ($self) = @_; | |||||||||
| 42 | 1 | my ( $filename, $directories, $suffix ) = fileparse( $self->input_file ); | |||||||||
| 43 | # The output produced by the program is a fastq file (unzipped) named $input_filename.keep | ||||||||||
| 44 | 1 | return join ('/', getcwd(), $filename.'.keep'); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | 1 | ▶ | sub run { | ||||||||
|
Subroutine
run: called CC=3 SCAR=11.9
Pod
documented
| |||||||||||
| 50 | 1 | my ($self) = @_; | |||||||||
| 51 | 1 | my $original_cwd = getcwd(); | |||||||||
| 52 | |||||||||||
| 53 | # Usually, we'd do all the intermediate steps in a temporary directory and copy over the results file. | ||||||||||
| 54 | # This doesn't produce any intermediate files so we carry on working in the directory we are in | ||||||||||
| 55 | |||||||||||
| 56 | 1 | my $stdout_of_program = ''; | |||||||||
| 57 | 1 | ▶ | $stdout_of_program = "> /dev/null 2>&1" if($self->debug == 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | 1 | my $paired_parameter = ""; | |||||||||
| 60 | 1 | ▶ | if($self->paired){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 1 | $paired_parameter = "-p"; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | system( | ||||||||||
| 65 | 1 | join( | |||||||||
| 66 | ' ', | ||||||||||
| 67 | ( | ||||||||||
| 68 | $self->python_exec, $self->khmer_exec, #Need atleast python-2.7 for this | ||||||||||
| 69 | $paired_parameter, # Paired | ||||||||||
| 70 | '-C', $self->desired_coverage, | ||||||||||
| 71 | '-k', $self->kmer_size, | ||||||||||
| 72 | '-N', $self->number_of_hashes, | ||||||||||
| 73 | '-x', $self->min_hash_size, | ||||||||||
| 74 | $self->input_file, | ||||||||||
| 75 | $stdout_of_program | ||||||||||
| 76 | ) | ||||||||||
| 77 | ) | ||||||||||
| 78 | ); | ||||||||||
| 79 | |||||||||||
| 80 | # By default, the script produces a fastq file named with the input filename and a .keep suffix | ||||||||||
| 81 | # We want to have the flexibility of calling it something we like. Hence, the move below. | ||||||||||
| 82 | |||||||||||
| 83 | 1 | my $zipped_results = $self->_zip_file( $self->_default_output_filename , $self->output_directory ); #As a principle, we always zip our results | |||||||||
| 84 | 0 | move ( $zipped_results, $self->_final_results_file); | |||||||||
| 85 | |||||||||||
| 86 | 0 | unlink( $self->_default_output_filename ); | |||||||||
| 87 | |||||||||||
| 88 | 0 | return $self; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | |||||||||||
| 94 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 95 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 96 | 2 | 1; | |||||||||
| 97 | |||||||||||
| 98 | __END__ | ||||||||||