[Bio] / FigKernelScripts / p3x-recall-patric-proteins.pl Repository:
ViewVC logotype

View of /FigKernelScripts/p3x-recall-patric-proteins.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Wed Nov 2 16:25:31 2016 UTC (3 years ago) by olson
Branch: MAIN
CVS Tags: HEAD
P3 utility scripts.

use strict;
use Proc::ParallelLoop;
use Getopt::Long::Descriptive;
use IPC::Run 'run';

my($opt, $usage) = describe_options("%c %o kmer-dir output-dir",
				    ["parallel|p=i", "Parallel threads", { default => 1 }],
				    ["min-hits=i", "Kmer search min_hits parameter", { default => 5 }],
				    ["max-gap=i", "Kmer search max_gap parameter", { default => 200 }],
				    ["genome-dir=s", "Directory holding PATRIC genome data", { default => "/vol/patric3/downloads/genomes" }],
				    ["help|h", "Show this help message."],
				    );
print($usage->text), exit 0 if $opt->help;
die($usage->text) unless @ARGV == 2;

my $kmer_dir = shift;
my $out_dir = shift;

-d $kmer_dir or die "Invalid kmer directory $kmer_dir\n";
-d $out_dir or die "Output directory $out_dir does not exist\n";

my $genome_dir = $opt->genome_dir;

opendir(D, $genome_dir) or die "Cannot open genome directory $genome_dir: $!";

my %made_out;
my @work;
while (my $g = readdir(D))
{
    next unless $g =~ /^(\d+)\.\d+$/;

    my $base = $1;
    my $tens = sprintf("%02d", $base % 100);

    my $prot = "$genome_dir/$g/$g.PATRIC.faa";

    my $out = "$out_dir/$tens";

    if (!$made_out{$out})
    {
	-d $out || mkdir($out) || die "Cannot mkdir $out: $!";
	$made_out{$out}++;
    }
    $out = "$out/$g";
    push(@work, [$prot, $out]);
}
closedir(D);
my $n = @work;
print "Process $n genomes\n";

pareach \@work, sub {
    my($work) = @_;
    my($prot, $out_file) = @$work;

    my @cmd = ("kmer_search",
	       "-a",
	       "-g", $opt->{max_gap},
	       "-m", $opt->{min_hits},
	       "-d", $kmer_dir);

    my $ok = run(\@cmd, '<', $prot, '>', $out_file);
    if (!$ok)
    {
	die "Error running '@cmd' < $prot > $out_file: $?\n";
    }
}, { Max_Workers => $opt->parallel };

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3