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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3