[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.3 - (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 :     my $usage = "create_import_job prev-nr prev-syn prev-sims";
32 :    
33 :     #
34 :     # Incoming NR data.
35 :     #
36 :     my $dir_biodb = "/vol/biodb";
37 :     #my $dir_biodb_nr_input = "$dir_biodb/processed_data/for_build_nr";
38 :     my $dir_biodb_nr_input = "/local/FIGdisk/FIG/Data/NR";
39 :    
40 :    
41 :     #
42 :     # Existing SEED data
43 :     #
44 :    
45 : olson 1.3 my $dir_reference_seed_data = "/vol/seed-data-anno-mirror/Data.Jan3";
46 :     #my $dir_reference_seed_data = "/local/FIGdisk/FIG/Data";
47 : olson 1.1
48 :     #
49 :     # RAST server from which to pull genomes to import.
50 :     #
51 :    
52 :     my $dir_rast_jobs = "/vol/48-hour/Jobs.prod.2007-0601";
53 :    
54 :     #
55 :     # Startup.
56 :     #
57 :    
58 :     @ARGV == 3 or die $usage;
59 :    
60 :     my $prev_nr_src = shift;
61 :     my $prev_syn_src = shift;
62 :     my $prev_sim_dir = shift;
63 :    
64 :     #
65 :     # Validate
66 :     #
67 :     if (open(F, "<$prev_nr_src"))
68 :     {
69 :     $_ = <F>;
70 :     if (! /^>/)
71 :     {
72 :     die "$prev_nr_src does not look like a fasta file\n";
73 :     }
74 :     close(F);
75 :     }
76 :     else
77 :     {
78 :     die "Cannot open previous NR file $prev_nr_src: $!\n";
79 :     }
80 :    
81 :     if (open(F, "<$prev_syn_src"))
82 :     {
83 :     $_ = <F>;
84 :     if (!/^xxx\d+,\d+\t/)
85 :     {
86 :     die "$prev_syn_src does not look like a peg.synonyms file\n";
87 :     }
88 :     close(F);
89 :     }
90 :     else
91 :     {
92 :     die "Cannot open previous synonyms file $prev_syn_src: $!\n";
93 :     }
94 :    
95 : olson 1.3 my @sfiles = <$prev_sim_dir/sims*>;
96 :     if (not(-d $prev_sim_dir and @sfiles > 0))
97 : olson 1.1 {
98 :     die "previous sim dir $prev_sim_dir does not appear to contain sims\n";
99 :     }
100 :    
101 :    
102 :     #
103 :     # Initial validation.
104 :     #
105 :     &validate_dirs($dir_biodb_nr_input, $dir_reference_seed_data, $dir_rast_jobs);
106 :    
107 :     #
108 :     # Create our jobdir.
109 :     #
110 :    
111 :     my ($jobnum, $err) = ImportJob->create_new_job();
112 :     #my ($jobnum, $err) = ('002', undef);
113 :    
114 :     if (!$jobnum)
115 :     {
116 :     die "Create failed with error: $err\n";
117 :     }
118 :    
119 :     my $job = ImportJob->new($jobnum);
120 :     my $jobdir = $job->dir;
121 :    
122 :     $job->meta->add_log_entry($0, "creating new job");
123 :    
124 :     #
125 :     # Symlink to prev_nr and prev_syn in the job directory.
126 :     #
127 :    
128 :     my $prev_nr = "$jobdir/prev_nr";
129 :     my $prev_syn = "$jobdir/prev_syn";
130 :     my $prev_sims = "$jobdir/prev_sims";
131 :    
132 :     unlink($prev_nr, $prev_syn, $prev_sims);
133 :    
134 :     symlink($prev_nr_src, $prev_nr) or die "symlimk $prev_nr_src $prev_nr failed: $!";
135 :     symlink($prev_syn_src, $prev_syn) or die "symlimk $prev_syn_src $prev_syn failed: $!";
136 :     symlink($prev_sim_dir, $prev_sims) or die "symlimk $prev_sim_dir $prev_sims failed: $!";
137 :    
138 :     #
139 :     # Build list of NR sources. We start with the directories in the reference
140 :     # SEED's NR dir, and override with anything in the biodb NR dir.
141 :     #
142 :    
143 :     my %NR_dirs;
144 :    
145 :     scan_NR_dir(\%NR_dirs, "$dir_reference_seed_data/NR");
146 :     scan_NR_dir(\%NR_dirs, "$dir_biodb_nr_input");
147 :     #scan_NR_dir(\%NR_dirs, "$dir_biodb_nr_input", { skip => qr(^(SwissProt|.*\.bak)) });
148 :    
149 :     #
150 :     # And write to job dir.
151 :     #
152 :     open(F, ">$jobdir/nr.dirs");
153 :     for my $d (keys %NR_dirs)
154 :     {
155 :     print F join("\t", $d, @{$NR_dirs{$d}}{'path', 'size'}), "\n";
156 :     }
157 :     close(F);
158 :    
159 :     #
160 :     # Scan for SEED organisms.
161 :     #
162 :    
163 :     scan_seed_dir(\%NR_dirs, "$dir_reference_seed_data/Organisms");
164 :    
165 :     #
166 :     # Scan for RAST jobs to import.
167 :     #
168 : olson 1.2 # We update our NR component list with the peg features from the job,
169 :     # and we add the job directory of each to the rast.jobs file. This
170 :     # will be used later during the installation of these jobs into the SEED.
171 :     #
172 :    
173 : olson 1.3 open(JOBS, ">$jobdir/rast.jobs") or die "Cannot create $jobdir/rast.jobs: $!";
174 : olson 1.1
175 :     my @rast_jobs;
176 :     scan_rast_jobs(\@rast_jobs, $dir_rast_jobs);
177 :    
178 : olson 1.3 my @new_rast_jobs;
179 : olson 1.1 for my $job (@rast_jobs)
180 :     {
181 :     my $gid = $job->genome_id;
182 :     my $gname = $job->genome_name;
183 :     my $j = $job->id;
184 :    
185 :     print "RAST job #$j: $gid $gname\n";
186 :    
187 :     if (exists($NR_dirs{$gid}))
188 :     {
189 : olson 1.3 warn "Rast job $j already exists in SEED server\n";
190 :     next;
191 : olson 1.1 }
192 : olson 1.3 push(@new_rast_jobs, $job);
193 :    
194 :     print JOBS $job->dir(), "\n";
195 : olson 1.1
196 :     my $fasta = $job->orgdir() . "/Features/peg/fasta";
197 :     -f $fasta or die "Job $j has no fasta file in $fasta\n";
198 :     $NR_dirs{$gid} = {type => "rast_job", name => $gname, path => $job->orgdir,
199 :     fasta_path => $fasta, size => -s _ };
200 :     }
201 : olson 1.2 close(JOBS);
202 : olson 1.3 @rast_jobs = @new_rast_jobs;
203 : olson 1.1
204 :     open(F, ">$jobdir/all.nr.dirs");
205 :     open(F2, ">$jobdir/nr.sources");
206 :     for my $d (sort bydb keys %NR_dirs)
207 :     {
208 :     print F join("\t", $d, @{$NR_dirs{$d}}{'path', 'size'}), "\n";
209 :     print F2 $NR_dirs{$d}->{fasta_path} . "\n";
210 :     }
211 :     close(F);
212 :     close(F2);
213 :    
214 :     sub bydb
215 :     {
216 :     if ($a =~ /^(\d+)\.(\d+)$/)
217 :     {
218 :     my($ga, $ia) = ($1, $2);
219 :     if ($b =~ /^(\d+)\.(\d+)$/)
220 :     {
221 :     my($gb, $ib) = ($1, $2);
222 :     return $ga <=> $gb or $ia <=> $ib;
223 :     }
224 :     else
225 :     {
226 :     return 1;
227 :     }
228 :     }
229 :     elsif ($b =~ /^\d+\.\d+$/)
230 :     {
231 :     return -1;
232 :     }
233 :     else
234 :     {
235 :     return $a cmp $b;
236 :     }
237 :     }
238 :    
239 :    
240 :     sub validate_dirs
241 :     {
242 :     my(@dirs) = @_;
243 :    
244 :     my $err;
245 :     for my $dir (@dirs)
246 :     {
247 :     if (! -d $dir)
248 :     {
249 :     warn "Required directory $dir is not present\n";
250 :     $err++;
251 :     }
252 :     }
253 :     exit(1) if $err;
254 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3