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

Annotation of /FigKernelScripts/svr_function_of.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :     use strict;
3 :    
4 :     use Getopt::Long;
5 :     use SAPserver;
6 :    
7 :     #
8 :     # This is a SAS Component.
9 :     #
10 :    
11 :     =head1 svr_function_of
12 :    
13 :     Get the functional assignment for each specified gene.
14 :    
15 :     This script takes as input a tab-delimited file with gene IDs at the end of each
16 :     line. For each gene ID, the functional assignment is appended to the line.
17 :    
18 :     This is a pipe command: the input is taken from the standard input and the output
19 :     is to the standard output.
20 :    
21 :     =head2 Command-Line Options
22 :    
23 :     =over 4
24 :    
25 :     =item source
26 :    
27 :     Database source of the IDs specified-- C<SEED> for FIG IDs, C<GENE> for standard
28 :     gene identifiers, or C<LocusTag> for locus tags. In addition, you may specify
29 :     C<RefSeq>, C<CMR>, C<NCBI>, C<Trembl>, or C<UniProt> for IDs from those databases.
30 :     Use C<mixed> to allow mixed ID types (though this may cause problems when the same
31 :     ID has different meanings in different databases). The default is C<SEED>.
32 :    
33 :     =item url
34 :    
35 :     The URL for the Sapling server, if it is to be different from the default.
36 :    
37 :     =back
38 :    
39 :     =cut
40 :    
41 :     # Parse the command-line options.
42 :     my $source = 'SEED';
43 :     my $url = '';
44 :     my $opted = GetOptions('source=s' => \$source, 'url=s' => \$url);
45 :     if (! $opted) {
46 :     print "usage: svr_function_of [--source=SEED] [--url=http://...] <input >output\n";
47 :     } else {
48 :     # Get the server object.
49 :     my $sapServer = SAPserver->new(url => $url);
50 :     # The main loop processes chunks of input, 100 lines at a time.
51 :     while (! eof STDIN) {
52 :     # We will build our list of IDs in here.
53 :     my @ids;
54 :     # This hash will map each ID to its input line.
55 :     my %lines;
56 :     # This will count the lines read in this batch.
57 :     my $reads = 0;
58 :     # Loop through the input. We stop at 1000 lines.
59 :     while ($reads <= 1000 && ! eof STDIN) {
60 :     # Read the line and trim it.
61 :     my $line = <STDIN>;
62 :     chomp $line;
63 :     # Count the read.
64 :     $reads++;
65 :     # Get the feature ID and save it.
66 :     my @fields = split /\t/, $line;
67 :     if (scalar @fields) {
68 :     my $fid = pop @fields;
69 :     push @ids, $fid;
70 :     # Save the input line for this ID.
71 :     $lines{$fid} = join("\t", @fields, $fid);
72 :    
73 :     }
74 :     }
75 :     # Ask the server for results.
76 :     my $document = $sapServer->ids_to_functions(-ids => \@ids,
77 :     -source => $source,
78 :     -functions => 1);
79 :     # Loop through the IDs, producing output.
80 :     for my $fid (@ids) {
81 :     # Get this feature's assignment.
82 :     my $function = $document->{$fid};
83 :     # Did we get something?
84 :     if (! $function) {
85 :     # No. Write an error notification.
86 :     print STDERR "Not found: $fid\n";
87 :     } else {
88 :     # Yes, print the output line.
89 :     print "$lines{$fid}\t$function\n";
90 :     }
91 :     }
92 :     }
93 :     }
94 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3