[From nobody Thu Sep  9 15:53:26 2004
Return-Path: &lt;msuchoro@fhcrc.org&gt;
Received: from jarlite.fhcrc.org (JARLITE.FHCRC.ORG [140.107.42.11])
	by bigred.bioteam.net (8.12.8/8.12.8) with ESMTP id i89IPgSf021333
	(version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO)
	for &lt;dag@sonsorol.org&gt;; Thu, 9 Sep 2004 14:25:49 -0400
Received: from hydra.fhcrc.org (HYDRA.FHCRC.ORG [140.107.42.42])
	by jarlite.fhcrc.org (8.12.7/8.12.7/SuSE Linux 0.6) with ESMTP id
	i89ITfKq010051 for &lt;dag@sonsorol.org&gt;; Thu, 9 Sep 2004 11:29:41 -0700
Received: from fhcrc.org (DHCP031217.FHCRC.ORG [140.107.31.217])
	(authenticated bits=0)
	by hydra.fhcrc.org (8.12.10/8.12.10/SuSE Linux 0.7) with ESMTP id
	i89ITel7024615
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for &lt;dag@sonsorol.org&gt;; Thu, 9 Sep 2004 11:29:40 -0700
Message-ID: &lt;4140A114.8030800@fhcrc.org&gt;
Date: Thu, 09 Sep 2004 11:29:40 -0700
From: Martin Suchorolski &lt;msuchoro@fhcrc.org&gt;
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.2) Gecko/20040308
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: dag@sonsorol.org
Subject: fixed bug... how do I submit the code?
Content-Type: multipart/mixed; boundary=&quot;------------090604050307070907040900&quot;
X-FHCRC: INTERNAL
X-PMX-Version: 4.6.1.107272, Antispam-Core: 4.6.1.106808,
	Antispam-Data: 2004.9.9.0
X-Spam-Score: (0.16) HTML_MESSAGE
X-Scanned-By: MIMEDefang 2.41

This is a multi-part message in MIME format.
--------------090604050307070907040900
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

