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

View of /FortyEight/migrate_job.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.1 - (download) (as text) (annotate)
Thu May 31 17:05:46 2007 UTC (13 years ago) by olson
Branch: MAIN
new script

# 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 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)$/;

@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 $new_jobdir = "$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 $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