lib/InSilicoSpectro/Databanks/DBEntry.pm

filter: Statementstmt 72.1% 119 / 165 Branchbran 59.4% 44 / 74 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 82.3% 14 / 17 Podpod 100% 11 / 11 totaltotal 70.3% 192 / 273 CC 48 SCAR 35.7
CC
48
Cov
68%
printHtml
156.0
readFasta
14.4
seqType
12.0
CRAP 35.6
« lib/InSilicoSpectro/Databanks/DBEntryUniprot.pm ↑ Summary script/fasta-decoy.pl »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package InSilicoSpectro::Databanks::DBEntry;
4 4 require Exporter;
5 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 InSilico::Databanks::DBEntry - fasta databank entry + header's annotated info
10  
11 =head1 SYNOPSIS
12  
13  
14 =head1 DESCRIPTION
15  
16 describes an databnk entry (header + sequence)
17  
18 =head1 FUNCTIONS
19  
20  
21 =head1 METHODS
22  
23  
24 =head3 my $dbe=InSilico::Databanks::DBEntry->new([\%h]);
25  
26 =head2 Accessors/Setters
27  
28 =head3 $dbe->AC([val])
29  
30 get/set accession code
31  
32 =head3 $dbe->ID([val])
33  
34 get/set accession ID
35  
36 =head3 $dbe->dbName([val])
37  
38 [GS]et databank name
39  
40 =head3 $dbe->taxoID([val])
41  
42 [GS]et taxonomy if (typically NCBI taxid
43  
44 =head3 $dbe->description([val])
45  
46 =head3 $dbe->sequence([val])
47  
48 Get/Set AC, ID, ...
49  
50 =head3 $dbe->seqType(["AA"|"DNA"])
51  
52 Get or set the sequence type
53  
54 =head3 $dbe->annotatedModRes(string|[[pos1, mod1], [pos2, mod2]]);
55  
56 get or set annotated PTM from a string (e.g. (1|ACET_nterm)(2|ACET_nterm)(185|PHOS)) or an array. All previously set TPM are removed
57  
58 =head3 $dbe->add_annotatedModRes(pos, modkey)
59  
60 add an annotated PTM
61  
62 =head3 $dbe->clear_annotatedModRes()
63  
64 remove all annotated modres
65  
66 =head3 $dbe->variants(string|[[pos1, seq1a, seq1b], [pos2, seq2a, seq2b]]);
67  
68 get or set variant a string (e.g. ("(9|F|Y)(30|D|N)(41|A|G)(43|Q|R)") or an array. All previously set TPM are removed
69  
70 =head3 $dbe->add_variant(pos, seqa, seqb)
71  
72 add a VARIANT, replacing seqa by seqb (often just one aminoacid) at pos
73  
74 =head3 $dbe->clear_variants()
75  
76 remove all Variants
77  
78 =head2 I/O
79  
80 =head3 $dbe->readFasta($fastacontent);
81  
82 read info from fasta contents (fitrs line with '>' and info + remaining is sequence.
83  
84 =head3 $dbe->printFasta();
85  
86 print the entry under fasta format (use SelectSaver or whatever select method to redirect towards a file descriptor);
87  
88 =head3 $dbe->printHtml();
89  
90 Print the entry under a html format.
91  
92 =head1 EXAMPLES
93  
94  
95 =head1 SEE ALSO
96  
97 =head1 COPYRIGHT
98  
99 Copyright (C) 2004-2005 Geneva Bioinformatics www.genebio.com
100  
101 This library is free software; you can redistribute it and/or
102 modify it under the terms of the GNU Lesser General Public
103 License as published by the Free Software Foundation; either
104 version 2.1 of the License, or (at your option) any later version.
105  
106 This library is distributed in the hope that it will be useful,
107 but WITHOUT ANY WARRANTY; without even the implied warranty of
108 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
109 Lesser General Public License for more details.
110  
111 You should have received a copy of the GNU Lesser General Public
112 License along with this library; if not, write to the Free Software
113 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
114  
115 =head1 AUTHORS
116  
117 Alexandre Masselot, www.genebio.com
118  
119 =cut
120  
121 4 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 {
123 4 ▶ use Object::InsideOut;
Subroutine BEGIN: called CC=1 SCAR=0.0
124  
125 4 my @AC :Field(Accessor => 'AC' );
126 4 my @ID :Field(Accessor => 'ID' );
127 4 my @ACorig :Field(Accessor => 'ACorig' );
128 4 my @dbName :Field(Accessor => 'dbName' );
129 4 my @taxoID :Field(Accessor => 'taxoID' );
130 4 my @__sequence :Field(Accessor => '__sequence', permission=>'Private');
131 4 my @description :Field(Accessor => 'description' );
132 4 my @ncbiTaxid :Field(Accessor => 'ncbiTaxid' );
133 4 my @annotatedModRes :Field(Accessor => '__annotatedModRes', Type=>'List', permission=>'Private');
134 4 my @variants :Field(Accessor => '__variants', Type=>'List', permission=>'Private');
135 4 my @PI :Field(Accessor => 'PI' );
136 4 my @mass :Field(Accessor => 'mass' );
137  
138 4 my %init_args :InitArgs = (
139 AC=>'AC',
140 COPY=>qr/^copy$/i,
141 );
142 4 ▶ sub _init :Init{
Subroutine _init: called CC=4 SCAR=13.9
143 4 my ($self, $h) = @_;
144 4 $self->__annotatedModRes([]);
145 4 $self->__variants([]);
146 4 ▶ if($h->{COPY}){
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{'COPY'}) { } 2 2 4
147 2 my $src=$h->{COPY};
148 2 foreach(qw(AC ID ACorig __sequence description ncbiTaxid __annotatedModRes __variants)){
149 16 $self->$_($src->$_());
150 }
151 }else{
152 2 foreach (keys %$h) {
153 0 $self->$_($h->{$_});
154 }
155 }
156 4 return $self;
157 4 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
158  
159  
160 22 ▶ sub sequence{
Subroutine sequence: called CC=2 SCAR=6.9
Pod documented
161 22 my ($self, $val)=@_;
162 22 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 8 14 22
163 8 $val=~s/\s+//g;
164 8 $self->__sequence($val);
165 8 return $val;
166 }
167 14 return $self->__sequence;
168 }
169  
170 0 ▶ sub seqType{
Subroutine seqType: not called CC=3 SCAR=24.8
Pod documented
171 0 my ($self, $val)=@_;
172 0 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
173 0 ▶ croak "DBEntry seqtype must be of (AA|DNA)" unless $val=~/^(AA|DNA)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ /^(AA|DNA)$/ 0 0 0
174 0 $self->{seqType}=$val;
175 0 return $val;
176 }
177 0 return $self->{seqType};
178 }
179  
180 13 ▶ sub annotatedModRes{
Subroutine annotatedModRes: called CC=7 SCAR=19.7
Pod documented
181 13 my $self=shift;
182 13 my $set=exists $_[0];
183 13 ▶ if ($set) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set) 1 12 13
184  
185 1 ▶ if ((ref $_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 1 1
186 0 my @tmp=@{$_[0]};
187 0 $self->__annotatedModRes(\@tmp);
188 } else {
189 1 my @tmp;
190 1 my $s=$_[0];
191 1 ▶ while ($s=/\((\d+)\|([^\)]+)\)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s = /\((\d+)\|([^\)]+)\)/g) 3 1 4
192 3 push @tmp, [$1, $2];
193 }
194 1 $self->__annotatedModRes(\@tmp);
195 }
196 1 return;
197 }
198 12 ▶ return undef unless defined $self->__annotatedModRes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->__annotatedModRes 0 12 12
199 12 my @tmp=@{$self->__annotatedModRes};
200 12 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 6 6 12
201 6 return @tmp;
202 } else {
203 6 my $ret;
204 6 foreach (@tmp) {
205 3 $ret.="($_->[0]|$_->[1])";
206 }
207 6 return $ret;
208 }
209 }
210  
211 0 ▶ sub add_annotatedModRes{
Subroutine add_annotatedModRes: not called CC=1 SCAR=6.9
Pod documented
212 0 my ($self, $p, $m)=@_;
213  
214 0 push @{$self->__annotatedModRes}, [$p, $m];
215 }
216  
217  
218 1 ▶ sub clear_annotatedModRes{
Subroutine clear_annotatedModRes: called CC=1 SCAR=0.0
Pod documented
219 1 my $self=shift;
220 1 $self->__annotatedModRes([]);
221 }
222  
223 18 ▶ sub variants{
Subroutine variants: called CC=7 SCAR=20.2
Pod documented
224 18 my $self=shift;
225 18 my $set=exists $_[0];
226 18 ▶ if ($set) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set) 1 17 18
227  
228 1 ▶ if ((ref $_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 1 1
229 0 my @tmp=@{$_[0]};
230 0 $self->__variants(\@tmp);
231 } else {
232 1 my @tmp;
233 1 my $s=$_[0];
234 1 ▶ while ($s=/\((\d+)\|(\w+)\|(\w+)\)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s = /\((\d+)\|(\w+)\|(\w+)\)/g) 0 1 1
235 0 push @tmp, [$1, $2, $3];
236 }
237 1 $self->__variants(\@tmp);
238 }
239 1 return;
240 }
241 17 ▶ return undef unless defined $self->__variants;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->__variants 0 17 17
242 17 my @tmp=@{$self->__variants};
243 17 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 6 11 17
244 6 return @tmp;
245 } else {
246 11 my $ret;
247 11 foreach (@tmp) {
248 52 $ret.="($_->[0]|$_->[1]|$_->[2])";
249 }
250 11 return $ret;
251 }
252 }
253  
254 36 ▶ sub add_variant{
Subroutine add_variant: called CC=1 SCAR=0.0
Pod documented
255 36 my ($self, $p, $s1, $s2)=@_;
256  
257 36 push @{$self->__variants}, [$p, $s1, $s2];
258 }
259  
260  
261 7 ▶ sub clear_variants{
Subroutine clear_variants: called CC=1 SCAR=0.0
Pod documented
262 7 my $self=shift;
263 7 $self->__variants([]);
264 }
265  
266 # I/O
267 1 ▶ sub readFasta{
Subroutine readFasta: called CC=14 SCAR=26.7
Pod documented
268 1 my $self=shift;
269 1 my ($header, $seq)=split /\n/, shift, 2;
270 1 $header=~s/^>//;
271 1 ▶ $header=~s/^(\S+)\s*// or croak "fasta header [$header] does not start with an no empty string for AC";
Branch: 1 branch
BranchTrueFalseTotal
$header =~ s/^(\S+)\s*// or croak("fasta header [$header] does not start with an no empty string for AC") 1 0 1
272 1 my $ac=$1;
273 1 $self->AC($ac);
274 1 foreach (split /\\(?=\w+=)/, $header) {
275 8 my ($key, $val)=split /=/, $_, 2;
276 8 ▶ $val=~s/\s+$// if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 7 1 8
277 8 ▶ next unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 1 7 8
278 7 ▶ if ($key eq 'AC') {
Branch: 8 branches
BranchTrueFalseTotal
if ($key eq 'AC') { } 0 7 7
elsif ($key eq 'ACOR') { } 1 6 7
elsif ($key eq 'ID') { } 1 5 6
elsif ($key eq 'DE') { } 1 4 5
elsif ($key eq 'NCBITAXID') { } 1 3 4
elsif ($key eq 'MODRES') { } 1 2 3
elsif ($key eq 'VARIANT') { } 1 1 2
elsif ($key eq 'LENGTH') { } 1 0 1
279 0 $self->AC($val);
280 } elsif ($key eq 'ACOR') {
281 1 $self->ACorig($val);
282 } elsif ($key eq 'ID') {
283 1 $self->ID($val);
284 } elsif ($key eq 'DE') {
285 1 $self->description($val);
286 } elsif ($key eq 'NCBITAXID') {
287 1 $self->ncbiTaxid($val);
288 } elsif ($key eq 'MODRES') {
289 1 $self->annotatedModRes($val);
290 } elsif ($key eq 'VARIANT') {
291 1 $self->variants($val);
292 } elsif ($key eq 'LENGTH') {
293 } else {
294 0 carp "DBEntry::readFasta no function handler for fasta head [$key]";
295 }
296 }
297 1 ▶ $self->description($header) unless $self->description;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->description 0 1 1
298 1 $seq=~s/\s+//g;
299 1 $self->sequence($seq);
300 }
301  
302 6 ▶ sub printFasta{
Subroutine printFasta: called CC=6 SCAR=18.0
Pod documented
303 6 my $self=shift;
304 6 ▶ print ">".$self->AC()." \\ID=".($self->ID|| '')." \\MODRES=".($self->annotatedModRes() ||'');
Condition75%3/4
$self->ID || ''
l!l
60
$self->annotatedModRes || ''
l!l
15
MC/DC0%0/1
$self->ID || ''
$self->ID
MC/DC100%1/1
$self->annotatedModRes || ''
$self->annotatedModRes
Truth table50%1/2
A
A= $self->ID
Aresult
11
00
Truth table100%2/2
A
A= $self->annotatedModRes
Aresult
11
00
305 6 ▶ print " \\VARIANT=".$self->variants if $self->variants;
Branch: 1 branch
BranchTrueFalseTotal
if $self->variants 5 1 6
306 6 ▶ print " \\ACOR=".$self->ACorig if $self->ACorig;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ACorig 5 1 6
307 6 ▶ print " \\NCBITAXID=".$self->ncbiTaxid if $self->ncbiTaxid;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ncbiTaxid 6 0 6
308 6 print " \\DE=".$self->description."\n";
309 6 my $seq=$self->sequence();
310 6 $seq=~s/(.{60})(?=.)/$1\n/g;
311 #$seq=~s/(.{10})(?=.)/$1 /g;
312  
313 6 print $seq."\n";
314 }
315  
316 0 ▶ sub printHtml{
Subroutine printHtml: not called CC=12 SCAR=50.5
Pod documented
317 0 my $self=shift;
318 0 print "<h3>".$self->AC."</h3>\n";
319 0 print "
320 <table border=1 cellspacing=0>
321 <tr><td><b>AC</b></td><td>".$self->AC."</td></tr>
322 <tr><td><b>ID</b></td><td>".$self->ID."</td></tr>
323 ";
324 0 ▶ print " <tr><td><b>original AC</b></td><td>".$self->ACorig."</td></tr>\n" if $self->ACorig;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ACorig 0 0 0
325 0 print " <tr><td><b>description</b></td><td>".$self->description."</td></tr>
326 </table>
327 ";
328 0 my @seq=split //, $self->sequence();
329 0 my @annot;
330 0 ▶ if ($self->annotatedModRes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->annotatedModRes) 0 0 0
331 0 my @tmp=$self->annotatedModRes;
332 0 foreach (@tmp) {
333 0 my ($p, $mr)=($_->[0]-1, $_->[1]);
334 0 ▶ $annot[$p].="</br>\n" if $annot[$p];
Branch: 1 branch
BranchTrueFalseTotal
if $annot[$p] 0 0 0
335 0 $annot[$p].="MOD_RES $mr";
336 }
337 }
338 0 ▶ if ($self->variants) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->variants) 0 0 0
339 0 my @tmp=$self->variants;
340 0 foreach (@tmp) {
341 0 my ($p, $s, $u)=($_->[0]-1, $_->[1], $_->[2]);
342 0 ▶ $annot[$p].="</br>" if $annot[$p];
Branch: 1 branch
BranchTrueFalseTotal
if $annot[$p] 0 0 0
343 0 $annot[$p].="VARIANT $s -> $u";
344 }
345 }
346 0 print "<div class='sequence'>\n";
347 0 foreach (0..$#seq) {
348 0 ▶ print " " unless $_%10;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ % 10 0 0 0
349 0 ▶ print "</br>\n" unless $_%60;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ % 60 0 0 0
350 0 ▶ if ($annot[$_]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($annot[$_]) { } 0 0 0
351 0 print "<b><a onmouseover=\"return escape('$annot[$_]')\">$seq[$_]</a></b>";
352 } else {
353 0 print $seq[$_];
354 }
355 }
356 0 print "</div>\n";
357 }
358 }
359  
360 4 return 1;
« lib/InSilicoSpectro/Databanks/DBEntryUniprot.pm ↑ Summary script/fasta-decoy.pl »