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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3