Debian Codegraph @

TFBS/SitePairSet.pm

raw symbols SCIP
1 # TFBS module for TFBS::SitePairSet
2 #
3 # Copyright Boris Lenhard
4 #
5 # You may distribute this module under the same terms as perl itself
6 #
7
8 # POD
9
10 =head1 NAME
11
12 TFBS::SitePairSet - a set of TFBS::SitePair objects
13
14 =head1 SYNOPSIS
15
16 my $site_pair_set = TFBS::SitePairSet->new(@list_of_site_pair_objects);
17
18 # add a TFBS::SitePair object to set:
19
20 $site_pair_set->add_site_pair($site_pair_obj);
21
22 # append another TFBS::SitePairSet contents:
23
24 $site_pair_set->add_site_pair_set($site_pair_obj);
25
26 # create an iterator:
27
28 my $it = $site_pair_set->Iterator(-sort_by => 'start');
29
30
31
32 =head1 DESCRIPTION
33
34 TFBS::SitePairSet is an aggregate class that contains a collection
35 of TFBS::SitePair objects. It can be created anew and filled with
36 TFBS::Site::Pair object. It is also returned by search_aln() method call
37 of TFBS::PatternI subclasses (e.g. TFBS::Matrix::PWM).
38
39 =head1 FEEDBACK
40
41 Please send bug reports and other comments to the author.
42
43 =head1 AUTHOR - Boris Lenhard
44
45 Boris Lenhard E<lt>[email protected]<gt>
46
47 =head1 APPENDIX
48
49 The rest of the documentation details each of the object
50 methods. Internal methods are preceded with an underscore.
51
52 =cut
53
54
55 # The code begins HERE:
56
57
58 package TFBS::SitePairSet;
59 use vars qw(@ISA $AUTOLOAD);
60 use strict;
61
62 use TFBS::SitePair;
63 use TFBS::_Iterator::_SiteSetIterator;
64 @ISA = qw(Bio::Root::Root);
65
66
67
68 sub new {
69
70
71 my ($class, @data) = @_;
72 my $self = bless {}, ref($class) || $class;
73 $self->{_site_array_ref} = [];
74 @data = @{$class->{_site_array_ref}} if !@data && ref($class);
75 $self->add_site_pair(@data);
76 return $self;
77 }
78
79 =head2 size
80
81 Title : size
82 Usage : my $size = $sitepairset->size()
83 Function: returns a number of TFBS::SitePair objects contained in the set
84 Returns : a scalar (integer)
85 Args : none
86
87 =cut
88
89 sub size {
90 scalar @{ $_[0]->{_site_array_ref} };
91 }
92
93
94 =head2 add_site_pair
95
96 Title : add_site_pair
97 Usage : $sitepairset->add_site_pair($site_pair_object)
98 $sitepairset->add_site_pair(@list_of_site_pair_objects)
99 Function: adds TFBS::SitePair objects to an existing TFBS::SitePairSet object
100 Returns : $sitepairset object (usually ignored)
101 Args : A list of TFBS::SitePair objects to add
102
103 =cut
104
105
106 sub add_site_pair {
107 my ($self, @site_list) = @_;
108 foreach my $site (@site_list) {
109 $site->isa("TFBS::SitePair")
110 or $self->throw("Attempted to add an element ".
111 "of a wrong type.");
112 push @{$self->{_site_array_ref}}, $site;
113 }
114 return 1;
115 }
116
117
118
119 =head2 add_site_pair_set
120
121 Title : add_site_pair_set
122 Usage : $sitepairset->add_site_pair_set($site_pair_set_object)
123 $sitepairset->add_site_pair(@list_of_site_pair_set_objects)
124 Function: adds the contents of other TFBS::SitePairSet objects
125 to an existing TFBS::SitePairSet object
126 Returns : $sitepairset object (usually ignored)
127 Args : A list of TFBS::SitePairSet objects whose contents should be
128 added to $sitepairset
129
130 =cut
131
132
133 sub add_site_pair_set {
134 my ($self, @sitesets) = @_;
135 foreach my $siteset (@sitesets) {
136 $siteset->isa("TFBS::SitePairSet")
137 or $self->throw("Attempted to add an element ".
138 "that is not a TFBS::SiteSet object.");
139 push @{$self->{_site_array_ref}},
140 @{ $siteset->{_site_array_ref} };
141 }
142 return $self;
143 }
144
145
146 =head2 Iterator
147
148 Title : Iterator
149 Usage : my $it = $sitepairset->Iterator(-sort_by=>'start');
150 while (my $site_pair = $it->next()) { #...
151 Function: Returns an iterator object, used to iterate thorugh elements
152 (TFBS::SitePair objects)
153 Returns : a TFBS::_Iterator object
154 Args : -sort_by # optional - currently it accepts
155 # (default sort order in parenthetse)
156 # 'name' (pattern name, alphabetically)
157 # 'ID' (pattern/matrix ID, alphabetically)
158 # 'start' (site start in sequence,
159 # numerically,increasing order)
160 # 'end' (site end in sequence,
161 # numerically, increasing order)
162 # 'score' (1st site in pair,
163 # numerically, decreasing order)
164 -reverse # optional - reverses the default sorting order if true
165
166 =cut
167
168
169 sub Iterator {
170 my ($self, %args) = @_;
171 return TFBS::_Iterator::_SiteSetIterator->new($self->{_site_array_ref},
172 $args{'-sort_by'},
173 $args{'-reverse'}
174 );
175 }
176
177
178
179 =head2 set1
180
181 =head2 set2
182
183 Title : set1
184 set2
185 Usage : my $siteset1 = $sitepairset->set1();
186 : my $siteset2 = $sitepairset->set2()
187 Function: Returns individual TFBS::SiteSet objects, from the site set pair
188 Returns : A TFBS::SiteSet object
189 Args : none
190
191 =cut
192
193
194 sub set1 {
195 $_[0]->_get_set(1);
196 }
197
198 sub set2 {
199 $_[0]->_get_set(2);
200 }
201
202
203 =head2 GFF
204
205 Title : GFF
206 Usage : print $site->GFF();
207 : print $site->GFF($gff_formatter)
208 Function: returns a "standard" multiline GFF string
209 Returns : a string (multiline, newline terminated)
210 Args : a $gff_formatter function reference (optional)
211
212 =cut
213
214
215 sub GFF {
216 my ($self, %args) = @_;
217 my $iterator = $self->Iterator(-sort_by=>'start');
218 my $gff_string = "";
219 while (my $sitepair = $iterator->next()) {
220 $gff_string .= $sitepair->GFF(%args)."\n";
221 }
222
223 return $gff_string;
224 }
225
226 ##############################################################
227 # PRIVATE AND AUTOMATIC METHODS
228 ##############################################################
229
230 sub _get_set {
231 my ($self, $set_nr) = @_;
232 my $feature = "feature$set_nr";
233 my $it = $self->Iterator();
234 my $siteset = TFBS::SiteSet->new();
235 no strict 'refs';
236 while (my $site_pair = $it->next()) {
237 eval "$siteset->add_site(\$site_pair->$feature())";
238 }
239 return $siteset;
240 }
241
242
243 sub AUTOLOAD {
244 my ($self) = @_;
245 my %discontinued = (sort => 1,
246 sort_by_name => 1,
247 sort_reversed => 1,
248 reverse => 1,
249 next_site => 1,
250 reset => 1
251 );
252 $AUTOLOAD =~ /.+::(\w+)/;
253 if ($discontinued{$1}) {
254 $self->_no_more($1);
255 }
256 else {
257 $self->throw("$1: no such method");
258 }
259 }
260
261 sub _no_more {
262 $_[0]->throw("Method '$_[1]' is no longer available in ".
263 ref($_[0]).". Use the 'Iterator' method instead.");
264 }
265
266 1;
267
268
269
270