~ubuntu-branches/ubuntu/lucid/bioperl/lucid

« back to all changes in this revision

Viewing changes to Bio/Coordinate/Utils.pm

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2004-04-18 14:24:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040418142411-gr92uexquw4w8liq
Tags: 1.4-1
* New upstream release
* Examples and working code are installed by default to usr/bin,
  this has been moved to usr/share/doc/bioperl/bin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# $Id: Utils.pm,v 1.4 2003/12/19 03:00:09 jason Exp $
 
2
#
 
3
# BioPerl module for Bio::Coordinate::Utils
 
4
#
 
5
# Cared for by Heikki Lehvaslaiho <heikki@ebi.ac.uk>
 
6
#
 
7
# Copyright Heikki Lehvaslaiho
 
8
#
 
9
# You may distribute this module under the same terms as perl itself
 
10
 
 
11
# POD documentation - main docs before the code
 
12
 
 
13
=head1 NAME
 
14
 
 
15
Bio::Coordinate::Utils - Additional methods to create Bio::Coordinate objects
 
16
 
 
17
=head1 SYNOPSIS
 
18
 
 
19
    use Bio::Coordinate::Utils;
 
20
    # get a Bio::Align::AlignI compliant object, $aln, somehow
 
21
    # it could be a Bio::SimpleAlign
 
22
 
 
23
    $mapper = Bio::Coordinate::Utils->from_align($aln, 1);
 
24
 
 
25
=head1 DESCRIPTION
 
26
 
 
27
This class is a holder of methods that work on or create
 
28
Bio::Coordinate::MapperI- compliant objects. . These methods are not
 
29
part of the Bio::Coordinate::MapperI interface and should in general
 
30
not be essential to the primary function of sequence objects. If you
 
31
are thinking of adding essential functions, it might be better to
 
32
create your own sequence class.  See L<Bio::PrimarySeqI>,
 
33
L<Bio::PrimarySeq>, and L<Bio::Seq> for more.
 
34
 
 
35
=head1 FEEDBACK
 
36
 
 
37
=head2 Mailing Lists
 
38
 
 
39
User feedback is an integral part of the evolution of this and other
 
40
Bioperl modules. Send your comments and suggestions preferably to one
 
41
of the Bioperl mailing lists.  Your participation is much appreciated.
 
42
 
 
43
  bioperl-l@bioperl.org                        - General discussion
 
44
  http://bio.perl.org/MailList.html             - About the mailing lists
 
45
 
 
46
=head2 Reporting Bugs
 
47
 
 
48
Report bugs to the Bioperl bug tracking system to help us keep track
 
49
the bugs and their resolution.  Bug reports can be submitted via email
 
50
or the web:
 
51
 
 
52
  bioperl-bugs@bio.perl.org
 
53
  http://bugzilla.bioperl.org/
 
54
 
 
55
=head1 AUTHOR - Heikki Lehvaslaiho
 
56
 
 
57
Email:  heikki@ebi.ac.uk
 
58
Address:
 
59
 
 
60
     EMBL Outstation, European Bioinformatics Institute
 
61
     Wellcome Trust Genome Campus, Hinxton
 
62
     Cambs. CB10 1SD, United Kingdom
 
63
 
 
64
=head1 APPENDIX
 
65
 
 
66
The rest of the documentation details each of the object
 
67
methods. Internal methods are usually preceded with a _
 
68
 
 
69
=cut
 
70
 
 
71
 
 
72
# Let the code begin...
 
73
 
 
74
 
 
75
package Bio::Coordinate::Utils;
 
76
use vars qw(@ISA);
 
77
 
 
78
use Bio::Location::Simple;
 
79
use Bio::Coordinate::Pair;
 
80
use Bio::Coordinate::Collection;
 
81
 
 
82
use strict;
 
83
 
 
84
@ISA = qw(Bio::Root::Root);
 
85
# new inherited from Root
 
86
 
 
87
=head2 from_align
 
88
 
 
89
 Title   : from_align
 
90
 Usage   : $mapper = Bio::Coordinate::Utils->from_align($aln, 1);
 
91
 Function:
 
92
           Create a mapper out of an alignment.
 
93
           The mapper will return a value only when both ends of
 
94
           the input range find a match.
 
95
 
 
96
           Note: This implementation works only on pairwise alignments
 
97
           and is not yet well tested!
 
98
 
 
99
 Returns : A Bio::Coordinate::MapperI
 
100
 Args    : Bio::Align::AlignI object
 
101
           Id for the reference sequence, optional
 
102
 
 
103
=cut
 
104
 
 
105
sub from_align {
 
106
   my ($self, $aln, $ref ) = @_;
 
107
 
 
108
   $aln->isa('Bio::Align::AlignI') ||
 
109
       $self->throw('Not a Bio::Align::AlignI object but ['. ref($self). ']');
 
110
 
 
111
   # default reference sequence to the first sequence
 
112
   $ref ||= 1;
 
113
   
 
114
   my $collection = Bio::Coordinate::Collection->new(-return_match=>1);
 
115
 
 
116
   # this works only for pairs, so split the MSA
 
117
   # take the ref
 
118
   #foreach remaining seq in aln, do:
 
119
 
 
120
   my $cs = $aln->gap_line;
 
121
   my $seq1 = $aln->get_seq_by_pos(1);
 
122
   my $seq2 = $aln->get_seq_by_pos(2);   
 
123
   
 
124
   while ( $cs =~ /([^-]+)/g) {
 
125
 
 
126
       # alignment coordinates
 
127
       my $start = pos($cs) - length($1) + 1;
 
128
       my $end   = $start + length($1)-1;
 
129
 
 
130
       my $match1 = Bio::Location::Simple->new
 
131
           (-seq_id => $seq1->id,
 
132
            -start  => $seq1->location_from_column($start)->start,
 
133
            -end    => $seq1->location_from_column($end)->start,
 
134
            -strand => $seq1->strand );
 
135
 
 
136
       my $match2 = Bio::Location::Simple->new
 
137
           (-seq_id => $seq2->id,
 
138
            -start  => $seq2->location_from_column($start)->start,
 
139
            -end    => $seq2->location_from_column($end)->start,
 
140
            -strand => $seq2->strand );
 
141
       
 
142
       my $pair = Bio::Coordinate::Pair->new
 
143
           (-in  => $match1,
 
144
            -out => $match2
 
145
            );
 
146
       $collection->add_mapper($pair);
 
147
   }
 
148
 
 
149
   return ($collection->each_mapper)[0] if $collection->mapper_count == 1;
 
150
   return $collection;
 
151
 
 
152
}
 
153
 
 
154
 
 
155
 
 
156
1;