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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3