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

View of /FortyEight/migrate_job.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.2 - (download) (as text) (annotate)
Wed Jun 6 17:53:22 2007 UTC (13 years, 1 month ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.1: +41 -3 lines
add -new option that assigns a new job number to the migrated job.

# Migrate the given job to the destination job directory.
# It will retain its job number.
# metadata and raw data are copied, and a new meta.xml is created
# with the required initial data.

my $usage = "usage: migrate_job [-new] job-dir target";

use strict;
use GenomeMeta;
use File::Basename;
use File::Copy;
use FIG;

my @meta_keys_to_copy = ( qr/^(?:genome|upload)\..*/,
my $files_to_skip = qr/^(?:ACTIVE|DONE|DELETED|meta\.xml)$/;

my $new_num;
while ($ARGV[0] =~ /^-(.*)/)
    my $arg = $1;
    if ($arg =~ /^new/)
	$new_num = 1;
	die "Unknown argument $arg\n";

@ARGV == 2 or die "$usage\n";

my $jobdir = shift;
my $target = shift;

opendir(JOBDIR, $jobdir) or die "Cannot open job $jobdir: $!\n";
my $jobnum = basename($jobdir);

$jobnum =~ /^\d+$/ or die "Job directory $jobdir is not numeric\n";

-d $target or die "Target directory $target does not exist\n";

-f "$jobdir/meta.xml" or die "Source meta.xml not present\n";

my $genome_id = &FIG::file_head("$jobdir/GENOME_ID", 1);
defined($genome_id) or die "Cannot read genomem id\n";
chomp $genome_id;

my $target_jobnum;
if ($new_num)
    # get new job id from job counter
    open(FH, "$target/JOBCOUNTER") or die "could not open jobcounter file: $!\n";
    $target_jobnum = <FH>;
    close FH;
    while (-d "$target/$target_jobnum")
    open(FH, ">$target/JOBCOUNTER") or die "could not write to jobcounter file: $!\n";
    print FH $target_jobnum;
    close FH;
    $target_jobnum = $jobnum;

my $new_jobdir = "$target/$target_jobnum";

warn "Copying job $jobnum for genome $genome_id from $jobdir to $new_jobdir\n";

my $old_meta = new GenomeMeta(undef, "$jobdir/meta.xml");
$old_meta or die "Cannot open $jobdir/meta.xml: $!\n";

-d $new_jobdir and die "Job $target_jobnum in $target already exists\n";

mkdir $new_jobdir or die "cannot mkdir $new_jobdir: $!\n";

my $new_meta = new GenomeMeta($genome_id, "$new_jobdir/meta.xml");
$new_meta or die "Cannot create $new_jobdir/meta.xml: $!\n";

for my $key ($old_meta->get_metadata_keys())
    if (grep { $key =~ /$_/ } @meta_keys_to_copy)
	$new_meta->set_metadata($key, $old_meta->get_metadata($key));

$new_meta->add_log_entry("creation", "Migrated job from $jobdir");

for my $f (readdir(JOBDIR))
    my $path = "$jobdir/$f";
    next unless -f $path;

    next if $f =~ /$files_to_skip/;

    copy($path, "$new_jobdir/$f") or die "Copy $path $new_jobdir/$f failed: $!";

# And copy the data.

my $rc = system("cp", "-r", "$jobdir/raw", "$new_jobdir");
$rc == 0 or die "Copy of $jobdir/raw to $new_jobdir failed";

# Don't send email, and automatically process corrections.

$new_meta->set_metadata('qc.email_notification_sent', 'yes');
$new_meta->set_metadata('correction.automatic', 1);
$new_meta->set_metadata('status.uploaded', 'complete');

# And make active.
open(F, ">$new_jobdir/ACTIVE");

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3