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

Annotation of /FigKernelPackages/CO.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (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 : parrello 1.3 feature IDs, or (2) a reference to a list of FIG feature IDs. In case (1),
82 :     the additional parameter C<-hash> can be provided. If it has a value of
83 :     TRUE, then the output will be a hash of lists instead of a list of lists.
84 : parrello 1.1
85 :     =item RETURN
86 :    
87 : parrello 1.3 Returns a reference to a hash or list of sub-lists. Each sub-list corresponds to
88 :     a feature in the input list. The sub-list itself is consists 4-tuples, one per
89 :     feature functionally coupled to the input feature. Each tuple contains the
90 :     coupling score, the FIG ID of the coupled feature, the coupled feature's current
91 :     functional assignment, and the ID of the pair set to which the coupling belongs.
92 :     If the output is a hash, it maps each incoming feature ID to that feature's
93 :     sub-list.
94 : parrello 1.1
95 :     =back
96 :    
97 :     =cut
98 :    
99 :     sub conserved_in_neighborhood {
100 :     # Get the parameters.
101 :     my ($self, $args) = @_;
102 :     # Get the sapling database.
103 :     my $sapling = $self->{db};
104 : parrello 1.3 # Determine the output format.
105 :     my $hashFormat = $args->{-hash} || 0;
106 : parrello 1.1 # Declare the return variable.
107 : parrello 1.3 my $retVal = ($hashFormat ? {} : []);
108 : parrello 1.1 # Convert a list to a hash.
109 :     if (ref $args ne 'HASH') {
110 :     $args = { -ids => $args };
111 :     }
112 :     # Get the list of feature IDs.
113 :     my $ids = ServerThing::GetIdList(-ids => $args);
114 :     # Loop through the features.
115 :     for my $id (@$ids) {
116 :     # Create a sub-list for this feature.
117 :     my $group = [];
118 :     # Ask for the functional coupling information.
119 :     my @co_occurs = &FC::co_occurs($sapling, $id);
120 :     # Loop through the coupling data found.
121 :     for my $tuple (@co_occurs) {
122 :     # Get the coupled feature's data.
123 :     my($sc, $fid, $pairset) = @$tuple;
124 :     # Add it to the group of tuples for this feature's couplings.
125 :     push(@$group, [$sc, $fid, $sapling->Assignment($fid), $pairset]);
126 :     }
127 : parrello 1.3 # Add this feature's couplings to the return value.
128 :     if ($hashFormat) {
129 :     $retVal->{$id} = $group;
130 :     } else {
131 :     push(@$retVal, $group);
132 :     }
133 : parrello 1.1 }
134 :     # Return the result.
135 :     return $retVal;
136 :     }
137 :    
138 :     =head3 pairsets
139 :    
140 :     my $document = $coObject->pairsets($args);
141 :    
142 :     This method takes as input a list of functional-coupling pair set IDs.
143 :     For each pair set, it returns the set's score (number of significant
144 :     couplings) and a list of the coupled pairs in the set.
145 :    
146 :     =over 4
147 :    
148 :     =item args
149 :    
150 :     Either (1) a reference to a list of functional-coupling pair set IDs, or (2) a reference
151 :     to a hash mapping the key C<-ids> to a list of functional-coupling pair set IDs.
152 :    
153 :     =item RETURN
154 :    
155 :     Returns a reference to a list of 2-tuples. Each 2-tuple corresponds to an ID
156 :     from the input list. The 2-tuples themselves each contain the pair set's ID
157 :     followed by another 2-tuple consisting of the score and a reference to a
158 :     list of the pairs in the set. The pairs are represented themselves by
159 :     2-tuples. Because the pairings all belong to the same set, all of the first
160 :     pegs in the pairings are similar to each other, and all of the second pegs
161 :     in the pairings are similar to each other.
162 :    
163 :     =back
164 :    
165 :     =cut
166 :    
167 :     sub pairsets {
168 :     # Get the parameters.
169 :     my ($self, $args) = @_;
170 :     # Get the sapling database.
171 :     my $sapling = $self->{db};
172 :     # Declare the return variable.
173 :     my $retVal = [];
174 :     # Convert a list to a hash.
175 :     if (ref $args ne 'HASH') {
176 :     $args = { -ids => $args };
177 :     }
178 :     # Get the list of pairset IDs.
179 :     my $ids = ServerThing::GetIdList(-ids => $args);
180 :     # Loop through the pairsets.
181 :     for my $id (@$ids) {
182 :     push(@$retVal, [$id, [&FC::co_occurrence_set($sapling, $id)]]);
183 :     }
184 :     # Return the result.
185 :     return $retVal;
186 :     }
187 :    
188 :     =head3 clusters_containing
189 :    
190 :     my $document = $coObject->clusters_containing($args);
191 :    
192 :     This method takes as input a list of feature IDs. For each feature, it
193 :     returns the IDs and functions of other features in the same cluster.
194 :    
195 :     =over 4
196 :    
197 :     =item args
198 :    
199 :     Either (1) a reference to a list of feature IDs, or (2) a reference to a hash
200 :     mapping the key C<-ids> to a list of feature IDs.
201 :    
202 :     =item RETURN
203 :    
204 :     Returns a reference to a list. For each incoming feature, there is a list
205 :     entry containing the feature ID, the feature's functional assignment, and
206 :     a sub-list of 2-tuples. Each 2-tuple contains the ID of another feature in
207 :     the same cluster and its functional assignment.
208 :    
209 :     =back
210 :    
211 :     =cut
212 :    
213 :     sub clusters_containing {
214 :     # Get the parameters.
215 :     my ($self, $args) = @_;
216 :     # Get the sapling database.
217 :     my $sapling = $self->{db};
218 :     # Declare the return variable.
219 :     my $retVal = [];
220 :     # Convert a list to a hash.
221 :     if (ref $args ne 'HASH') {
222 :     $args = { -ids => $args };
223 :     }
224 :     # Get the list of feature IDs.
225 :     my $ids = ServerThing::GetIdList(-ids => $args);
226 :     # Loop through the features.
227 :     for my $id (@$ids) {
228 :     # Get this feature's cluster data.
229 :     my $cluster = &FC::in_co_occurrence_cluster($sapling, $id);
230 :     # If we found something, put it into the output list.
231 :     if ($cluster) {
232 :     my $func = scalar $sapling->Assignment($id);
233 :     push @$retVal, [$id, $func, [map { [$_, $sapling->Assignment($_)] } @$cluster]];
234 :     }
235 :     }
236 :     # Return the result.
237 :     return $retVal;
238 :     }
239 :    
240 :     =head3 related_clusters
241 :    
242 :     my $document = $coObject->related_clusters($args);
243 :    
244 : parrello 1.4 This method returns the functional-coupling clusters related to the specified
245 :     input features. Each cluster contains features on a single genome that are
246 :     related by functional coupling.
247 : parrello 1.1
248 :     =over 4
249 :    
250 :     =item args
251 :    
252 :     Either (1) a reference to a list of FIG feature IDs, or (2) a reference to a hash
253 :     mapping the key C<-ids> to a list of FIG feature IDs.
254 :    
255 :     =item RETURN
256 :    
257 :     Returns a reference to a list. For each incoming feature ID, the output list
258 :     contains a sub-list of clusters. Each cluster in the sub-list is a 3-tuple
259 :     consisting of the ID of a feature similar to the incoming feature, the
260 :     similarity P-score, and a reference to a list of 2-tuples for clustered features.
261 :     Each feature 2-tuple contains the feature ID followed by the functional
262 :     assignment.
263 :    
264 :     =back
265 :    
266 :     =cut
267 :    
268 :     sub related_clusters {
269 :     # Get the parameters.
270 :     my ($self, $args) = @_;
271 :     # Get the sapling database.
272 :     my $sapling = $self->{db};
273 :     # Declare the return variable.
274 :     my $retVal = [];
275 :     # Convert a list to a hash.
276 :     if (ref $args ne 'HASH') {
277 :     $args = { -ids => $args };
278 :     }
279 :     # Get the list of feature IDs.
280 :     my $ids = ServerThing::GetIdList(-ids => $args);
281 :     # Loop through the features.
282 :     for my $id (@$ids) {
283 :     # Create the output list for this feature.
284 :     my $output = [];
285 :     # Loop through the related clusters.
286 :     for my $cluster (FC::largest_co_occurrence_clusters($sapling, $id)) {
287 :     # Get this cluster's data.
288 :     my ($fid, $sc, $other_fids) = @$cluster;
289 :     # Extract the functional roles of the other features in the cluster.
290 :     my $other_tuples = [ map { [$_, $sapling->Assignment($_)] } @$other_fids ];
291 :     # Assemble the result into the output list.
292 :     push @$output, [$fid, $sc, $other_tuples];
293 :     }
294 :     # Push this list of clusters into the master return list.
295 :     push @$retVal, $output;
296 :     }
297 :     # Return the result.
298 :     return $retVal;
299 :     }
300 :    
301 : parrello 1.4 =head3 co_occurrence_evidence
302 :    
303 :     my $document = $coObject->co_occurrence_evidence($args);
304 :    
305 :     For each specified pair of genes, this method returns the evidence that
306 :     the genes are functionally coupled (if any); that is, it returns a list
307 :     of the physically close homologs for the pair.
308 :    
309 :     =over 4
310 :    
311 :     =item args
312 :    
313 :     Reference to a hash containing the parameters.
314 :    
315 :     =item RETURN
316 :    
317 :     Returns a hash mapping each incoming gene pair to a list of 2-tuples. Each 2-tuple
318 :     contains a pair of physically close genes, the first of which is similar to the first
319 :     gene in the input pair, and the second of which is similar to the second gene in the
320 :     input pair. The hash keys will consist of the two gene IDs separated by a colon (e.g.
321 :     C<fig|273035.4.peg.1016:fig|273035.4.peg.1018>).
322 :    
323 :     =back
324 :    
325 :     =head4 Parameter Hash Fields
326 :    
327 :     =over 4
328 :    
329 :     =item -pairs
330 :    
331 :     Reference to a list of functionally-coupled pairs. Each pair is represented by two
332 :     FIG gene IDs, either in the form of a 2-tuple or as a string with the two gene IDs
333 :     separated by a colon.
334 :    
335 :     =back
336 :    
337 :     =cut
338 :    
339 :     sub co_occurrence_evidence {
340 :     # Get the parameters.
341 :     my ($self, $args) = @_;
342 :     # Declare the return variable.
343 :     my $retVal = {};
344 :     # Get the Sapling database.
345 :     my $sap = $self->{db};
346 :     # Get the list of pairs.
347 :     my $pairs = ServerThing::GetIdList(-pairs => $args);
348 :     # Loop through the pairs.
349 :     for my $pair (@$pairs) {
350 :     # Determine the IDs in this pair.
351 :     my ($peg1, $peg2);
352 :     if (ref $pair) {
353 :     ($peg1, $peg2) = @$pair;
354 :     } else {
355 :     ($peg1, $peg2) = split /:/, $pair;
356 :     }
357 :     # Get the evidence and store it in the return hash.
358 :     $retVal->{"$peg1:$peg2"} = FC::co_occurrence_evidence($sap, $peg1, $peg2);
359 :     }
360 :     # Return the result.
361 :     return $retVal;
362 :     }
363 :    
364 :    
365 : parrello 1.1
366 :     =head3 related_figfams
367 :    
368 :     my $document = $coObject->related_figfams($args);
369 :    
370 :     This method takes a list of FIGfam IDs. For each FIGfam, it returns a
371 :     list of FIGfams related to it by functional coupling.
372 :    
373 :     =over 4
374 :    
375 :     =item args
376 :    
377 :     Either (1) a reference to a list of FIGfam IDs, or (2) a reference to a hash
378 :     mapping the key C<-ids> to a list of FIGfam IDs.
379 :    
380 :     =item RETURN
381 :    
382 :     Returns a reference to a list of 2-tuples. Each 2-tuple contains an incoming
383 :     FIGfam ID followed by a sub-list of 2-tuples for other FIGfams. The 2-tuples
384 :     in the sub-list each consist of a related FIGfam's ID followed by a 2-tuple
385 :     containing a coupling score and the related FIGfam's function.
386 :    
387 :     =back
388 :    
389 :     =cut
390 :    
391 :     sub related_figfams {
392 :     # Get the parameters.
393 :     my ($self, $args) = @_;
394 :     # Get the sapling database.
395 :     my $sapling = $self->{db};
396 :     # Declare the return variable.
397 :     my $retVal = [];
398 :     # Convert a list to a hash.
399 :     if (ref $args ne 'HASH') {
400 :     $args = { -ids => $args };
401 :     }
402 :     # Get the list of FIGfam IDs.
403 :     my $ids = ServerThing::GetIdList(-ids => $args);
404 :     # Loop through the FIGfams.
405 :     for my $id (@$ids) {
406 :     push(@$retVal, [$id, [&FC::co_occurring_FIGfams($sapling, $id)]]);
407 :     }
408 :     # Return the result.
409 :     return $retVal;
410 :     }
411 :    
412 :    
413 :    
414 :    
415 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3