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

Annotation of /FigKernelScripts/svr_location_of.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 use strict;
2 :     use Data::Dumper;
3 :     use Carp;
4 :    
5 :     #
6 :     # This is a SAS Component
7 :     #
8 :    
9 :    
10 :     =head1 svr_location_of
11 :    
12 :     Get physical locations of genes.
13 :    
14 :     ------
15 :    
16 :     Example:
17 :    
18 :     svr_all_features 3702.1 peg | svr_location_of
19 :    
20 :     would produce a 2-column table. The first column would contain
21 :     PEG IDs for genes occurring in genome 3702.1, and the second
22 :     would contain the locations of those genes.
23 :    
24 :     ------
25 :    
26 :     The standard input should be a tab-separated table (i.e., each line
27 :     is a tab-separated set of fields). Normally, the last field in each
28 :     line would contain the ID of the feature for which locations are being requested.
29 :     If some other column contains the feature IDs, use
30 :    
31 :     -c N
32 :    
33 :     where N is the column (from 1) that contains the PEG in each case.
34 :    
35 :     This is a pipe command. The input is taken from the standard input, and the
36 :     output is to the standard output.
37 :    
38 :     =head2 Command-Line Options
39 :    
40 :     =over 4
41 :    
42 :     =item -c Column
43 :    
44 :     This is used only if the column containing PEGs is not the last.
45 :    
46 :     =item -bounds
47 :    
48 :     Normally, the location is returned as a comma-delimited list of location strings (each
49 :     containing a contig ID, a start location, a strand indicator, and a length). Normally
50 :     this would be a single location string, but some genes have multiple contiguous segments,
51 :     and each segment is a separate string. If this option is specified, then only a single
52 :     location-- one that covers all segments of the gene-- is output.
53 :    
54 :     =back
55 :    
56 :     =head2 Output Format
57 :    
58 :     The standard output is a tab-delimited file. It consists of the input
59 :     file with an extra column added (the location associated with the feature).
60 :    
61 :     =cut
62 :    
63 :     use SeedUtils;
64 :     use SAPserver;
65 :     use ScriptThing;
66 :     use Getopt::Long;
67 :    
68 :     my $usage = "usage: svr_location_of [-c column] [-bounds]";
69 :    
70 :     my $column;
71 :     my $bounds = 0;
72 : parrello 1.2 my $url = '';
73 :     my $rc = GetOptions('c=i' => \$column, "bounds" => \$bounds, "url=s" => \$url);
74 :     my $sapObject = SAPserver->new(url => $url);
75 : parrello 1.1 if (! $rc) { print STDERR $usage; exit }
76 :     while (my @tuples = ScriptThing::GetBatch(\*STDIN, undef, $column)) {
77 :     # Get the locations for this batch of features.
78 :     my $fidHash = $sapObject->fid_locations(-ids => [map { $_->[0] } @tuples], -boundaries => $bounds);
79 :     # Loop through them, generating output.
80 :     for my $tuple (@tuples) {
81 :     # Get the feature ID and input line for this tuple.
82 :     my ($fid, $line) = @$tuple;
83 :     # Find the locations for this feature.
84 :     my $locs = $fidHash->{$fid};
85 :     if (! defined $locs) {
86 :     # Here no location was found.
87 :     print STDERR "$fid not found.\n";
88 :     } elsif (ref $locs ne 'ARRAY') {
89 :     # Here we have a singleton location.
90 :     print "$line\t$locs\n";
91 :     } else {
92 :     # Here we have a list of location segments.
93 :     my $locString = join(", ", @$locs);
94 :     print "$line\t$locString\n";
95 :     }
96 :     }
97 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3