Bio/Matrix/PSM/IO/transfac.pm

filter: Statementstmt 74.4% 102 / 137 Branchbran 55.1% 32 / 58 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 92.3% 12 / 13 Podpod 100% 2 / 2 totaltotal 69.7% 157 / 225 CC 34 SCAR 32.7
CC
34
Cov
69%
_parse_ref
90.0
next_psm
19.4
_make_matrix
6.1
CRAP 26.3
« Bio/Root/Test.pm ↑ Summary Bio/Ontology/OntologyStore.pm »
1 #---------------------------------------------------------
2  
3 =head1 NAME
4  
5 Bio::Matrix::PSM::IO::transfac - PSM transfac parser
6  
7 =head1 SYNOPSIS
8  
9 See Bio::Matrix::PSM::IO for documentation
10  
11 =head1 DESCRIPTION
12  
13 #
14  
15 =head1 FEEDBACK
16  
17 =head2 Mailing Lists
18  
19 User feedback is an integral part of the evolution of this and other
20 Bioperl modules. Send your comments and suggestions preferably to one
21 of the Bioperl mailing lists. Your participation is much appreciated.
22  
23 bioperl-l@bioperl.org - General discussion
24 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
25  
26 =head2 Support
27  
28 Please direct usage questions or support issues to the mailing list:
29  
30 I<bioperl-l@bioperl.org>
31  
32 rather than to the module maintainer directly. Many experienced and
33 reponsive experts will be able look at the problem and quickly
34 address it. Please include a thorough description of the problem
35 with code and data examples if at all possible.
36  
37 =head2 Reporting Bugs
38  
39 Report bugs to the Bioperl bug tracking system to help us keep track
40 the bugs and their resolution. Bug reports can be submitted via the
41 web:
42  
43 https://github.com/bioperl/bioperl-live/issues
44  
45 =head1 AUTHOR - Stefan Kirov
46  
47 Email skirov@utk.edu
48  
49 =head1 APPENDIX
50  
51 =cut
52  
53  
54 # Let the code begin...
55 package Bio::Matrix::PSM::IO::transfac;
56 2 $Bio::Matrix::PSM::IO::transfac::VERSION = '1.7.8';
57 2 ▶use Bio::Matrix::PSM::Psm;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 2 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 2 ▶use Bio::Annotation::Reference;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 2 ▶use Bio::Annotation::Comment;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 2 ▶use Bio::Annotation::DBLink;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 2 ▶use base qw(Bio::Matrix::PSM::PsmHeader Bio::Matrix::PSM::IO);
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 =head2 new
67  
68 Title : new
69 Usage : my $psmIO = Bio::Matrix::PSM::IO->new(-format=>'transfac',
70 -file=>$file);
71 Function: Associates a file with the appropriate parser
72 Throws :
73 Example :
74 Args :
75 Returns : "Bio::Matrix::PSM::$format"->new(@args);
76  
77 =cut
78  
79 1 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
80 1 my ($class,@args)=@_;
81 1 my $line;
82 1 my $self = $class->SUPER::new(@args);
83 1 my ($file)=$self->_rearrange(['FILE'], @args);
84 1 ▶ $self->_initialize_io(@args) || warn "Did you intend to use STDIN?"; #Read only for now
Branch: 1 branch
BranchTrueFalseTotal
$self->_initialize_io(@args) or warn "Did you intend to use STDIN?" 1 0 1
85 #Remove header
86 1 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
($line =~ m[^//] or not defined $line) or do { do { $line = $self->_readline; chomp $line; push @{$$self{"unstructured"};}, $line if length $line > 2 } } 1 2 3
Condition66%2/3
$line =~ m[^//] or not defined $line
l!l&&r!l&&!r
102
MC/DC50%1/2
$line =~ m[^//] or not defined $line
$line =~ m[^//] not defined $line
Truth table66%2/3
A or not(B)
A= $line =~ m[^//]B= not defined $line
ABresult
1X1
011
000
87 3 $line=$self->_readline;
88 3 chomp $line;
89 3 ▶ push @{$self->{unstructured}},$line if (length($line)>2); } until ($line =~ m{^//}) || (!defined($line)); #Unstructured header
Branch: 1 branch
BranchTrueFalseTotal
if length $line > 2 1 2 3
90 1 $self->_initialize;
91 1 return $self;
92 }
93  
94  
95 =head2 next_psm
96  
97 Title : next_psm
98 Usage : my $psm=$psmIO->next_psm();
99 Function: Reads the next PSM from the input file, associated with this object
100 Throws : Upon finding a line, defining the matrix, where one or more positions
101 are not defined, see _make_matrix
102 Returns : Bio::Matrix::PSM::Psm object
103 Args : none
104  
105 =cut
106  
107 1 ▶sub next_psm {
Subroutine next_psm: called CC=17 SCAR=29.7
Pod documented
108 1 my $self=shift;
109 1 my $line;
110 1 ▶ return if ($self->{end});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"end"} 0 1 1
111 1 my (@a,@c,@g,@t, $id, $tr1, @refs,$accn, $bf, $sites);
112 1 my $i=0;
113 1 ▶ while (defined( $line=$self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 28 0 28
114 28 chomp($line);
115 28 ▶ if ($line=~/^\d{2}/) { #Begining of the frequency data
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\d{2}/) 12 16 28
116 12 ($a[$i],$c[$i],$g[$i],$t[$i])=_parse_matrix($line);
117 12 $i++;
118 }
119 28 ▶ ($tr1,$accn)=split(/\s{2}/,$line) if ($line=~/^AC\s/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^AC\s/ 1 27 28
120 28 ▶ ($tr1,$bf)=split(/\s{2}/,$line) if ($line=~/^BF\s/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^BF\s/ 1 27 28
121 28 ▶ ($tr1,$id)=split(/\s{2}/,$line) if ($line=~/^ID\s/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^ID\s/ 1 27 28
122 28 ▶ last if (($line=~/^XX/) && ($i>0));
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^XX/ and $i > 0 1 27 28
Condition100%3/3
$line =~ /^XX/ and $i > 0
!ll&&!rl&&r
2161
MC/DC100%2/2
$line =~ /^XX/ and $i > 0
$line =~ /^XX/ $i > 0
Truth table100%3/3
A and B
A= $line =~ /^XX/B= $i > 0
ABresult
0X0
100
111
123 }
124 1 ▶ if (!(defined($id) && defined($accn))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id and defined $accn) 0 1 1
Condition33%1/3
defined $id and defined $accn
!ll&&!rl&&r
001
MC/DC0%0/2
defined $id and defined $accn
defined $id defined $accn
Truth table33%1/3
A and B
A= defined $idB= defined $accn
ABresult
0X0
100
111
125 0 $self->{end}=1;
126 0 return;
127 }
128 1 ▶ while (defined( $line=$self->_readline)) { #How many sites?
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 5 0 5
129 5 ▶ if ($line=~/^BA\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^BA\s/) 1 4 5
130 1 my ($tr1,$ba)=split(/\s{2}/,$line);
131 1 ($sites)=split(/\s/,$ba);
132 }
133 5 ▶ if ($line=~/^RN/) { #Adding a reference as Bio::Annotation object (self)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^RN/) 0 5 5
134 # not interested in RN line itself, since has only transfac-specific
135 # reference id? - no push back of line
136 0 my $ref=_parse_ref($self);
137 0 push @refs,$ref
138 }
139 5 ▶ last if ($line=~m{^//});
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ m[^//] 1 4 5
140 }
141 # We have the frequencies, let's create a SiteMatrix object
142 1 my %matrix = &_make_matrix($self,\@a,\@c,\@g,\@t,$id, $accn);
143 1 ▶ $matrix{-sites}=$sites if ($sites);
Branch: 1 branch
BranchTrueFalseTotal
if $sites 1 0 1
144 1 $matrix{-width}=@a;
145 1 my $psm=Bio::Matrix::PSM::Psm->new(%matrix);
146 0 foreach my $ref (@refs) { $psm->add_Annotation('reference',$ref); }
147 1 return $psm;
148 }
149  
150 =head2 _parseMatrix
151  
152 Title : _parseMatrix
153 Usage :
154 Function: Parses a line
155 Throws :
156 Example : Internal stuff
157 Returns : array (frequencies for A,C,G,T in this order).
158 Args : string
159  
160 =cut
161  
162 12 ▶sub _parse_matrix {
Subroutine _parse_matrix: called CC=1 SCAR=0.0
163 12 my $line=shift;
164 12 $line=~s/\s+/,/g;
165 12 my ($tr,$a,$c,$g,$t)=split(/,/,$line);
166 12 return $a,$c,$g,$t;
167 }
168  
169  
170 =head2 _make_matrix
171  
172 Title : _make_matrix
173 Usage :
174 Function:
175 Throws : If a position is undefined, for example if you have line like this
176 in the file you are parsing: 08 4,7,,9
177 Example : Internal stuff
178 Returns :
179 Args :
180  
181 =cut
182  
183 1 ▶sub _make_matrix {
Subroutine _make_matrix: called CC=6 SCAR=18.1
184 1 my ($a, $c, $g, $t, @fa, @fc,@fg, @ft, @a,@c,@g,@t);
185 1 my $ave=0;
186 1 my ($self,$cA,$cC,$cG,$cT, $id, $accn)= @_;
187  
188 1 ▶ for (my $i=0; $i < @{$cA};$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$cA;}) 12 1 13
189 #No value can be undefined -throw an exception, since setting to 0 probably would be wrong
190 #If this happens it would indicate most probably that the file, being parsed is in a different format
191 12 ▶ map { $self->throw('Parsing error, a position is not defined') unless defined(${$_}[$i]) } ($cA, $cG, $cC, $cT);
Branch: 1 branch
BranchTrueFalseTotal
unless defined do { $_ }->[$i] 0 48 48
192
193 12 ▶ if ( (${$cA}[$i] + ${$cC}[$i] +
Branch: 1 branch
BranchTrueFalseTotal
if (do { $cA }->[$i] + do { $cC }->[$i] + do { $cG }->[$i] + do { $cT }->[$i] == 0) { } 0 12 12
194 12 ${$cG}[$i] + ${$cT}[$i] ) ==0 ) {
195 0 push @a,$ave;
196 0 push @c,$ave;
197 0 push @g,$ave;
198 0 push @t,$ave;
199 }
200 else {
201 12 push @a,${$cA}[$i];
202 12 push @c,${$cC}[$i];
203 12 push @g,${$cG}[$i];
204 12 push @t,${$cT}[$i];
205 12 $ave = ((${$cA}[$i]+${$cC}[$i]+
206 12 ${$cG}[$i]+${$cT}[$i]) / 4 +$ave)/2;
207 }
208 }
209  
210 1 ▶ for (my $i=0; $i<@a;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @a) 12 1 13
211 12 my $zero=($a[$i]+$c[$i]+$g[$i]+$t[$i]);
212 12 ▶ next if ($zero==0);
Branch: 1 branch
BranchTrueFalseTotal
if $zero == 0 0 12 12
213 12 push @fa, $a[$i];
214 12 push @fc, $c[$i];
215 12 push @fg, $g[$i];
216 12 push @ft, $t[$i];
217 }
218 1 return (-pA=>\@fa,-pC=>\@fc,-pG=>\@fg,-pT=>\@ft, -id=>$id, -accession_number=>$accn)
219 }
220  
221 0 ▶sub _parse_ref {
Subroutine _parse_ref: not called CC=9 SCAR=45.0
222 0 my $self=shift;
223 0 my ($authors,$title,$loc,@refs,$tr,$db,$dbid);
224 0 ▶ while (my $refline=$self->_readline) { #Poorely designed, should go through an array with fields
Branch: 1 branch
BranchTrueFalseTotal
if (my $refline = $self->_readline) 0 0 0
225 0 chomp $refline;
226 0 my ($field,$arg)=split(/\s+/,$refline,2);
227 0 ▶ last if ($field=~/XX/);
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /XX/ 0 0 0
228 0 $field.=' ';
229 REF: {
230 0 ▶ if ($field=~/RX/) { #DB Reference
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /RX/) 0 0 0
231 0 $refline=~s/[;\.]//g;
232 0 ($tr, $db, $dbid)=split(/\s+/,$refline);
233 0 last REF;
234 }
235 0 ▶ if ($field=~/RT/) { #Title
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /RT/) 0 0 0
236 0 $title .= $arg;
237 0 last REF;
238 }
239 0 ▶ if ($field=~/RA/) { #Author
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /RA/) 0 0 0
240 0 $authors .= $arg;
241 0 last REF;
242 }
243 0 ▶ if ($field=~/RL/) { #Journal
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /RL/) 0 0 0
244 0 $loc .= $arg;
245 0 last REF;
246 }
247 }
248 }
249 0 my $reference=Bio::Annotation::Reference->new(-authors=>$authors, -title=>$title,
250 -location=>$loc);
251 0 ▶ if ($db eq 'MEDLINE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($db eq 'MEDLINE') { } 0 0 0
elsif ($dbid) { } 0 0 0
252 # does it ever equal medline?
253 0 $reference->medline($dbid);
254 }
255 elsif ($dbid) {
256 0 $reference->pubmed($dbid);
257 }
258 0 return $reference;
259 }
260  
261 1 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
262 1 my $self=shift;
263 1 $self->close;
264 }
265  
266 2 1;
267
« Bio/Root/Test.pm ↑ Summary Bio/Ontology/OntologyStore.pm »