[Bio] / FortyEight / rp_write_exports.pl Repository:
ViewVC logotype

View of /FortyEight/rp_write_exports.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (as text) (annotate)
Tue Aug 12 20:14:21 2008 UTC (11 years, 7 months ago) by olson
Branch: MAIN
CVS Tags: rast_2008_0924, rast_rel_2008_09_30, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, mgrast_rel_2008_0625, rast_rel_2008_10_09, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, mgrast_rel_2008_1110, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, rast_rel_2008_11_24, rast_rel_2008_08_07
Changes since 1.3: +34 -0 lines
Rollup of RAST release changes.

#
# Write the export files for this completed job.
#

use Data::Dumper;
use Carp;
use strict;
use FIG;
use FIG_Config;
use FileHandle;
use File::Basename;
use GenomeMeta;
use SeedExport;
use Job48;

@ARGV == 1 or die "Usage: $0 job-dir\n";

my $jobdir = shift;

-d $jobdir or die "$0: job dir $jobdir does not exist\n";

my $job = new Job48($jobdir);
$job or die "cannot create job for $jobdir";

my $hostname = `hostname`;
chomp $hostname;

my $genome = &FIG::file_head("$jobdir/GENOME_ID");
chomp $genome;
$genome =~ /^\d+\.\d+/ or die "$0: Cannnot find genome ID for jobdir $jobdir\n";

my $meta = new GenomeMeta($genome, "$jobdir/meta.xml");

my $genome_dir = "$jobdir/rp/$genome";

my $export_dir = "$jobdir/download";
&FIG::verify_dir($export_dir);

$meta->set_metadata("export.hostname", $hostname);
$meta->set_metadata("export.running", "yes");
$meta->set_metadata("status.export", "in_progress");

#
# Before writing the export, perform a final check on the genome directory.
# If this is not intended for SEED use, we pass the -no_fatal_stops
# option in order to have jobs not fail in the face of some of the
# genes with bad stops that are currently being generated.
#

my @verify_cmd = ("$FIG_Config::bin/verify_genome_directory");

if (!($meta->get_metadata("import.candidate")))
{
    push(@verify_cmd, "-no_fatal_stops");
}
if ((my $code = $meta->get_metadata("genome.genetic_code")) ne '')
{
    push(@verify_cmd, "-code=$code");
}
push(@verify_cmd, $genome_dir);

my $verify_cmd = "@verify_cmd > $jobdir/rp.errors/verify_genome_directory.report 2>&1";

$meta->add_log_entry($0, "Verifying with command: $verify_cmd");
my $rc = system($verify_cmd);

if ($rc != 0)
{
    $meta->set_metadata("genome.directory_verification_status", "failed_$rc");
    &fatal("verify_genome_directory failed with rc=$rc");
}

$meta->set_metadata("genome.directory_verification_status", "success");
$meta->add_log_entry($0, "Verification succeeded");

$meta->add_log_entry($0, "Writing exports to $export_dir");


my @export_types = qw(genbank GTF embl gff);
my @strip_ec_flag = (0, 1);
my %export_names = (genbank => "Genbank",
		    GTF => "GTF",
		    embl => "EMBL",
		    gff => "GFF3",
		    );
my %export_suffix = (genbank => "gbk",
		    GTF => "gtf",
		    embl => "embl",
		    gff => "gff",
		    );

#
# If we have not yet indexed the contigs, do that here. Speeds a lot
# of stuff up.
#

if (! -f "$genome_dir/contigs.btree")
{
    my $rc = system("$FIG_Config::bin/make_fasta_btree",
		    "$genome_dir/contigs",
		    "$genome_dir/contigs.btree",
		    "$genome_dir/contig_len.btree");
    if ($rc != 0)
    {
	warn "make_fasta_btree failed with rc $rc\n";
    }
}

open(I, ">$export_dir/index");
for my $strip_ec (@strip_ec_flag)
{
    my $strip_fn_part = $strip_ec ? ".ec-stripped" : "";
    my $strip_msg = $strip_ec ? " (EC numbers stripped)" : "";
    for my $type (@export_types)
    {
	$meta->add_log_entry($0, "Exporting type $type");

	my $filename = "$genome${strip_fn_part}.$export_suffix{$type}";
	
	my $p = {
	    virtual_genome_directory => $genome_dir,
	    genome => $genome,
	    directory => "$export_dir/",
	    filename => "$export_dir/$filename",
	    export_format => $type,
	    strip_ec => $strip_ec,
	};
	eval {
	    SeedExport::export($p);
	    print I "$filename\t$export_names{$type}$strip_msg\n";
	};
	if ($@)
	{
	    &fatal("Error exporting type $type of genome $genome to $export_dir: $@");
	}
    }
}
I->autoflush(1);

#
# Also export the entire genome directory as a tgz file.
#

my @cmd = ("tar", "-C", "$jobdir/rp", "-z", "-c", "-f", "$export_dir/$genome.tgz", $genome);
my $rc = system(@cmd);
if ($rc != 0)
{
    &fatal("error $rc creating tarfile with: @cmd");
}

print I "$genome.tgz\tGenome directory\n";
close(I);

$meta->set_metadata("export.running", "no");
$meta->set_metadata("status.export", "complete");

exit(0);

sub fatal
{
    my($msg) = @_;

    if ($meta)
    {
	$meta->add_log_entry($0, ['fatal error', $msg]);
	$meta->set_metadata("export.running", "no");
	$meta->set_metadata("status.export", "error");
    }
    croak "$0: $msg";
}
    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3