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

Annotation of /FigKernelScripts/svr_subsystem_spreadsheet.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (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_subsystem_spreadsheet
13 :    
14 :     svr_subsystem_spreadsheet "subsystem ID" >sub_data.tbl
15 :    
16 :     Output a subsystem's spreadsheet.
17 :    
18 :     This script takes as input a subsystem name on the command line and produces a
19 :     tab-delimited file that organizes the features of the subsystem by genome and role.
20 :     There will be one output line per genome. The first column will contain the genome ID,
21 :     the second the relevant variant code, and then each other column will correspond to one
22 :     of the subsystem's roles (effectively, a spreadsheet cell). The features performing the
23 :     role in the subsystem will be placed in the appropriate position as a comma-delimited list.
24 :    
25 :     Note that because the subsystem name likely contains spaces, it will need to be
26 :     enclosed in quotes on the command-line.
27 :    
28 :     =head2 Command-Line Options
29 :    
30 :     =over 4
31 :    
32 :     =item url
33 :    
34 :     The URL for the Sapling server, if it is to be different from the default.
35 :    
36 :     =item aux
37 :    
38 :     If specified, auxiliary roles will be included in the output. Normally these are
39 :     excluded.
40 :    
41 :     =back
42 :    
43 :     =cut
44 :    
45 :     # Parse the command-line options.
46 :     my $url = '';
47 :     my $aux;
48 :     my $opted = GetOptions('url=s' => \$url, aux => \$aux);
49 :     my $subID = $ARGV[0];
50 :     if (! $opted || ! $subID) {
51 :     print "usage: svr_subsystem_spreadsheet [--url=http://...] [--aux] \"subsystem name\" >output\n";
52 :     } else {
53 :     # Get the server object.
54 :     my $sapServer = SAPserver->new(url => $url);
55 :     # Get the roles.
56 :     my $subHash = $sapServer->subsystem_roles(-ids => $subID, -aux => $aux, -abbr => 1);
57 :     my $roles = $subHash->{$subID};
58 :     if (! $roles) {
59 :     print STDERR "Could not find \"$subID\".\n";
60 :     } else {
61 :     # Build a hash that maps role IDs to role indices.
62 :     my %roleHash;
63 :     for (my $i = 0; $i < @$roles; $i++) {
64 :     $roleHash{$roles->[$i][0]} = $i;
65 :     }
66 :     # Now get the subsystem's genomes and features.
67 :     $subHash = $sapServer->pegs_in_variants(-subsystems => $subID);
68 :     # Loop through the genomes, producing spreadsheet rows.
69 :     my $genomeHash = $subHash->{$subID};
70 :     for my $genome (sort { $a <=> $b } keys %$genomeHash) {
71 :     # Get the row for this genome.
72 :     my $ssRow = $genomeHash->{$genome};
73 :     # Yank out the variant code.
74 :     my $variant = shift @$ssRow;
75 :     # The spreadsheet cells will be put in here.
76 :     my @cells;
77 :     # Now we loop through the row, putting feature IDs in cells.
78 :     for my $ssCell (@$ssRow) {
79 :     # Get the role ID and the features;
80 :     my ($role, @fids) = @$ssCell;
81 :     # If this role is one we're interested in, put the features in the cell.
82 :     my $cellIndex = $roleHash{$role};
83 :     if (defined $cellIndex) {
84 :     $cells[$cellIndex] = join(', ', @fids);
85 :     }
86 :     }
87 :     # Form all the cells into an output line.
88 :     my $line = join("\t", $genome, $variant, map { $_ || '' } @cells);
89 :     print "$line\n";
90 :     }
91 :     }
92 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3