[Bio] / FortyEightMeta / mg_upgrade_preprocess.pl Repository:
ViewVC logotype

Annotation of /FortyEightMeta/mg_upgrade_preprocess.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : redwards 1.1 #__perl__
2 :    
3 :    
4 :     =pod
5 :    
6 :     =head1 upgrade_metagenome
7 :    
8 :     This will take a metagenome and copy most of the important information over to a new metagenome, and then run it through the upgrade steps.
9 :    
10 :     At the moment, we make it DELETE so that the auto job checker doesn't try and process it.
11 :    
12 :    
13 :     The program has two options at the moment:
14 :    
15 :     -j job number or directory. You can provide either
16 :     -u user for the new job, in case you want to run as someone else and then let them take over later.
17 :    
18 :     Please note that there is no authentication control in this. It is assumed if you are running it you can see the jobs anyway.
19 :    
20 :     =author
21 :    
22 :     Rob Edwards
23 :     December 11 2008
24 :    
25 :     =cut
26 :    
27 :     use strict;
28 :     use warnings;
29 :    
30 :     use GenomeMeta;
31 :     use Job48;
32 :     use FIG_Config;
33 :     use ClusterStage;
34 :     use SGE;
35 :     my $sge=new SGE;
36 :    
37 :    
38 :     use Getopt::Std;
39 :     my %opts;
40 :     getopts('j:u:', \%opts);
41 :     my $usage=<<EOF;
42 :     $0
43 :     -j original job number or directory (if you use the number, we'll add the base directory $FIG_Config::mgrast_jobs)
44 :     -u new user name for the job. Otherwise will be the same as the old username
45 :    
46 :     EOF
47 :    
48 :     my $jobdir;
49 :     if ($opts{j} && $opts{j} =~ /^\d+$/) {
50 :     $jobdir=$FIG_Config::mgrast_jobs."/".$opts{j};
51 :     }
52 :     elsif ($opts{j} && -d $opts{j} && -e "$opts{j}/meta.xml") {$jobdir=$opts{j}}
53 :     else {die $usage}
54 :    
55 :     $jobdir =~ m/(\d+)$/;
56 :     my $jobid = $1;
57 :    
58 :     unless (-e "$jobdir/meta.xml") {die "There does not appear to be a meta.xml file in $jobdir. Is that the correct directory?"}
59 :     my $mf = "$jobdir/meta.xml";
60 :    
61 :     my $meta = GenomeMeta->new(undef, $mf);
62 :    
63 :     # find the fasta file from the meta
64 :     my $faf;
65 :     eval {$faf=$meta->get_metadata("preprocess.fasta_file")};
66 :     if ($@) {die "There was an error getting the preprocess.fasta_file from $mf"}
67 :     my $qaf=$meta->get_metadata("preprocess.qual_file");
68 :    
69 :    
70 :     my $genome = `cat $jobdir/GENOME`; chomp($genome);
71 :     my $proj = `cat $jobdir/PROJECT`; chomp($proj);
72 :     my $user = $opts{u} || `cat $jobdir/USER`; chomp($user);
73 :     my $public = (-e "$jobdir/PUBLIC") ? 1 : 0;
74 :     my $dups = $meta->get_metadata('remove_duplicates') || 1;
75 :     my $desc = $meta->get_metadata("project.description");
76 :    
77 :     my $job = {
78 :     'genome' => $genome,
79 :     'project' => $proj,
80 :     'user' => $user,
81 :     'taxonomy' => '',
82 :     'metagenome' => 1,
83 :     'meta' => {
84 :     'source_file' => $faf,
85 :     'project.description' => $desc,
86 :     'options.remove_duplicates' => $dups,
87 :     'options.public' => $public,
88 :     },
89 :     };
90 :    
91 :    
92 :     for my $opt (qw(altitude longitude latitude time habitat))
93 :     {
94 :     my $val = $meta->get_metadata("optional_info.$opt");
95 :     $val =~ s/\n//g;
96 :     $val =~ s/\r//g;
97 :     $val =~ s/\s*$//;
98 :     $val =~ s/^\s*//;
99 :     while (chomp($val)) {$val =~ s/\s*$//; $val =~ s/^\s*//;} # I'm not sure why this creating so many blank lines in the meta.xml file
100 :     if ($val =~ /\S/) {
101 :     $job->{meta}->{"optional_info.$opt"} = $val;
102 :     }
103 :     }
104 :     $job->{meta}->{source_fasta} = $faf;
105 :     $job->{meta}->{source_qual} = $qaf if (defined $qaf);
106 :    
107 :     # create the job
108 :     # from here, all things like job id, jobdir, and meta have new in front of them if they refer to the new job version
109 :    
110 :     my ($newjobid, $msg) = Job48->create_new_job($job);
111 :     if ($newjobid) {
112 :     print "The job was created with job id $newjobid\n";
113 :     } else {
114 :     print STDERR "The job was not created but this is it's info: ", Dumper($job), "\n";
115 :     }
116 :    
117 :     if ($msg) {
118 :     print STDERR "There was a warning: $msg while trying to create the job\n";
119 :     }
120 :    
121 :     ## END COPY PART - the above section was imported from copy_metagenome
122 :    
123 :     my $newjobdir=$FIG_Config::mgrast_jobs."/".$newjobid;
124 :    
125 :     # mark it as DELETED so we don't work on it automatically
126 :    
127 :     `mv $newjobdir/ACTIVE $newjobdir/DELETE`
128 :    
129 :     # Set the meta flag that says where we came from
130 :    
131 :     my $nmf = "$newjobdir/meta.xml";
132 :     my $newmeta = GenomeMeta->new(undef, $nmf);
133 :    
134 :     $newmeta->set("upgrade_source", $jobid);
135 :     $newmeta->set("original_preprocess.count_proc.file", $job->{meta}->{'preprocess.count_proc.file'});
136 :    
137 :     # now we want to submit the preprocess to the cluster
138 :    
139 :     my $name = 'preprocess';
140 :     my $processor = ClusterStage->new('mg_preprocess', sge_flag => "-l mg_preprocess");
141 :    
142 :     eval {
143 :     if (ref($processor) eq 'CODE')
144 :     {
145 :     &$processor($name, $newjobid, $newjobdir, $newmeta, $sge);
146 :     }
147 :     elsif (ref($processor))
148 :     {
149 :     $processor->process($name, $newjobid, $newjobdir, $newmeta, $sge);
150 :     }
151 :     else
152 :     {
153 :     warn "Unknown processor " . Dumper($processor);
154 :     }
155 :     };
156 :     if ($@)
157 :     {
158 :     print "Error processing job $newjobid\n$@\n";
159 :     }
160 :    
161 :    
162 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3