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

View of /FigKernelScripts/svr_function_of.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.1 - (download) (as text) (annotate)
Tue Oct 20 20:22:08 2009 UTC (10 years, 5 months ago) by parrello
Branch: MAIN
More extensive documentation for the various server scripts.

#!/usr/bin/perl -w
use strict;

use Getopt::Long;
use SAPserver;

#	This is a SAS Component.

=head1 svr_function_of

Get the functional assignment for each specified gene.

This script takes as input a tab-delimited file with gene IDs at the end of each
line. For each gene ID, the functional assignment is appended to the line.

This is a pipe command: the input is taken from the standard input and the output
is to the standard output.

=head2 Command-Line Options

=over 4

=item source

Database source of the IDs specified-- C<SEED> for FIG IDs, C<GENE> for standard
gene identifiers, or C<LocusTag> for locus tags. In addition, you may specify
C<RefSeq>, C<CMR>, C<NCBI>, C<Trembl>, or C<UniProt> for IDs from those databases.
Use C<mixed> to allow mixed ID types (though this may cause problems when the same
ID has different meanings in different databases). The default is C<SEED>.

=item url

The URL for the Sapling server, if it is to be different from the default.



# Parse the command-line options.
my $source = 'SEED';
my $url = '';
my $opted =  GetOptions('source=s' => \$source, 'url=s' => \$url);
if (! $opted) {
    print "usage: svr_function_of [--source=SEED] [--url=http://...] <input >output\n";
} else {
    # Get the server object.
    my $sapServer = SAPserver->new(url => $url);
    # The main loop processes chunks of input, 100 lines at a time.
    while (! eof STDIN) {
        # We will build our list of IDs in here.
        my @ids;
        # This hash will map each ID to its input line.
        my %lines;
        # This will count the lines read in this batch.
        my $reads = 0;
        # Loop through the input. We stop at 1000 lines.
        while ($reads <= 1000 && ! eof STDIN) {
            # Read the line and trim it.
            my $line = <STDIN>;
            chomp $line;
            # Count the read.
            # Get the feature ID and save it.
            my @fields = split /\t/, $line;
            if (scalar @fields) {
                my $fid = pop @fields;
                push @ids, $fid;
                # Save the input line for this ID.
                $lines{$fid} = join("\t", @fields, $fid);
        # Ask the server for results.
        my $document = $sapServer->ids_to_functions(-ids => \@ids,
                                                    -source => $source,
                                                    -functions => 1);
        # Loop through the IDs, producing output.
        for my $fid (@ids) {
            # Get this feature's assignment.
            my $function = $document->{$fid};
            # Did we get something?
            if (! $function) {
                # No. Write an error notification.
                print STDERR "Not found: $fid\n";
            } else {
                # Yes, print the output line.
                print "$lines{$fid}\t$function\n";

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3