Bio::Matrix::PSM::IO
transfac
Toolbar
Summary
Bio::Matrix::PSM::IO::transfac - PSM transfac parser
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
See Bio::Matrix::PSM::IO for documentation
Description
#
Methods
Methods description
Title : new Usage : my $psmIO = Bio::Matrix::PSM::IO->new(-format=>'transfac', -file=>$file); Function: Associates a file with the appropriate parser Throws : Example : Args : Returns : "Bio::Matrix::PSM::$format"->new(@args); |
Title : next_psm Usage : my $psm=$psmIO->next_psm(); Function: Reads the next PSM from the input file, associated with this object Throws : Upon finding a line, defining the matrix, where one or more positions are not defined, see _make_matrix Returns : Bio::Matrix::PSM::Psm object Args : none |
Title : _make_matrix Usage : Function: Throws : If a position is undefined, for example if you have line like this in the file you are parsing: 08 4,7,,9 Example : Internal stuff Returns : Args : |
Methods code
sub new
{ my ($class,@args)=@_;
my $line;
my $self = $class->SUPER::new(@args);
my ($file)=$self->_rearrange(['FILE'], @args);
$self->_initialize_io(@args) || warn "Did you intend to use STDIN?"; do {
$line=$self->_readline;
chomp $line;
push @{$self->{unstructured}},$line if (length($line)>2); } until ($line =~ m{^//}) || (!defined($line)); $self->_initialize;
return $self;} |
sub next_psm
{ my $self=shift;
my $line;
return if ($self->{end});
my (@a,@c,@g,@t, $id, $tr1, @refs,$accn, $bf, $sites);
my $i=0;
while (defined( $line=$self->_readline)) {
chomp($line);
if ($line=~/^\d{2}/) { ($a[$i],$c[$i],$g[$i],$t[$i])=_parse_matrix($line);
$i++;
}
($tr1,$accn)=split(/\s{2}/,$line) if ($line=~/^AC\s/);
($tr1,$bf)=split(/\s{2}/,$line) if ($line=~/^BF\s/);
($tr1,$id)=split(/\s{2}/,$line) if ($line=~/^ID\s/);
last if (($line=~/^XX/) && ($i>0));
}
if (!(defined($id) && defined($accn))) {
$self->{end}=1;
return;
}
while (defined( $line=$self->_readline)) { if ($line=~/^BA\s/) {
my ($tr1,$ba)=split(/\s{2}/,$line);
($sites)=split(/\s/,$ba);
}
if ($line=~/^RN/) { my $ref=_parse_ref($self);
push @refs,$ref
}
last if ($line=~m{^//});
}
my %matrix = &_make_matrix($self,\@a,\@c,\@g,\@t,$id, $accn);
$matrix{-sites}=$sites if ($sites);
$matrix{-width}=@a;
my $psm=Bio::Matrix::PSM::Psm->new(%matrix);
foreach my $ref (@refs) { $psm->add_Annotation('reference',$ref); }
return $psm;} |
sub _parse_matrix
{ my $line=shift;
$line=~s/\s+/,/g; my ($tr,$a,$c,$g,$t)=split(/,/,$line);
return $a,$c,$g,$t;} |
sub _make_matrix
{ my ($a, $c, $g, $t, @fa, @fc,@fg, @ft, @a,@c,@g,@t);
my $ave=0;
my ($self,$cA,$cC,$cG,$cT, $id, $accn)= @_;
for (my $i=0; $i < @{$cA};$i++) {
map { $self->throw('Parsing error, a position is not defined') unless defined(${$_}[$i]) } ($cA, $cG, $cC, $cT);
if ( (${$cA}[$i] + ${$cC}[$i] +
${$cG}[$i] + ${$cT}[$i] ) ==0 ) {
push @a,$ave;
push @c,$ave;
push @g,$ave;
push @t,$ave;
}
else {
push @a,${$cA}[$i];
push @c,${$cC}[$i];
push @g,${$cG}[$i];
push @t,${$cT}[$i];
$ave = ((${$cA}[$i]+${$cC}[$i]+
${$cG}[$i]+${$cT}[$i]) / 4 +$ave)/2;
}
}
for (my $i=0; $i<@a;$i++) {
my $zero=($a[$i]+$c[$i]+$g[$i]+$t[$i]);
next if ($zero==0);
push @fa, $a[$i];
push @fc, $c[$i];
push @fg, $g[$i];
push @ft, $t[$i];
}
return (-pA=>\@fa,-pC=>\@fc,-pG=>\@fg,-pT=>\@ft, -id=>$id, -accession_number=>$accn)} |
sub _parse_ref
{my $self=shift;
my ($authors,$title,$loc,@refs,$tr,$db,$dbid);
while (my $refline=$self->_readline) { chomp $refline;
my ($field,$arg)=split(/\s+/,$refline,2);
last if ($field=~/XX/);
$field.=' ';
REF: {
if ($field=~/RX/) { $refline=~s/[;\.]//g; ($tr, $db, $dbid)=split(/\s+/,$refline);
last REF;
}
if ($field=~/RT/) { $title .= $arg;
last REF;
}
if ($field=~/RA/) { $authors .= $arg;
last REF;
}
if ($field=~/RL/) { $loc .= $arg;
last REF;
}
}
}
my $reference=Bio::Annotation::Reference->new(-authors=>$authors, -title=>$title,
-location=>$loc);
if ($db eq 'MEDLINE') {
$reference->medline($dbid);
}
elsif ($dbid) {
$reference->pubmed($dbid);
}
return $reference;} |
sub DESTROY
{ my $self=shift;
$self->close;
}
1;} |
General documentation
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via the
web:
https://redmine.open-bio.org/projects/bioperl/
Title : _parseMatrix
Usage :
Function: Parses a line
Throws :
Example : Internal stuff
Returns : array (frequencies for A,C,G,T in this order).
Args : string