I just fixed a bug(#1693) and would like to commit the change to your 
CVS archive. 

How do I do this? Is there a process by which the fix needs to be 
reviewed?  I am attaching the fixed code (Bio/Matrix/PSM/IO/meme.pm) , 
if this is only allowed by Bioperl developers

Cheers,
-Martin

--------------090604050307070907040900
Content-Type: text/plain;
 name=&quot;meme.pm&quot;
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename=&quot;meme.pm&quot;

#---------------------------------------------------------
# $Id: meme.pm,v 1.7 2003/12/12 17:01:42 skirov Exp $

=head1 NAME

Bio::Matrix::PSM::meme - PSM meme parser implementation

=head1 SYNOPSIS

See Bio::Matrix::PSM::IO for detailed documentation on how to use PSM parsers

=head1 DESCRIPTION

Parser for meme.

=head1 FEEDBACK

=head2 Mailing Lists

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

=head2 Reporting Bugs

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/

=head1 AUTHOR - Stefan Kirov

Email skirov@utk.edu

=head1 APPENDIX

=cut


# Let the code begin...
package Bio::Matrix::PSM::IO::meme;
use Bio::Matrix::PSM::IO;
use Bio::Matrix::PSM::InstanceSite;
use Bio::Matrix::PSM::SiteMatrix;
use Bio::Matrix::PSM::Psm;
use Bio::Matrix::PSM::PsmHeader;
use vars qw(@ISA @HEADER);
use strict;

@ISA=qw(Bio::Matrix::PSM::PsmHeader Bio::Matrix::PSM::IO Bio::Root::Root);

@Bio::Matrix::PSM::IO::meme::HEADER = qw(e_val sites IC width);

=head2 new

 Title   : new
 Usage   : my $psmIO =  new Bio::Matrix::PSM::IO(-format=&gt;'meme', 
						 -file=&gt;$file);
 Function: Associates a file with the appropriate parser
 Throws  : Throws if the file passed is in HTML format or 
           if the MEME header cannot be found.
 Example :
 Args    : hash
 Returns : &quot;Bio::Matrix::PSM::$format&quot;-&gt;new(@args);

=cut

sub new {
    my($class, @args)=@_;
    my $self = $class-&gt;SUPER::new(@args);
    my ($file)=$self-&gt;_rearrange(['FILE'], @args);
    my ($query,$tr1)=split(/\./,$file,2);
    $self-&gt;{file} = $file;
    $self-&gt;{query}= $query;
    $self-&gt;{end}  = 0;
    $self-&gt;_initialize_io(@args) || warn &quot;Did you intend to use STDIN?&quot;; #Read only for now
    #Skip header
    my $line;
    while (my $line=$self-&gt;_readline) {
	$self-&gt;throw('Cannot parse HTML, please use text output\n') if ($line=~/&lt;HEAD&gt;/); #Should start parsing HTML output, not a bug deal
	chomp($line);
	if ($line=~&quot;^ALPHABET&quot;) {
	    $self=_parse_coordinates($self);
	    last;
	}
	push @{$self-&gt;{unstructured}},$line unless (($line=~/\*{10,}/) || ($line eq ''));
    }
    $self-&gt;_initialize;
    return $self;
}

=head2 _parse_coordinates

 Title   : _parse_coordinates
 Usage   :
 Function:
 Throws  :
 Example : Internal stuff
 Returns :
 Args    :

=cut

sub _parse_coordinates {
    my $self=shift;
    $self-&gt;_readline;
    $self-&gt;_readline;
    my $line=$self-&gt;_readline;
    while ($line !~ /^\*{10,}/ ) {
	chomp $line;
	$line=~s/\s+/,/g;
	my ($id1,$w1,$l1,$id2,$w2,$l2)=split(/,/,$line);
	push @{$self-&gt;{hid}},$id1;
	$self-&gt;{weight}-&gt;{$id1}=$w1;
	$self-&gt;{length}-&gt;{$id1}=$l1;
	if ($id2) {
	    push @{$self-&gt;{hid}},$id2;
	    $self-&gt;{weight}-&gt;{$id2}=$w2;
	    $self-&gt;{length}-&gt;{$id2}=$l2;
	}
	$line=$self-&gt;_readline;
    }
    return $self;
}

=head2 header

 Title   : header
 Usage   :  my %header=$psmIO-&gt;header;
 Function:  Returns the header for the MEME file
 Throws  :
 Example : Fetching all the sequences included in the MEME analysis, 
           being parsed
           my %header=$psmIO-&gt;header;
            foreach my $seqid (@{$header{instances}}) {
               my $seq=$db-&gt;get_Seq_by_acc($id);
               #Do something with the sequence
            }
            where $db might be Bio::DB:GenBank object, see
 Returns : Hash with three keys: instances, weights and lengths, which
           should be self-explenatory. Each value is an array
           reference. Each array element corresponds to the same
           element in the other two arrays. So $header{instances}-&gt;[$i]
           will refer to the same sequence in the motif file as
           $header{weights}-&gt;[$i] and $header{lengths}-&gt;[$i]
 Args    :  none
 Notes   :  OBSOLETE!

=cut

sub header {
    my $self=shift;
    my @instances=@{$self-&gt;{_inst_name}};
    my @weights=@{$self-&gt;{_inst_weight}};
    my @lengths=@{$self-&gt;{_inst_coord}};
    return (instances=&gt;\@instances,weights=&gt;\@weights,lengths=&gt;\@lengths);
}

=head2 next_psm

 Title   : next_psm
 Usage   : my $psm=$psmIO-&gt;next_psm();
 Function: Reads the next PSM from the input file, associated with this object
 Throws  : Throws if the format is inconsistent with the rules for MEME 3.0.4:
            no SUMMARY Section present or some keywords are missing/altered.
 Example :
 Returns : Bio::Matrix::PSM::Psm object
 Args    : none

=cut

sub next_psm {
    #Parses the next prediction and returns a psm objects
    my $self=shift;
    return undef if ($self-&gt;{end});
    my ($endm,$line,$instances,$tr,$width,$motif_id,$sites,$e_val,$id,$ic);
    while (defined( $line = $self-&gt;_readline) ) {
	if ($line=~ m/\sSite\s/) {
	    $instances=$self-&gt;_parseInstance;
	}
	#Here starts the next motif
	if ( ($line=~/width/) &amp;&amp; ($line=~/sites/)) {
	    chomp($line);
	    $line=~s/[\t\s=]+/,/g;
	    $line=~s/\t/,/g;
	    #Parsing the general information for this prediction
	    ($tr,$motif_id,$tr,$width,$tr,$sites,
	     $tr,$tr,$tr,$e_val)=split(/,/,$line);
	    $self-&gt;{id}=$self-&gt;{query} . $motif_id;
	}
	if ($line =~ /content/i) {
	    $line=$self-&gt;_readline;
	    chomp($line);
	    $line=~s/[\)\(]//g;
	    ($ic)=split(/\s/,$line);
	}
        #Last info-prob matrix data
	if ($line=~/letter\-probability\s+matrix/) {
	    my %matrix_dat=$self-&gt;_parseMatrix($motif_id);
	    my $psm= new Bio::Matrix::PSM::Psm(%matrix_dat, 
					       -instances=&gt;$instances, 
					       -e_val=&gt;$e_val,
					       -IC=&gt;$ic, 
					       -width=&gt;$width, 
					       -sites=&gt;$sites);
	    return $psm;
	}
	if ($line=~&quot;SUMMARY OF MOTIFS&quot;) {
	    $self-&gt;{end}=1;
	    return undef;
	}
	$endm=1 if ($line=~/^Time\s/); 
    }
	if ($endm) { #End of file found, end of current motif too, but not all predictions were made as requested (No summary)
	    $self-&gt;{end}=1;
		warn &quot;This MEME analysis was terminated prematurely, you may have less motifs than you requested\n&quot;;
	    return undef;
	}
    $self-&gt;throw(&quot;Wrong format\n&quot;); # Multiple keywords not found, probably wrong format
}

=head2 _parseMatrix

 Title   : _parseMatrix
 Usage   :
 Function: Parses the next site matrix information in the meme file
 Throws  :
 Example :  Internal stuff
 Returns :  hash as for constructing a SiteMatrix object (see SiteMatrixI)
 Args    :  string

=cut

sub _parseMatrix {
    my ($self,$id)=@_;
    my (@pA,@pC,@pG,@pT);
    my $i=0;
    my $line = $self-&gt;_readline;
    #Most important part- the probability matrix
    do {
	chomp $line;
	last if ($line eq '');
	$line=~s/\s\s/,/g;
	$line=~s/\s//g;
	($pA[$i],$pC[$i],$pG[$i],$pT[$i])=split(/,/,$line);
	$i++;
	$line=$self-&gt;_readline;
    } until $line =~ /\-{10,}/;
    
    return (-pA=&gt;\@pA,-pC=&gt;\@pC,-pG=&gt;\@pG,-pT=&gt;\@pT,-id=&gt;$id);
}


=head2 _parseInstance

 Title   : _parseInstance
 Usage   :
 Function:  Parses the next sites instances from the meme file
 Throws  :
 Example :  Internal stuff
 Returns :  Bio::Matrix::PSM::InstanceSite object
 Args    :  none

=cut

sub _parseInstance {
    my $self = shift;
    my $i=0;
    $self-&gt;_readline;
    my ($line,@instance);
    while (defined($line=$self-&gt;_readline) ) {
	last if ($line =~ /\-{5}/ );
	chomp($line);
	my $seq = $line;
	$seq  =~ s/[^AGCTXN-]//g;
	$line =~ s/\s[AGCTXN-]+\s[AGCTXN-]+\s[AGCTXN-]+//g;
        $line=~s/\s[\s\+-]*/,/g; #Patched up by mts
	my ($id,$start,$score)=split(/,/,$line);
	my $sid = $self-&gt;{id} . '@' . $id;
	$instance[$i] = new Bio::Matrix::PSM::InstanceSite
	    (-mid   =&gt; $self-&gt;{id}, 
	     -start =&gt; $start, 
	     -score =&gt; $score,
	     -seq   =&gt; $seq, 
	     -accession_number =&gt; $id, 
	     -primary_id =&gt; $sid, 
	     -desc =&gt; 'Bioperl MEME parser object' );
	$i++;
    }
    $self-&gt;{instances} = \@instance;
    return \@instance;
}

1;

--------------090604050307070907040900--
]