[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.11 - (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.1 my $unformatted = "$raw_dir/unformatted_contigs";
62 :    
63 :     if (! -f $unformatted)
64 :     {
65 :     &fatal("Unformatted contigs file $unformatted does not exist\n");
66 :     }
67 :    
68 :     #
69 : olson 1.8 # Determine genetic code.
70 :     #
71 :    
72 :     my $genetic_code = $meta->get_metadata("genome.genetic_code");
73 : olson 1.9 if (!defined($genetic_code))
74 : olson 1.8 {
75 :     $meta->add_log_entry("Genetic code not defined; defaulting to 11");
76 :     $genetic_code = 11;
77 :     }
78 :    
79 :     #
80 : olson 1.1 # Reformat and split.
81 :     #
82 : olson 1.7 # Only do this if we are doing gene calling.
83 :     #
84 : olson 1.1
85 :     my $formatted = "$raw_dir/contigs";
86 : olson 1.7 my @cmd;
87 : olson 1.1
88 : olson 1.10 my $split_size = 3;
89 :     if ($FIG_Config::rast_contig_ambig_split_size =~ /^\d+$/)
90 :     {
91 :     $split_size = $FIG_Config::rast_contig_ambig_split_size;
92 :     }
93 :    
94 : olson 1.7 if ($keep_genecalls)
95 :     {
96 :     my $reformat_log = "$errdir/reformat_contigs.stderr";
97 :    
98 :     @cmd = ("$FIG_Config::bin/reformat_contigs", "-v", "-logfile=$reformat_log", $unformatted, $formatted);
99 :     }
100 :     else
101 :     {
102 :     my $reformat_split_log = "$errdir/reformat_contigs_split.stderr";
103 :    
104 : olson 1.10 @cmd = ("$FIG_Config::bin/reformat_contigs", "-v", "-logfile=$reformat_split_log", "-split=$split_size", $unformatted, $formatted);
105 : olson 1.7 }
106 : olson 1.1
107 :     print "Run @cmd\n";
108 :    
109 :     $meta->add_log_entry($0, ['running', @cmd]);
110 :    
111 :     my $rc = system(@cmd);
112 :     if ($rc != 0)
113 :     {
114 :     &fatal("reformat command failed with rc=$rc: @cmd\n");
115 :     }
116 :    
117 :     #
118 :     # Do the rapid propagation itself.
119 :     #
120 :    
121 :     my $tmp = "tmprp.job$job.$$";
122 :     my $tmpdir = "/scratch/$tmp";
123 :    
124 :     &FIG::verify_dir("$jobdir/rp");
125 :    
126 : olson 1.3 #
127 :     # Determine if we are keeping the original gene calls.
128 :     #
129 :    
130 :     my @keep_genecalls_flag;
131 :    
132 :     if ($keep_genecalls)
133 :     {
134 :     $meta->add_log_entry($0, "Keeping original gene calls");
135 :     @keep_genecalls_flag = ("--keep");
136 :     }
137 :    
138 : olson 1.11 #
139 :     # Make sure we don't have any leftover restart directories in $errdir, since
140 :     # they will make rapid_propagation think it's restarting, which would be bad.
141 :     # Also reset the status.rp.* values to zero.
142 :     #
143 :    
144 :     my @restart_dirs = <$errdir/$genome.*>;
145 :     if (@restart_dirs)
146 :     {
147 :     my $targ = strftime("$errdir/restart.%Y-%m-%d-%H-%M-%S", localtime);
148 :     mkdir($targ);
149 :     for my $dir (@restart_dirs)
150 :     {
151 :     my $b = basename($dir);
152 :     rename($dir, "$targ/$b");
153 :     $meta->add_log_entry($0, "Moved existing restart directory $b to $targ");
154 :     }
155 :     }
156 :    
157 :     for my $key (grep { /^status\.rp\./ } $meta->get_metadata_keys())
158 :     {
159 :     my $old = $meta->get_metadata($key);
160 :     $meta->add_log_entry($0, "Reset old $key=$old to 0");
161 :     $meta->set_metadata($key, 0);
162 :     }
163 :    
164 : olson 1.1 @cmd = ("$FIG_Config::bin/rapid_propagation", "--errdir", $errdir,
165 : olson 1.3 @keep_genecalls_flag,
166 : olson 1.8 "--code", $genetic_code,
167 : olson 1.3 "--meta", $meta_file,
168 :     "--tmpdir", $tmpdir,
169 :     $raw_dir, $rp_dir);
170 : olson 1.1 print "Run @cmd\n";
171 :     $meta->add_log_entry($0, ['running', @cmd]);
172 :    
173 :     $rc = system(@cmd);
174 :    
175 :     if ($rc != 0)
176 :     {
177 :     &fatal("rapid_propagation command failed with rc=$rc: @cmd\n");
178 :     }
179 :    
180 :     #
181 :     # RP should be done. Check to see that we at least had a features directory created.
182 :     #
183 :    
184 :     if (! -d "$rp_dir/Features/peg")
185 :     {
186 :     &fatal("rapid_propagation did not create any features");
187 :     }
188 :    
189 :     $meta->add_log_entry($0, "rapid_propagation completed\n");
190 :     $meta->set_metadata("rp.running", "no");
191 :     $meta->set_metadata("status.rp", "complete");
192 :    
193 :     exit;
194 :    
195 :     sub fatal
196 :     {
197 :     my($msg) = @_;
198 :    
199 :     $meta->add_log_entry($0, ['fatal error', $msg]);
200 : olson 1.5 $meta->set_metadata("rp.error", $msg);
201 : olson 1.7 $meta->set_metadata("rp.running", "no");
202 : olson 1.2 $meta->set_metadata("status.rp", "error");
203 : olson 1.1
204 :     croak "$0: $msg";
205 :     }
206 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3