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 =~ /^\/\//) || (!defined($line)); $self->_initialize;
return $self;} |
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}/) { ($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)) { if ($line=~/^BA\s/) {
my ($tr1,$ba)=split(/\s{2}/,$line);
($sites)=split(/\s/,$ba);
last;
}
last if ($line=~/^\/\//);
}
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;} |
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)} |
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