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

Annotation of /FigKernelScripts/svr_upstream.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (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_upstream
12 :    
13 :     Retrieve upstream regions from the Sapling Server.
14 :    
15 :     This script takes as input a tab-delimited file with feature IDs at the end. For
16 :     each feature ID, the upstream DNA is computed and written to the output file in
17 :     FASTA format. Sections of DNA that occur inside a feature are shown in upper
18 :     case. DNA between known features is shown in lower case.
19 :    
20 : parrello 1.4 This is a pipe command. Input is from the standard input and output is to the
21 :     standard output.
22 :    
23 : parrello 1.1 =head2 Command-Line Options
24 :    
25 :     =over 4
26 :    
27 :     =item skipGene
28 :    
29 :     If specified, then only the upstream region is output. Otherwise, the upstream
30 :     region and the feature interior are output together.
31 :    
32 :     =item size
33 :    
34 :     Number of base pairs to show in the upstream region. The default is C<200>.
35 :    
36 :     =item url
37 :    
38 : parrello 1.3 The URL for the Sapling server, if it is to be different from the default.
39 : parrello 1.1
40 :     =back
41 :    
42 :     =cut
43 :    
44 :     # Parse the command-line options.
45 :     my $skipGene = '';
46 :     my $size = 200;
47 : parrello 1.2 my $url = '';
48 : parrello 1.3 my $opted = GetOptions('skipGene' => \$skipGene, 'size=i' => \$size, 'url=s' => \$url);
49 : parrello 1.1 if (! $opted) {
50 : parrello 1.3 print "usage: svr_upstream [--skipGene] [--size=200] [-url=http://...] <input >output\n";
51 : parrello 1.1 } else {
52 : parrello 1.4 # Get the server object.
53 :     my $sapServer = SAPserver->new(url => $url);
54 :     # The main loop processes chunks of input, 100 lines at a time.
55 :     while (! eof STDIN) {
56 :     # We will build our list of IDs in here.
57 :     my @ids;
58 :     # This hash will map each ID to its extra fields.
59 :     my %comments;
60 :     # This will count the lines read in this batch.
61 :     my $reads = 0;
62 :     # Loop through the input. We stop at 100 lines.
63 :     while ($reads <= 100 && ! eof STDIN) {
64 :     # Read the line and trim it.
65 :     my $line = <STDIN>;
66 :     chomp $line;
67 :     # Count the read.
68 :     $reads++;
69 :     # Get the feature ID and save it.
70 :     my @fields = split /\t/, $line;
71 :     if (scalar @fields) {
72 :     my $fid = pop @fields;
73 :     push @ids, $fid;
74 :     $comments{$fid} = join(" ", @fields);
75 : parrello 1.1 }
76 : parrello 1.4 }
77 :     # Ask the server for results.
78 :     my $document = $sapServer->upstream(-ids => \@ids, -size => $size,
79 :     -comments => \%comments,
80 :     -skipGene => $skipGene);
81 :     # Loop through the IDs, producing output.
82 :     for my $fid (@ids) {
83 :     # Get this feature's FASTA.
84 :     my $fasta = $document->{$fid};
85 :     # Did we get something?
86 :     if (! $fasta) {
87 :     # No. Write an error notification.
88 :     print STDERR "Not found: $fid\n";
89 :     } else {
90 :     # Yes. output the FASTA.
91 :     print "$fasta";
92 : parrello 1.1 }
93 :     }
94 :     }
95 :     }
96 :    
97 :    
98 : parrello 1.4
99 : parrello 1.1

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3