[Bio] / FigWebServices / fig_scripts_service.cgi Repository:
ViewVC logotype

Diff of /FigWebServices/fig_scripts_service.cgi

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

revision 1.11, Tue May 27 16:23:06 2008 UTC revision 1.12, Wed May 28 16:24:51 2008 UTC
# Line 17  Line 17 
17  -> handle;  -> handle;
18    
19  package Scripts;  package Scripts;
20    
21  use FIG;  use FIG;
22    use FIGV;
23  use FIG_Config;  use FIG_Config;
24  use Data::Dumper;  use Data::Dumper;
25  use FigFams;  use FigFams;
# Line 25  Line 27 
27  use IPC::Open3;  use IPC::Open3;
28  use raelib;  use raelib;
29    
30    my $dbm;
31    BEGIN {
32            eval { $dbm = DBMaster->new(-database => 'FortyEight_WebApplication') };
33            die $@ if $@;
34    };
35    
36    
37    
38  =begin WSDL  =begin WSDL
39  _IN auth $string  _IN auth $string
40  _IN args $string  _IN args $string
# Line 107  Line 117 
117    
118          #print STDERR "Check $job_id, $login_name";          #print STDERR "Check $job_id, $login_name";
119          $ENV{DBHOST} = 'bioseed.mcs.anl.gov';          $ENV{DBHOST} = 'bioseed.mcs.anl.gov';
120          my $dbm = DBMaster->new('FortyEight_WebApplication');                  # my $dbm = DBMaster->new(-database => 'FortyEight_WebApplication');
121          my $users = $dbm->User->get_objects({ login => $login_name });          my $users = $dbm->User->get_objects({ login => $login_name });
122          my $user;          my $user;
123          if ($users && @$users) {          if ($users && @$users) {
# Line 154  Line 164 
164  _IN job $string  _IN job $string
165  _IN username $string  _IN username $string
166  _RETURN $string  _RETURN $string
167  _DOC Input is a job id and a username, output is a tuple of [id, user, genome id, and genome name]  _DOC Input is a job id and a username, output is a tuple of [id, user, genome id, genome name, size, number of contigs, number of pegs]
168  =cut  =cut
169  sub mg_rast_job_info {  sub mg_rast_job_info {
170          my ($class, $job_id, $login_name)  = @_;          my ($class, $job_id, $login_name)  = @_;
# Line 162  Line 172 
172          my $job=$class->_validate_mg_rast_user($job_id, $login_name, 'getjob');          my $job=$class->_validate_mg_rast_user($job_id, $login_name, 'getjob');
173          if ($job =~ /Access Error/) {return $job}          if ($job =~ /Access Error/) {return $job}
174    
175          return join(", ", $job->id, $job->user, $job->genome_id, $job->genome_name);          my ($sz, $numcontigs, $npegs)=(0,0,0);
176            my $orgdir=$class->_validate_mg_rast_user($job_id, $login_name);
177            my $figv=FIGV->new($orgdir);
178            $npegs=$figv->genome_pegs($job->genome_id);
179    
180            my $contig_lens = $figv->contig_lengths($job->genome_id);
181            while ( my($contig,$len) = each %$contig_lens)
182            {
183                    $sz += $len;
184                    $numcontigs++
185            }
186    
187            return join(", ", $job->id, $job->user, $job->genome_id, $job->genome_name, $sz, $numcontigs, $npegs);
188    }
189    
190    =begin WSDL
191    _IN username $string
192    _RETURN $string
193    _DOC Input is a username and output is a list of tuples of [job id, user, genome id, and genome name]
194    =cut
195    sub mg_rast_users_job_info {
196            my ($class, $login_name)  = @_;
197            my ($userj, $orgj)=$class->_user_mg_rast_jobs($login_name);
198            my $output;
199            foreach my $jobid (@$userj, @$orgj)
200            {
201                    my $job=$class->_validate_mg_rast_user($jobid, $login_name, 'getjob');
202                    next if ($job =~ /Access Error/);
203    
204                    my ($coords, $time, $meta);
205                    eval {$meta = GenomeMeta->new(undef, "/vol/metagenome-48-hour/Jobs.prod/$jobid/meta.xml");};
206                    if ($@) {$coords = $time = "Error with xml"}
207                    else {
208                            eval {$coords = $class->mg_rast_lat_lon($jobid, $login_name)};
209                            eval {$time   = $meta->get_metadata("optional_info.time");};
210                            $coords =~ s/^\s+//; $coords =~ s/\s+$//; $coords =~ s/^\s*\,\s*$//;
211                            $time =~ s/^\s+//; $time =~ s/\s+$//;
212                    }
213    
214                    $output .= join("\t", $job->id, $job->user, $job->genome_id,
215                                    $job->genome_name,  $coords, $time). "\n";
216            }
217            chomp($output);
218            return $output;
219    }
220    
221    
222    =begin WSDL
223    _IN job $string
224    _IN username $string
225    _IN searchterm $string
226    _RETURN $string search results
227    _DOC Input is a job, a username, and a term to search for, and the results are the search results from querying that metagenome
228    =cut
229    sub mg_search_metagenome {
230            my ($class, $job_id, $login_name, $search)  = @_;
231            return undef unless ($search);
232    
233            my $orgdir=$class->_validate_mg_rast_user($job_id, $login_name);
234            if ($orgdir =~ /Access Error/ || !(-e $orgdir)) {return $orgdir}
235    
236            my $figv=FIGV->new($orgdir);
237            my $res=$figv->search_features_by_annotation($search, 1);
238            my $return;
239    
240            foreach my $fn (keys %$res)
241            {
242                    $return .= join("\n", map {join("\t", $_, $fn)} @{$res->{$fn}});
243            }
244            return  $return;
245    
246    }
247    
248    =begin WSDL
249    _IN username $string
250    _IN searchterm $string
251    _RETURN $string search results
252    _DOC Input is a username, and a term to search for, and the results are the search results from querying all metagenomes that user has access to
253    =cut
254    sub mg_search_users_metagenomes {
255            my ($class, $login_name, $search)  = @_;
256            return undef unless ($search);
257    
258            my ($userj, $orgj)=$class->_user_mg_rast_jobs($login_name);
259            my $return;
260            foreach my $job_id (@$userj, @$orgj)
261            {
262    
263                    my $orgdir=$class->_validate_mg_rast_user($job_id, $login_name);
264                    if ($orgdir =~ /Access Error/ || !(-e $orgdir)) {return $orgdir}
265    
266                    my $figv=FIGV->new($orgdir);
267                    my $res=$figv->search_features_by_annotation($search, 1);
268    
269                    foreach my $fn (keys %$res)
270                    {
271                            $return .= join("\n", map {join("\t", $_, $fn)} @{$res->{$fn}})."\n";
272                    }
273            }
274            chomp($return);
275            return  $return;
276    
277  }  }
278    
279    
# Line 241  Line 352 
352          if ($orgdir =~ /Access Error/ || !(-e $orgdir)) {return $orgdir}          if ($orgdir =~ /Access Error/ || !(-e $orgdir)) {return $orgdir}
353    
354          my $meta = GenomeMeta->new(undef, "/vol/metagenome-48-hour/Jobs.prod/$job_id/meta.xml");          my $meta = GenomeMeta->new(undef, "/vol/metagenome-48-hour/Jobs.prod/$job_id/meta.xml");
355          return $meta->get_metadata("optional_info.latitude") .",".$meta->get_metadata("optional_info.longitude");          my $ret = $meta->get_metadata("optional_info.latitude") .",".$meta->get_metadata("optional_info.longitude");
356            $ret =~ s/^\s*\,\s*$//;
357            return $ret;
358  }  }
359    
360  =begin WSDL  =begin WSDL
# Line 620  Line 733 
733                  push (@result_list, (join("\t", @$entry)));                  push (@result_list, (join("\t", @$entry)));
734          }          }
735    
736          push (@result_list, (join("\t", @$roles)));          # push (@result_list, (join("\t", @$roles)));
737          chomp @result_list;          chomp @result_list;
738          my $return_value = join ("\n", @result_list);          my $return_value = join ("\n", @result_list);
739          return $return_value;          return $return_value;
# Line 642  Line 755 
755  }  }
756    
757  =begin WSDL  =begin WSDL
758    _RETURN $string list of subsystems and their classifications
759    _DOC No Input, output is a list of all the subsystems and their classifications
760    =cut
761    sub all_subsystem_classifications {
762            my ($class) = @_;
763            my $fig = new FIG;
764            my $output;
765    
766            my %found;
767            map {
768                    my @classification=@{$fig->subsystem_classification($_)};
769                    $#classification=1;
770                    push @classification, $_;
771                    $output.= join("\t", @classification)."\n";
772            } sort {$a cmp $b} ($fig->all_subsystems());
773            return $output;
774    }
775    
776    
777    =begin WSDL
778  _RETURN $string list of families and funcs  _RETURN $string list of families and funcs
779  _DOC No Input, output is list of all families  _DOC No Input, output is list of all families
780  =cut  =cut
# Line 818  Line 951 
951    
952          my ($self, $job_id, $login_name, $getjob)=@_;          my ($self, $job_id, $login_name, $getjob)=@_;
953          $ENV{DBHOST} = 'bioseed.mcs.anl.gov';          $ENV{DBHOST} = 'bioseed.mcs.anl.gov';
954          my $dbm = DBMaster->new(-database => 'FortyEight_WebApplication');  # my $dbm = DBMaster->new(-database => 'FortyEight_WebApplication');
955          my $users = $dbm->User->get_objects({ login => $login_name });          my $users = $dbm->User->get_objects({ login => $login_name });
956          my $org=$users->[0]->{organisation};          my $org=$users->[0]->{organisation};
957          my $user;          my $user;
# Line 828  Line 961 
961  # Also, I return "Access Error" regardless of whether the job is there or not to stop people  # Also, I return "Access Error" regardless of whether the job is there or not to stop people
962  # hacking.  # hacking.
963          $job_id="/vol/metagenome-48-hour/Jobs.prod/$job_id";          $job_id="/vol/metagenome-48-hour/Jobs.prod/$job_id";
964          return "Access Error 1" unless (-e $job_id); # simple check that we have that id          return "Access Error 1 and $job_id" unless (-e $job_id); # simple check that we have that id
965    
966  # now make sure we are a valid user. If we are not a valid user this should throw an error  # now make sure we are a valid user. If we are not a valid user this should throw an error
967    
# Line 854  Line 987 
987          # The first is user jobs, and the second is jobs of the users organization          # The first is user jobs, and the second is jobs of the users organization
988          my ($self, $login_name)=@_;          my ($self, $login_name)=@_;
989          $ENV{DBHOST} = 'bioseed.mcs.anl.gov';          $ENV{DBHOST} = 'bioseed.mcs.anl.gov';
990          my $dbm = DBMaster->new(-database => 'FortyEight_WebApplication');          my $org;
991    # my $dbm = DBMaster->new(-database => 'FortyEight_WebApplication');
992          my $users = $dbm->User->get_objects({ login => $login_name });          my $users = $dbm->User->get_objects({ login => $login_name });
993          my $org=$users->[0]->{organisation};          my $org=$users->[0]->{organisation};
994    
# Line 864  Line 998 
998          foreach my $dir (grep {m/^\d+$/} readdir(DIR))          foreach my $dir (grep {m/^\d+$/} readdir(DIR))
999          {          {
1000                  my $job_id="/vol/metagenome-48-hour/Jobs.prod/$dir";                  my $job_id="/vol/metagenome-48-hour/Jobs.prod/$dir";
1001                    next unless (-d $job_id && -e "$job_id/DONE" && !-e "$job_id/DELETE");
1002                    # print STDERR "$job_id\n";
1003                  my $job;                  my $job;
1004                  eval {$job = Job48->new($job_id)};                  eval {$job = Job48->new($job_id)};
1005                  die $@ if ($@ || !$job);                  die $@ if ($@);
1006                    die "No job for $job\n" if (!$job);
1007                  next if ($job->to_be_deleted);                  next if ($job->to_be_deleted);
1008                  ($job->user eq $login_name) ? push @user, $job->id :                  ($job->user eq $login_name) ? push @user, $job->id :
1009                          ($job->getUserObject->{organisation} == $org) ? push @org, $job->id : 1;                          ($job->getUserObject->{organisation} == $org) ? push @org, $job->id : 1;

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3