Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/Index/SwissPfam.pm @ 0:1f6dce3d34e0
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 02:01:53 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1f6dce3d34e0 |
---|---|
1 | |
2 # | |
3 # $Id: SwissPfam.pm,v 1.15 2002/10/22 07:38:33 lapp Exp $ | |
4 # | |
5 # BioPerl module for Bio::Index::SwissPfam | |
6 # | |
7 # Cared for by Ewan Birney <birney@sanger.ac.uk> | |
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::Index::SwissPfam - Interface for indexing swisspfam files | |
16 | |
17 =head1 SYNOPSIS | |
18 | |
19 use Bio::Index::SwissPfam; | |
20 use strict; | |
21 | |
22 my $Index_File_Name = shift; | |
23 my $inx = Bio::Index::SwissPfam->new('-filename' => $Index_File_Name, | |
24 '-write_flag' => 'WRITE'); | |
25 $inx->make_index(@ARGV); | |
26 | |
27 use Bio::Index::SwissPfam; | |
28 use strict; | |
29 | |
30 my $Index_File_Name = shift; | |
31 my $inx = Bio::Index::SwissPfam->new('-filename' => $Index_File_Name); | |
32 | |
33 foreach my $id (@ARGV) { | |
34 my $seq = $inx->fetch($id); # Returns stream | |
35 while( <$seq> ) { | |
36 if(/^>/) { | |
37 print; | |
38 last; | |
39 } | |
40 } | |
41 } | |
42 | |
43 | |
44 =head1 DESCRIPTION | |
45 | |
46 SwissPfam is one of the flat files released with Pfam. This modules | |
47 provides a way of indexing this module. | |
48 | |
49 Inherits functions for managing dbm files from | |
50 Bio::Index::Abstract.pm, and provides the basic funtionallity for | |
51 indexing SwissPfam files. Only retrieves FileStreams at the | |
52 moment. Once we have something better (ie, an object!), will use | |
53 that. Heavily snaffled from James Gilbert's Fasta system. Note: for | |
54 best results 'use strict'. | |
55 | |
56 =head1 FEED_BACK | |
57 | |
58 =head2 Mailing Lists | |
59 | |
60 User feedback is an integral part of the evolution of this and other | |
61 Bioperl modules. Send your comments and suggestions preferably to one | |
62 of the Bioperl mailing lists. Your participation is much appreciated. | |
63 | |
64 bioperl-l@bioperl.org - General discussion | |
65 http://bioperl.org/MailList.shtml - About the mailing lists | |
66 | |
67 =head2 Reporting Bugs | |
68 | |
69 Report bugs to the Bioperl bug tracking system to help us keep track | |
70 the bugs and their resolution. Bug reports can be submitted via | |
71 email or the web: | |
72 | |
73 bioperl-bugs@bio.perl.org | |
74 http://bugzilla.bioperl.org/ | |
75 | |
76 =head1 AUTHOR - Ewan Birney | |
77 | |
78 Email - birney@sanger.ac.uk | |
79 | |
80 =head1 APPENDIX | |
81 | |
82 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ | |
83 | |
84 =cut | |
85 | |
86 | |
87 # Let's begin the code... | |
88 | |
89 | |
90 package Bio::Index::SwissPfam; | |
91 | |
92 use vars qw($VERSION @ISA); | |
93 use strict; | |
94 | |
95 use Bio::Index::Abstract; | |
96 use Bio::Seq; | |
97 | |
98 @ISA = qw(Bio::Index::Abstract); | |
99 | |
100 # | |
101 # Suggested fix by Michael G Schwern <schwern@pobox.com> to | |
102 # get around a clash with CPAN shell... | |
103 # | |
104 | |
105 BEGIN { | |
106 $VERSION = 0.1; | |
107 } | |
108 | |
109 sub _version { | |
110 return $VERSION; | |
111 } | |
112 | |
113 =head2 _index_file | |
114 | |
115 Title : _index_file | |
116 Usage : $index->_index_file( $file_name, $i ) | |
117 Function: Specialist function to index swisspfam format files. | |
118 Is provided with a filename and an integer | |
119 by make_index in its SUPER class. | |
120 Example : | |
121 Returns : | |
122 Args : | |
123 | |
124 =cut | |
125 | |
126 sub _index_file { | |
127 my( $self, | |
128 $file, # File name | |
129 $i # Index-number of file being indexed | |
130 ) = @_; | |
131 | |
132 my( $begin, # Offset from start of file of the start | |
133 # of the last found record. | |
134 $end, # Offset from start of file of the end | |
135 # of the last found record. | |
136 $id, # ID of last found record. | |
137 $acc, # accession of last record. Also put into the index | |
138 $nid, $nacc, # new ids for the record just found | |
139 ); | |
140 | |
141 $begin = 0; | |
142 $end = 0; | |
143 | |
144 open SP, $file or $self->throw("Can't open file for read : $file"); | |
145 | |
146 # Main indexing loop | |
147 while (<SP>) { | |
148 if (/^>(\S+)\s+\|=*\|\s+(\S+)/) { | |
149 $nid = $1; | |
150 $nacc = $2; | |
151 my $new_begin = tell(SP) - length( $_ ); | |
152 $end = $new_begin - 1; | |
153 | |
154 if( $id ) { | |
155 $self->add_record($id, $i, $begin, $end); | |
156 if( $acc ne $id ) { | |
157 $self->add_record($acc, $i, $begin, $end); | |
158 } | |
159 } | |
160 $begin = $new_begin; | |
161 $id = $nid; | |
162 $acc = $nacc; | |
163 } | |
164 } | |
165 # Don't forget to add the last record | |
166 $end = tell(SP); | |
167 $self->add_record($id, $i, $begin, $end) if $id; | |
168 | |
169 close SP; | |
170 return 1; | |
171 } | |
172 | |
173 | |
174 =head2 fetch | |
175 | |
176 Title : fetch | |
177 Usage : $index->fetch( $id ) | |
178 Function: Returns a Bio::Seq object from the index | |
179 Example : $seq = $index->fetch( 'dJ67B12' ) | |
180 Returns : Bio::Seq object | |
181 Args : ID | |
182 | |
183 =cut | |
184 | |
185 sub fetch { | |
186 my( $self, $id ) = @_; | |
187 my $desc; | |
188 my $db = $self->db(); | |
189 if (my $rec = $db->{ $id }) { | |
190 my( @record ); | |
191 | |
192 my ($file, $begin, $end) = $self->unpack_record( $rec ); | |
193 | |
194 # Get the (possibly cached) filehandle | |
195 my $fh = $self->_file_handle( $file ); | |
196 | |
197 # move to start | |
198 seek($fh, $begin, 0); | |
199 | |
200 return $fh; | |
201 } else { | |
202 $self->throw("Unable to find a record for $id in SwissPfam flat file index"); | |
203 } | |
204 } | |
205 | |
206 1; |