[Bio] / FigKernelScripts / svr_figfam_functions.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/svr_figfam_functions.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :     use strict;
3 :    
4 :     use Getopt::Long;
5 :     use SAPserver;
6 :     use ScriptThing;
7 :     use SeedUtils;
8 :    
9 :     #
10 :     # This is a SAS Component.
11 :     #
12 :    
13 :     =head1 svr_figfam_functions
14 :    
15 :     svr_figfam_functions <figfam_ids.tbl >figfam_functions.tbl
16 :    
17 :     Output the functions for the specified FIGfams.
18 :    
19 :     This script takes as input a tab-delimited file with FIGfam IDs at the end of
20 :     each line. For each FIGfam ID, the FIGfam's function will be appended to the list.
21 :    
22 :     This is a pipe command: the input is taken from the standard input and the
23 : parrello 1.2 output is to the standard output. Alternatively, a list of FIGfan IDs can be
24 :     specified as command-line parameters.
25 : parrello 1.1
26 :     =head2 Command-Line Options
27 :    
28 :     =over 4
29 :    
30 :     =item url
31 :    
32 :     The URL for the Sapling server, if it is to be different from the default.
33 :    
34 :     =item c
35 :    
36 :     Column index. If specified, indicates that the input IDs should be taken from the
37 :     indicated column instead of the last column. The first column is column 1.
38 :    
39 : parrello 1.2 =item all
40 :    
41 :     Instead of reading FIGfam IDs from the input, all FIGfams will be listed.
42 :    
43 : parrello 1.1 =back
44 :    
45 :     =cut
46 :    
47 :     # Parse the command-line options.
48 :     my $url = '';
49 :     my $column = 0;
50 : parrello 1.2 my $all = 0;
51 :     my $opted = GetOptions('url=s' => \$url, 'c=i' => \$column, 'all' => \$all);
52 : parrello 1.1 if (! $opted) {
53 : parrello 1.2 print "usage: svr_figfam_functions [--url=http://...] [--c=N] [--all] <input >output\n";
54 : parrello 1.1 } else {
55 :     # Get the server object.
56 :     my $sapServer = SAPserver->new(url => $url);
57 : parrello 1.2 my $input;
58 :     if ($all) {
59 :     # Here the user wants all the FIGfams. This is accomplished with a different
60 :     # call than the normal script.
61 :     my $ffHash = $sapServer->all_figfams();
62 :     for my $ff (sort keys %$ffHash) {
63 :     print "$ff\t$ffHash->{$ff}\n";
64 :     }
65 :     } else {
66 :     # Here the user wants selected FIGfams. Find out if we're getting input
67 :     # from STDIN or the command line.
68 :     my $input = (@ARGV ? [@ARGV] : \*STDIN);
69 :     # The main loop processes chunks of input.
70 :     while (my @tuples = ScriptThing::GetBatch($input, undef, $column)) {
71 :     # Ask the server for results.
72 :     my $document = $sapServer->figfam_function(-ids => [map { $_->[0] } @tuples]);
73 :     # Loop through the IDs, producing output.
74 :     for my $tuple (@tuples) {
75 :     my ($id, $line) = @$tuple;
76 :     # Get this FIGfam's function.
77 :     my $function = $document->{$id};
78 :     # Did we get something?
79 :     if (! $function) {
80 :     # No. Write an error notification.
81 :     print STDERR "Not found: $id\n";
82 :     } else {
83 :     # Yes. Write it out.
84 :     print "$line\t$function\n";
85 :     }
86 : parrello 1.1 }
87 :     }
88 :     }
89 :     }
90 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3