Skip to content

Commit

Permalink
Some better file cleanup; native mash fastq.gz support; v0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
lskatz committed Oct 4, 2017
1 parent e426b4e commit 1eb265d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
34 changes: 21 additions & 13 deletions bin/mashtree.pl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ sub mashSketch{

# If any file needs to be converted, it will end up in
# this directory.
my $tempdir=tempdir("$$settings{tempdir}/convertFasta.XXXXXX", CLEANUP=>1);
my $tempdir=tempdir("$$settings{tempdir}/convertSeq.XXXXXX", CLEANUP=>1);

my @msh;
# $fastq is a misnomer: it could be any kind of accepted sequence file
Expand All @@ -163,20 +163,24 @@ sub mashSketch{
my $unzipped="$tempdir/".basename($fastq);
$unzipped=~s/\.(gz|bz2?|zip)$//i;
my $was_unzipped=0;
if($fastq=~/\.gz$/i){
system("gzip -cd $fastq > $unzipped");
die "ERROR with gzip -cd $fastq" if $?;
$was_unzipped=1;
} elsif($fastq=~/\.bz2?$/i){
system("bzip2 -cd $fastq > $unzipped");
die "ERROR with bzip2 -cd $fastq" if $?;
$was_unzipped=1;
} elsif($fastq=~/\.zip$/i){
system("unzip -p $fastq > $unzipped");
die "ERROR with unzip -p $fastq" if $?;
$was_unzipped=1;
# Don't bother unzipping if it's a fastq file b/c Mash can read those
if(!grep {$_ eq $fileExt} @fastqExt){
if($fastq=~/\.gz$/i){
system("gzip -cd $fastq > $unzipped");
die "ERROR with gzip -cd $fastq" if $?;
$was_unzipped=1;
} elsif($fastq=~/\.bz2?$/i){
system("bzip2 -cd $fastq > $unzipped");
die "ERROR with bzip2 -cd $fastq" if $?;
$was_unzipped=1;
} elsif($fastq=~/\.zip$/i){
system("unzip -p $fastq > $unzipped");
die "ERROR with unzip -p $fastq" if $?;
$was_unzipped=1;
}
}

# If the file was uncompressed, parse the filename again.
if($was_unzipped){
$fastq=$unzipped;
($fileName,$filePath,$fileExt)=fileparse($fastq,@fastqExt,@fastaExt,@richseqExt,@mshExt);
Expand Down Expand Up @@ -244,6 +248,8 @@ sub mashSketch{
push(@msh,"$outPrefix.msh");
}

system("rm -rf $tempdir");

return \@msh;
}

Expand Down Expand Up @@ -334,6 +340,8 @@ sub mashDist{
# this sub ends but I wanted to do it directly and
# in a readable fashion.
$mashtreeDb->disconnect();
close($distFileFh);
unlink($distFile);
}

sub determineMinimumDepth{
Expand Down
2 changes: 1 addition & 1 deletion lib/Mashtree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local $0=basename $0;
######
# CONSTANTS

our $VERSION = "0.21";
our $VERSION = "0.22";
our $MASHTREE_VERSION=$VERSION;
our @fastqExt=qw(.fastq.gz .fastq .fq .fq.gz);
our @fastaExt=qw(.fasta .fna .faa .mfa .fas .fsa .fa);
Expand Down

0 comments on commit 1eb265d

Please sign in to comment.