t/AlignIO/AlignIO.t: fix number of tests in plan (fixup c523e6bed866)
[bioperl-live.git] / Bio / MapIO / mapmaker.pm
blob7bc435c970dd5775dfbc67d930ab5a520be56a8e
2 # BioPerl module for Bio::MapIO::mapmaker
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason@bioperl.org>
8 # Copyright Jason Stajich
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::MapIO::mapmaker - A Mapmaker Map reader
18 =head1 SYNOPSIS
20 # do not use this object directly it is accessed through the Bio::MapIO system
22 use Bio::MapIO;
23 my $mapio = Bio::MapIO->new(-format => "mapmaker",
24 -file => "mapfile.map");
25 while ( my $map = $mapio->next_map ) { # get each map
26 foreach my $marker ( $map->each_element ) {
27 # loop through the markers associated with the map
31 =head1 DESCRIPTION
33 This object contains code for parsing and processing Mapmaker output
34 and creating L<Bio::Map::MapI> objects from it.
36 =head1 FEEDBACK
38 =head2 Mailing Lists
40 User feedback is an integral part of the evolution of this and other
41 Bioperl modules. Send your comments and suggestions preferably to
42 the Bioperl mailing list. Your participation is much appreciated.
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47 =head2 Support
49 Please direct usage questions or support issues to the mailing list:
51 I<bioperl-l@bioperl.org>
53 rather than to the module maintainer directly. Many experienced and
54 reponsive experts will be able look at the problem and quickly
55 address it. Please include a thorough description of the problem
56 with code and data examples if at all possible.
58 =head2 Reporting Bugs
60 Report bugs to the Bioperl bug tracking system to help us keep track
61 of the bugs and their resolution. Bug reports can be submitted via the
62 web:
64 https://github.com/bioperl/bioperl-live/issues
66 =head1 AUTHOR - Jason Stajich
68 Email jason@bioperl.org
70 =head1 APPENDIX
72 The rest of the documentation details each of the object methods.
73 Internal methods are usually preceded with a _
75 =cut
77 # Let the code begin...
79 package Bio::MapIO::mapmaker;
80 use strict;
82 use Bio::Map::SimpleMap;
83 use Bio::Map::LinkagePosition;
84 use Bio::Map::Marker;
86 use base qw(Bio::MapIO);
88 =head2 next_map
90 Title : next_map
91 Usage : my $map = $factory->next_map;
92 Function: Get one or more map objects from the Mapmaker input
93 Returns : Bio::Map::MapI
94 Args : none
96 See L<Bio::Map::MapI>
98 =cut
100 sub next_map{
101 my ($self) = @_;
102 my $map = Bio::Map::SimpleMap->new(-name => '',
103 -units => 'cM',
104 -type => 'Genetic');
106 # Mapmaker input can be free-form, like the result of a copy-paste
107 # from a terminal, with no particular format before or after the
108 # map data. The $in_map variable is a flag that's set to 1 when
109 # we're reading map data lines and set back to 0 when we're finished.
110 my ($in_map,$runningDistance);
112 while ( defined ($_ = $self->_readline()) ) {
113 if ( /^\s+Markers\s+Distance/ ) {
114 $in_map = 1;
115 next;
117 next unless $in_map;
119 s/ +/\t/;
120 my ($number,$name,$distance) = split;
121 $runningDistance += $distance unless ($distance =~ /-+/);
122 $runningDistance = '0.0' if ($runningDistance == 0 || $distance =~ /-+/);
124 my $pos = Bio::Map::LinkagePosition->new(-order => $number,
125 -map => $map,
126 -value => $runningDistance );
127 my $marker = Bio::Map::Marker->new(-name => $name,
128 -position => $pos );
130 if ($distance =~ /-+/) { # last marker
131 $in_map = 0;
132 return $map;
137 =head2 write_map
139 Title : write_map
140 Usage : $factory->write_map($map);
141 Function: Write a map out through the factory
142 Returns : none
143 Args : Bio::Map::MapI
145 =cut
147 sub write_map{
148 my ($self,@args) = @_;
149 $self->throw_not_implemented();