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

Annotation of /FigKernelScripts/svr_neighborhood_of_role.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : overbeek 1.1 use strict;
2 :     use SeedEnv;
3 :     use Data::Dumper;
4 :     use Carp;
5 : olson 1.2 use Getopt::Long;
6 : overbeek 1.1
7 :     #
8 :     # This is a SAS Component
9 :     #
10 :    
11 :    
12 :     =head1 svr_neighborhood_of_role -r 2 < file.with.roles > with.added.role
13 :    
14 :     Find roles in metabolic-function neighborhood
15 :    
16 :     ------
17 :    
18 :     Example:
19 :    
20 :     svr_neighborhood_of_roles < roles.in.file > with.steps.and.role.column.added
21 :    
22 :     would take as input a file in which the last column was functional roles.
23 :     Two columns would be added
24 :    
25 :     steps is the number of steps traversed to reach the neighbor
26 :     neighbor is the neighboring role
27 :    
28 :    
29 :     ------
30 :    
31 :     The standard input should be a tab-separated table (i.e., each line
32 :     is a tab-separated set of fields). Normally, the last field in each
33 :     line would contain a role for which relevant clusters are desired.
34 :     If some other column contains the roles, use
35 :    
36 :     -c N
37 :    
38 :     where N is the column (from 1) that contains the role in each case.
39 :    
40 :     This is a pipe command. The input is taken from the standard input, and the
41 :     output is to the standard output.
42 :    
43 :     =head2 Command-Line Options
44 :    
45 :     =over 4
46 :    
47 :     =item -c Column
48 :    
49 :     This is used only if the column containing roles is not the last.
50 :    
51 :     =item -r MaxSteps [default is 2]
52 :    
53 :     This parameter gives the maximum number of steps (i.e., the "radius") the
54 :     program can take to create the neighborhood of a role
55 :    
56 :     =back
57 :    
58 :     =head2 Output Format
59 :    
60 :     The standard output is a tab-delimited file. It consists of the input
61 :     file with two extra columns added. The extra columns will contain the
62 :     number of steps to the neighbor, along with the neighbor.
63 :    
64 :     =cut
65 :    
66 :     my $sapO = SAPserver->new();
67 :     my $modO = FBAMODELserver->new;
68 :    
69 :     my $usage = "usage: svr_neighborhood_of_role [-r Maxsteps] [-c column]";
70 :    
71 :     my $column;
72 :     my $radius = 1;
73 :    
74 :     my $rc = GetOptions('c=i' => \$column,
75 :     'r=i' => \$radius
76 :     );
77 :    
78 :     if (! $rc) { print STDERR $usage; exit }
79 :    
80 :     my @lines = map { chomp; [split(/\t/,$_)] } <STDIN>;
81 :     if (! $column) { $column = @{$lines[0]} }
82 :    
83 :     my @roles = map { $_->[$column-1] } @lines;
84 :     my $neighH = &neighbors_of(\@roles,$modO,$radius);
85 :    
86 :     foreach my $line (@lines)
87 :     {
88 :     my $role = $line->[$column-1];
89 :     my $neigh = $neighH->{$role};
90 :     foreach my $role2 (keys(%$neigh))
91 :     {
92 :     print join("\t",@$line,$neigh->{$role2},$role2),"\n";
93 :     }
94 :     }
95 :     sub neighbors_of {
96 :     my($roles,$modO,$radius) = @_;
97 :    
98 :     my %roleH = map { $_ => { $_ => 1 }} @$roles;
99 :     my $i;
100 :     for ($i=0; ($i < $radius); $i++)
101 :     {
102 :     &expand(\%roleH,$modO,$i+1);
103 :     }
104 :     return \%roleH;
105 :     }
106 :    
107 :     sub expand {
108 :     my($roleH,$modO,$steps) = @_;
109 :    
110 :     my $roles_to_expand = {};
111 :     foreach my $role (keys(%$roleH))
112 :     {
113 :     foreach my $role1 (keys(%{$roleH->{$role}}))
114 :     {
115 :     $roles_to_expand->{$role1} = $steps;
116 :     }
117 :     }
118 :     my $connH = &get_immediate_neighbors($modO,$roles_to_expand);
119 :     foreach my $role (keys(%$roleH))
120 :     {
121 :     my @start = keys(%{$roleH->{$role}});
122 :     foreach my $role1 (@start)
123 :     {
124 :     foreach my $role2 (keys(%{$connH->{$role1}}))
125 :     {
126 :     if (! $roleH->{$role}->{$role2})
127 :     {
128 :     $roleH->{$role}->{$role2} = $steps;
129 :     }
130 :     }
131 :     }
132 :     }
133 :     }
134 :    
135 :     sub get_immediate_neighbors {
136 :     my($modO,$roles_to_expand) = @_;
137 :    
138 :     my $tmp_roles = [keys(%$roles_to_expand)];
139 :     my $connH = {};
140 :     my $tmpH = $modO-> metabolic_neighborhood_of_roles({ids => $tmp_roles});
141 :     foreach my $role (keys(%$tmpH))
142 :     {
143 :     my $by_compound = $tmpH->{$role};
144 :     foreach my $compound (keys(%$by_compound))
145 :     {
146 :     my $roles_via_compound = $by_compound->{$compound};
147 :     foreach my $role2 (@$roles_via_compound)
148 :     {
149 :     $connH->{$role}->{$role2} = 1;
150 :     }
151 :     }
152 :     }
153 :     return $connH;
154 :     }
155 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3