[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.7 - (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 :     # Reformat and split.
69 :     #
70 : olson 1.7 # Only do this if we are doing gene calling.
71 :     #
72 : olson 1.1
73 :     my $formatted = "$raw_dir/contigs";
74 : olson 1.7 my @cmd;
75 : olson 1.1
76 : olson 1.7 if ($keep_genecalls)
77 :     {
78 :     my $reformat_log = "$errdir/reformat_contigs.stderr";
79 :    
80 :     @cmd = ("$FIG_Config::bin/reformat_contigs", "-v", "-logfile=$reformat_log", $unformatted, $formatted);
81 :     }
82 :     else
83 :     {
84 :     my $reformat_split_log = "$errdir/reformat_contigs_split.stderr";
85 :    
86 :     @cmd = ("$FIG_Config::bin/reformat_contigs", "-v", "-logfile=$reformat_split_log", "-split", $unformatted, $formatted);
87 :     }
88 : olson 1.1
89 :     print "Run @cmd\n";
90 :    
91 :     $meta->add_log_entry($0, ['running', @cmd]);
92 :    
93 :     my $rc = system(@cmd);
94 :     if ($rc != 0)
95 :     {
96 :     &fatal("reformat command failed with rc=$rc: @cmd\n");
97 :     }
98 :    
99 :     #
100 :     # Do the rapid propagation itself.
101 :     #
102 :    
103 :     my $tmp = "tmprp.job$job.$$";
104 :     my $tmpdir = "/scratch/$tmp";
105 :    
106 :     &FIG::verify_dir("$jobdir/rp");
107 :    
108 : olson 1.3 #
109 :     # Determine if we are keeping the original gene calls.
110 :     #
111 :    
112 :     my @keep_genecalls_flag;
113 :    
114 :     if ($keep_genecalls)
115 :     {
116 :     $meta->add_log_entry($0, "Keeping original gene calls");
117 :     @keep_genecalls_flag = ("--keep");
118 :     }
119 :    
120 : olson 1.1 @cmd = ("$FIG_Config::bin/rapid_propagation", "--errdir", $errdir,
121 : olson 1.3 @keep_genecalls_flag,
122 :     "--meta", $meta_file,
123 :     "--tmpdir", $tmpdir,
124 :     $raw_dir, $rp_dir);
125 : olson 1.1 print "Run @cmd\n";
126 :     $meta->add_log_entry($0, ['running', @cmd]);
127 :    
128 :     $rc = system(@cmd);
129 :    
130 :     if ($rc != 0)
131 :     {
132 :     &fatal("rapid_propagation command failed with rc=$rc: @cmd\n");
133 :     }
134 :    
135 :     #
136 :     # RP should be done. Check to see that we at least had a features directory created.
137 :     #
138 :    
139 :     if (! -d "$rp_dir/Features/peg")
140 :     {
141 :     &fatal("rapid_propagation did not create any features");
142 :     }
143 :    
144 :     $meta->add_log_entry($0, "rapid_propagation completed\n");
145 :     $meta->set_metadata("rp.running", "no");
146 :     $meta->set_metadata("status.rp", "complete");
147 :    
148 :     exit;
149 :    
150 :     sub fatal
151 :     {
152 :     my($msg) = @_;
153 :    
154 :     $meta->add_log_entry($0, ['fatal error', $msg]);
155 : olson 1.5 $meta->set_metadata("rp.error", $msg);
156 : olson 1.7 $meta->set_metadata("rp.running", "no");
157 : olson 1.2 $meta->set_metadata("status.rp", "error");
158 : olson 1.1
159 :     croak "$0: $msg";
160 :     }
161 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3