[Bio] / FigKernelPackages / CO.pm Repository:
ViewVC logotype

Annotation of /FigKernelPackages/CO.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :     use strict;
3 :    
4 :     #
5 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
6 :     # for Interpretations of Genomes. All Rights Reserved.
7 :     #
8 :     # This file is part of the SEED Toolkit.
9 :     #
10 :     # The SEED Toolkit is free software. You can redistribute
11 :     # it and/or modify it under the terms of the SEED Toolkit
12 :     # Public License.
13 :     #
14 :     # You should have received a copy of the SEED Toolkit Public License
15 :     # along with this program; if not write to the University of Chicago
16 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
17 :     # Genomes at veronika@thefig.info or download a copy from
18 :     # http://www.theseed.org/LICENSE.TXT.
19 :     #
20 :     package CO;
21 :    
22 :     use strict;
23 :     use ERDB;
24 :     use Tracer;
25 :     use SeedUtils;
26 :     use ServerThing;
27 :     use FC;
28 :    
29 :     =head1 Co-Occurrence Server Function Object
30 :    
31 :     This file contains the functions and utilities used by the Co-Occurrence Server
32 : parrello 1.2 (B<co_occurs_server.cgi>). The L</Primary Methods> represent function
33 : parrello 1.1 calls direct to the server. These all have a signature similar to the following.
34 :    
35 :     my $document = $coObject->function_name($args);
36 :    
37 : parrello 1.2 where C<$coObject> is an object created by this module, C<$args> is a parameter
38 :     structure, and C<function_name> is the Co-Occurrence Server function name. The
39 :     output is a structure, generally a hash reference, but sometimes a string or a
40 :     list reference.
41 : parrello 1.1
42 :     =head2 Special Methods
43 :    
44 :     =head3 new
45 :    
46 :     my $coObject = CO->new();
47 :    
48 :     Create a new co-occurrence server function object. The server function object
49 : parrello 1.2 contains a pointer to a L<Sapling> object, and is used to invoke the
50 : parrello 1.1 server functions.
51 :    
52 :     =cut
53 :    
54 :     sub new {
55 :     my ($class) = @_;
56 :     # Create the sapling object.
57 :     my $sap = ERDB::GetDatabase('Sapling');
58 :     # Create the server object.
59 :     my $retVal = { db => $sap };
60 :     # Bless and return it.
61 :     bless $retVal, $class;
62 :     return $retVal;
63 :     }
64 :    
65 :    
66 :     =head2 Primary Methods
67 :    
68 :     =head3 conserved_in_neighborhood
69 :    
70 :     my $document = $coObject->conserved_in_neighborhood($args);
71 :    
72 :     This method takes a list of feature IDs. For each feature ID, it will
73 :     return the set of other features to which it is functionally coupled,
74 :     along with the appropriate score.
75 :    
76 :     =over 4
77 :    
78 :     =item args
79 :    
80 :     Either (1) a reference to a hash mapping the key C<-ids> to a list of FIG
81 :     feature IDs, or (2) a reference to a list of FIG feature IDs.
82 :    
83 :     =item RETURN
84 :    
85 :     Returns a reference to a list of sub-lists. Each sub-list corresponds to
86 :     a feature in the input list. The sub-list itself is a list of 4-tuples,
87 :     one per feature functionally coupled to the input feature. Each tuple
88 :     contains the coupling score, the FIG ID of the coupled feature, the
89 :     coupled feature's current functinal assignment, and the ID of the pair
90 :     set to which the coupling belongs.
91 :    
92 :     =back
93 :    
94 :     =cut
95 :    
96 :     sub conserved_in_neighborhood {
97 :     # Get the parameters.
98 :     my ($self, $args) = @_;
99 :     # Get the sapling database.
100 :     my $sapling = $self->{db};
101 :     # Declare the return variable.
102 :     my $retVal = [];
103 :     # Convert a list to a hash.
104 :     if (ref $args ne 'HASH') {
105 :     $args = { -ids => $args };
106 :     }
107 :     # Get the list of feature IDs.
108 :     my $ids = ServerThing::GetIdList(-ids => $args);
109 :     # Loop through the features.
110 :     for my $id (@$ids) {
111 :     # Create a sub-list for this feature.
112 :     my $group = [];
113 :     # Ask for the functional coupling information.
114 :     my @co_occurs = &FC::co_occurs($sapling, $id);
115 :     # Loop through the coupling data found.
116 :     for my $tuple (@co_occurs) {
117 :     # Get the coupled feature's data.
118 :     my($sc, $fid, $pairset) = @$tuple;
119 :     # Add it to the group of tuples for this feature's couplings.
120 :     push(@$group, [$sc, $fid, $sapling->Assignment($fid), $pairset]);
121 :     }
122 :     # Add this feature's couplings to the return list.
123 :     push(@$retVal, $group);
124 :     }
125 :     # Return the result.
126 :     return $retVal;
127 :     }
128 :    
129 :     =head3 pairsets
130 :    
131 :     my $document = $coObject->pairsets($args);
132 :    
133 :     This method takes as input a list of functional-coupling pair set IDs.
134 :     For each pair set, it returns the set's score (number of significant
135 :     couplings) and a list of the coupled pairs in the set.
136 :    
137 :     =over 4
138 :    
139 :     =item args
140 :    
141 :     Either (1) a reference to a list of functional-coupling pair set IDs, or (2) a reference
142 :     to a hash mapping the key C<-ids> to a list of functional-coupling pair set IDs.
143 :    
144 :     =item RETURN
145 :    
146 :     Returns a reference to a list of 2-tuples. Each 2-tuple corresponds to an ID
147 :     from the input list. The 2-tuples themselves each contain the pair set's ID
148 :     followed by another 2-tuple consisting of the score and a reference to a
149 :     list of the pairs in the set. The pairs are represented themselves by
150 :     2-tuples. Because the pairings all belong to the same set, all of the first
151 :     pegs in the pairings are similar to each other, and all of the second pegs
152 :     in the pairings are similar to each other.
153 :    
154 :     =back
155 :    
156 :     =cut
157 :    
158 :     sub pairsets {
159 :     # Get the parameters.
160 :     my ($self, $args) = @_;
161 :     # Get the sapling database.
162 :     my $sapling = $self->{db};
163 :     # Declare the return variable.
164 :     my $retVal = [];
165 :     # Convert a list to a hash.
166 :     if (ref $args ne 'HASH') {
167 :     $args = { -ids => $args };
168 :     }
169 :     # Get the list of pairset IDs.
170 :     my $ids = ServerThing::GetIdList(-ids => $args);
171 :     # Loop through the pairsets.
172 :     for my $id (@$ids) {
173 :     push(@$retVal, [$id, [&FC::co_occurrence_set($sapling, $id)]]);
174 :     }
175 :     # Return the result.
176 :     return $retVal;
177 :     }
178 :    
179 :     =head3 clusters_containing
180 :    
181 :     my $document = $coObject->clusters_containing($args);
182 :    
183 :     This method takes as input a list of feature IDs. For each feature, it
184 :     returns the IDs and functions of other features in the same cluster.
185 :    
186 :     =over 4
187 :    
188 :     =item args
189 :    
190 :     Either (1) a reference to a list of feature IDs, or (2) a reference to a hash
191 :     mapping the key C<-ids> to a list of feature IDs.
192 :    
193 :     =item RETURN
194 :    
195 :     Returns a reference to a list. For each incoming feature, there is a list
196 :     entry containing the feature ID, the feature's functional assignment, and
197 :     a sub-list of 2-tuples. Each 2-tuple contains the ID of another feature in
198 :     the same cluster and its functional assignment.
199 :    
200 :     =back
201 :    
202 :     =cut
203 :    
204 :     sub clusters_containing {
205 :     # Get the parameters.
206 :     my ($self, $args) = @_;
207 :     # Get the sapling database.
208 :     my $sapling = $self->{db};
209 :     # Declare the return variable.
210 :     my $retVal = [];
211 :     # Convert a list to a hash.
212 :     if (ref $args ne 'HASH') {
213 :     $args = { -ids => $args };
214 :     }
215 :     # Get the list of feature IDs.
216 :     my $ids = ServerThing::GetIdList(-ids => $args);
217 :     # Loop through the features.
218 :     for my $id (@$ids) {
219 :     # Get this feature's cluster data.
220 :     my $cluster = &FC::in_co_occurrence_cluster($sapling, $id);
221 :     # If we found something, put it into the output list.
222 :     if ($cluster) {
223 :     my $func = scalar $sapling->Assignment($id);
224 :     push @$retVal, [$id, $func, [map { [$_, $sapling->Assignment($_)] } @$cluster]];
225 :     }
226 :     }
227 :     # Return the result.
228 :     return $retVal;
229 :     }
230 :    
231 :     =head3 related_clusters
232 :    
233 :     my $document = $coObject->related_clusters($args);
234 :    
235 :     This method returns the functional-coupling clusters for features related
236 :     to the specified input features.
237 :    
238 :     =over 4
239 :    
240 :     =item args
241 :    
242 :     Either (1) a reference to a list of FIG feature IDs, or (2) a reference to a hash
243 :     mapping the key C<-ids> to a list of FIG feature IDs.
244 :    
245 :     =item RETURN
246 :    
247 :     Returns a reference to a list. For each incoming feature ID, the output list
248 :     contains a sub-list of clusters. Each cluster in the sub-list is a 3-tuple
249 :     consisting of the ID of a feature similar to the incoming feature, the
250 :     similarity P-score, and a reference to a list of 2-tuples for clustered features.
251 :     Each feature 2-tuple contains the feature ID followed by the functional
252 :     assignment.
253 :    
254 :     =back
255 :    
256 :     =cut
257 :    
258 :     sub related_clusters {
259 :     # Get the parameters.
260 :     my ($self, $args) = @_;
261 :     # Get the sapling database.
262 :     my $sapling = $self->{db};
263 :     # Declare the return variable.
264 :     my $retVal = [];
265 :     # Convert a list to a hash.
266 :     if (ref $args ne 'HASH') {
267 :     $args = { -ids => $args };
268 :     }
269 :     # Get the list of feature IDs.
270 :     my $ids = ServerThing::GetIdList(-ids => $args);
271 :     # Loop through the features.
272 :     for my $id (@$ids) {
273 :     # Create the output list for this feature.
274 :     my $output = [];
275 :     # Loop through the related clusters.
276 :     for my $cluster (FC::largest_co_occurrence_clusters($sapling, $id)) {
277 :     # Get this cluster's data.
278 :     my ($fid, $sc, $other_fids) = @$cluster;
279 :     # Extract the functional roles of the other features in the cluster.
280 :     my $other_tuples = [ map { [$_, $sapling->Assignment($_)] } @$other_fids ];
281 :     # Assemble the result into the output list.
282 :     push @$output, [$fid, $sc, $other_tuples];
283 :     }
284 :     # Push this list of clusters into the master return list.
285 :     push @$retVal, $output;
286 :     }
287 :     # Return the result.
288 :     return $retVal;
289 :     }
290 :    
291 :    
292 :     =head3 related_figfams
293 :    
294 :     my $document = $coObject->related_figfams($args);
295 :    
296 :     This method takes a list of FIGfam IDs. For each FIGfam, it returns a
297 :     list of FIGfams related to it by functional coupling.
298 :    
299 :     =over 4
300 :    
301 :     =item args
302 :    
303 :     Either (1) a reference to a list of FIGfam IDs, or (2) a reference to a hash
304 :     mapping the key C<-ids> to a list of FIGfam IDs.
305 :    
306 :     =item RETURN
307 :    
308 :     Returns a reference to a list of 2-tuples. Each 2-tuple contains an incoming
309 :     FIGfam ID followed by a sub-list of 2-tuples for other FIGfams. The 2-tuples
310 :     in the sub-list each consist of a related FIGfam's ID followed by a 2-tuple
311 :     containing a coupling score and the related FIGfam's function.
312 :    
313 :     =back
314 :    
315 :     =cut
316 :    
317 :     sub related_figfams {
318 :     # Get the parameters.
319 :     my ($self, $args) = @_;
320 :     # Get the sapling database.
321 :     my $sapling = $self->{db};
322 :     # Declare the return variable.
323 :     my $retVal = [];
324 :     # Convert a list to a hash.
325 :     if (ref $args ne 'HASH') {
326 :     $args = { -ids => $args };
327 :     }
328 :     # Get the list of FIGfam IDs.
329 :     my $ids = ServerThing::GetIdList(-ids => $args);
330 :     # Loop through the FIGfams.
331 :     for my $id (@$ids) {
332 :     push(@$retVal, [$id, [&FC::co_occurring_FIGfams($sapling, $id)]]);
333 :     }
334 :     # Return the result.
335 :     return $retVal;
336 :     }
337 :    
338 :    
339 :    
340 :    
341 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3