Bio/AlignIO/meme.pm

filter: Statementstmt 89.2% 50 / 56 Branchbran 76.6% 23 / 30 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 83.4% 91 / 109 CC 19 SCAR 28.2
CC
19
Cov
84%
next_aln
20.8
write_aln
2.0
BEGIN
1.0
CRAP 16.7
« Bio/SearchIO/erpin.pm ↑ Summary Bio/DB/Registry.pm »
1 #
2 # BioPerl module for Bio::AlignIO::meme
3 # Based on the Bio::SeqIO modules
4 # by Ewan Birney <birney@ebi.ac.uk>
5 # and Lincoln Stein <lstein@cshl.org>
6 # and the SimpleAlign.pm module of Ewan Birney
7 #
8 # Copyright Benjamin Berman
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 =head1 NAME
13  
14 Bio::AlignIO::meme - meme sequence input/output stream
15  
16 =head1 SYNOPSIS
17  
18 Do not use this module directly. Use it via the Bio::AlignIO class.
19  
20 use Bio::AlignIO;
21 # read in an alignment from meme
22 my $in = Bio::AlignIO->new(-format => 'meme',
23 -file => 'meme.out');
24 while( my $aln = $in->next_aln ) {
25 # do something with the alignment
26 }
27  
28 =head1 DESCRIPTION
29  
30 This object transforms the "sites sorted by position p-value" sections
31 of a meme (text) output file into a series of Bio::SimpleAlign
32 objects. Each SimpleAlign object contains Bio::LocatableSeq
33 objects which represent the individual aligned sites as defined by
34 the central portion of the "site" field in the meme file. The start
35 and end coordinates are derived from the "Start" field. See
36 L<Bio::SimpleAlign> and L<Bio::LocatableSeq> for more information.
37  
38 This module can only parse MEME version 3 and 4. Previous
39 versions have output formats that are more difficult to parse
40 correctly. If the meme output file is not version 3.0 or greater
41 we signal an error.
42  
43 =head1 FEEDBACK
44  
45 =head2 Support
46  
47 Please direct usage questions or support issues to the mailing list:
48  
49 I<bioperl-l@bioperl.org>
50  
51 rather than to the module maintainer directly. Many experienced and
52 reponsive experts will be able look at the problem and quickly
53 address it. Please include a thorough description of the problem
54 with code and data examples if at all possible.
55  
56 =head2 Reporting Bugs
57  
58 Report bugs to the Bioperl bug tracking system to help us keep track
59 the bugs and their resolution. Bug reports can be submitted via the
60 web:
61  
62 https://github.com/bioperl/bioperl-live/issues
63  
64 =head1 AUTHORS - Benjamin Berman
65  
66 Bbased on the Bio::SeqIO modules by Ewan Birney and others
67 Email: benb@fruitfly.berkeley.edu
68  
69 =head1 APPENDIX
70  
71 The rest of the documentation details each of the object
72 methods. Internal methods are usually preceded with an
73 underscore.
74  
75 =cut
76  
77 # Let the code begin...
78  
79 package Bio::AlignIO::meme;
80 2 $Bio::AlignIO::meme::VERSION = '1.7.8';
81 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 2 ▶use Bio::LocatableSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 2 ▶use base qw(Bio::AlignIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 # Constants
87 2 my $MEME_VERS_ERR =
88 "MEME output file must be generated by version 3.0 or higher";
89 2 my $MEME_NO_HEADER_ERR =
90 "MEME output file contains no header line (ex: MEME version 3.0)";
91 2 my $HTML_VERS_ERR = "MEME output file must be generated with the -text option";
92  
93 =head2 next_aln
94  
95 Title : next_aln
96 Usage : $aln = $stream->next_aln()
97 Function: returns the next alignment in the stream
98 Returns : Bio::SimpleAlign object with the score() set to the evalue of the
99 motif.
100 Args : NONE
101  
102 =cut
103  
104 3 ▶sub next_aln {
Subroutine next_aln: called CC=19 SCAR=30.4
Pod documented
105 3 my ($self) = @_;
106 3 my $aln = Bio::SimpleAlign->new( -source => 'meme' );
107 3 my $line;
108 3 my $good_align_sec = 0;
109 3 my $in_align_sec = 0;
110 3 my $evalue;
111 3 ▶ while ( !$good_align_sec && defined( $line = $self->_readline() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $good_align_sec and defined($line = $self->_readline)) 510 3 513
Condition66%2/3
not $good_align_sec and defined($line = $self->_readline)
!ll&&!rl&&r
30510
MC/DC50%1/2
not $good_align_sec and defined($line = $self->_readline)
not $good_align_sec defined($line = $self->_readline)
Truth table66%2/3
not(A) and B
A= not $good_align_secB= defined($line = $self->_readline)
ABresult
0X0
100
111
112 510 ▶ if ( !$in_align_sec ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $in_align_sec) { } 436 74 510
elsif ($line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+ \S+\s+[.A-Z\-]*\s+([A-Z\-]+)\s+ ([.A-Z\-]*)/xi or $line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+ \S+\s+\.\s+([A-Z\-]+)/xi) { } 59 15 74
elsif ($line =~ /^\-/ or $line =~ /Sequence name/) { } 12 3 15
elsif ($line =~ /^\s*$/) { } 3 0 3
113  
114 # Check for the meme header
115 436 ▶ if ( $line =~ /^\s*MEME\s+version\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*MEME\s+version\s+(\S+)/) 3 433 436
116 3 $self->{'meme_vers'} = $1;
117 3 my ($vers) = $self->{'meme_vers'} =~ /^(\d)/;
118 3 ▶ $self->throw($MEME_VERS_ERR) unless ( $vers >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless $vers >= 3 0 3 3
119 3 $self->{'seen_header'} = 1;
120 }
121  
122 # Check if they've output the HTML version
123 436 ▶ if ( $line =~ /\<TITLE\>/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\<TITLE\>/i) 0 436 436
124 0 $self->throw($HTML_VERS_ERR);
125 }
126  
127 # Grab the evalue
128 436 ▶ if ( $line =~ /MOTIF\s+\d+\s+width.+E-value = (\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /MOTIF\s+\d+\s+width.+E-value = (\S+)/) 3 433 436
129 $self->throw($MEME_NO_HEADER_ERR)
130 3 ▶ unless ( $self->{'seen_header'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"seen_header"} 0 3 3
131 3 $evalue = $1;
132 }
133  
134 # Check if we're going into an alignment section
135 436 ▶ if ( $line =~ /sites sorted by position/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /sites sorted by position/) 3 433 436
136 $self->throw($MEME_NO_HEADER_ERR)
137 3 ▶ unless ( $self->{'seen_header'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"seen_header"} 0 3 3
138 3 $in_align_sec = 1;
139 }
140 }
141 # The first regexp is for version 3, the second is for version 4
142 ▶ elsif ( $line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+
Condition66%2/3
$line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+ \S+\s+[.A-Z\-]*\s+([A-Z\-]+)\s+ ([.A-Z\-]*)/xi or $line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+ \S+\s+\.\s+([A-Z\-]+)/xi
l!l&&r!l&&!r
59015
MC/DC50%1/2
$line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+ \S+\s+[.A-Z\-]*\s+([A-Z\-]+)\s+ ([.A-Z\-]*)/xi or $line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+ \S+\s+\.\s+([A-Z\-]+)/xi
$line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+ \S+\s+[.A-Z\-]*\s+([A-Z\-]+)\s+ ([.A-Z\-]*)/xi $line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+ \S+\s+\.\s+([A-Z\-]+)/xi
Truth table66%2/3
A or B
A= $line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+ \S+\s+[.A-Z\-]*\s+([A-Z\-]+)\s+ ([.A-Z\-]*)/xiB= $line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+ \S+\s+\.\s+([A-Z\-]+)/xi
ABresult
1X1
011
000
143 \S+\s+[.A-Z\-]*\s+([A-Z\-]+)\s+
144 ([.A-Z\-]*)/xi
145 ||
146 $line =~ /^(\S+)\s+([+-]?)\s+(\d+)\s+
147 \S+\s+\.\s+([A-Z\-]+)/xi
148 )
149 {
150 # Got a sequence line
151 59 my $seq_name = $1;
152 59 ▶ my $strand = ( $2 eq '-' ) ? -1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$2 eq '-' ? : 1 58 59
153 59 my $start_pos = $3;
154 59 my $central = uc($4);
155  
156 # my $p_val = $4;
157 # my $left_flank = uc($5);
158 # my $right_flank = uc($7);
159  
160 # Info about the flanking sequence
161 # my $start_len = ($strand > 0) ? length($left_flank) :
162 # length($right_flank);
163 # my $end_len = ($strand > 0) ? length($right_flank) :
164 # length($left_flank);
165  
166 # Make the sequence. Meme gives the start coordinate at the left
167 # hand side of the motif relative to the INPUT sequence.
168 59 my $end_pos = $start_pos + length($central) - 1;
169 59 my $seq = Bio::LocatableSeq->new(
170 -seq => $central,
171 -display_id => $seq_name,
172 -start => $start_pos,
173 -end => $end_pos,
174 -strand => $strand,
175 -alphabet => $self->alphabet,
176 );
177  
178 # Add the sequence motif to the alignment
179 59 $aln->add_seq($seq);
180 }
181 ▶ elsif ( ( $line =~ /^\-/ ) || ( $line =~ /Sequence name/ ) ) {
Condition100%3/3
$line =~ /^\-/ or $line =~ /Sequence name/
l!l&&r!l&&!r
933
MC/DC100%2/2
$line =~ /^\-/ or $line =~ /Sequence name/
$line =~ /^\-/ $line =~ /Sequence name/
Truth table100%3/3
A or B
A= $line =~ /^\-/B= $line =~ /Sequence name/
ABresult
1X1
011
000
182  
183 # These are acceptable things to be in the site section
184 }
185 elsif ( $line =~ /^\s*$/ ) {
186  
187 # This ends the site section
188 3 $in_align_sec = 0;
189 3 $good_align_sec = 1;
190 }
191 else {
192 0 $self->warn("Unrecognized format:\n$line");
193 0 return;
194 }
195 }
196  
197 # Signal an error if we didn't find a header section
198 3 ▶ $self->throw($MEME_NO_HEADER_ERR) unless ( $self->{'seen_header'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"seen_header"} 0 3 3
199  
200 3 ▶ if ($good_align_sec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($good_align_sec) 3 0 3
201 3 $aln->score($evalue);
202 3 return $aln;
203 }
204  
205 0 return;
206 }
207  
208 =head2 write_aln
209  
210 Title : write_aln
211 Usage : $stream->write_aln(@aln)
212 Function: Not implemented
213 Returns : 1 for success and 0 for error
214 Args : Bio::SimpleAlign object
215  
216 =cut
217  
218 0 ▶sub write_aln {
Subroutine write_aln: not called CC=1 SCAR=6.9
Pod documented
219 0 my ( $self, @aln ) = @_;
220 0 $self->throw_not_implemented();
221 }
222  
223 # ----------------------------------------
224 # - Private methods
225 # ----------------------------------------
226  
227 3 ▶sub _initialize {
Subroutine _initialize: called CC=1 SCAR=0.0
228 3 my ( $self, @args ) = @_;
229  
230 # Call into our base version
231 3 $self->SUPER::_initialize(@args);
232  
233 # Then initialize our data variables
234 3 $self->{'seen_header'} = 0;
235 }
236  
237 2 1;
« Bio/SearchIO/erpin.pm ↑ Summary Bio/DB/Registry.pm »