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

Annotation of /FigKernelPackages/CO.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (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 :     This method returns the functional-coupling clusters for features related
245 :     to the specified input features.
246 :    
247 :     =over 4
248 :    
249 :     =item args
250 :    
251 :     Either (1) a reference to a list of FIG feature IDs, or (2) a reference to a hash
252 :     mapping the key C<-ids> to a list of FIG feature IDs.
253 :    
254 :     =item RETURN
255 :    
256 :     Returns a reference to a list. For each incoming feature ID, the output list
257 :     contains a sub-list of clusters. Each cluster in the sub-list is a 3-tuple
258 :     consisting of the ID of a feature similar to the incoming feature, the
259 :     similarity P-score, and a reference to a list of 2-tuples for clustered features.
260 :     Each feature 2-tuple contains the feature ID followed by the functional
261 :     assignment.
262 :    
263 :     =back
264 :    
265 :     =cut
266 :    
267 :     sub related_clusters {
268 :     # Get the parameters.
269 :     my ($self, $args) = @_;
270 :     # Get the sapling database.
271 :     my $sapling = $self->{db};
272 :     # Declare the return variable.
273 :     my $retVal = [];
274 :     # Convert a list to a hash.
275 :     if (ref $args ne 'HASH') {
276 :     $args = { -ids => $args };
277 :     }
278 :     # Get the list of feature IDs.
279 :     my $ids = ServerThing::GetIdList(-ids => $args);
280 :     # Loop through the features.
281 :     for my $id (@$ids) {
282 :     # Create the output list for this feature.
283 :     my $output = [];
284 :     # Loop through the related clusters.
285 :     for my $cluster (FC::largest_co_occurrence_clusters($sapling, $id)) {
286 :     # Get this cluster's data.
287 :     my ($fid, $sc, $other_fids) = @$cluster;
288 :     # Extract the functional roles of the other features in the cluster.
289 :     my $other_tuples = [ map { [$_, $sapling->Assignment($_)] } @$other_fids ];
290 :     # Assemble the result into the output list.
291 :     push @$output, [$fid, $sc, $other_tuples];
292 :     }
293 :     # Push this list of clusters into the master return list.
294 :     push @$retVal, $output;
295 :     }
296 :     # Return the result.
297 :     return $retVal;
298 :     }
299 :    
300 :    
301 :     =head3 related_figfams
302 :    
303 :     my $document = $coObject->related_figfams($args);
304 :    
305 :     This method takes a list of FIGfam IDs. For each FIGfam, it returns a
306 :     list of FIGfams related to it by functional coupling.
307 :    
308 :     =over 4
309 :    
310 :     =item args
311 :    
312 :     Either (1) a reference to a list of FIGfam IDs, or (2) a reference to a hash
313 :     mapping the key C<-ids> to a list of FIGfam IDs.
314 :    
315 :     =item RETURN
316 :    
317 :     Returns a reference to a list of 2-tuples. Each 2-tuple contains an incoming
318 :     FIGfam ID followed by a sub-list of 2-tuples for other FIGfams. The 2-tuples
319 :     in the sub-list each consist of a related FIGfam's ID followed by a 2-tuple
320 :     containing a coupling score and the related FIGfam's function.
321 :    
322 :     =back
323 :    
324 :     =cut
325 :    
326 :     sub related_figfams {
327 :     # Get the parameters.
328 :     my ($self, $args) = @_;
329 :     # Get the sapling database.
330 :     my $sapling = $self->{db};
331 :     # Declare the return variable.
332 :     my $retVal = [];
333 :     # Convert a list to a hash.
334 :     if (ref $args ne 'HASH') {
335 :     $args = { -ids => $args };
336 :     }
337 :     # Get the list of FIGfam IDs.
338 :     my $ids = ServerThing::GetIdList(-ids => $args);
339 :     # Loop through the FIGfams.
340 :     for my $id (@$ids) {
341 :     push(@$retVal, [$id, [&FC::co_occurring_FIGfams($sapling, $id)]]);
342 :     }
343 :     # Return the result.
344 :     return $retVal;
345 :     }
346 :    
347 :    
348 :    
349 :    
350 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3