[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.10 - (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.1
13 :     @ARGV == 1 or die "Usage: $0 job-dir\n";
14 :    
15 :     my $jobdir = shift;
16 :    
17 :     -d $jobdir or die "$0: job dir $jobdir does not exist\n";
18 :    
19 : olson 1.4 my $hostname = `hostname`;
20 :     chomp $hostname;
21 :    
22 : olson 1.1 my $genome = &FIG::file_head("$jobdir/GENOME_ID");
23 :     chomp $genome;
24 :     $genome =~ /^\d+\.\d+/ or die "$0: Cannnot find genome ID for jobdir $jobdir\n";
25 :    
26 :     my $job = basename($jobdir);
27 :    
28 :     my $meta_file = "$jobdir/meta.xml";
29 :     my $meta = new GenomeMeta($genome, $meta_file);
30 :    
31 :     my $raw_dir = "$jobdir/raw/$genome";
32 :     my $rp_dir = "$jobdir/rp/$genome";
33 :    
34 :     my $errdir = "$jobdir/rp.errors";
35 :     &FIG::verify_dir($errdir);
36 :    
37 :     if (! -d $raw_dir)
38 :     {
39 :     &fatal("raw genome directory $raw_dir does not exist");
40 :     }
41 :    
42 : olson 1.4 $meta->set_metadata("rp.hostname", $hostname);
43 : olson 1.1
44 :     #
45 :     # Perform the rapid propagation.
46 :     #
47 :     # We work from the raw genome directory. We assume the incoming contigs
48 :     # are present in raw/genome-id/unformatted_contigs. We run
49 :     # reformat_contigs -split before the actual rapid propagation to
50 :     # split any scaffolds present in the contigs.
51 :     #
52 :     # When the rp is finished, we move the split contigs out of the way
53 :     # and rerun reformat_contigs without the split option in order
54 :     # to recover the original contig coordinates.
55 :     #
56 : olson 1.7 # If keep_genecalls is enabled, we do not split the contigs.
57 :     #
58 : olson 1.1
59 : olson 1.7 my $keep_genecalls = $meta->get_metadata("keep_genecalls");
60 : olson 1.1 my $unformatted = "$raw_dir/unformatted_contigs";
61 :    
62 :     if (! -f $unformatted)
63 :     {
64 :     &fatal("Unformatted contigs file $unformatted does not exist\n");
65 :     }
66 :    
67 :     #
68 : olson 1.8 # Determine genetic code.
69 :     #
70 :    
71 :     my $genetic_code = $meta->get_metadata("genome.genetic_code");
72 : olson 1.9 if (!defined($genetic_code))
73 : olson 1.8 {
74 :     $meta->add_log_entry("Genetic code not defined; defaulting to 11");
75 :     $genetic_code = 11;
76 :     }
77 :    
78 :     #
79 : olson 1.1 # Reformat and split.
80 :     #
81 : olson 1.7 # Only do this if we are doing gene calling.
82 :     #
83 : olson 1.1
84 :     my $formatted = "$raw_dir/contigs";
85 : olson 1.7 my @cmd;
86 : olson 1.1
87 : olson 1.10 my $split_size = 3;
88 :     if ($FIG_Config::rast_contig_ambig_split_size =~ /^\d+$/)
89 :     {
90 :     $split_size = $FIG_Config::rast_contig_ambig_split_size;
91 :     }
92 :    
93 : olson 1.7 if ($keep_genecalls)
94 :     {
95 :     my $reformat_log = "$errdir/reformat_contigs.stderr";
96 :    
97 :     @cmd = ("$FIG_Config::bin/reformat_contigs", "-v", "-logfile=$reformat_log", $unformatted, $formatted);
98 :     }
99 :     else
100 :     {
101 :     my $reformat_split_log = "$errdir/reformat_contigs_split.stderr";
102 :    
103 : olson 1.10 @cmd = ("$FIG_Config::bin/reformat_contigs", "-v", "-logfile=$reformat_split_log", "-split=$split_size", $unformatted, $formatted);
104 : olson 1.7 }
105 : olson 1.1
106 :     print "Run @cmd\n";
107 :    
108 :     $meta->add_log_entry($0, ['running', @cmd]);
109 :    
110 :     my $rc = system(@cmd);
111 :     if ($rc != 0)
112 :     {
113 :     &fatal("reformat command failed with rc=$rc: @cmd\n");
114 :     }
115 :    
116 :     #
117 :     # Do the rapid propagation itself.
118 :     #
119 :    
120 :     my $tmp = "tmprp.job$job.$$";
121 :     my $tmpdir = "/scratch/$tmp";
122 :    
123 :     &FIG::verify_dir("$jobdir/rp");
124 :    
125 : olson 1.3 #
126 :     # Determine if we are keeping the original gene calls.
127 :     #
128 :    
129 :     my @keep_genecalls_flag;
130 :    
131 :     if ($keep_genecalls)
132 :     {
133 :     $meta->add_log_entry($0, "Keeping original gene calls");
134 :     @keep_genecalls_flag = ("--keep");
135 :     }
136 :    
137 : olson 1.1 @cmd = ("$FIG_Config::bin/rapid_propagation", "--errdir", $errdir,
138 : olson 1.3 @keep_genecalls_flag,
139 : olson 1.8 "--code", $genetic_code,
140 : olson 1.3 "--meta", $meta_file,
141 :     "--tmpdir", $tmpdir,
142 :     $raw_dir, $rp_dir);
143 : olson 1.1 print "Run @cmd\n";
144 :     $meta->add_log_entry($0, ['running', @cmd]);
145 :    
146 :     $rc = system(@cmd);
147 :    
148 :     if ($rc != 0)
149 :     {
150 :     &fatal("rapid_propagation command failed with rc=$rc: @cmd\n");
151 :     }
152 :    
153 :     #
154 :     # RP should be done. Check to see that we at least had a features directory created.
155 :     #
156 :    
157 :     if (! -d "$rp_dir/Features/peg")
158 :     {
159 :     &fatal("rapid_propagation did not create any features");
160 :     }
161 :    
162 :     $meta->add_log_entry($0, "rapid_propagation completed\n");
163 :     $meta->set_metadata("rp.running", "no");
164 :     $meta->set_metadata("status.rp", "complete");
165 :    
166 :     exit;
167 :    
168 :     sub fatal
169 :     {
170 :     my($msg) = @_;
171 :    
172 :     $meta->add_log_entry($0, ['fatal error', $msg]);
173 : olson 1.5 $meta->set_metadata("rp.error", $msg);
174 : olson 1.7 $meta->set_metadata("rp.running", "no");
175 : olson 1.2 $meta->set_metadata("status.rp", "error");
176 : olson 1.1
177 :     croak "$0: $msg";
178 :     }
179 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3