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

Diff of /FortyEight/rp_auto_assign.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4, Fri Jun 8 19:20:20 2007 UTC revision 1.15, Fri Dec 3 21:37:56 2010 UTC
# Line 1  Line 1 
1    # -*- 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    
19  #  #
20  # Perform auto-assignment on unassigned pegs.  # Perform auto-assignment on unassigned pegs.
21  #  #
22    
23  use strict;  use strict;
24    
25  use FIG;  use FIG;
26  use FIG_Config;  use FIG_Config;
27  use File::Basename;  use SeedUtils;
28    
29    use Job48;
30  use GenomeMeta;  use GenomeMeta;
31    
32    use File::Basename;
33    use Carp qw(croak confess);
34    
35  @ARGV == 1 or die "Usage: $0 job-dir\n";  @ARGV == 1 or die "Usage: $0 job-dir\n";
36    
37  my $jobdir = shift;  my $jobdir = shift;
# Line 18  Line 41 
41  my $genome = &FIG::file_head("$jobdir/GENOME_ID");  my $genome = &FIG::file_head("$jobdir/GENOME_ID");
42  chomp $genome;  chomp $genome;
43  $genome =~ /^\d+\.\d+/ or die "$0: Cannnot find genome ID for jobdir $jobdir\n";  $genome =~ /^\d+\.\d+/ or die "$0: Cannnot find genome ID for jobdir $jobdir\n";
44    my $genome_dir = "$jobdir/rp/$genome";
45    
46  my $meta = new GenomeMeta($genome, "$jobdir/meta.xml");  my $meta = new GenomeMeta($genome, "$jobdir/meta.xml");
47    
48    my %done;
49    
50  my $tbl = "$jobdir/rp/$genome/Features/peg/tbl";  my $tbl = "$jobdir/rp/$genome/Features/peg/tbl";
51  -f $tbl or die "$0: Cannot find tbl file $tbl\n";  (-f $tbl) || die "$0: Cannot find tbl file $tbl\n";
52    open(TBL, "<$tbl") or &fatal("Cannot open tbl file $tbl: $!");
53    
54  my $proposed = "$jobdir/rp/$genome/proposed_functions";  my $proposed = "$jobdir/rp/$genome/proposed_functions";
55    if (!open(PROP, "<$proposed")) {
 my %done;  
   
 if (!open(PROP, "<$proposed"))  
 {  
56      warn "could not  open proposed functions $proposed: $!";      warn "could not  open proposed functions $proposed: $!";
57      $meta->add_log_entry($0, "could not open proposed fucntions $proposed");      $meta->add_log_entry($0, "could not open proposed fucntions $proposed");
58  }  }
59  else  else {
60  {      while (<PROP>) {
     while (<PROP>)  
     {  
61          chomp;          chomp;
62          my($peg, $assign) = split;          my($peg, $assign) = split;
63          $done{$peg} = $assign;          $done{$peg} = $assign;
# Line 45  Line 66 
66  }  }
67    
68  my $simfile = "$jobdir/rp/$genome/expanded_similarities";  my $simfile = "$jobdir/rp/$genome/expanded_similarities";
69    my $cmd = "$FIG_Config::bin/auto_assign -orgdir $jobdir/rp/$genome > $jobdir/rp/$genome/proposed_non_ff_functions";
 open(TBL, "<$tbl") or &fatal("Cannot open tbl file $tbl: $!");  
   
 my $cmd = "$FIG_Config::bin/auto_assign sims=$simfile > $jobdir/rp/$genome/proposed_non_ff_functions";  
70  print "running $cmd\n";  print "running $cmd\n";
71  open(AA, "| $cmd")  open(AA, "| $cmd")
72          or &fatal("aa failed: $!");          or &fatal("aa failed: $!");
73    
74  my $peg_count = 0;  my $peg_count = 0;
75  while (<TBL>)  while (<TBL>) {
 {  
76      chomp;      chomp;
77      my($peg, @rest) = split(/\t/);      my($peg, @rest) = split(/\t/);
78      if (!$done{$peg})      if (!$done{$peg}) {
79      {          ++$peg_count;
         $peg_count++;  
80          print AA "$peg\n";          print AA "$peg\n";
81      }      }
82  }  }
# Line 68  Line 84 
84    
85  $meta->add_log_entry($0, "computing auto_assign on $peg_count pegs");  $meta->add_log_entry($0, "computing auto_assign on $peg_count pegs");
86    
87  if (!close(AA))  if (!close(AA)) {
88  {      &fatal("error on close of pipe-cmd=\'$cmd\': \$?=$? \$!=$!");
89      &fatal("error on close \$?=$? \$!=$!");  }
90    
91    
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    # When auto assign is complete, we are able to submit the model computation.
114    #-----------------------------------------------------------------------
115    if ($meta->get_metadata("model_build.enabled")) {
116        my $userid;
117        my $link;
118        eval {
119            my $job = Job48->new($jobdir);
120            my $uo = $job->getUserObject;
121            if ($uo) {
122                $userid = $uo->_id;
123            }
124        };
125    
126        if (defined($userid)) {
127            $link = "http://rast.nmpdr.org/seedviewer.cgi?model=Seed${genome}.${userid}&page=ModelView";
128  }  }
129        else {
130            $meta->add_log_entry($0, "Could not get user id");
131        }
132    
133    
134        my $user = &FIG::file_head("$jobdir/USER", 1);
135        chomp $user;
136        my $cmd = ("/vol/model-prod/FIGdisk/bin/ModelDriver.sh 'createmodelfile?$genome?1?$user' > $jobdir/rp.errors/create_model.stderr 2>&1");
137        my $rc = system($cmd);
138        if ($rc != 0) {
139            $meta->add_log_entry($0, ['error creating model', $rc]);
140        }
141        else {
142            $meta->add_log_entry($0, ['model submitted']);
143    
144            if (defined($link)) {
145                $meta->set_metadata("model_build.viewing_link", $link) ;
146            }
147        }
148    }
149    
150    
151  $meta->add_log_entry($0, "auto_assign completed\n");  $meta->add_log_entry($0, "auto_assign completed\n");
152  $meta->set_metadata("status.auto_assign", "complete");  $meta->set_metadata("status.auto_assign", "complete");
153    $meta->set_metadata("auto_assign.running", "no");
154    
155  sub fatal  sub fatal {
 {  
156      my($msg) = @_;      my($msg) = @_;
157    
158      $meta->add_log_entry($0, ['fatal error', $msg]);      $meta->add_log_entry($0, ['fatal error', $msg]);
159      $meta->set_metadata("status.auto_assign", "error");      $meta->set_metadata("status.auto_assign", "error");
160    
161      croak "$0: $msg";      confess "$0: $msg";
162  }  }
163    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.15

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3