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

Annotation of /FortyEight/rp_rapid_propagation.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : olson 1.1
2 :     #
3 :     # Perform rapid propagation.
4 :     #
5 :    
6 :     use strict;
7 :     use FIG;
8 :     use FIG_Config;
9 :     use File::Basename;
10 :     use GenomeMeta;
11 : olson 1.6 use Carp 'croak';
12 : olson 1.11 use POSIX;
13 : olson 1.1
14 :     @ARGV == 1 or die "Usage: $0 job-dir\n";
15 :    
16 :     my $jobdir = shift;
17 :    
18 :     -d $jobdir or die "$0: job dir $jobdir does not exist\n";
19 :    
20 : olson 1.4 my $hostname = `hostname`;
21 :     chomp $hostname;
22 :    
23 : olson 1.1 my $genome = &FIG::file_head("$jobdir/GENOME_ID");
24 :     chomp $genome;
25 :     $genome =~ /^\d+\.\d+/ or die "$0: Cannnot find genome ID for jobdir $jobdir\n";
26 :    
27 :     my $job = basename($jobdir);
28 :    
29 :     my $meta_file = "$jobdir/meta.xml";
30 :     my $meta = new GenomeMeta($genome, $meta_file);
31 :    
32 :     my $raw_dir = "$jobdir/raw/$genome";
33 :     my $rp_dir = "$jobdir/rp/$genome";
34 :    
35 :     my $errdir = "$jobdir/rp.errors";
36 :     &FIG::verify_dir($errdir);
37 :    
38 :     if (! -d $raw_dir)
39 :     {
40 :     &fatal("raw genome directory $raw_dir does not exist");
41 :     }
42 :    
43 : olson 1.4 $meta->set_metadata("rp.hostname", $hostname);
44 : olson 1.1
45 :     #
46 :     # Perform the rapid propagation.
47 :     #
48 :     # We work from the raw genome directory. We assume the incoming contigs
49 :     # are present in raw/genome-id/unformatted_contigs. We run
50 :     # reformat_contigs -split before the actual rapid propagation to
51 :     # split any scaffolds present in the contigs.
52 :     #
53 :     # When the rp is finished, we move the split contigs out of the way
54 :     # and rerun reformat_contigs without the split option in order
55 :     # to recover the original contig coordinates.
56 :     #
57 : olson 1.7 # If keep_genecalls is enabled, we do not split the contigs.
58 :     #
59 : olson 1.1
60 : olson 1.7 my $keep_genecalls = $meta->get_metadata("keep_genecalls");
61 : olson 1.12 my $call_using_glimmer = $meta->get_metadata("use_glimmer");
62 : olson 1.1 my $unformatted = "$raw_dir/unformatted_contigs";
63 :    
64 :     if (! -f $unformatted)
65 :     {
66 :     &fatal("Unformatted contigs file $unformatted does not exist\n");
67 :     }
68 :    
69 :     #
70 : olson 1.8 # Determine genetic code.
71 :     #
72 :    
73 :     my $genetic_code = $meta->get_metadata("genome.genetic_code");
74 : olson 1.9 if (!defined($genetic_code))
75 : olson 1.8 {
76 :     $meta->add_log_entry("Genetic code not defined; defaulting to 11");
77 :     $genetic_code = 11;
78 :     }
79 :    
80 :     #
81 : olson 1.1 # Reformat and split.
82 :     #
83 : olson 1.7 # Only do this if we are doing gene calling.
84 :     #
85 : olson 1.1
86 :     my $formatted = "$raw_dir/contigs";
87 : olson 1.7 my @cmd;
88 : olson 1.1
89 : olson 1.10 my $split_size = 3;
90 :     if ($FIG_Config::rast_contig_ambig_split_size =~ /^\d+$/)
91 :     {
92 :     $split_size = $FIG_Config::rast_contig_ambig_split_size;
93 :     }
94 :    
95 : olson 1.7 if ($keep_genecalls)
96 :     {
97 :     my $reformat_log = "$errdir/reformat_contigs.stderr";
98 :    
99 :     @cmd = ("$FIG_Config::bin/reformat_contigs", "-v", "-logfile=$reformat_log", $unformatted, $formatted);
100 :     }
101 :     else
102 :     {
103 :     my $reformat_split_log = "$errdir/reformat_contigs_split.stderr";
104 :    
105 : olson 1.10 @cmd = ("$FIG_Config::bin/reformat_contigs", "-v", "-logfile=$reformat_split_log", "-split=$split_size", $unformatted, $formatted);
106 : olson 1.7 }
107 : olson 1.1
108 :     print "Run @cmd\n";
109 :    
110 :     $meta->add_log_entry($0, ['running', @cmd]);
111 :    
112 :     my $rc = system(@cmd);
113 :     if ($rc != 0)
114 :     {
115 :     &fatal("reformat command failed with rc=$rc: @cmd\n");
116 :     }
117 :    
118 :     #
119 :     # Do the rapid propagation itself.
120 :     #
121 :    
122 :     my $tmp = "tmprp.job$job.$$";
123 : olson 1.14 #my $tmpdir = "/scratch/$tmp";
124 :     my $tmpdir = "$FIG_Config::temp/$tmp";
125 : olson 1.1
126 :     &FIG::verify_dir("$jobdir/rp");
127 :    
128 : olson 1.3 #
129 :     # Determine if we are keeping the original gene calls.
130 :     #
131 :    
132 :     my @keep_genecalls_flag;
133 :    
134 :     if ($keep_genecalls)
135 :     {
136 :     $meta->add_log_entry($0, "Keeping original gene calls");
137 :     @keep_genecalls_flag = ("--keep");
138 :     }
139 :    
140 : olson 1.11 #
141 :     # Make sure we don't have any leftover restart directories in $errdir, since
142 :     # they will make rapid_propagation think it's restarting, which would be bad.
143 :     # Also reset the status.rp.* values to zero.
144 :     #
145 :    
146 :     my @restart_dirs = <$errdir/$genome.*>;
147 :     if (@restart_dirs)
148 :     {
149 :     my $targ = strftime("$errdir/restart.%Y-%m-%d-%H-%M-%S", localtime);
150 :     mkdir($targ);
151 :     for my $dir (@restart_dirs)
152 :     {
153 :     my $b = basename($dir);
154 :     rename($dir, "$targ/$b");
155 :     $meta->add_log_entry($0, "Moved existing restart directory $b to $targ");
156 :     }
157 :     }
158 :    
159 : olson 1.12
160 :     #
161 :     # If we are to call using glimmer instead of the usual mechanism, first
162 :     # invoke call_genome_using_glimmer.
163 :     #
164 :    
165 :     if ($call_using_glimmer)
166 :     {
167 : olson 1.13 my @cmd = ("$FIG_Config::bin/call_genome_using_glimmer",
168 : olson 1.12 "--glimmerV=3",
169 :     "--code=$genetic_code",
170 :     "--meta=$meta_file",
171 :     $raw_dir);
172 :    
173 :     print "Run @cmd\n";
174 :     $meta->add_log_entry($0, ['running', @cmd]);
175 :    
176 :     $rc = system(@cmd);
177 :    
178 :     if ($rc != 0)
179 :     {
180 :     &fatal("call_using_glimmer command failed with rc=$rc: @cmd\n");
181 :     }
182 :     }
183 :    
184 : olson 1.11 for my $key (grep { /^status\.rp\./ } $meta->get_metadata_keys())
185 :     {
186 :     my $old = $meta->get_metadata($key);
187 :     $meta->add_log_entry($0, "Reset old $key=$old to 0");
188 :     $meta->set_metadata($key, 0);
189 :     }
190 :    
191 : olson 1.17 my $user = &FIG::file_head("$jobdir/USER");
192 :     chomp $user;
193 :    
194 : olson 1.21 #
195 :     # Determine if we are choosing a kmer dataset.
196 :     #
197 :    
198 :     my $kmerDataset;
199 :     my @opt_kmer_dataset;
200 :     if (my $ds = $meta->get_metadata('options.figfam_version'))
201 :     {
202 :     $kmerDataset = $ds;
203 :     $ENV{SVR_DEFAULT_KMER_DATASET} = $ds;
204 :     @opt_kmer_dataset = (-kmerDataset => $ds);
205 :     }
206 :    
207 : olson 1.17 my $rp_script = $FIG_Config::rapid_propagation_script{$user};
208 :     $rp_script = $FIG_Config::rapid_propagation_script if $rp_script eq '';
209 : olson 1.15 my %valid_rapid_propagation = (rapid_propagation => 1,
210 : olson 1.18 rapid_propagation2 => 1,
211 : olson 1.19 rapid_propagation3 => 1,
212 :     rapid_propagation4 => 1,
213 : olson 1.21 rapid_propagation5 => 1,
214 : olson 1.19 );
215 : olson 1.15
216 :     if (!$valid_rapid_propagation{$rp_script})
217 :     {
218 : olson 1.20 &fatal("invalid rapid_propagation script $rp_script\n");
219 : olson 1.15 }
220 :    
221 : olson 1.16 $meta->add_log_entry($0, "Processing using rapid propagation script '$rp_script'");
222 : olson 1.15 @cmd = ("$FIG_Config::bin/$rp_script", "--errdir", $errdir,
223 : olson 1.3 @keep_genecalls_flag,
224 : olson 1.21 @opt_kmer_dataset,
225 : olson 1.8 "--code", $genetic_code,
226 : olson 1.3 "--meta", $meta_file,
227 :     "--tmpdir", $tmpdir,
228 :     $raw_dir, $rp_dir);
229 : olson 1.1 print "Run @cmd\n";
230 :     $meta->add_log_entry($0, ['running', @cmd]);
231 :    
232 :     $rc = system(@cmd);
233 :    
234 :     if ($rc != 0)
235 :     {
236 :     &fatal("rapid_propagation command failed with rc=$rc: @cmd\n");
237 :     }
238 :    
239 :     #
240 :     # RP should be done. Check to see that we at least had a features directory created.
241 :     #
242 :    
243 :     if (! -d "$rp_dir/Features/peg")
244 :     {
245 :     &fatal("rapid_propagation did not create any features");
246 :     }
247 :    
248 :     $meta->add_log_entry($0, "rapid_propagation completed\n");
249 :     $meta->set_metadata("rp.running", "no");
250 :     $meta->set_metadata("status.rp", "complete");
251 :    
252 :     exit;
253 :    
254 :     sub fatal
255 :     {
256 :     my($msg) = @_;
257 :    
258 :     $meta->add_log_entry($0, ['fatal error', $msg]);
259 : olson 1.5 $meta->set_metadata("rp.error", $msg);
260 : olson 1.7 $meta->set_metadata("rp.running", "no");
261 : olson 1.2 $meta->set_metadata("status.rp", "error");
262 : olson 1.1
263 :     croak "$0: $msg";
264 :     }
265 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3