#!/usr/bin/env perl use strict; use File::Basename qw(basename); use Getopt::Long; my ($out_path, $level, $threads); GetOptions( 'out=s' => \$out_path, 'level=i' => \$level, 'threads=i' => \$threads, ) or die "Can't parse command line arguments\n"; if (!defined $out_path) { die "Output file is not specified\n"; } if (!defined $level) { die "Level is not specified\n"; } if (!defined $threads) { $threads = 1; } my $name = basename($out_path); $name =~ s/\s/_/g; my $temp_dir; if (!defined $temp_dir and exists $ENV{'TMPDIR'}) { $temp_dir = $ENV{'TMPDIR'}; } if (!defined $temp_dir and exists $ENV{'TEMP'}) { $temp_dir = $ENV{'TEMP'}; } if (!defined $temp_dir and exists $ENV{'TMP'}) { $temp_dir = $ENV{'TMP'}; } if (!defined $temp_dir) { die "Can't detect temp directory, please define TMPDIR environment variable\n"; } if (!-e $temp_dir or !-d $temp_dir) { die "Can't find temporary directory\n"; } my $temp_fasta = "$temp_dir/$name.zpaq-temp.fasta"; my $buf_size = 1000000; my $buffer; binmode STDIN; open(my $FA, '>', $temp_fasta) or die "Can't create temporary file \"$temp_fasta\"\n"; binmode $FA; while (read(STDIN, $buffer, $buf_size)) { print $FA $buffer; } close $FA; if (-e $out_path) { unlink $out_path; } if (-e "$out_path.temp") { unlink "$out_path.temp"; } my $cmd = "zpaq a '$out_path.temp' '$temp_fasta' -m$level -t$threads >/dev/null 2>&1"; my $error = system($cmd); if ($error) { die "Command failed: $cmd\n"; } rename "$out_path.temp", $out_path; unlink $temp_fasta;