1
# $Id: Infernal.pm 15231 2008-12-22 21:51:02Z cjfields $
3
# BioPerl module for Bio::Tools::Infernal
5
# Cared for by Chris Fields <cjfields-at-uiuc-dot-edu>
7
# Copyright Chris Fields
9
# You may distribute this module under the same terms as perl itself
11
# POD documentation - main docs before the code
15
Bio::Tools::Infernal - A parser for Infernal output
19
use Bio::Tools::Infernal;
20
my $parser = Bio::Tools::Infernal->new(-file => $rna_output,
21
-motiftag => 'misc_binding'
22
-desctag => 'Lysine riboswitch',
26
#parse the results, get a Bio::SeqFeature::FeaturePair
27
while( my $motif = $parser->next_prediction) {
33
This is a highly experimental parser for Infernal output from the cmsearch
34
program. At some point it is anticipated that this will morph into a proper
35
SearchIO parser, along with the related RNAMotif and ERPIN tools.
37
The Infernal suite of programs are used for generating RNA CM (covariance
38
models) and searching sequences using CMs to locate potentially similar
39
structures. The program is under active development; it is anticiapted that
40
this will support the latest version available.
42
This parser has been tested and is capable of parsing Infernal 0.7 and 0.71
43
output. However, future Infernal versions may break parsing as the output is
44
constantly evolving, so keep an eye on this space for additional notes.
46
Currently data is parsed into a Bio::SeqFeature::FeaturePair object, consisting
47
of a query (the covariance model) and the hit (sequence searched).
49
Model data is accessible via the following:
51
Data SeqFeature::FeaturePair Note
52
--------------------------------------------------------------------------
53
primary tag $sf->primary_tag Rfam ID (if passed to new())
54
start $sf->start Based on CM length
55
end $sf->end Based on CM length
56
score $sf->score Bit score
57
strand $sf->strand 0 (CM does not have a strand)
58
seqid $sf->seq_id Rfam ID (if passed to new())
59
display name $sf->feature1->display_name CM name (if passed to new())
60
source $sf->feature1->source tag 'Infernal' followed by version
62
Hit data is accessible via the following:
64
Data SeqFeature::FeaturePair Note
65
------------------------------------------------------------------
68
score(bits) $sf->hscore
71
Primary Tag $sf->hprimary_tag
72
Source Tag $sf->hsource_tag
74
Added FeaturePair tags are :
76
secstructure - entire description line (in case the regex used for
77
sequence ID doesn't adequately catch the name
78
model - name of the descriptor file (may include path to file)
79
midline - contains structural information from the descriptor
81
hit - sequence of motif, separated by spaces according to
82
matches to the structure in the descriptor (in
84
seqname - raw sequence name (for downstream parsing if needed)
86
An additional parameter ('minscore') is added due to the huge number
87
of spurious hits generated by cmsearch. This screens data, only building
88
and returning objects when a minimal bitscore is present.
90
See t/rnamotif.t for example usage.
96
User feedback is an integral part of the evolution of this and other
97
Bioperl modules. Send your comments and suggestions preferably to
98
the Bioperl mailing list. Your participation is much appreciated.
100
bioperl-l@bioperl.org - General discussion
101
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
103
=head2 Reporting Bugs
105
Report bugs to the Bioperl bug tracking system to help us keep track
106
of the bugs and their resolution. Bug reports can be submitted via the
109
http://bugzilla.open-bio.org/
111
=head1 AUTHOR - Chris Fields
113
Email cjfields-at-uiuc-dot-edu
117
The rest of the documentation details each of the object methods.
118
Internal methods are usually preceded with a _
122
# Let the code begin...
124
package Bio::Tools::Infernal;
127
use Bio::SeqFeature::Generic;
128
use Bio::SeqFeature::FeaturePair;
130
use base qw(Bio::Tools::AnalysisResult);
132
our($MotifTag,$SrcTag,$DescTag) = qw(misc_binding Infernal infernal);
135
our $DEFAULT_VERSION = '0.71';
140
Usage : my $obj = Bio::Tools::Infernal->new();
141
Function: Builds a new Bio::Tools::Infernal object
142
Returns : an instance of Bio::Tools::Infernal
143
Args : -fh/-file - for input filehandle/filename
144
-motiftag - primary tag used in gene features (default 'misc_binding')
145
-desctag - tag used for display_name name (default 'infernal')
146
-srctag - source tag used in all features (default 'Infernal')
147
-rfam - Rfam id number
148
-cm - covariance model used in analysis (may be same as rfam #)
149
-minscore - minimum score (simple screener, since Infernal generates
150
a ton of spurious hits)
151
-version - Infernal program version
155
# yes, this is actually _initialize, but the args are passed to
157
# see Bio::Tools::AnalysisResult for further details
160
my($self,@args) = @_;
161
$self->warn('Use of this module is deprecated. Use Bio::SearchIO::infernal instead');
162
$self->SUPER::_initialize(@args);
163
my ($motiftag,$desctag,$srctag,$rfam,$cm,$ms,$ver) =
164
$self->SUPER::_rearrange([qw(MOTIFTAG
172
$self->motif_tag(defined $motiftag ? $motiftag : $MotifTag);
173
$self->source_tag(defined $srctag ? $srctag : $SrcTag);
174
$self->desc_tag(defined $desctag ? $desctag : $DescTag);
175
$cm && $self->covariance_model($cm);
176
$rfam && $self->rfam($rfam);
177
$self->program_version(defined $ver ? $ver : $DEFAULT_VERSION);
178
$self->minscore(defined $ms ? $ms : $MINSCORE);
184
Usage : $obj->motif_tag($newval)
185
Function: Get/Set the value used for 'motif_tag', which is used for setting the
187
Default is 'misc_binding' as set by the global $MotifTag.
188
'misc_binding' is used here because a conserved RNA motif is capable
189
of binding proteins (regulatory proteins), antisense RNA (siRNA),
190
small molecules (riboswitches), or nothing at all (tRNA,
191
terminators, etc.). It is recommended that this be changed to other
192
tags ('misc_RNA', 'protein_binding', 'tRNA', etc.) where appropriate.
193
For more information, see:
194
http://www.ncbi.nlm.nih.gov/collab/FT/index.html
195
Returns : value of motif_tag (a scalar)
196
Args : on set, new value (a scalar or undef, optional)
203
return $self->{'motif_tag'} = shift if @_;
204
return $self->{'motif_tag'};
210
Usage : $obj->source_tag($newval)
211
Function: Get/Set the value used for the 'source_tag'.
212
Default is 'Infernal' as set by the global $SrcTag
213
Returns : value of source_tag (a scalar)
214
Args : on set, new value (a scalar or undef, optional)
222
return $self->{'source_tag'} = shift if @_;
223
return $self->{'source_tag'};
229
Usage : $obj->desc_tag($newval)
230
Function: Get/Set the value used for the query motif. This will be placed in
231
the tag '-display_name'. Default is 'infernal' as set by the global
232
$DescTag. Use this to manually set the descriptor (motif searched for).
233
Since there is no way for this module to tell what the motif is from the
234
name of the descriptor file or the Infernal output, this should
235
be set every time an Infernal object is instantiated for clarity
236
Returns : value of exon_tag (a scalar)
237
Args : on set, new value (a scalar or undef, optional)
244
return $self->{'desc_tag'} = shift if @_;
245
return $self->{'desc_tag'};
248
=head2 covariance_model
250
Title : covariance_model
251
Usage : $obj->covariance_model($newval)
252
Function: Get/Set the value used for the covariance model used in the analysis.
253
Returns : value of exon_tag (a scalar)
254
Args : on set, new value (a scalar or undef, optional)
258
sub covariance_model{
261
return $self->{'_cmodel'} = shift if @_;
262
return $self->{'_cmodel'};
268
Usage : $obj->rfam($newval)
269
Function: Get/Set the Rfam accession number
270
Returns : value of exon_tag (a scalar)
271
Args : on set, new value (a scalar or undef, optional)
278
return $self->{'_rfam'} = shift if @_;
279
return $self->{'_rfam'};
285
Usage : $obj->minscore($newval)
286
Function: Get/Set the minimum score threshold for generating SeqFeatures
287
Returns : value of exon_tag (a scalar)
288
Args : on set, new value (a scalar or undef, optional)
295
return $self->{'_minscore'} = shift if @_;
296
return $self->{'_minscore'};
299
=head2 program_version
301
Title : program_version
302
Usage : $obj->program_version($newval)
303
Function: Get/Set the Infernal program version
304
Returns : value of exon_tag (a scalar)
305
Args : on set, new value (a scalar or undef, optional)
306
Note: this is set to $DEFAULT_VERSION by, um, default
310
sub program_version {
313
return $self->{'_program_version'} = shift if @_;
314
return $self->{'_program_version'};
317
=head2 analysis_method
319
Usage : $obj->analysis_method();
320
Purpose : Inherited method. Overridden to ensure that the name matches
327
sub analysis_method {
328
my ($self, $method) = @_;
329
if($method && ($method !~ /Infernal/i)) {
330
$self->throw("method $method not supported in " . ref($self));
332
return $self->SUPER::analysis_method($method);
338
Usage : while($gene = $obj->next_feature()) {
341
Function: Returns the next gene structure prediction of the RNAMotif result
342
file. Call this method repeatedly until FALSE is returned.
343
The returned object is actually a SeqFeatureI implementing object.
344
This method is required for classes implementing the
345
SeqAnalysisParserI interface, and is merely an alias for
346
next_prediction() at present.
347
Returns : A Bio::Tools::Prediction::Gene object.
348
Args : None (at present)
353
my ($self,@args) = @_;
354
# even though next_prediction doesn't expect any args (and this method
355
# does neither), we pass on args in order to be prepared if this changes
357
return $self->next_prediction(@args);
360
=head2 next_prediction
362
Title : next_prediction
363
Usage : while($gene = $obj->next_prediction()) {
366
Function: Returns the next gene structure prediction of the RNAMotif result
367
file. Call this method repeatedly until FALSE is returned.
368
Returns : A Bio::SeqFeature::Generic object
369
Args : None (at present)
373
sub next_prediction {
376
my ($start, $end, $strand, $score);
378
my %hsp_key = ('0' => 'structure',
384
while($line = $self->_readline) {
385
next if $line =~ m{^\s+$};
386
if ($line =~ m{^sequence:\s+(\S+)} ){
387
$self->_current_hit($1);
389
} elsif ($line =~ m{^hit\s+\d+\s+:\s+(\d+)\s+(\d+)\s+(\d+\.\d+)\s+bits}xms) {
391
($start, $end, $score) = ($1, $2, $3);
393
($start, $end) = ($end, $start);
396
#$self->debug(sprintf("Hit: %-30s\n\tStrand:%-4d Start:%-6d End:%-6d Score:%-10s\n",
397
# $self->_current_hit, $strand, $start, $end, $score));
398
} elsif ($line =~ m{^(\s+)[<>\{\}\(\)\[\]:_,-\.]+}xms) { # start of HSP
399
$self->_pushback($line); # set up for loop
400
# what is length of the gap to the structure data?
401
my $offset = length($1);
402
my ($ct, $strln) = 0;
405
while ($line = $self->_readline) {
406
next if $line =~ m{^\s*$}; # toss empty lines
408
# exit loop if at end of file or upon next hit/HSP
409
if (!defined($line) || $line =~ m{^(sequence|hit)}) {
410
$self->_pushback($line);
413
# iterate to keep track of each line (4 lines per hsp block)
414
my $iterator = $ct%4;
415
# strlen set only with structure lines (proper length)
416
$strln = length($line) if $iterator == 0;
417
# only grab the data needed (hit start and stop in hit line above;
418
# query start, end are from the actual query length (entire hit is
419
# mapped to CM data, so all CM data is represented
421
# yes this is kinda clumsy, but I'll probably morph this into
422
# a proper SearchIO module soon. For now this works...
423
my $data = substr($line, $offset, $strln-$offset);
424
$hsp->{ $hsp_key{$iterator} } .= $data;
427
if ($self->minscore < $score) {
428
my ($name, $program, $rfam, $cm, $dt, $st, $mt) =
429
($self->_current_hit, $self->analysis_method, $self->rfam,
430
$self->covariance_model, $self->desc_tag, $self->source_tag,
432
my $ver = $self->program_version || '';
434
if ($name =~ m{(?:gb|gi|emb|dbj|sp|pdb|bbs|ref|lcl)\|(\d+)((?:\:|\|)\w+\|(\S*.\d+)\|)?}xms) {
437
my $fp = Bio::SeqFeature::FeaturePair->new();
438
my $strlen = $hsp->{'model'} =~ tr{A-Za-z}{A-Za-z}; # gaps don't count
439
my $qf = Bio::SeqFeature::Generic->new( -primary_tag => $mt,
440
-source_tag => "$st $ver",
441
-display_name => $cm || '',
445
-seq_id => $rfam || '',
446
-strand => 0, # covariance model does not have a strand
448
my $hf = Bio::SeqFeature::Generic->new( -primary_tag => $mt,
449
-source_tag => "$st $ver",
450
-display_name => $dt || '',
458
$fp->feature2($hf); # should emphasis be on the hit?
459
$fp->add_tag_value('secstructure', $hsp->{'structure'});
460
$fp->add_tag_value('model', $hsp->{'model'});
461
$fp->add_tag_value('midline', $hsp->{'midline'});
462
$fp->add_tag_value('hit', $hsp->{'hit'});
463
$fp->add_tag_value('seq_name', $name);
464
$fp->display_name($dt);
471
return (defined($line)) ? 1 : 0;
476
return $self->{'_currhit'} = shift if @_;
477
return $self->{'_currhit'};