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

Annotation of /FigKernelScripts/svr_upstream.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :     use strict;
3 :    
4 :     use Getopt::Long;
5 :     use SAPserver;
6 : parrello 1.5 use ScriptThing;
7 : parrello 1.1
8 :     #
9 :     # This is a SAS Component.
10 :     #
11 :    
12 :     =head1 svr_upstream
13 :    
14 : parrello 1.7 svr_upstream <gene_ids.tbl >upstream_dna.fasta
15 :    
16 : parrello 1.1 Retrieve upstream regions from the Sapling Server.
17 :    
18 :     This script takes as input a tab-delimited file with feature IDs at the end. For
19 :     each feature ID, the upstream DNA is computed and written to the output file in
20 :     FASTA format. Sections of DNA that occur inside a feature are shown in upper
21 :     case. DNA between known features is shown in lower case.
22 :    
23 : parrello 1.4 This is a pipe command. Input is from the standard input and output is to the
24 :     standard output.
25 :    
26 : parrello 1.1 =head2 Command-Line Options
27 :    
28 :     =over 4
29 :    
30 :     =item skipGene
31 :    
32 :     If specified, then only the upstream region is output. Otherwise, the upstream
33 :     region and the feature interior are output together.
34 :    
35 :     =item size
36 :    
37 :     Number of base pairs to show in the upstream region. The default is C<200>.
38 :    
39 :     =item url
40 :    
41 : parrello 1.3 The URL for the Sapling server, if it is to be different from the default.
42 : parrello 1.1
43 : parrello 1.8 =item c
44 :    
45 :     Column index. If specified, indicates that the input IDs should be taken from the
46 :     indicated column instead of the last column. The first column is column 1.
47 :    
48 : parrello 1.1 =back
49 :    
50 :     =cut
51 :    
52 :     # Parse the command-line options.
53 :     my $skipGene = '';
54 :     my $size = 200;
55 : parrello 1.2 my $url = '';
56 : parrello 1.8 my $column = 0;
57 :     my $opted = GetOptions('skipGene' => \$skipGene, 'size=i' => \$size, 'url=s' => \$url,
58 :     'c=i' => \$column);
59 : parrello 1.1 if (! $opted) {
60 : parrello 1.8 print "usage: svr_upstream [--skipGene] [--c=N] [--size=200] [-url=http://...] <input >output\n";
61 : parrello 1.1 } else {
62 : parrello 1.6 # Fix STDIN.
63 :     ScriptThing::AdjustStdin();
64 : parrello 1.4 # Get the server object.
65 :     my $sapServer = SAPserver->new(url => $url);
66 : parrello 1.5 # The main loop processes chunks of input, 1000 lines at a time.
67 : parrello 1.8 while (my @tuples = ScriptThing::GetBatch(\*STDIN, undef, $column)) {
68 : parrello 1.5 # Compute the comment strings.
69 :     my %comments = ScriptThing::CommentHash(\@tuples);
70 : parrello 1.4 # Ask the server for results.
71 : parrello 1.5 my $document = $sapServer->upstream(-ids => [ map { $_->[0] } @tuples],
72 :     -size => $size,
73 : parrello 1.6 -fasta => 1,
74 : parrello 1.4 -comments => \%comments,
75 :     -skipGene => $skipGene);
76 : parrello 1.5 # Loop through the tuples, producing output.
77 :     for my $tuple (@tuples) {
78 :     # Get the feature ID.
79 :     my $fid = $tuple->[0];
80 : parrello 1.4 # Get this feature's FASTA.
81 :     my $fasta = $document->{$fid};
82 :     # Did we get something?
83 :     if (! $fasta) {
84 :     # No. Write an error notification.
85 :     print STDERR "Not found: $fid\n";
86 :     } else {
87 :     # Yes. output the FASTA.
88 :     print "$fasta";
89 : parrello 1.1 }
90 :     }
91 :     }
92 :     }
93 :    
94 :    
95 : parrello 1.4
96 : parrello 1.1

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3