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

Annotation of /FortyEight/create_import_job.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : olson 1.1 #
2 :     # Create a SEED-import job.
3 :     #
4 :     # The job initially has a listing of SEED fasta sources, NR fasta sources, and
5 :     # RAST fasta sources. The new NR will not have been built - it will be the first stage
6 :     # in the pipeline.
7 :     #
8 :     # For now we need to pass in the path to the NR and peg.synonyms files we are building from.
9 :     #
10 :     # We create the following files:
11 :     #
12 :     # nr.dirs
13 :     # Tab-delimited data of db-name, source path, size of fasta file
14 :     #
15 :     # nr.sources
16 :     # Listing of all fasta source files from which the nr is to be built
17 :     #
18 :     # We hardcode in the script, for now, the source locations of things. This is an ANL internal
19 :     # application at this point.
20 :     #
21 :     #
22 :     #
23 :    
24 :     use strict;
25 :     use Data::Dumper;
26 :     use DirHandle;
27 :     use ImportJob;
28 :     use Job48;
29 :     use NRTools;
30 :    
31 : olson 1.4 my $usage = "create_import_job [-import-biodb] [-from-job jobnum] [prev-nr prev-syn prev-sims]";
32 : olson 1.1
33 :     #
34 :     # Incoming NR data.
35 :     #
36 :     my $dir_biodb = "/vol/biodb";
37 : olson 1.4 my $dir_biodb_nr_input = "$dir_biodb/processed_data/for_build_nr";
38 : olson 1.1
39 :     #
40 :     # Existing SEED data
41 :     #
42 :    
43 : olson 1.3 my $dir_reference_seed_data = "/vol/seed-data-anno-mirror/Data.Jan3";
44 :     #my $dir_reference_seed_data = "/local/FIGdisk/FIG/Data";
45 : olson 1.1
46 :     #
47 :     # RAST server from which to pull genomes to import.
48 :     #
49 :    
50 :     my $dir_rast_jobs = "/vol/48-hour/Jobs.prod.2007-0601";
51 :    
52 :     #
53 :     # Startup.
54 :     #
55 :    
56 : olson 1.4 my $do_biodb_import;
57 :     my $from_job_id;
58 :    
59 :     while ((@ARGV > 0) && ($ARGV[0] =~ /^-/))
60 :     {
61 :     my $arg = shift @ARGV;
62 :     if ($arg =~ /^-import-biodb/i)
63 :     {
64 :     $do_biodb_import++;
65 :     }
66 :     elsif ($arg =~ /^-from-job/)
67 :     {
68 :     $from_job_id = shift @ARGV;
69 :     }
70 :     else
71 :     {
72 :     die $usage;
73 :     }
74 :     }
75 :    
76 :     my $prev_nr_src;
77 :     my $prev_syn_src;
78 :     my $prev_sim_dir;
79 :     my $from_job;
80 : olson 1.1
81 : olson 1.4 if (defined($from_job_id))
82 :     {
83 :     @ARGV == 0 or die $usage;
84 :    
85 :     $from_job = ImportJob->new($from_job_id);
86 :     $from_job or die "From-job id $from_job_id does not exist";
87 :    
88 :     my $dir = $from_job->dir();
89 :     $prev_nr_src = "$dir/nr";
90 :     $prev_syn_src = "$dir/peg.synonyms";
91 :     $prev_sim_dir = sprintf("$dir/Sims.%03d", $from_job_id);
92 :     }
93 :     else
94 :     {
95 :     @ARGV == 3 or die $usage;
96 :    
97 :     $prev_nr_src = shift;
98 :     $prev_syn_src = shift;
99 :     $prev_sim_dir = shift;
100 :     }
101 : olson 1.1
102 :     #
103 :     # Validate
104 :     #
105 :     if (open(F, "<$prev_nr_src"))
106 :     {
107 :     $_ = <F>;
108 :     if (! /^>/)
109 :     {
110 :     die "$prev_nr_src does not look like a fasta file\n";
111 :     }
112 :     close(F);
113 :     }
114 :     else
115 :     {
116 :     die "Cannot open previous NR file $prev_nr_src: $!\n";
117 :     }
118 :    
119 :     if (open(F, "<$prev_syn_src"))
120 :     {
121 :     $_ = <F>;
122 :     if (!/^xxx\d+,\d+\t/)
123 :     {
124 :     die "$prev_syn_src does not look like a peg.synonyms file\n";
125 :     }
126 :     close(F);
127 :     }
128 :     else
129 :     {
130 :     die "Cannot open previous synonyms file $prev_syn_src: $!\n";
131 :     }
132 :    
133 : olson 1.3 my @sfiles = <$prev_sim_dir/sims*>;
134 :     if (not(-d $prev_sim_dir and @sfiles > 0))
135 : olson 1.1 {
136 :     die "previous sim dir $prev_sim_dir does not appear to contain sims\n";
137 :     }
138 :    
139 :    
140 : olson 1.4 print "Creating import job\n";
141 :     print "\tprev_nr=$prev_nr_src\n";
142 :     print "\tprev_syn=$prev_syn_src\n";
143 :     print "\tprev_sim=$prev_sim_dir\n";
144 :    
145 : olson 1.1 #
146 :     # Initial validation.
147 :     #
148 :     &validate_dirs($dir_biodb_nr_input, $dir_reference_seed_data, $dir_rast_jobs);
149 :    
150 : olson 1.4 if ($do_biodb_import)
151 :     {
152 :     &validate_dirs($dir_biodb_nr_input);
153 :     }
154 :    
155 : olson 1.1 #
156 :     # Create our jobdir.
157 :     #
158 :    
159 :     my ($jobnum, $err) = ImportJob->create_new_job();
160 :     #my ($jobnum, $err) = ('002', undef);
161 :    
162 :     if (!$jobnum)
163 :     {
164 :     die "Create failed with error: $err\n";
165 :     }
166 :    
167 :     my $job = ImportJob->new($jobnum);
168 :     my $jobdir = $job->dir;
169 :    
170 :     $job->meta->add_log_entry($0, "creating new job");
171 :    
172 :     #
173 :     # Symlink to prev_nr and prev_syn in the job directory.
174 :     #
175 :    
176 :     my $prev_nr = "$jobdir/prev_nr";
177 :     my $prev_syn = "$jobdir/prev_syn";
178 :     my $prev_sims = "$jobdir/prev_sims";
179 :    
180 :     unlink($prev_nr, $prev_syn, $prev_sims);
181 :    
182 :     symlink($prev_nr_src, $prev_nr) or die "symlimk $prev_nr_src $prev_nr failed: $!";
183 :     symlink($prev_syn_src, $prev_syn) or die "symlimk $prev_syn_src $prev_syn failed: $!";
184 :     symlink($prev_sim_dir, $prev_sims) or die "symlimk $prev_sim_dir $prev_sims failed: $!";
185 :    
186 :     #
187 :     # Build list of NR sources. We start with the directories in the reference
188 :     # SEED's NR dir, and override with anything in the biodb NR dir.
189 :     #
190 :    
191 :     my %NR_dirs;
192 :    
193 :     scan_NR_dir(\%NR_dirs, "$dir_reference_seed_data/NR");
194 :     scan_NR_dir(\%NR_dirs, "$dir_biodb_nr_input");
195 :     #scan_NR_dir(\%NR_dirs, "$dir_biodb_nr_input", { skip => qr(^(SwissProt|.*\.bak)) });
196 :    
197 :     #
198 :     # And write to job dir.
199 :     #
200 :     open(F, ">$jobdir/nr.dirs");
201 :     for my $d (keys %NR_dirs)
202 :     {
203 :     print F join("\t", $d, @{$NR_dirs{$d}}{'path', 'size'}), "\n";
204 :     }
205 :     close(F);
206 :    
207 :     #
208 :     # Scan for SEED organisms.
209 :     #
210 :    
211 :     scan_seed_dir(\%NR_dirs, "$dir_reference_seed_data/Organisms");
212 :    
213 :     #
214 :     # Scan for RAST jobs to import.
215 :     #
216 : olson 1.2 # We update our NR component list with the peg features from the job,
217 :     # and we add the job directory of each to the rast.jobs file. This
218 :     # will be used later during the installation of these jobs into the SEED.
219 :     #
220 :    
221 : olson 1.3 open(JOBS, ">$jobdir/rast.jobs") or die "Cannot create $jobdir/rast.jobs: $!";
222 : olson 1.1
223 :     my @rast_jobs;
224 :     scan_rast_jobs(\@rast_jobs, $dir_rast_jobs);
225 :    
226 : olson 1.3 my @new_rast_jobs;
227 : olson 1.1 for my $job (@rast_jobs)
228 :     {
229 :     my $gid = $job->genome_id;
230 :     my $gname = $job->genome_name;
231 :     my $j = $job->id;
232 :    
233 :     print "RAST job #$j: $gid $gname\n";
234 :    
235 :     if (exists($NR_dirs{$gid}))
236 :     {
237 : olson 1.3 warn "Rast job $j already exists in SEED server\n";
238 :     next;
239 : olson 1.1 }
240 : olson 1.3 push(@new_rast_jobs, $job);
241 :    
242 :     print JOBS $job->dir(), "\n";
243 : olson 1.1
244 :     my $fasta = $job->orgdir() . "/Features/peg/fasta";
245 :     -f $fasta or die "Job $j has no fasta file in $fasta\n";
246 :     $NR_dirs{$gid} = {type => "rast_job", name => $gname, path => $job->orgdir,
247 :     fasta_path => $fasta, size => -s _ };
248 :     }
249 : olson 1.2 close(JOBS);
250 : olson 1.3 @rast_jobs = @new_rast_jobs;
251 : olson 1.1
252 :     open(F, ">$jobdir/all.nr.dirs");
253 :     open(F2, ">$jobdir/nr.sources");
254 :     for my $d (sort bydb keys %NR_dirs)
255 :     {
256 :     print F join("\t", $d, @{$NR_dirs{$d}}{'path', 'size'}), "\n";
257 :     print F2 $NR_dirs{$d}->{fasta_path} . "\n";
258 :     }
259 :     close(F);
260 :     close(F2);
261 :    
262 :     sub bydb
263 :     {
264 :     if ($a =~ /^(\d+)\.(\d+)$/)
265 :     {
266 :     my($ga, $ia) = ($1, $2);
267 :     if ($b =~ /^(\d+)\.(\d+)$/)
268 :     {
269 :     my($gb, $ib) = ($1, $2);
270 :     return $ga <=> $gb or $ia <=> $ib;
271 :     }
272 :     else
273 :     {
274 :     return 1;
275 :     }
276 :     }
277 :     elsif ($b =~ /^\d+\.\d+$/)
278 :     {
279 :     return -1;
280 :     }
281 :     else
282 :     {
283 :     return $a cmp $b;
284 :     }
285 :     }
286 :    
287 :    
288 :     sub validate_dirs
289 :     {
290 :     my(@dirs) = @_;
291 :    
292 :     my $err;
293 :     for my $dir (@dirs)
294 :     {
295 :     if (! -d $dir)
296 :     {
297 :     warn "Required directory $dir is not present\n";
298 :     $err++;
299 :     }
300 :     }
301 :     exit(1) if $err;
302 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3