[Bio] / FigKernelScripts / p3x-create-release-dir.pl Repository:
ViewVC logotype

View of /FigKernelScripts/p3x-create-release-dir.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Thu Oct 5 17:20:50 2017 UTC (2 years, 1 month ago) by olson
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +15 -1 lines
Add metadata to the query_cb callback. Also use the return value of query_cb
to determine whether the query continues (return true value to continue the query, return
false value to terminate the query).

#
# Create the release directory for a family build.
#

use strict;
use File::Basename;
use Getopt::Long::Descriptive;
use P3DataAPI;
use Data::Dumper;

my($opt, $usage) = describe_options("%c %o release-dir family-dir version kmer-version family-file",
				    ["help|h" => "Show this help message"]);
print($usage->text), exit 0 if $opt->help;
die($usage->text) if @ARGV != 5;

my $rel_dir = shift;
my $fam_dir = shift;
my $fam_version = shift;
my $kmer_version = shift;
my $fam_file = shift;

-d $fam_dir or die "Family directory $fam_dir does not exist\n";
-d $rel_dir or die "Release directory $rel_dir does not exist\n";

-d "$fam_dir/kmers" or die "Family directory should have a kmers symlink at $fam_dir/kmers\n";

for my $kf (<$fam_dir/kmers/*>)
{
    my $f = basename($kf);
    symlink($kf, "$rel_dir/$f") or die "Cannot symlink $kf to $rel_dir/$f: $!\n";
}

symlink($fam_file, "$rel_dir/families.dat") or die "Cannot symlink $fam_file to $rel_dir/families.dat: $!\n";

my $api = P3DataAPI->new();

#
# The genera in the data comes from the genome table, not the taxonomy table. Best we can
# do is request all genomes' genus and uniquify.
#
my %gdata;
#my @gdata = $api->query("taxonomy", ["select", "taxon_id", "taxon_name"], ["eq", "taxon_rank", "genus"]);
die;
$api->query_cb("genome",
	       sub {
		   my($data) = @_;
		   $gdata{$_->{genus}}++ foreach @$data;
		   return 1;
	       },["select", "genus"], ["eq", "genus", "*"]);

open(F, ">", "$rel_dir/families.genus_map") or die "Cannot write $rel_dir/families.genus_map: $!\n";

print F "taxon_name\ttaxon_id\n";
for my $ent (sort { $a->{taxon_name} cmp $b->{taxon_name} } @gdata)
{
    print F "$ent->{taxon_name}\t$ent->{taxon_id}\n";
}
close(F);

open(F, ">", "$rel_dir/VERSION") or die "Cannot write $rel_dir/VERSION: $!\n";
print F "$kmer_version\n";
close(F);

open(F, ">", "$rel_dir/families.version") or die "Cannot write $rel_dir/families.version: $!\n";
print F "$fam_version\n";
close(F);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3