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

Annotation of /FigKernelScripts/svr_contigs_in_genome.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (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 :    
8 :     #
9 :     # This is a SAS Component.
10 :     #
11 :    
12 :     =head1 svr_contigs_in_genome
13 :    
14 :     svr_contigs_in_genome <genome_ids.tbl >genome_data.tbl
15 :    
16 :     For each incoming genome ID, return the IDs of its contigs.
17 :    
18 :     This script takes as input a tab-delimited file with genome IDs at the end of each
19 :     line. For each genome ID, multiple output lines are produced containing the ID
20 :     of each contig in the genome.
21 :    
22 :     This is a pipe command: the input is taken from the standard input and the output
23 : parrello 1.3 is to the standard output. It can alternatively take as input a list of genome IDs
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 :     =back
40 :    
41 :     =cut
42 :    
43 :     # Parse the command-line options.
44 :     my $url = '';
45 :     my $column = '';
46 :     my $opted = GetOptions('url=s' => \$url, 'c=i' => \$column);
47 :     if (! $opted) {
48 : parrello 1.2 print "usage: svr_contigs_in_genome [--url=http://...] [--c=N] <input >output\n";
49 : parrello 1.1 } else {
50 :     # Get the server object.
51 :     my $sapServer = SAPserver->new(url => $url);
52 : parrello 1.3 # Find out if we're getting input from STDIN or the command line.
53 :     my $input = (@ARGV ? [@ARGV] : \*STDIN);
54 : parrello 1.1 # The main loop processes chunks of input.
55 : parrello 1.3 while (my @tuples = ScriptThing::GetBatch($input, undef, $column)) {
56 : parrello 1.1 # Ask the server for results.
57 :     my $document = $sapServer->genome_contigs(-ids => [map { $_->[0] } @tuples]);
58 :     # Loop through the IDs, producing output.
59 :     for my $tuple (@tuples) {
60 :     my ($id, $line) = @$tuple;
61 :     # Get this genome's data.
62 :     my $genomeData = $document->{$id};
63 :     # Did we get something?
64 :     if (! $genomeData) {
65 :     # No. Write an error notification.
66 :     print STDERR "None found: $id\n";
67 :     } else {
68 :     # Yes. Print the output lines.
69 :     for my $contigID (@$genomeData) {
70 :     print join("\t", $line, $contigID) . "\n";
71 :     }
72 :     }
73 :     }
74 :     }
75 :     }
76 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3