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

Annotation of /FortyEight/migrate_job.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (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 : olson 1.2 my $usage = "usage: migrate_job [-new] job-dir target";
11 : olson 1.1
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 : olson 1.2 my $new_num;
24 :     while ($ARGV[0] =~ /^-(.*)/)
25 :     {
26 :     shift;
27 :     my $arg = $1;
28 :     if ($arg =~ /^new/)
29 :     {
30 :     $new_num = 1;
31 :     }
32 :     else
33 :     {
34 :     die "Unknown argument $arg\n";
35 :     }
36 :     }
37 :    
38 :    
39 :    
40 : olson 1.1 @ARGV == 2 or die "$usage\n";
41 :    
42 :     my $jobdir = shift;
43 :     my $target = shift;
44 :    
45 :     opendir(JOBDIR, $jobdir) or die "Cannot open job $jobdir: $!\n";
46 :     my $jobnum = basename($jobdir);
47 :    
48 :     $jobnum =~ /^\d+$/ or die "Job directory $jobdir is not numeric\n";
49 :    
50 :     -d $target or die "Target directory $target does not exist\n";
51 :    
52 :    
53 :     -f "$jobdir/meta.xml" or die "Source meta.xml not present\n";
54 :    
55 :    
56 :     my $genome_id = &FIG::file_head("$jobdir/GENOME_ID", 1);
57 :     defined($genome_id) or die "Cannot read genomem id\n";
58 :     chomp $genome_id;
59 :    
60 : olson 1.2 my $target_jobnum;
61 :     if ($new_num)
62 :     {
63 :     # get new job id from job counter
64 :     open(FH, "$target/JOBCOUNTER") or die "could not open jobcounter file: $!\n";
65 :     $target_jobnum = <FH>;
66 :     $target_jobnum++;
67 :     close FH;
68 :     while (-d "$target/$target_jobnum")
69 :     {
70 :     $target_jobnum++;
71 :     }
72 :     open(FH, ">$target/JOBCOUNTER") or die "could not write to jobcounter file: $!\n";
73 :     print FH $target_jobnum;
74 :     close FH;
75 :     }
76 :     else
77 :     {
78 :     $target_jobnum = $jobnum;
79 :     }
80 :    
81 :     my $new_jobdir = "$target/$target_jobnum";
82 : olson 1.1
83 :     warn "Copying job $jobnum for genome $genome_id from $jobdir to $new_jobdir\n";
84 :    
85 :     my $old_meta = new GenomeMeta(undef, "$jobdir/meta.xml");
86 :     $old_meta or die "Cannot open $jobdir/meta.xml: $!\n";
87 :    
88 : olson 1.2 -d $new_jobdir and die "Job $target_jobnum in $target already exists\n";
89 : olson 1.1
90 :     mkdir $new_jobdir or die "cannot mkdir $new_jobdir: $!\n";
91 :    
92 :     my $new_meta = new GenomeMeta($genome_id, "$new_jobdir/meta.xml");
93 :     $new_meta or die "Cannot create $new_jobdir/meta.xml: $!\n";
94 :    
95 :     for my $key ($old_meta->get_metadata_keys())
96 :     {
97 :     if (grep { $key =~ /$_/ } @meta_keys_to_copy)
98 :     {
99 :     $new_meta->set_metadata($key, $old_meta->get_metadata($key));
100 :     }
101 :     }
102 :    
103 :     $new_meta->add_log_entry("creation", "Migrated job from $jobdir");
104 :    
105 :     for my $f (readdir(JOBDIR))
106 :     {
107 :     my $path = "$jobdir/$f";
108 :     next unless -f $path;
109 :    
110 :     next if $f =~ /$files_to_skip/;
111 :    
112 :     copy($path, "$new_jobdir/$f") or die "Copy $path $new_jobdir/$f failed: $!";
113 :     }
114 :    
115 :     #
116 :     # And copy the data.
117 :     #
118 :    
119 :     my $rc = system("cp", "-r", "$jobdir/raw", "$new_jobdir");
120 :     $rc == 0 or die "Copy of $jobdir/raw to $new_jobdir failed";
121 :    
122 :     #
123 :     # Don't send email, and automatically process corrections.
124 :     #
125 :    
126 :     $new_meta->set_metadata('qc.email_notification_sent', 'yes');
127 :     $new_meta->set_metadata('correction.automatic', 1);
128 :     $new_meta->set_metadata('status.uploaded', 'complete');
129 :    
130 :     #
131 :     # And make active.
132 :     #
133 :     open(F, ">$new_jobdir/ACTIVE");
134 :     close(F);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3