[Bio] / Clearinghouse / upload_genome.pl Repository:
ViewVC logotype

View of /Clearinghouse/upload_genome.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Tue Jun 14 16:02:34 2005 UTC (14 years, 4 months ago) by olson
Branch: MAIN
CVS Tags: myrast_33, HEAD
genome upload script.

#
# Upload a genome to the clearinghouse.
#

use strict;

use SOAP::Lite;
use LWP::UserAgent;
use HTTP::Request::Common;
use Getopt::Long;

use FIG;
use Clearinghouse::utils;

my $usage = "upload_genome  gff_file [gff_file ...]";

my $url = "http://clearinghouse.theseed.org/clearinghouse_services.cgi";
#my $url = "http://listeria.uchicago.edu/TestCH/clearinghouse_services.cgi";
#my $url = "http://localhost/FIG/clearinghouse_services.cgi";

my $upload_type = 'GENOME';
my $verbose;
my $who = 'olson@mcs.anl.gov';

my $optresult = GetOptions("who|w=s" => \$who,
			   "verbose|v" => \$verbose);

if (!$optresult)
{
    die "$usage\n";
}

print "Uploading to clearinghouse $url\n" if $verbose;

my $proxy = SOAP::Lite-> uri('http://www.soaplite.com/Scripts')
	-> proxy($url);

my $ua = new LWP::UserAgent;

for my $pkg (@ARGV)
{
    my %meta;

    eval {
	%meta = validate_package($pkg, $upload_type);
    };

    if ($@)
    {
	die "Error validating genome:\n$@\n";
	exit;
    }

    #
    # Validate a bit.
    #

    my ($gs, $taxon_id, $name, $genome_id) = @meta{qw(genus_species taxon_id name genome_id)};

    $gs ne '' or die "Invalid species in package $pkg\n";
    $taxon_id =~ /^\d+$/ or die "Invalid taxon_id '$taxon_id' in package $pkg\n";
    $name ne '' or die "Invalid name in package $pkg\n";


    #
    # See if this genome is registered.
    #

    my $res = $proxy->is_genome_registered($genome_id);

    $res->fault and die "is_genome_registered call failed: ", $res->faultcode, " ", $res->faultstring, "\n";

    $res->result  or die "Genome $name $genome_id is not registered\n";

    print "Uploading $name $genome_id\n";

    #
    # Ready to upload now.
    #

    my $res = $proxy->get_upload_url();
    $res->fault and die "Failure getting upload url: ", $res->faultcode, " ", $res->faultstring;

    my($url, $id) = @{$res->result};

    my $size = -s $pkg;

    $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1;

    my $req = POST($url,
		   Content_Type => 'form-data',
		   Content => [file_id => $id,
			       file_size=> $size,
			       file => [$pkg]]);

    my $resp = $ua->request($req);
    if (!$resp->is_success) {
	die "Failed to upload $pkg";
    }

    #step 3 - finish up, this makes the entry in the DB
    # now finish the deposit

    my $metadata = join('', map { "$_\t$meta{$_}\n" } keys(%meta));

    my $description = "Genome $name uploaded on " . localtime;
    my $source = &FIG::get_local_hostname();
    
    my $uresp = $proxy->finish_upload([$id], $upload_type, $who, $metadata, $description, $source);  
    #check this response sometime
}
    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3