Bio::Matrix::PSM::IO transfac
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
Bio::Matrix::PSM::transfac - PSM transfac parser
Package variables
No package variables defined.
Included modules
Bio::Matrix::PSM::IO
Bio::Matrix::PSM::Psm
Bio::Matrix::PSM::PsmHeader
Bio::Root::Root
strict
Inherit
Bio::Matrix::PSM::IO Bio::Matrix::PSM::PsmHeader Bio::Root::Root
Synopsis
See Bio::Matrix::PSM::IO for documentation
Description
#
Methods
newDescriptionCode
next_psmDescriptionCode
_parse_matrix
No description
Code
_make_matrixDescriptionCode
DESTROY
No description
Code
Methods description
newcode    nextTop
 Title   : new
 Usage   : my $psmIO =  new Bio::Matrix::PSM::IO(-format=>'transfac', 
						 -file=>$file);
 Function: Associates a file with the appropriate parser
 Throws  :
 Example :
 Args    :
 Returns : "Bio::Matrix::PSM::$format"->new(@args);
next_psmcodeprevnextTop
 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
_make_matrixcodeprevnextTop
 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
newdescriptionprevnextTop
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?"; #Read only for now
#Remove header
do { $line=$self->_readline; chomp $line; push @{$self->{unstructured}},$line if (length($line)>2); } until ($line =~ /^\/\//) || (!defined($line)); #Unstructured header
$self->_initialize; return $self;
}
next_psmdescriptionprevnextTop
sub next_psm {
    my $self=shift;
    my $line;
    return undef if ($self->{end});
    my (@a,@c,@g,@t, $id, $tr1, $accn, $bf, $sites);
    my $i=0;
    while (defined( $line=$self->_readline)) {
	chomp($line);
	if ($line=~/^\d{2}/) {	#Begining of the frequency data
($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 undef; } while (defined( $line=$self->_readline)) { #How many sites?
if ($line=~/^BA\s/) { my ($tr1,$ba)=split(/\s{2}/,$line); ($sites)=split(/\s/,$ba); last; } last if ($line=~/^\/\//); } # We have the frequencies, let's create a SiteMatrix object
my %matrix = &_make_matrix($self,\@a,\@c,\@g,\@t,$id, $accn); $matrix{-sites}=$sites if ($sites); $matrix{-width}=@a; my $psm=new Bio::Matrix::PSM::Psm(%matrix); return $psm;
}
_parse_matrixdescriptionprevnextTop
sub _parse_matrix {
    my $line=shift;
    $line=~s/\s+/,/g;
my ($tr,$a,$c,$g,$t)=split(/,/,$line); return $a,$c,$g,$t;
}
_make_matrixdescriptionprevnextTop
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++) {
	#No value can be undefined -throw an exception, since setting to 0 probably would be wrong
#If this happens it would indicate most probably that the file, being parsed is in a different format
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)
}
DESTROYdescriptionprevnextTop
sub DESTROY {
    my $self=shift;
    $self->close;
}
General documentation
FEEDBACKTop
Mailing ListsTop
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://bio.perl.org/MailList.html     - About the mailing lists
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution.
Bug reports can be submitted via email or the web:
  bioperl-bugs@bio.perl.org
  http://bugzilla.bioperl.org/
AUTHOR - Stefan KirovTop
Email skirov@utk.edu
APPENDIXTop
_parseMatrixTop
 Title   : _parseMatrix
 Usage   :
 Function: Parses a line
 Throws  :
 Example :  Internal stuff
 Returns :  array (frequencies for A,C,G,T in this order).
 Args    :  string