[Bio] / FortyEight / rp_auto_assign.pl Repository:
ViewVC logotype

Annotation of /FortyEight/rp_auto_assign.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (view) (download) (as text)

1 : gdpusch 1.14 # -*- perl -*-
2 :     #########################################################################
3 :     # Copyright (c) 2003-2008 University of Chicago and Fellowship
4 :     # for Interpretations of Genomes. All Rights Reserved.
5 :     #
6 :     # This file is part of the SEED Toolkit.
7 :     #
8 :     # The SEED Toolkit is free software. You can redistribute
9 :     # it and/or modify it under the terms of the SEED Toolkit
10 :     # Public License.
11 :     #
12 :     # You should have received a copy of the SEED Toolkit Public License
13 :     # along with this program; if not write to the University of Chicago
14 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15 :     # Genomes at veronika@thefig.info or download a copy from
16 :     # http://www.theseed.org/LICENSE.TXT.
17 :     #########################################################################
18 : olson 1.1
19 :     #
20 :     # Perform auto-assignment on unassigned pegs.
21 :     #
22 :    
23 :     use strict;
24 : gdpusch 1.15
25 : olson 1.1 use FIG;
26 :     use FIG_Config;
27 : gdpusch 1.15 use SeedUtils;
28 :    
29 :     use Job48;
30 :     use GenomeMeta;
31 :    
32 : olson 1.1 use File::Basename;
33 : gdpusch 1.15 use Carp qw(croak confess);
34 : olson 1.1
35 :     @ARGV == 1 or die "Usage: $0 job-dir\n";
36 :    
37 :     my $jobdir = shift;
38 :    
39 :     -d $jobdir or die "$0: job dir $jobdir does not exist\n";
40 :    
41 :     my $genome = &FIG::file_head("$jobdir/GENOME_ID");
42 :     chomp $genome;
43 :     $genome =~ /^\d+\.\d+/ or die "$0: Cannnot find genome ID for jobdir $jobdir\n";
44 : gdpusch 1.15 my $genome_dir = "$jobdir/rp/$genome";
45 : olson 1.1
46 :     my $meta = new GenomeMeta($genome, "$jobdir/meta.xml");
47 :    
48 : gdpusch 1.15 my %done;
49 :    
50 : olson 1.1 my $tbl = "$jobdir/rp/$genome/Features/peg/tbl";
51 : gdpusch 1.15 (-f $tbl) || die "$0: Cannot find tbl file $tbl\n";
52 :     open(TBL, "<$tbl") or &fatal("Cannot open tbl file $tbl: $!");
53 : olson 1.1
54 :     my $proposed = "$jobdir/rp/$genome/proposed_functions";
55 : gdpusch 1.15 if (!open(PROP, "<$proposed")) {
56 : olson 1.1 warn "could not open proposed functions $proposed: $!";
57 :     $meta->add_log_entry($0, "could not open proposed fucntions $proposed");
58 :     }
59 : gdpusch 1.15 else {
60 :     while (<PROP>) {
61 : olson 1.1 chomp;
62 :     my($peg, $assign) = split;
63 :     $done{$peg} = $assign;
64 :     }
65 :     close(PROP);
66 :     }
67 :    
68 : olson 1.4 my $simfile = "$jobdir/rp/$genome/expanded_similarities";
69 : olson 1.6 my $cmd = "$FIG_Config::bin/auto_assign -orgdir $jobdir/rp/$genome > $jobdir/rp/$genome/proposed_non_ff_functions";
70 : olson 1.1 print "running $cmd\n";
71 :     open(AA, "| $cmd")
72 : gdpusch 1.15 or &fatal("aa failed: $!");
73 : olson 1.1
74 :     my $peg_count = 0;
75 : gdpusch 1.15 while (<TBL>) {
76 : olson 1.1 chomp;
77 :     my($peg, @rest) = split(/\t/);
78 : gdpusch 1.15 if (!$done{$peg}) {
79 :     ++$peg_count;
80 : olson 1.1 print AA "$peg\n";
81 :     }
82 :     }
83 :     close(TBL);
84 :    
85 :     $meta->add_log_entry($0, "computing auto_assign on $peg_count pegs");
86 :    
87 : gdpusch 1.15 if (!close(AA)) {
88 :     &fatal("error on close of pipe-cmd=\'$cmd\': \$?=$? \$!=$!");
89 : olson 1.1 }
90 :    
91 : gdpusch 1.15
92 :    
93 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
94 :     #... Call of `rapid_subsystem_inference` removed from `rapid_propagation`
95 :     # to here. -- /gdp
96 :     #-----------------------------------------------------------------------
97 :     my %func_of;
98 :     foreach my $file (map { $genome_dir . q(/) . $_
99 :     } qw(assigned_functions proposed_non_ff_functions proposed_functions)) {
100 :     if (-s $file) {
101 :     map { chomp; m/^(\S+)\t(.*)$/o ? ($func_of{$1} = $2) : () } &SeedUtils::file_read($file);
102 :     }
103 :     }
104 :    
105 :     open(METAB, qq(| rapid_subsystem_inference $genome_dir/Subsystems))
106 :     || die qq(Could not pipe-open rapid_subsystem_inference);
107 :     print METAB map { $_ . qq(\t) . $func_of{$_} . qq(\n) } (sort keys %func_of);
108 :     close(METAB);
109 :    
110 :    
111 :    
112 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
113 : olson 1.8 # When auto assign is complete, we are able to submit the model computation.
114 : gdpusch 1.15 #-----------------------------------------------------------------------
115 :     if ($meta->get_metadata("model_build.enabled")) {
116 : olson 1.11 my $userid;
117 :     my $link;
118 :     eval {
119 :     my $job = Job48->new($jobdir);
120 : olson 1.12 my $uo = $job->getUserObject;
121 : gdpusch 1.15 if ($uo) {
122 : olson 1.11 $userid = $uo->_id;
123 :     }
124 :     };
125 :    
126 : gdpusch 1.15 if (defined($userid)) {
127 : olson 1.13 $link = "http://rast.nmpdr.org/seedviewer.cgi?model=Seed${genome}.${userid}&page=ModelView";
128 : olson 1.11 }
129 : gdpusch 1.15 else {
130 : olson 1.11 $meta->add_log_entry($0, "Could not get user id");
131 :     }
132 :    
133 : gdpusch 1.15
134 : olson 1.9 my $user = &FIG::file_head("$jobdir/USER", 1);
135 :     chomp $user;
136 : olson 1.10 my $cmd = ("/vol/model-prod/FIGdisk/bin/ModelDriver.sh 'createmodelfile?$genome?1?$user' > $jobdir/rp.errors/create_model.stderr 2>&1");
137 : olson 1.9 my $rc = system($cmd);
138 : gdpusch 1.15 if ($rc != 0) {
139 : olson 1.9 $meta->add_log_entry($0, ['error creating model', $rc]);
140 :     }
141 : gdpusch 1.15 else {
142 : olson 1.9 $meta->add_log_entry($0, ['model submitted']);
143 :    
144 : gdpusch 1.15 if (defined($link)) {
145 : olson 1.11 $meta->set_metadata("model_build.viewing_link", $link) ;
146 :     }
147 : olson 1.9 }
148 : olson 1.8 }
149 :    
150 :    
151 : olson 1.1 $meta->add_log_entry($0, "auto_assign completed\n");
152 :     $meta->set_metadata("status.auto_assign", "complete");
153 : olson 1.7 $meta->set_metadata("auto_assign.running", "no");
154 : olson 1.1
155 : gdpusch 1.15 sub fatal {
156 :     my ($msg) = @_;
157 :    
158 : olson 1.1 $meta->add_log_entry($0, ['fatal error', $msg]);
159 :     $meta->set_metadata("status.auto_assign", "error");
160 : gdpusch 1.15
161 : gdpusch 1.14 confess "$0: $msg";
162 : olson 1.1 }
163 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3