Bio::DB::TFBS namespace has been moved to its own distribution named after itself
[bioperl-live.git] / Bio / Map / Contig.pm
blobbc1d128ee4e717bbfd6a3d6d13bc2ad63ca9f680
2 # BioPerl module for Bio::Map::Contig
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Sendu Bala <bix@sendu.me.uk>
8 # Copyright Gaurav Gupta
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::Map::Contig - A MapI implementation handling the contigs of a
17 Physical Map (such as FPC)
19 =head1 SYNOPSIS
21 # get the contig object of $contig from the Bio::Map::Physical
22 my $ctgobj = $physical->get_contigobj($contig);
24 # acquire all the markers that lie in this contig
25 foreach my $marker ($ctgobj->each_markerid()) {
26 print " +++$marker\n";
29 # find the group of this contig
30 print "Group: ",$ctgobj->group(),"\n";
32 # find the range of this contig
33 print "RANGE: start:",$ctgobj->range()->start(),"\tend: ",
34 $ctgobj->range()->end(),"\n";
36 # find the position of this contig in $group (chromosome)
37 print "Position in Group $group"," = ",$ctgobj->position($group),"\n";
40 =head1 DESCRIPTION
42 This is an implementation of Bio::Map::MapI. It handles the
43 essential storage of name, species, type, and units as well as in
44 memory representation of the elements of a map.
46 Bio::Map::Contig has been tailored to work for FPC physical maps, but
47 could probably be used for others as well (with the appropriate MapIO
48 module).
50 =head1 FEEDBACK
52 =head2 Mailing Lists
54 User feedback is an integral part of the evolution of this and other
55 Bioperl modules. Send your comments and suggestions preferably to
56 the Bioperl mailing list. Your participation is much appreciated.
58 bioperl-l@bioperl.org - General discussion
59 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
61 =head2 Support
63 Please direct usage questions or support issues to the mailing list:
65 I<bioperl-l@bioperl.org>
67 rather than to the module maintainer directly. Many experienced and
68 reponsive experts will be able look at the problem and quickly
69 address it. Please include a thorough description of the problem
70 with code and data examples if at all possible.
72 =head2 Reporting Bugs
74 Report bugs to the Bioperl bug tracking system to help us keep track
75 of the bugs and their resolution. Bug reports can be submitted via the
76 web:
78 https://github.com/bioperl/bioperl-live/issues
80 =head1 AUTHOR - Gaurav Gupta
82 Email gaurav@genome.arizona.edu
84 =head1 CONTRIBUTORS
86 Sendu Bala bix@sendu.me.uk
88 =head1 PROJECT LEADERS
90 Jamie Hatfield jamie@genome.arizona.edu
91 Dr. Cari Soderlund cari@genome.arizona.edu
93 =head1 PROJECT DESCRIPTION
95 The project was done in Arizona Genomics Computational Laboratory (AGCoL)
96 at University of Arizona.
98 This work was funded by USDA-IFAFS grant #11180 titled "Web Resources for
99 the Computation and Display of Physical Mapping Data".
101 For more information on this project, please refer:
102 http://www.genome.arizona.edu
104 =head1 APPENDIX
106 The rest of the documentation details each of the object methods.
107 Internal methods are usually preceded with a _
109 =cut
111 # Let the code begin...
113 package Bio::Map::Contig;
114 use vars qw($MAPCOUNT);
115 use strict;
117 # Object preamble - inherits from Bio::Root::Root
119 use Bio::Range;
121 use base qw(Bio::Map::SimpleMap);
122 BEGIN { $MAPCOUNT = 1; }
124 =head2 new
126 Title : new
127 Usage : my $clone = Bio::Map::Contig->new
129 -name => $name,
130 -chr_remark => $cremark,
131 -user_remark => $uremark,
132 -trace_remark => $tremark,
133 -group => $group,
134 -subgroup=> $subgroup,
135 -anchor => $anchor,
136 -markers => \%markers,
137 -clones => \%clones,
138 -position => $pos
139 -range => Bio::Range->new(-start =>$s,-end=>$e),
142 Function: Initialize a new Bio::Map::Contig object
143 Most people will not use this directly but get Markers
144 through L<Bio::MapIO::fpc>
145 Returns : L<Bio::Map::Contig> object
146 Args : ( -name => name string,
147 -chr_remark => chr remark string,
148 -user_remark => userremark string,
149 -trace_remark => tremark string,
150 -group => group string,
151 -subgroup=> subgroup string,
152 -anchor => boolean if this is anchored or not,
153 -markers => hashref of contained markers,
154 -clones => hashref of contained clones,
155 -position => position
156 -range => L<Bio::Range>
158 =cut
160 sub new {
161 my ($class,@args) = @_;
162 my $self = $class->SUPER::new(@args);
164 my ($name,$cremark,$uremark,$tremark,
165 $group,$subgroup, $anchor,$markers, $clones,
166 $position,$range) = $self->_rearrange([qw(NAME CHR_REMARK USER_REMARK
167 TRACE_REMARK GROUP SUBGROUP
168 ANCHOR MARKERS CLONES
169 POSITION RANGE)],@args);
171 $self->name($name) if defined $name;
172 $self->chr_remark($cremark) if defined $cremark;
173 $self->user_remark($uremark) if defined $uremark;
174 $self->trace_remark($tremark) if defined $tremark;
175 $self->group($group) if defined $group;
176 $self->subgroup($group) if defined $subgroup;
177 $self->anchor($anchor) if defined $anchor;
179 $self->set_markers($markers) if defined $markers;
180 $self->set_clones($clones) if defined $clones;
181 $self->range($range) if defined $range;
182 $self->position($position) if defined $position;
184 return $self;
187 =head2 Modifier methods
189 All methods present in L<Bio::Map::SimpleMap> are implemented by this class.
190 Most of the methods are inherited from SimpleMap. The following methods
191 have been modified to reflect the needs of physical maps.
193 =head2 chr_remark
195 Title : chr_remark
196 Usage : my $chrremark = $contigobj->chr_remark();
197 Function: Get/set the group remark for this contig
198 Returns : scalar representing the current group_remark of this contig
199 Args : none to get, OR string to set
201 =cut
203 sub chr_remark {
204 my ($self) = shift;
205 $self->{'_cremark'} = shift if @_;
206 return defined $self->{'_cremark'} ? $self->{'_cremark'} : '';
209 =head2 user_remark
211 Title : user_remark
212 Usage : my $userremark = $contigobj->user_remark();
213 Function: Get/set the user remark for this contig
214 Returns : scalar representing the current user_remark of this contig
215 Args : none to get, OR string to set
217 =cut
219 sub user_remark {
220 my ($self) = shift;
221 $self->{'_uremark'} = shift if @_;
222 return defined $self->{'_uremark'} ? $self->{'_uremark'} : '';
225 =head2 trace_remark
227 Title : trace_remark
228 Usage : my $traceremark = $contigobj->trace_remark();
229 Function: Get/set the trace remark for this contig
230 Returns : scalar representing the current trace_remark of this contig
231 Args : none to get, OR string to set
233 =cut
235 sub trace_remark {
236 my ($self) = shift;
237 $self->{'_tremark'} = shift if @_;
238 return defined $self->{'_tremark'} ? $self->{'_tremark'} : '';
241 =head2 range
243 Title : range
244 Usage : my $range = $contigobj->range();
245 Function: Get/set the range for this Contig
246 Returns : Bio::Range representing the current range of this contig,
247 start and end of the contig can be thus found using:
248 my $start = $contigobj->range()->start();
249 my $end = $contigobj->range()->end();
250 Args : none to get, OR Bio::Range to set
252 =cut
254 sub range {
255 my ($self) = shift;
256 return $self->{'_range'} = shift if @_;
257 return $self->{'_range'};
260 =head2 position
262 Title : position
263 Usage : $ctgpos = $contigobj->position();
264 Function: Get/set the position of the contig in the group
265 Returns : scalar representing the position of the contig in the group
266 Args : none to get, OR string to set
268 =cut
270 sub position {
271 my ($self) = shift;
272 $self->{'_position'} = shift if @_;
273 return $self->{'_position'} || 0;
276 =head2 anchor
278 Title : anchor
279 Usage : $ctganchor = $contig->anchor();
280 Function: Get/set the anchor value for this Contig (True | False)
281 Returns : scalar representing the anchor (1 | 0) for this contig
282 Args : none to get, OR string to set
284 =cut
286 sub anchor {
287 my ($self) = shift;
288 return $self->{'_anchor'} = shift if @_;
289 return $self->{'_anchor'};
292 =head2 group
294 Title : group
295 Usage : $groupno = $contigobj->group();
296 Function: Get/set the group number for this contig.
297 This is a generic term, used for Linkage-Groups as well as for
298 Chromosomes.
299 Returns : scalar representing the group number of this contig
300 Args : none
302 =cut
304 sub group {
305 my ($self) = shift;
306 $self->{'_group'} = shift if @_;
307 return $self->{'_group'} || 0;
310 =head2 subgroup
312 Title : subgroup
313 Usage : $subgroup = $contig->subgroup();
314 Function: Get/set the subgroup for this contig. This is a generic term:
315 subgroup here could represent subgroup of a Chromosome or of a
316 Linkage Group. The user must take care of which subgroup he/she is
317 querying for.
318 Returns : A scalar representing the subgroup of this contig
319 Args : none
321 =cut
323 sub subgroup {
324 my ($self) = @_;
325 return $self->{'_subgroup'} = shift if @_;
326 return $self->{'_subgroup'} || 0;
329 =head2 each_cloneid
331 Title : each_cloneid
332 Usage : my @clones = $map->each_cloneid();
333 Function: retrieves all the clone ids in a map unordered
334 Returns : list of strings (ids)
335 Args : none
337 *** This only supplies the ids set with the set_clones method ***
338 *** It has nothing to do with actual Bio::Map::MappableI objects ***
340 =cut
342 sub each_cloneid {
343 my ($self) = @_;
344 return $self->_each_element('clones');
347 =head2 each_markerid
349 Title : each_markerid
350 Usage : my @markers = $map->each_markerid();
351 Function: retrieves all the marker ids in a map unordered
352 Returns : list of strings (ids)
353 Args : none
355 *** This only supplies the ids set with the set_markers method ***
356 *** It has nothing to do with actual Bio::Map::MarkerI objects ***
358 =cut
360 sub each_markerid {
361 my ($self) = @_;
362 return $self->_each_element('markers');
365 sub _each_element {
366 my ($self, $type) = @_;
367 $type = 'clones' if (!defined($type));
368 $type = lc("_$type");
369 return keys %{$self->{$type} || {}};
372 =head2 set_clones
374 Title : set_clones
375 Usage : $marker->set_clones(\%clones)
376 Function: Set the clones hashref
377 Returns : None
378 Args : Hashref of clone ids
380 *** This only sets a hash of ids ***
381 *** It has nothing to do with actual Bio::Map::MappableI objects ***
383 =cut
385 sub set_clones {
386 my ($self,$clones) = @_;
387 if( defined $clones && ref($clones) =~ /HASH/ ) {
388 $self->{'_clones'} = $clones;
392 =head2 set_markers
394 Title : markers
395 Usage : $obj->set_markers($newval)
396 Function: Set list of Markers (hashref)
397 Returns : None
398 Args : Hashref of marker ids
400 *** This only sets a hash of ids ***
401 *** It has nothing to do with actual Bio::Map::MarkerI objects ***
403 =cut
405 sub set_markers {
406 my ($self,$markers) = @_;
407 if( defined $markers && ref($markers) =~ /HASH/ ) {
408 $self->{'_markers'} = $markers;