Bio/Matrix/PSM/IO.pm

filter: Statementstmt 61.0% 36 / 59 Branchbran 31.2% 5 / 16 Conditioncond 21.4% 3 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 42.8% 6 / 14 Podpod 100% 4 / 4 totaltotal 46.9% 54 / 115 CC 14 SCAR 22.7
CC
14
Cov
49%
_guess_format
30.0
new
10.0
fh
6.0
CRAP 9.7
« Bio/Ontology/TermI.pm ↑ Summary Bio/Tools/Signalp/ExtendedSignalp.pm »
1 #---------------------------------------------------------
2  
3 =head1 NAME
4  
5 Bio::Matrix::PSM::IO - PSM parser
6  
7 =head1 SYNOPSIS
8  
9 use Bio::Matrix::PSM::IO;
10  
11 my $psmIO= Bio::Matrix::PSM::IO->new(-file=>$file, -format=>'transfac');
12  
13 my $release=$psmIO->release; #Using Bio::Matrix::PSM::PsmHeader methods
14  
15 my $release=$psmIO->release;
16  
17 while (my $psm=$psmIO->next_psm) {
18 my %psm_header=$psm->header;
19 my $ic=$psm_header{IC};
20 my $sites=$psm_header{sites};
21 my $width=$psm_header{width};
22 my $score=$psm_header{e_val};
23 my $IUPAC=$psm->IUPAC;
24 }
25  
26 my $instances=$psm->instances;
27 foreach my $instance (@{$instances}) {
28 my $id=$instance->primary_id;
29 }
30  
31  
32 =head1 DESCRIPTION
33  
34 This module allows you to read DNA position scoring matrices and/or
35 their respective sequence matches from a file.
36  
37 There are two header methods, one belonging to
38 Bio::Matrix::PSM::IO::driver and the other to
39 Bio::Matrix::PSM::Psm. They provide general information about the file
40 (driver) and for the current PSM result (Psm) respectively. Psm header
41 method always returns the same thing, but some values in the hash
42 might be empty, depending on the file you are parsing. You will get
43 undef in this case (no exceptions are thrown).
44  
45 Please note that the file header data (commenatries, version, input
46 data, configuration, etc.) might be obtained through
47 Bio::Matrix::PSM::PsmHeader methods. Some methods are driver specific
48 (meme, transfac, etc.): meme: weight mast: seq, instances
49  
50 If called when you parse a different file type you will get undef. For
51 example:
52  
53 my $psmIO= Bio::Matrix::PSM::IO->new(file=>$file, format=>'transfac');
54 my %seq=$psmIO->seq;
55  
56 will return an empty hash. To see all methods and how to use them go
57 to Bio::Matrix::PSM::PsmHeaderI.
58  
59 See also Bio::Matrix::PSM::PsmI for details on using and manipulating
60 the parsed data.
61  
62 The only way to write PFM/PWM is through masta module (something like fasta for
63 DNA matrices). You can see an example by reading Bio::Matrix::PSM::IO::masta
64 documentation.
65  
66 =head1 See also
67  
68 Bio::Matrix::PSM::PsmI, Bio::Matrix::PSM::PsmHeaderI, Bio::Matrix::PSM::IO::masta
69  
70 =head1 FEEDBACK
71  
72 =head2 Mailing Lists
73  
74 User feedback is an integral part of the evolution of this and other
75 Bioperl modules. Send your comments and suggestions preferably to one
76 of the Bioperl mailing lists. Your participation is much appreciated.
77  
78 bioperl-l@bioperl.org - General discussion
79 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
80  
81 =head2 Support
82  
83 Please direct usage questions or support issues to the mailing list:
84  
85 I<bioperl-l@bioperl.org>
86  
87 rather than to the module maintainer directly. Many experienced and
88 reponsive experts will be able look at the problem and quickly
89 address it. Please include a thorough description of the problem
90 with code and data examples if at all possible.
91  
92 =head2 Reporting Bugs
93  
94 Report bugs to the Bioperl bug tracking system to help us keep track
95 the bugs and their resolution. Bug reports can be submitted via the
96 web:
97  
98 https://github.com/bioperl/bioperl-live/issues
99  
100 =head1 AUTHOR - Stefan Kirov
101  
102 Email skirov@utk.edu
103  
104 =head1 APPENDIX
105  
106 =cut
107  
108  
109 # Let the code begin...
110 package Bio::Matrix::PSM::IO;
111 11 $Bio::Matrix::PSM::IO::VERSION = '1.7.8';
112 11 ▶use vars qw(@PSMFORMATS);
Subroutine BEGIN: called CC=1 SCAR=0.0
113 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 11 ▶use base qw(Bio::Root::IO);
Subroutine BEGIN: called CC=1 SCAR=0.0
116  
117 11 @PSMFORMATS = qw(meme transfac mast psiblast masta);
118  
119 =head2 new
120  
121 Title : new
122 Usage : my $psmIO = Bio::Matrix::PSM::IO->new(-format=>'meme',
123 -file=>$file);
124 Function: Associates a file with the appropriate parser
125 Throws : Throws if the file passed is in HTML format or
126 if some criteria for the file
127 format are not met. See L<Bio::Matrix::PSM::IO::meme> and
128 L<Bio::Matrix::PSM::IO::transfac> for more details.
129 Example :
130 Returns : psm object, associated with a file with matrix file
131 Args : hash
132  
133 =cut
134  
135 11 ▶sub new {
Subroutine new: called CC=8 SCAR=23.0
Pod documented
136 11 my($caller,@args) = @_;
137 11 ▶ my $class = ref($caller) || $caller;
Condition33%1/3
ref $caller || $caller
l!l&&r!l&&!r
0110
MC/DC0%0/2
ref $caller || $caller
ref $caller $caller
Truth table33%1/3
A || B
A= ref $callerB= $caller
ABresult
1X1
011
000
138 11 my $self;
139 # or do we want to call SUPER on an object if $caller is an
140 # object?
141 11 ▶ if( $class =~ /Bio::Matrix::PSM::IO(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /Bio::Matrix::PSM::IO(\S+)/) { } 3 8 11
142 3 $self = $class->SUPER::new(@args);
143 3 $self->_initialize(@args);
144 3 return $self;
145 } else {
146 8 my %param = @args;
147 8 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
148 my $format = $param{'-format'} ||
149 8 ▶ $class->_guess_format( $param{'-file'} || $ARGV[0] ) ||
Condition25%2/8
$param{'-format'} || $class->_guess_format($param{'-file'} || $ARGV[0]) || 'scoring'
l!l
80
$param{"-format"} or $class->_guess_format($param{"-file"} || $ARGV[0])
l!l&&r!l&&!r
800
$param{'-file'} || $ARGV[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$param{'-format'} || $class->_guess_format($param{'-file'} || $ARGV[0]) || 'scoring'
$param{"-format"} $class->_guess_format($param{"-file"} || $ARGV[0])
MC/DC0%0/2
$param{'-file'} || $ARGV[0]
$param{'-file'} $ARGV[0]
Truth table33%1/3
A or B
A= $param{"-format"}B= $class->_guess_format($param{"-file"} || $ARGV[0])
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $param{'-file'}B= $ARGV[0]
ABresult
1X1
011
000
150 'scoring';
151 8 ▶ $class->throw("$format format unrecognized or an argument error occurred\n.") if (!grep(/$format/,@Bio::Matrix::PSM::IO::PSMFORMATS));
Branch: 1 branch
BranchTrueFalseTotal
unless grep /$format/, @Bio::Matrix::PSM::IO::PSMFORMATS 0 8 8
152 8 $format = "\L$format"; # normalize capitalization to lower case
153  
154 # normalize capitalization
155 8 ▶ return unless( $class->_load_format_module($format) );
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_load_format_module($format) 0 8 8
156 8 return "Bio::Matrix::PSM::IO::$format"->new(@args);
157 }
158 }
159  
160 =head2 fh
161  
162 Title : fh
163 Usage : $obj->fh
164 Function: Get a filehandle type access to the matrix parser
165 Example : $fh = $obj->fh; # make a tied filehandle
166 $matrix = <$fh>; # read a matrix object
167 Returns : filehandle tied to Bio::Matrix::PSM::IO class
168 Args : none
169  
170 =cut
171  
172 0 ▶sub fh {
Subroutine fh: not called CC=2 SCAR=17.9
Pod documented
173 0 my $self = shift;
174 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
175 0 my $s = Symbol::gensym;
176 0 tie $$s,$class,$self;
177 0 return $s;
178 }
179  
180  
181 =head2 _load_format_module
182  
183 Title : _load_format_module
184 Usage : *INTERNAL Matrix::PSM::IO stuff*
185 Function: Loads up (like use) a module at run time on demand
186  
187 =cut
188  
189 8 ▶sub _load_format_module {
Subroutine _load_format_module: called CC=2 SCAR=7.1
190 8 my ($self,$format) = @_;
191 8 my $module = "Bio::Matrix::PSM::IO::" . $format;
192 8 my $ok;
193  
194 8 eval {
195 8 $ok = $self->_load_module($module);
196 };
197 8 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 8 8
198 0 print STDERR <<END;
199 $self: $format cannot be found
200 Exception $@
201 For more information about the Matrix::PSM::IO system please see the
202 Matrix::PSM::IO docs. This includes ways of checking for formats at
203 compile time, not run time
204 END
205 ;
206 }
207 8 return $ok;
208 }
209  
210  
211 =head2 _guess_format
212  
213 Title : _guess_format
214 Usage : $obj->_guess_format($filename)
215 Returns : guessed format of filename (lower case)
216 Args : filename
217  
218 =cut
219  
220 0 ▶sub _guess_format {
Subroutine _guess_format: not called CC=5 SCAR=34.0
221 0 my $class = shift;
222 0 ▶ return unless $_ = shift;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ = shift() 0 0 0
223 0 ▶ return 'meme' if /.meme$|meme.html$/i;
Branch: 1 branch
BranchTrueFalseTotal
if /.meme$|meme.html$/i 0 0 0
224 0 ▶ return 'transfac' if /\.dat$/i;
Branch: 1 branch
BranchTrueFalseTotal
if /\.dat$/i 0 0 0
225 0 ▶ return 'mast' if /^mast\.|\.mast.html$|.mast$/i;
Branch: 1 branch
BranchTrueFalseTotal
if /^mast\.|\.mast.html$|.mast$/i 0 0 0
226 }
227  
228 =head2 next_psm
229  
230 Title : next_psm
231 Usage : my $psm=$psmIO->next_psm();
232 Function: Reads the next PSM from the input file, associated with this object
233 Throws : Throws if there ara format violations in the input file (checking is not
234 very strict with all drivers).
235 Example :
236 Returns : Bio::Matrix::PSM::Psm object
237 Args : none
238  
239 =cut
240  
241 0 ▶sub next_psm {
Subroutine next_psm: not called CC=1 SCAR=6.9
Pod documented
242 0 my $self = shift;
243 0 $self->throw_not_implemented();
244 }
245  
246 =head2 _parseMatrix
247  
248 Title : _parseMatrix
249 Usage :
250 Function: Parses the next site matrix information in the meme file
251 Throws :
252 Example : Internal stuff
253 Returns : hash as for constructing a SiteMatrix object (see SiteMatrixI)
254 Args : string
255  
256 =cut
257  
258 0 ▶sub _parseMatrix {
Subroutine _parseMatrix: not called CC=1 SCAR=6.9
259 0 my $self = shift;
260 0 $self->throw_not_implemented();
261 }
262  
263 =head2 _parseInstance
264  
265 Title : _parseInstance
266 Usage :
267 Function: Parses the next sites instances from the meme file
268 Throws :
269 Example : Internal stuff
270 Returns : Bio::Matrix::PSM::SiteMatrix object
271 Args : array references
272  
273 =cut
274  
275 0 ▶sub _parseInstance {
Subroutine _parseInstance: not called CC=1 SCAR=6.9
276 0 my $self = shift;
277 0 $self->throw_not_implemented();
278 }
279  
280 =head2 _parse_coordinates
281  
282 Title : _parse_coordinates
283 Usage :
284 Function:
285 Throws :
286 Example : Internal stuff
287 Returns :
288 Args :
289  
290 =cut
291  
292 0 ▶sub _parse_coordinates {
Subroutine _parse_coordinates: not called CC=1 SCAR=6.9
293 0 my $self = shift;
294 0 $self->throw_not_implemented();
295 }
296  
297 =head2 header
298  
299 Title : header
300 Usage : my %header=$psmIO->header;
301 Function: Returns the header for the PSM file, format specific
302 Throws :
303 Example :
304 Returns : Hash or a single string with driver specific information
305 Args : none
306  
307 =cut
308  
309 0 ▶sub header {
Subroutine header: not called CC=1 SCAR=6.9
Pod documented
310 0 my $self = shift;
311 0 $self->throw_not_implemented();
312 }
313  
314 =head2 _make_matrix
315  
316 Title : _make_matrix
317 Usage :
318 Function: makes a matrix from 4 array references (A C G T)
319 Throws :
320 Example :
321 Returns : SiteMatrix object
322 Args : array of references(A C G T)
323  
324 =cut
325  
326 0 ▶sub _make_matrix {
Subroutine _make_matrix: not called CC=1 SCAR=6.9
327 0 my $self = shift;
328 0 $self->throw_not_implemented();
329 }
330  
331  
332 4 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
333 4 my $self = shift;
334 4 $self->close();
335 }
336  
337 11 1;
338  
« Bio/Ontology/TermI.pm ↑ Summary Bio/Tools/Signalp/ExtendedSignalp.pm »