Mercurial > repos > willmclaren > ensembl_vep
comparison variant_effect_predictor/Bio/Coordinate/Utils.pm @ 0:21066c0abaf5 draft
Uploaded
author | willmclaren |
---|---|
date | Fri, 03 Aug 2012 10:04:48 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:21066c0abaf5 |
---|---|
1 # $Id: Utils.pm,v 1.1.2.1 2003/02/20 05:11:45 heikki 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->consensus_string(49); | |
121 while ( $cs =~ /([^-]+)/g) { | |
122 | |
123 # alignment coordinates | |
124 my $start = pos($cs) - length($1) + 1; | |
125 my $end = $start+length($1)-1; | |
126 | |
127 my $seq1 = $aln->get_seq_by_pos(1); | |
128 my $seq2 = $aln->get_seq_by_pos(2); | |
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-> | |
143 new(-in => $match1, | |
144 -out => $match2 | |
145 ); | |
146 | |
147 $collection->add_mapper($pair); | |
148 } | |
149 | |
150 return @{$collection->each_mapper}[0] if $collection->each_mapper == 1; | |
151 return $collection; | |
152 | |
153 } | |
154 | |
155 | |
156 | |
157 1; |