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

Annotation of /FortyEight/migrate_job.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : olson 1.1 #
2 :     # Migrate the given job to the destination job directory.
3 :     #
4 :     # It will retain its job number.
5 :     #
6 :     # metadata and raw data are copied, and a new meta.xml is created
7 :     # with the required initial data.
8 :     #
9 :    
10 :     my $usage = "usage: migrate_job job-dir target";
11 :    
12 :    
13 :     use strict;
14 :     use GenomeMeta;
15 :     use File::Basename;
16 :     use File::Copy;
17 :     use FIG;
18 :    
19 :     my @meta_keys_to_copy = ( qr/^(?:genome|upload)\..*/,
20 :     qr/^correction\.automatic/);
21 :     my $files_to_skip = qr/^(?:ACTIVE|DONE|DELETED|meta\.xml)$/;
22 :    
23 :     @ARGV == 2 or die "$usage\n";
24 :    
25 :     my $jobdir = shift;
26 :     my $target = shift;
27 :    
28 :     opendir(JOBDIR, $jobdir) or die "Cannot open job $jobdir: $!\n";
29 :     my $jobnum = basename($jobdir);
30 :    
31 :     $jobnum =~ /^\d+$/ or die "Job directory $jobdir is not numeric\n";
32 :    
33 :     -d $target or die "Target directory $target does not exist\n";
34 :    
35 :    
36 :     -f "$jobdir/meta.xml" or die "Source meta.xml not present\n";
37 :    
38 :    
39 :     my $genome_id = &FIG::file_head("$jobdir/GENOME_ID", 1);
40 :     defined($genome_id) or die "Cannot read genomem id\n";
41 :     chomp $genome_id;
42 :    
43 :     my $new_jobdir = "$target/$jobnum";
44 :    
45 :     warn "Copying job $jobnum for genome $genome_id from $jobdir to $new_jobdir\n";
46 :    
47 :     my $old_meta = new GenomeMeta(undef, "$jobdir/meta.xml");
48 :     $old_meta or die "Cannot open $jobdir/meta.xml: $!\n";
49 :    
50 :     -d $new_jobdir and die "Job $jobnum in $target already exists\n";
51 :    
52 :     mkdir $new_jobdir or die "cannot mkdir $new_jobdir: $!\n";
53 :    
54 :     my $new_meta = new GenomeMeta($genome_id, "$new_jobdir/meta.xml");
55 :     $new_meta or die "Cannot create $new_jobdir/meta.xml: $!\n";
56 :    
57 :     for my $key ($old_meta->get_metadata_keys())
58 :     {
59 :     if (grep { $key =~ /$_/ } @meta_keys_to_copy)
60 :     {
61 :     $new_meta->set_metadata($key, $old_meta->get_metadata($key));
62 :     }
63 :     }
64 :    
65 :     $new_meta->add_log_entry("creation", "Migrated job from $jobdir");
66 :    
67 :     for my $f (readdir(JOBDIR))
68 :     {
69 :     my $path = "$jobdir/$f";
70 :     next unless -f $path;
71 :    
72 :     next if $f =~ /$files_to_skip/;
73 :    
74 :     copy($path, "$new_jobdir/$f") or die "Copy $path $new_jobdir/$f failed: $!";
75 :     }
76 :    
77 :     #
78 :     # And copy the data.
79 :     #
80 :    
81 :     my $rc = system("cp", "-r", "$jobdir/raw", "$new_jobdir");
82 :     $rc == 0 or die "Copy of $jobdir/raw to $new_jobdir failed";
83 :    
84 :     #
85 :     # Don't send email, and automatically process corrections.
86 :     #
87 :    
88 :     $new_meta->set_metadata('qc.email_notification_sent', 'yes');
89 :     $new_meta->set_metadata('correction.automatic', 1);
90 :     $new_meta->set_metadata('status.uploaded', 'complete');
91 :    
92 :     #
93 :     # And make active.
94 :     #
95 :     open(F, ">$new_jobdir/ACTIVE");
96 :     close(F);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3