Skip to content

Commit

Permalink
create temp directories in the current working directory to stop file…
Browse files Browse the repository at this point in the history
… copy to the nodes tmp dir
  • Loading branch information
andrewjpage committed Jul 30, 2012
1 parent deb6029 commit c3eea17
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
1 change: 0 additions & 1 deletion modules/MLST/Blast/BlastN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ $blast_database->top_hit();

package MLST::Blast::BlastN;
use Moose;
use File::Temp;
use MLST::Types;

# input variables
Expand Down
3 changes: 2 additions & 1 deletion modules/MLST/Blast/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package MLST::Blast::Database;
use Moose;
use File::Temp;
use MLST::Types;
use Cwd;

# input variables
has 'fasta_file' => ( is => 'ro', isa => 'Str', required => 1 );
has 'exec' => ( is => 'ro', isa => 'MLST::Executable', default => 'makeblastdb' );

# Generated
has '_working_directory' => ( is => 'ro', isa => 'File::Temp::Dir', default => sub { File::Temp->newdir(CLEANUP => 1); });
has '_working_directory' => ( is => 'ro', isa => 'File::Temp::Dir', default => sub { File::Temp->newdir(DIR => getcwd, CLEANUP => 1); });
has 'location' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_location' );

sub _build_location
Expand Down
24 changes: 10 additions & 14 deletions modules/MLST/MultipleFastas.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use MLST::ProcessFasta;
use MLST::Spreadsheet::File;
use MLST::NormaliseFasta;
use File::Temp;
use Cwd;

has 'species' => ( is => 'ro', isa => 'Str', required => 1 );
has 'base_directory' => ( is => 'ro', isa => 'Str', required => 1 );
Expand All @@ -43,7 +44,7 @@ has '_input_fasta_files' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, build

has '_concat_names' => ( is => 'rw', isa => 'ArrayRef', default => sub {[]} );
has '_concat_sequences' => ( is => 'rw', isa => 'ArrayRef', default => sub {[]} );
has '_working_directory' => ( is => 'ro', isa => 'File::Temp::Dir', default => sub { File::Temp->newdir(CLEANUP => 1); });
has '_working_directory' => ( is => 'ro', isa => 'File::Temp::Dir', default => sub { File::Temp->newdir(DIR => getcwd, CLEANUP => 1); });

sub _generate_spreadsheet_rows
{
Expand Down Expand Up @@ -71,10 +72,16 @@ sub _generate_spreadsheet_rows
for my $fastafile (@{$self->_input_fasta_files})
{
$pm->start and next; # do the fork

my $output_fasta_obj = MLST::NormaliseFasta->new(
fasta_filename => $fastafile,
working_directory => $self->_working_directory->dirname()
);

my $fasta_sequence_type_results = MLST::ProcessFasta->new(
species => $self->species,
base_directory => $self->base_directory,
fasta_file => $fastafile,
fasta_file => $output_fasta_obj->processed_fasta_filename(),
makeblastdb_exec => $self->makeblastdb_exec,
blastn_exec => $self->blastn_exec,
output_directory => $self->output_directory,
Expand All @@ -96,18 +103,7 @@ sub _generate_spreadsheet_rows
sub _build__input_fasta_files
{
my($self) = @_;
my @normalised_fasta_files;

for my $fastafile (@{$self->raw_input_fasta_files})
{
my $output_fasta_obj = MLST::NormaliseFasta->new(
fasta_filename => $fastafile,
working_directory => $self->_working_directory->dirname()
);
push(@normalised_fasta_files,$output_fasta_obj->processed_fasta_filename());
}

return \@normalised_fasta_files;
return $self->raw_input_fasta_files;
}

sub create_result_files
Expand Down
8 changes: 6 additions & 2 deletions t/Output/MultipleFastas.t
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ok(($multiple_fastas = MLST::MultipleFastas->new(
output_directory => $tmpdirectory,
output_fasta_files => 1,
spreadsheet_basename => 'mlst_results',
parallel_processes => 1
parallel_processes => 3
)),'Initialise 3 files where 1 has near matches');
ok(($multiple_fastas->create_result_files),'create all the results files for three fastas');
compare_files('t/data/expected_three_mlst_results.genomic.csv', $tmpdirectory.'/mlst_results.genomic.csv');
Expand All @@ -79,5 +79,9 @@ sub compare_files
open(ACTUAL, $actual_file);
my $expected_line = <EXPECTED>;
my $actual_line = <ACTUAL>;
is($expected_line,$actual_line, 'Content matches expected');

# parallel processes mean the order isnt guaranteed.
my $sorted_expected = sort(split(/\n/,$expected_line));
my $sorted_actual = sort(split(/\n/,$actual_line));
is_deeply($sorted_expected,$sorted_actual, 'Content matches expected');
}

0 comments on commit c3eea17

Please sign in to comment.