blib/lib/Chem/Structure/Parser.pm

filter: Statementstmt 98.0% 1920 / 1958 Branchbran 88.7% 982 / 1106 Conditioncond 77.6% 591 / 761 MC/DCmcdc 61.4% 266 / 433 Subroutinesub 98.2% 111 / 113 Podpod 100% 22 / 22 totaltotal 88.6% 3892 / 4393 CC 982 SCAR 35.3
CC
982
Cov
91%
_pdb_header
106.5
_parse_meta
96.1
_cif_header
65.4
CRAP 34.2
↑ Summary Parser.xs »
1 #!/usr/bin/env perl
2 # ABSTRACT: Read a molecular structure file into a hash of hashes, sequences and all, using XS for the coordinate section
3 24 require 5.010001;
4 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 package Chem::Structure::Parser;
6 24 our $VERSION = '0.0401';
7 24 require XSLoader;
8 24 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 # No `use autodie': it would ask every installer for a prerequisite in order to
10 # check five calls. They are checked by hand instead, in autodie's own words,
11 # and anything fallible added here must be checked the same way.
12 24 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 24 ▶use Scalar::Util 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 24 XSLoader::load('Chem::Structure::Parser', $VERSION);
15  
16 24 our @EXPORT_OK = qw(
17 structure_info structure_info_string
18 structure_atoms structure_residues structure_ligands structure_sequences
19 chain_sequence structure_summary is_single_ion
20 structure_features structure_sasa structure_pi_stacking structure_disulfides
21 structure_base_pairs structure_base_stacks structure_contacts structure_hbonds
22 structure_dssp structure_interface structure_rmsd convert
23 aa3to1 aa1to3 res1 res_type formats h
24 );
25 24 our @EXPORT = @EXPORT_OK;
26  
27 #
28 # Formats
29 #
30 # The module is named for structures, not for PDB, because the file format is
31 # an accident of history and the thing the caller wants -- chains, residues,
32 # a single-letter sequence, coordinates -- is the same whichever format it
33 # arrived in. So there is one way in, structure_info(), which works out the
34 # format and hands the file to a reader; the returned hash of hashes has the
35 # same shape no matter which reader filled it.
36 #
37 # Adding a format means writing a reader that returns that shape and adding
38 # it here. Nothing else in the module, and nothing in calling code, needs to
39 # know that a second format exists.
40 #
41 24 my %READER = (
42 pdb => \&_read_pdb,
43 mmcif => \&_read_cif,
44 );
45  
46 # The XS parser for each format. Both fill the same hash -- the same column
47 # arrays, the same residue boundaries, the same counts -- so everything below
48 # this table is written once and reads either format. What differs is the
49 # header: a PDB file hands its header back as raw lines by record name, an
50 # mmCIF file as tags and loops, and that is the one place the two part company.
51 24 my %XS = (
52 pdb => { file => \&_parse_file, string => \&_parse_string },
53 mmcif => { file => \&_parse_cif_file, string => \&_parse_cif_string },
54 );
55  
56 # formats a reader is not written for yet, kept here so that handing one over
57 # gets a straight answer rather than a puzzling parse of the wrong thing
58 24 my %NOT_YET = (
59 mol2 => 'Tripos MOL2 (.mol2)',
60 sdf => 'MDL SDF/MOL (.sdf, .mol)',
61 );
62  
63 # The names a format goes by, for format => . A caller writing
64 # format => 'cif' means the format whose files are called .cif, and dying at
65 # them over the difference between that and 'mmcif' would be pedantry: there is
66 # only one thing they could have meant. The name a format is filed under is
67 # still the one it reports back as, so $info->{format} has one spelling.
68 24 my %ALIAS = (
69 cif => 'mmcif', pdbx => 'mmcif', mmcif => 'mmcif',
70 ent => 'pdb', pdb => 'pdb',
71 );
72  
73 # Options
74 #
75 # Anything not listed here is a typo, and a typo that is quietly ignored is a
76 # silent wrong answer later on -- pass 'hydrogen' for 'hydrogens' and you get
77 # a structure with the hydrogens still in it and no hint of why.
78 #
79 24 my %DEFAULT = (
80 model => 1, # which MODEL to build chains from; 'all' for every one
81 altloc => 'first', # 'first' or 'highest' occupancy, when an atom has alternates
82 hydrogens => 1, # keep hydrogen/deuterium atoms
83 waters => 1, # keep waters
84 hetatm => 1, # keep HETATM records (ligands, ions, modified residues)
85 atoms => 1, # build the per-atom hashes; 0 stops at the residue level
86 features => 1, # compute the physical properties; needs atoms => 1
87 meta => 1, # parse the header records
88 anisou => 0, # keep ANISOU lines (they double the size of the file)
89 chains => undef, # arrayref: read only these chains
90 format => undef, # override format detection
91 dssp => 0, # also put the secondary structure roll-up at $info->{dssp}
92 partners => undef, # the two sides of the interface feature; undef = worked out
93 );
94  
95 # The numeric fields of a REMARK are free text, and some of them are not
96 # numbers: 5m04 writes its pH as "5.4.-5.8", a range with a stray dot in it,
97 # and [\d.]+ happily matches "5.4." -- which Perl will then refuse to add.
98 # This matches a number and stops, so a malformed field gives up the part of
99 # itself that is one, and a field of NULL gives up nothing.
100 24 my $NUM = qr/[0-9]*\.?[0-9]+/;
101  
102 # Public entry points
103  
104 # The views structure_info($file, $view) will hand back on their own, and how
105 # each is taken out of the structure. A second argument that is a plain string
106 # is a request for one of these rather than the first half of an option pair,
107 # and the two forms cannot be confused: a file and an even number of arguments
108 # after it is always an odd-sized option list, which is an error.
109 my %VIEW = (
110 53 ▶ dssp => sub { $_[0]{dssp} },
Subroutine __ANON__: called CC=1 SCAR=0.0
111 24 torsions => \&_torsion_view,
112 );
113 # the options a view turns on for itself. The dssp view is dssp => 1, which
114 # computes the secondary structure on its own when the rest of the features are
115 # off; the torsions have no such option, and need the features.
116 24 my %VIEW_OPT = (dssp => { dssp => 1 });
117 # other spellings of a view, which the error message does not list
118 24 my %VIEW_ALIAS = (torsion => 'torsions');
119  
120 # _args($who, @args) -- @args, once it is a first argument followed by name =>
121 # value pairs. A list with a stray element in it died where it was unpacked
122 # into a hash, of 'Odd number of elements in hash assignment' under FATAL
123 # warnings, which said neither which function had been called nor what was wrong
124 # with the call.
125 483 ▶sub _args {
Subroutine _args: called CC=3 SCAR=11.0
126 483 my $who = shift;
127 483 ▶ die "$who: the options after the first argument come in name => value pairs, "
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 and not @_ % 2 1 482 483
Condition100%3/3
@_ > 1 and not @_ % 2
!ll&&!rl&&r
3041781
MC/DC100%2/2
@_ > 1 and not @_ % 2
@_ > 1 not @_ % 2
Truth table100%3/3
A and not(B)
A= @_ > 1B= not @_ % 2
ABresult
0X0
100
111
128 . 'and these are an odd number' if @_ > 1 && !(@_ % 2);
129 482 return @_;
130 }
131  
132 # _view_args($who, $first, @args) -- the view a call names, if it names one, and
133 # its options as a hash reference with the ones the view needs added. $first
134 # is how the message spells the first argument, '$file' or '$text'. A second
135 # argument that is a plain string with an even number after it is a view rather
136 # than the first half of an option pair; an odd number after anything else is a
137 # list that is not pairs.
138 1225 ▶sub _view_args {
Subroutine _view_args: called CC=9 SCAR=22.0
139 1225 my ($who, $first, @args) = @_;
140 1225 my $view;
141 1225 ▶ if (@args % 2 == 1 && defined $args[0] && !ref $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args % 2 == 1 and defined $args[0] and not ref $args[0]) 83 1142 1225
Condition83%5/6
@args % 2 == 1 and defined $args[0] and not ref $args[0]
!ll&&!rl&&r
1141183
@args % 2 == 1 and defined $args[0]
!ll&&!rl&&r
1141084
MC/DC66%2/3
@args % 2 == 1 and defined $args[0] and not ref $args[0]
@args % 2 == 1 defined $args[0] not ref $args[0]
Truth table75%3/4
A and B and not(C)
A= @args % 2 == 1B= defined $args[0]C= not ref $args[0]
ABCresult
0XX0
10X0
1100
1111
142 83 $view = shift @args;
143 83 ▶ $view = $VIEW_ALIAS{$view} if exists $VIEW_ALIAS{$view};
Branch: 1 branch
BranchTrueFalseTotal
if exists $VIEW_ALIAS{$view} 1 82 83
144 die "$who: '$view' is not a view; the ones there are: "
145 . join(', ', sort keys %VIEW) . "\nOr did you mean an option? "
146 . "Those are named pairs: $who($first, $view => 1)"
147 83 ▶ unless exists $VIEW{$view};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $VIEW{$view} 8 75 83
148 }
149 1217 ▶ die "$who: the options come in name => value pairs, and these are an odd number"
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 1 1216 1217
150 if @args % 2;
151 1216 ▶ return ($view, { @args, (defined $view && $VIEW_OPT{$view} ? %{ $VIEW_OPT{$view} } : ()) });
Branch: 1 branch
BranchTrueFalseTotal
defined $view && $VIEW_OPT{$view} ? : 55 1161 1216
Condition100%3/3
defined $view and $VIEW_OPT{$view}
!ll&&!rl&&r
11412055
MC/DC100%2/2
defined $view and $VIEW_OPT{$view}
defined $view $VIEW_OPT{$view}
Truth table100%3/3
A and B
A= defined $viewB= $VIEW_OPT{$view}
ABresult
0X0
100
111
152 }
153  
154 # _view_of($info, $view, $o, $who) -- the structure, or the one view of it asked for
155 1167 ▶sub _view_of {
Subroutine _view_of: called CC=5 SCAR=16.1
156 1167 my ($info, $view, $o, $who) = @_;
157 1167 ▶ return $info unless defined $view;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $view 1094 73 1167
158 # a view asked for on its own is the whole answer, and asking for one of a
159 # file read with features => 0 or atoms => 0 is a mistake worth saying out
160 # loud rather than an empty hash that reads as a structure with none
161 die "$who: '$view' needs the features, and this file was read with "
162 . (!$o->{atoms} ? 'atoms => 0' : 'features => 0')
163 73 ▶ unless $info->{features} || $VIEW_OPT{$view};
Branch: 2 branches
BranchTrueFalseTotal
unless $info->{"features"} or $VIEW_OPT{$view} 1 72 73
!$o->{'atoms'} ? : 0 1 1
Condition100%3/3
$info->{"features"} or $VIEW_OPT{$view}
l!l&&r!l&&!r
7021
MC/DC100%2/2
$info->{"features"} or $VIEW_OPT{$view}
$info->{"features"} $VIEW_OPT{$view}
Truth table100%3/3
A or B
A= $info->{"features"}B= $VIEW_OPT{$view}
ABresult
1X1
011
000
164 72 return $VIEW{$view}->($info);
165 }
166  
167 # structure_info($file, %opt) -- read a structure file into a hash of hashes.
168 # structure_info($file, $view, %opt) -- one view of it, and nothing else.
169 844 ▶sub structure_info {
Subroutine structure_info: called CC=9 SCAR=22.0
Pod documented
170 844 my $file = shift;
171 844 my ($view, $optref) = _view_args('structure_info', '$file', @_);
172 837 my %opt = %$optref;
173 837 ▶ die 'structure_info: no file name given' unless defined $file && length $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file and length $file 3 834 837
Condition100%3/3
defined $file and length $file
!ll&&!rl&&r
21834
MC/DC100%2/2
defined $file and length $file
defined $file length $file
Truth table100%3/3
A and B
A= defined $fileB= length $file
ABresult
0X0
100
111
174 834 ▶ die "structure_info: '$file' does not exist" unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 2 832 834
175 832 ▶ die "structure_info: '$file' is a directory" if -d $file;
Branch: 1 branch
BranchTrueFalseTotal
if -d $file 1 831 832
176 # The format is worked out from the name with a .Z taken off, but a .Z is
177 # never unpacked, so it was read as the raw bytes of a compressed file and
178 # came back as a structure with no atoms in it. IO::Compress has no reader
179 # for compress(1)'s LZW.
180 831 ▶ die "structure_info: '$file' is compressed with compress, which this module "
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.z\z/i 3 828 831
181 . 'does not unpack; gzip or bzip2 it, or unpack it first'
182 if $file =~ /\.z\z/i;
183 828 my $o = _options(\%opt, 'structure_info');
184 814 ▶ my $fmt = defined $o->{format} ? _alias($o->{format}) : _detect_format($file);
Branch: 1 branch
BranchTrueFalseTotal
defined $o->{'format'} ? : 15 799 814
185 my $reader = $READER{$fmt}
186 or die "structure_info: cannot read '$file': "
187 814 ▶ . (exists $NOT_YET{$fmt}
Branch: 2 branches
BranchTrueFalseTotal
my $reader = $READER{$fmt} or die "structure_info: cannot read '${file}': " . (exists $NOT_YET{$fmt} ? "$NOT_YET{$fmt} is not implemented yet; formats read today: " . join(", ", sort(keys %READER)) : "unrecognized format '${fmt}'; formats read today: " . join(", ", sort(keys %READER))) 806 8 814
exists $NOT_YET{$fmt} ? : 5 3 8
188 ? "$NOT_YET{$fmt} is not implemented yet; formats read today: " . join(', ', sort keys %READER)
189 : "unrecognized format '$fmt'; formats read today: " . join(', ', sort keys %READER));
190 806 return _view_of($reader->($file, $o), $view, $o, 'structure_info');
191 }
192  
193 # _torsion_view($info) -- each chain's torsions hash, keyed by chain id, with
194 # the chain's residue_order beside the angles: the arrays are parallel to it,
195 # and the view throws away the rest of the structure that would have said which
196 # residue an element came from. It is the chain's own array, not a copy,
197 # because nothing is left holding the structure to share it with. A chain with no angle at all -- a
198 # water chain, a lone ligand -- is left out, as a key no residue has is left
199 # out of the torsions hash itself.
200 19 ▶sub _torsion_view {
Subroutine _torsion_view: called CC=4 SCAR=13.9
201 19 my ($info) = @_;
202 19 my %out;
203 19 for my $id (@{ $info->{chain_order} }) {
204 33 my $c = $info->{chains}{$id};
205 33 ▶ next unless $c->{torsions} && %{ $c->{torsions} };
Branch: 1 branch
BranchTrueFalseTotal
unless $c->{"torsions"} and %{$c->{"torsions"};} 8 25 33
Condition66%2/3
$c->{"torsions"} and %{$c->{"torsions"};}
!ll&&!rl&&r
0825
MC/DC50%1/2
$c->{"torsions"} and %{$c->{"torsions"};}
$c->{"torsions"} %{$c->{"torsions"};}
Truth table66%2/3
A and B
A= $c->{"torsions"}B= %{$c->{"torsions"};}
ABresult
0X0
100
111
206 25 $out{$id} = { %{ $c->{torsions} }, residue_order => $c->{residue_order} };
207 }
208 19 return \%out;
209 }
210  
211 # structure_info_string($text, %opt) -- the same, from a string already in hand.
212 # structure_info_string($text, $view, %opt) -- and one view of it, the same way.
213 381 ▶sub structure_info_string {
Subroutine structure_info_string: called CC=6 SCAR=17.9
Pod documented
214 381 my $text = shift;
215 381 my ($view, $opt) = _view_args('structure_info_string', '$text', @_);
216 379 ▶ die 'structure_info_string: text is undefined' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 1 378 379
217 378 my $o = _options($opt, 'structure_info_string');
218 377 ▶ my $fmt = defined $o->{format} ? _alias($o->{format}) : _sniff_format($text);
Branch: 1 branch
BranchTrueFalseTotal
defined $o->{'format'} ? : 163 214 377
219 # a string has no name to go on, and the caller has already said this is a
220 # structure, so text that looks like nothing in particular is read as PDB.
221 # Text that looks like something else still gets a straight answer.
222 377 ▶ $fmt = 'pdb' if $fmt eq 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
if $fmt eq "unknown" 3 374 377
223 die "structure_info_string: cannot read this text: "
224 . (exists $NOT_YET{$fmt}
225 ? "$NOT_YET{$fmt} is not implemented yet"
226 : "no reader for format '$fmt'")
227 377 ▶ unless $READER{$fmt};
Branch: 2 branches
BranchTrueFalseTotal
unless $READER{$fmt} 1 376 377
exists $NOT_YET{$fmt} ? : 1 0 1
228 376 my $parse = $XS{$fmt}{string};
229 376 my $p = $parse->($text, _xs_options($o));
230 376 return _view_of(_build_structure(_retry_model($p, $o, $parse, $text), $o, undef),
231 $view, $o, 'structure_info_string');
232 }
233  
234 # formats() -- the formats that can be read, in list context; in scalar
235 # context a hashref of every format known, including the unwritten ones.
236 4 ▶sub formats {
Subroutine formats: called CC=2 SCAR=6.9
Pod documented
237 return wantarray
238 ? (sort keys %READER)
239 4 ▶ : { (map { $_ => 'supported' } keys %READER), (map { $_ => "not implemented: $NOT_YET{$_}" } keys %NOT_YET) };
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 2 4
240 }
241  
242 # convert($in, $out, %opt) -- a structure written out in another format, or in
243 # its own.
244 #
245 # The coordinates go through the XS: the reader for the input's format reads it
246 # as structure_info() would, options and all, and hands each atom it keeps to a
247 # writer for the output's format instead of building it -- see the note at
248 # cv_atom in Parser.xs. The header is read by the Perl that reads it for
249 # structure_info() and written out again from what that makes of it; see
250 # _convert_header().
251 24 my %CONVERT = (
252 from => undef, # the input's format; worked out as structure_info() works it out
253 to => undef, # the output's; worked out from the output file's name
254 model => 'all', # which MODEL to write; 'all' for every one
255 hydrogens => 1, # write hydrogen/deuterium atoms
256 waters => 1, # write waters
257 hetatm => 1, # write HETATM records
258 chains => undef, # arrayref: write only these chains
259 anisou => 1, # write ANISOU records, or the _atom_site_anisotrop table
260 header => 1, # write the header facts convert() carries; 0 for the coordinates alone
261 );
262  
263 # The header records and categories convert() reads, by input format: the ones
264 # the facts it writes come out of, and nothing else. The parse keeps only
265 # these, so that an entry's residue-length tables -- _pdbx_poly_seq_scheme,
266 # _pdbx_nonpoly_scheme, a ribosome's REMARK 465 -- are not built into SVs to be
267 # thrown away. A PDB record is named as it is written, an mmCIF category in
268 # lower case, which is how each parse looks them up.
269 24 my %CONVERT_KEEP = (
270 pdb => [ qw(HEADER TITLE COMPND KEYWDS EXPDTA REMARK SEQRES HELIX SHEET SSBOND LINK
271 CRYST1) ],
272 mmcif => [ qw(_entry _struct _struct_keywords _pdbx_database_status _exptl _refine
273 _reflns _em_3d_reconstruction _cell _symmetry _entity _entity_poly
274 _entity_poly_seq _struct_conf _struct_sheet _struct_sheet_order
275 _struct_sheet_range _struct_conn) ],
276 );
277  
278 # the compressors for an output named as compressed, as %UNPACK has the
279 # decompressors for an input; both come with IO::Compress
280 my %PACK = (
281 gz => { class => 'IO::Compress::Gzip', verb => 'gzip', what => 'gzipped',
282 0 ▶ error => sub { no warnings 'once'; $IO::Compress::Gzip::GzipError } },
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
283 bz2 => { class => 'IO::Compress::Bzip2', verb => 'bzip2', what => 'compressed with bzip2',
284 0 ▶ error => sub { no warnings 'once'; $IO::Compress::Bzip2::Bzip2Error } },
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
285 24 );
286  
287 443 ▶sub convert {
Subroutine convert: called CC=51 SCAR=39.3
Pod documented
288 443 my ($in, $out, @args) = @_;
289 443 ▶ die 'convert: no structure given; the first argument is a file name or a reference to its text'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in and ref $in || length $in 2 441 443
Condition100%6/6
defined $in and ref $in || length $in
!ll&&!rl&&r
11441
ref $in or length $in
l!l&&r!l&&!r
1153261
MC/DC100%3/3
defined $in and ref $in || length $in
defined $in ref $in length $in
Truth table100%4/4
A and B or C
A= defined $inB= ref $inC= length $in
ABCresult
0XX0
1000
11X1
1011
290 unless defined $in && (ref $in || length $in);
291 441 ▶ die 'convert: nowhere to write it; the second argument is a file name, a file handle '
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out and ref $out || length $out 2 439 441
Condition100%6/6
defined $out and ref $out || length $out
!ll&&!rl&&r
11439
ref $out or length $out
l!l&&r!l&&!r
362771
MC/DC100%3/3
defined $out and ref $out || length $out
defined $out ref $out length $out
Truth table100%4/4
A and B or C
A= defined $outB= ref $outC= length $out
ABCresult
0XX0
1000
11X1
1011
292 . 'or a reference to a scalar'
293 unless defined $out && (ref $out || length $out);
294 439 ▶ die 'convert: the options after the output come in name => value pairs, and these are an odd number'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 1 438 439
295 if @args % 2;
296 438 my %opt = @args;
297 438 for my $k (sort keys %opt) {
298 die "convert: unknown option '$k'; known options are: " . join(', ', sort keys %CONVERT)
299 450 ▶ unless exists $CONVERT{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $CONVERT{$k} 1 449 450
300 }
301 437 _no_undef(\%opt, 'convert', \%CONVERT);
302 436 my %o = (%CONVERT, %opt);
303 436 _model_and_chains(\%o, 'convert');
304  
305 # what to read
306 432 my $what = 'this text';
307 432 ▶ if (ref $in) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in) { } 115 317 432
308 115 ▶ die 'convert: the structure is a file name or a reference to its text, not a '
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::reftype($in) || "") eq "SCALAR" 1 114 115
Condition40%2/5
builtin::reftype($in) || ''
l!l
1150
builtin::reftype($in) || ref $in
l!l&&r!l&&!r
100
MC/DC0%0/1
builtin::reftype($in) || ''
builtin::reftype($in)
MC/DC0%0/2
builtin::reftype($in) || ref $in
builtin::reftype($in) ref $in
Truth table50%1/2
A
A= builtin::reftype($in)
Aresult
11
00
Truth table33%1/3
A || B
A= builtin::reftype($in)B= ref $in
ABresult
1X1
011
000
309 . (reftype($in) || ref $in) . ' reference'
310 unless (reftype($in) || '') eq 'SCALAR';
311 114 ▶ die 'convert: the text to convert is undefined' unless defined $$in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$in 1 113 114
312 } else {
313 317 ▶ die "convert: '$in' does not exist" unless -e $in;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $in 1 316 317
314 316 ▶ die "convert: '$in' is a directory" if -d $in;
Branch: 1 branch
BranchTrueFalseTotal
if -d $in 1 315 316
315 315 ▶ die "convert: '$in' is compressed with compress, which this module does not unpack; "
Branch: 1 branch
BranchTrueFalseTotal
if $in =~ /\.z\z/i 1 314 315
316 . 'gzip or bzip2 it, or unpack it first'
317 if $in =~ /\.z\z/i;
318 314 $what = "'$in'";
319 }
320 my $from = defined $o{from} ? _alias($o{from})
321 427 ▶ : ref $in ? _sniff_format($$in)
Branch: 2 branches
BranchTrueFalseTotal
defined $o{'from'} ? : 3 424 427
ref $in ? : 113 311 424
322 : _detect_format($in);
323 # text that looks like nothing in particular is PDB, as structure_info_string() reads it
324 427 ▶ $from = 'pdb' if ref $in && !defined $o{from} && $from eq 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
if ref $in and not defined $o{"from"} and $from eq "unknown" 2 425 427
Condition83%5/6
ref $in and not defined $o{"from"} and $from eq "unknown"
!ll&&!rl&&r
3141112
ref $in and not defined $o{"from"}
!ll&&!rl&&r
3140113
MC/DC66%2/3
ref $in and not defined $o{"from"} and $from eq "unknown"
ref $in not defined $o{"from"} $from eq "unknown"
Truth table75%3/4
A and not(B) and C
A= ref $inB= not defined $o{"from"}C= $from eq "unknown"
ABCresult
0XX0
10X0
1100
1111
325 die "convert: cannot read $what: "
326 . (exists $NOT_YET{$from} ? "$NOT_YET{$from} is not implemented yet"
327 : "unrecognized format '$from'")
328 . '; formats read today: ' . join(', ', sort keys %READER)
329 427 ▶ unless $READER{$from};
Branch: 2 branches
BranchTrueFalseTotal
unless $READER{$from} 2 425 427
exists $NOT_YET{$from} ? : 1 1 2
330  
331 # what to write
332 425 ▶ my $kind = ref $out ? (reftype($out) || '') : 'FILE';
Branch: 1 branch
BranchTrueFalseTotal
ref $out ? : 348 77 425
Condition50%1/2
builtin::reftype($out) or ""
l!l
3480
MC/DC0%0/1
builtin::reftype($out) or ""
builtin::reftype($out)
Truth table50%1/2
A
A= builtin::reftype($out)
Aresult
11
00
333 425 ▶ die "convert: the output is a file name, a file handle or a reference to a scalar, not a $kind reference"
Branch: 1 branch
BranchTrueFalseTotal
unless $kind =~ /\A(?:FILE|GLOB|IO|SCALAR)\z/ 1 424 425
334 unless $kind =~ /\A(?:FILE|GLOB|IO|SCALAR)\z/;
335 424 ▶ my $to = defined $o{to} ? _alias($o{to}) : ref $out ? undef : _format_of_name($out);
Branch: 2 branches
BranchTrueFalseTotal
defined $o{'to'} ? : 347 77 424
ref $out ? : 1 76 77
336 424 ▶ die "convert: say which format to write, with to => 'pdb' or to => 'mmcif': "
Branch: 2 branches
BranchTrueFalseTotal
unless defined $to 2 422 424
ref $out ? : 1 1 2
337 . (ref $out ? 'a handle or a scalar has no name to tell it by'
338 : "'$out' has no suffix that names one")
339 unless defined $to;
340 422 ▶ die "convert: cannot write '$to'; formats written: mmcif, pdb"
Branch: 1 branch
BranchTrueFalseTotal
unless $to eq "pdb" or $to eq "mmcif" 2 420 422
Condition100%3/3
$to eq "pdb" or $to eq "mmcif"
l!l&&r!l&&!r
2202002
MC/DC100%2/2
$to eq "pdb" or $to eq "mmcif"
$to eq "pdb" $to eq "mmcif"
Truth table100%3/3
A or B
A= $to eq "pdb"B= $to eq "mmcif"
ABresult
1X1
011
000
341 unless $to eq 'pdb' || $to eq 'mmcif';
342  
343 my $x = {
344 model => ($o{model} eq 'all' ? -1 : $o{model}),
345 hydrogens => $o{hydrogens},
346 waters => $o{waters},
347 hetatm => $o{hetatm},
348 anisou => $o{anisou},
349 meta => $o{header} ? 1 : 0,
350 6342 ▶ keep => { map { ($_ => 1) } @{ $CONVERT_KEEP{$from} } },
Branch: 1 branch
BranchTrueFalseTotal
defined $o{'chains'} ? : 21 399 420
351 420 ▶ (defined $o{chains} ? (chains => { map { ($_ => 1) } @{ $o{chains} } }) : ()),
Branch: 2 branches
BranchTrueFalseTotal
$o{'model'} eq 'all' ? : 414 6 420
$o{'header'} ? : 418 2 420
352 };
353 420 ▶ my @how = ($from eq 'mmcif' ? 1 : 0, $to eq 'pdb' ? 1 : 0, $x);
Branch: 2 branches
BranchTrueFalseTotal
$from eq 'mmcif' ? : 217 203 420
$to eq 'pdb' ? : 220 200 420
354 420 ▶ my $p = ref $in ? _convert_string($$in, @how)
Branch: 2 branches
BranchTrueFalseTotal
ref $in ? : 113 307 420
_compression($in) ? : 1 306 307
355 : _compression($in) ? _convert_string(_slurp_maybe_compressed($in, undef), @how)
356 : _convert_file($in, @how);
357  
358 # A file with atoms in it and options that left none of them is a mistake,
359 # and an empty file written for it would be the silent kind. The model
360 # numbers are the likely reason, so they are named.
361 408 my $had = $p->{n_atom_records} + $p->{n_hetatm_records};
362 die "convert: the options leave none of the $had atoms of $what to write"
363 2 . (@{ $p->{model_numbers} } ? '; its models are ' . join(', ', @{ $p->{model_numbers} }) : '')
364 408 ▶ if $had && !$p->{n_written};
Branch: 2 branches
BranchTrueFalseTotal
if $had and not $p->{"n_written"} 2 406 408
@{$p->{'model_numbers'};} ? : 1 1 2
Condition100%3/3
$had and not $p->{"n_written"}
!ll&&!rl&&r
163902
MC/DC100%2/2
$had and not $p->{"n_written"}
$had not $p->{"n_written"}
Truth table100%3/3
A and not(B)
A= $hadB= not $p->{"n_written"}
ABresult
0X0
100
111
365  
366 406 my @notes;
367 406 ▶ my $h = $o{header} ? _convert_header($p, $from) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$o{'header'} ? : 404 2 406
368 406 my @pieces;
369 406 ▶ if ($to eq 'pdb') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq 'pdb') { } 206 200 406
370 206 ▶ my $head = $h ? _pdb_header($h, $p->{chains_written}, \@notes) : '';
Branch: 1 branch
BranchTrueFalseTotal
$h ? : 205 1 206
371 206 my $end = sprintf "%-80s\n", 'END';
372 206 push @pieces, \$head, \$p->{coordinates}, \$end;
373 } else {
374 200 ▶ my $id = _cif_block_name($h, ref $in ? undef : $in);
Branch: 1 branch
BranchTrueFalseTotal
ref $in ? : 54 146 200
375 200 ▶ my $head = "data_$id\n#\n" . ($h ? _cif_header($h, $id, $p->{chains_written}, \@notes) : '');
Branch: 1 branch
BranchTrueFalseTotal
$h ? : 199 1 200
376 200 my $hash = "#\n";
377 200 push @pieces, \$head;
378 200 ▶ push @pieces, \$p->{coordinates}, \$hash if length $p->{coordinates};
Branch: 1 branch
BranchTrueFalseTotal
if length $p->{"coordinates"} 192 8 200
379 200 ▶ push @pieces, \$p->{anisotrop}, \$hash if length $p->{anisotrop};
Branch: 1 branch
BranchTrueFalseTotal
if length $p->{"anisotrop"} 4 196 200
380 }
381 406 _convert_write($out, \@pieces);
382 return {
383 from => $from,
384 to => $to,
385 atoms => $p->{n_written},
386 anisou => $p->{n_anisou_written},
387 models => $p->{models_written},
388 rounded => $p->{n_rounded},
389 404 notes => \@notes,
390 };
391 }
392  
393 # _convert_write($out, \@pieces) -- the converted text, a piece at a time, to
394 # wherever $out says: a file, compressed when its name says so, a handle, or a
395 # scalar. The pieces are written one after another rather than joined, because
396 # the coordinates are most of the file and joining them would hold the whole
397 # output twice. Each write is checked, as autodie would have checked it.
398 406 ▶sub _convert_write {
Subroutine _convert_write: called CC=16 SCAR=28.0
399 406 my ($out, $pieces) = @_;
400 406 ▶ my $kind = ref $out ? reftype($out) : 'FILE';
Branch: 1 branch
BranchTrueFalseTotal
ref $out ? : 332 74 406
401 406 ▶ if ($kind eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "SCALAR") 329 77 406
402 329 $$out = join '', map { $$_ } @$pieces;
403 329 return;
404 }
405 77 ▶ if ($kind ne 'FILE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind ne "FILE") 3 74 77
406 3 for my $s (@$pieces) {
407 7 ▶ print {$out} $$s or die "Can't write to the output handle: '$!'";
Branch: 1 branch
BranchTrueFalseTotal
print {$out;} $$s or die "Can't write to the output handle: '$!'" 6 1 7
408 }
409 2 return;
410 }
411 74 ▶ if (my $c = _compression($out)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = _compression($out)) 2 72 74
412 2 my $u = $PACK{$c};
413 2 (my $pm = "$u->{class}.pm") =~ s{::}{/}g;
414 2 ▶ eval { require $pm; 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $pm; 1 } } or die qq[convert: '${out}' is to be $u->{"what"} but $u->{"class"} is not installed: $@] 2 0 2
415 or die "convert: '$out' is to be $u->{what} but $u->{class} is not installed: $@";
416 my $z = $u->{class}->new($out)
417 2 ▶ or die "convert: cannot $u->{verb} '$out': " . $u->{error}->();
Branch: 1 branch
BranchTrueFalseTotal
my $z = $u->{"class"}->new($out) or die qq[convert: cannot $u->{"verb"} '${out}': ] . $u->{"error"}->() 2 0 2
418 2 for my $s (@$pieces) {
419 6 ▶ $z->print($$s) or die "Can't write to '$out': '" . $z->error . "'";
Branch: 1 branch
BranchTrueFalseTotal
$z->print($$s) or die "Can't write to '${out}': '" . $z->error . q['] 6 0 6
420 }
421 2 ▶ $z->close or die "Can't close '$out': '" . $z->error . "'";
Branch: 1 branch
BranchTrueFalseTotal
$z->close or die "Can't close '${out}': '" . $z->error . q['] 2 0 2
422 2 return;
423 }
424 72 ▶ open my $fh, '>:raw', $out or die "Can't open '$out' with mode '>:raw': '$!'";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:raw", $out or die "Can't open '${out}' with mode '>:raw': '$!'" 71 1 72
425 71 for my $s (@$pieces) {
426 209 ▶ print {$fh} $$s or die "Can't write to '$out': '$!'";
Branch: 1 branch
BranchTrueFalseTotal
print {$fh;} $$s or die "Can't write to '${out}': '$!'" 209 0 209
427 }
428 71 ▶ close $fh or die "Can't close '$out': '$!'";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Can't close '${out}': '$!'" 71 0 71
429 71 return;
430 }
431  
432 #
433 # convert()'s header
434 #
435 # The header is read by the code structure_info() reads it with, into the keys
436 # the README's table lists, and written back out from those. So the two
437 # formats' spellings of a fact meet in one place -- the key -- and a fact goes
438 # across only where both readers already file it there:
439 #
440 # header (id, classification, date) HEADER _entry, _struct_keywords,
441 # _pdbx_database_status
442 # title TITLE _struct
443 # keywords KEYWDS _struct_keywords
444 # experiment EXPDTA _exptl
445 # resolution REMARK 2 _refine, or _em_3d_reconstruction
446 # compound (molecule and chains) COMPND _entity, _entity_poly
447 # seqres SEQRES _entity_poly_seq
448 # helix, sheet HELIX _struct_conf
449 # SHEET _struct_sheet, _struct_sheet_order,
450 # _struct_sheet_range
451 # ssbond, link SSBOND _struct_conn
452 # LINK
453 # cryst1 CRYST1 _cell, _symmetry
454 #
455 # The rest of a header -- the REMARKs, the citation, the sources, the heterogen
456 # names, the sites -- stays behind, and the documentation says so. A fact the
457 # target has no room for -- an id longer than HEADER's four columns, a chain id
458 # SEQRES cannot hold -- is left out and named in the notes convert() returns,
459 # rather than ending the conversion as an atom that will not fit does: the
460 # coordinates are the structure, and a header fact is one line about it.
461  
462 # the header the parse kept, as structure_info() makes sense of it
463 404 ▶sub _convert_header {
Subroutine _convert_header: called CC=3 SCAR=11.0
464 404 my ($p, $from) = @_;
465 404 my %h;
466 404 ▶ if ($from eq 'mmcif') { _parse_cif_meta(\%h, $p) }
Branch: 1 branch
BranchTrueFalseTotal
if ($from eq 'mmcif') { } 204 200 404
467 200 ▶ else { _parse_meta(\%h, $p->{meta} || {}) }
Condition50%1/2
$p->{'meta'} || {}
l!l
2000
MC/DC0%0/1
$p->{'meta'} || {}
$p->{'meta'}
Truth table50%1/2
A
A= $p->{'meta'}
Aresult
11
00
468 404 return \%h;
469 }
470  
471 24 my @MONTH = qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC);
472 24 my %MONTH = map { ($MONTH[$_] => $_ + 1) } 0 .. 11;
473  
474 # A deposition date as each format writes it: 01-JAN-20 in HEADER, 2020-01-01
475 # in mmCIF. The two-digit year is the twentieth century from 70 on: the
476 # archive's first entries were deposited in the 1970s, and a year 2070 entry
477 # is not a thing a PDB file can be asked to hold. A date in neither shape is
478 # not a date either can be written as, and is left out.
479 211 ▶sub _pdb_date {
Subroutine _pdb_date: called CC=7 SCAR=19.5
480 211 my ($d) = @_;
481 211 ▶ return '' unless defined $d;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d 147 64 211
482 64 ▶ return uc $d if $d =~ /\A\d\d-[A-Za-z]{3}-\d\d\z/ && $MONTH{ uc substr($d, 3, 3) };
Branch: 1 branch
BranchTrueFalseTotal
if $d =~ /\A\d\d-[A-Za-z]{3}-\d\d\z/ and $MONTH{uc substr($d, 3, 3)} 30 34 64
Condition66%2/3
$d =~ /\A\d\d-[A-Za-z]{3}-\d\d\z/ and $MONTH{uc substr($d, 3, 3)}
!ll&&!rl&&r
34030
MC/DC50%1/2
$d =~ /\A\d\d-[A-Za-z]{3}-\d\d\z/ and $MONTH{uc substr($d, 3, 3)}
$d =~ /\A\d\d-[A-Za-z]{3}-\d\d\z/ $MONTH{uc substr($d, 3, 3)}
Truth table66%2/3
A and B
A= $d =~ /\A\d\d-[A-Za-z]{3}-\d\d\z/B= $MONTH{uc substr($d, 3, 3)}
ABresult
0X0
100
111
483 34 ▶ return '' unless $d =~ /\A(\d{4})-(\d\d)-(\d\d)\z/ && $2 >= 1 && $2 <= 12;
Branch: 1 branch
BranchTrueFalseTotal
unless $d =~ /\A(\d{4})-(\d\d)-(\d\d)\z/ and $2 >= 1 and $2 <= 12 6 28 34
Condition83%5/6
$d =~ /\A(\d{4})-(\d\d)-(\d\d)\z/ and $2 >= 1 and $2 <= 12
!ll&&!rl&&r
5128
$d =~ /\A(\d{4})-(\d\d)-(\d\d)\z/ and $2 >= 1
!ll&&!rl&&r
5029
MC/DC66%2/3
$d =~ /\A(\d{4})-(\d\d)-(\d\d)\z/ and $2 >= 1 and $2 <= 12
$d =~ /\A(\d{4})-(\d\d)-(\d\d)\z/ $2 >= 1 $2 <= 12
Truth table75%3/4
A and B and C
A= $d =~ /\A(\d{4})-(\d\d)-(\d\d)\z/B= $2 >= 1C= $2 <= 12
ABCresult
0XX0
10X0
1100
1111
484 28 return sprintf '%s-%s-%s', $3, $MONTH[$2 - 1], substr($1, 2);
485 }
486  
487 220 ▶sub _cif_date {
Subroutine _cif_date: called CC=6 SCAR=17.9
488 220 my ($d) = @_;
489 220 ▶ return undef unless defined $d;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d 144 76 220
490 76 ▶ return $d if $d =~ /\A\d{4}-\d\d-\d\d\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $d =~ /\A\d{4}-\d\d-\d\d\z/ 16 60 76
491 60 ▶ return undef unless $d =~ /\A(\d\d)-([A-Za-z]{3})-(\d\d)\z/ && $MONTH{ uc $2 };
Branch: 1 branch
BranchTrueFalseTotal
unless $d =~ /\A(\d\d)-([A-Za-z]{3})-(\d\d)\z/ and $MONTH{uc $2} 8 52 60
Condition66%2/3
$d =~ /\A(\d\d)-([A-Za-z]{3})-(\d\d)\z/ and $MONTH{uc $2}
!ll&&!rl&&r
8052
MC/DC50%1/2
$d =~ /\A(\d\d)-([A-Za-z]{3})-(\d\d)\z/ and $MONTH{uc $2}
$d =~ /\A(\d\d)-([A-Za-z]{3})-(\d\d)\z/ $MONTH{uc $2}
Truth table66%2/3
A and B
A= $d =~ /\A(\d\d)-([A-Za-z]{3})-(\d\d)\z/B= $MONTH{uc $2}
ABresult
0X0
100
111
492 52 ▶ return sprintf '%s%s-%02d-%s', ($3 >= 70 ? '19' : '20'), $3, $MONTH{ uc $2 }, $1;
Branch: 1 branch
BranchTrueFalseTotal
$3 >= 70 ? : 9 43 52
493 }
494  
495 # _rec(@fields) -- one 80-column record, each field an arrayref of (first
496 # column, width, value, 'R' for right-justified), placed by the column numbers
497 # the wwPDB format v3.3 gives them. A value longer than its width would push
498 # every column after it along, so it is a bug in the caller and dies as one;
499 # _too_long() is what the callers ask first.
500 1173 ▶sub _rec {
Subroutine _rec: called CC=5 SCAR=16.1
501 1173 my $l = ' ' x 80;
502 1173 for my $f (@_) {
503 6838 my ($col, $w, $v, $r) = @$f;
504 6838 ▶ $v = '' unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 25 6813 6838
505 6838 ▶ die "convert: internal: '$v' is longer than the $w columns from $col" if length $v > $w;
Branch: 1 branch
BranchTrueFalseTotal
if length $v > $w 0 6838 6838
506 6838 ▶ substr($l, $col - 1, $w) = $r ? sprintf('%*s', $w, $v) : sprintf('%-*s', $w, $v);
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 3996 2842 6838
507 }
508 1173 return "$l\n";
509 }
510  
511 # the first field of a record that will not fit, said so; undef when they all do
512 276 ▶sub _too_long {
Subroutine _too_long: called CC=6 SCAR=23.5
513 276 for my $f (@_) {
514 2773 my ($col, $w, $v, $r, $name) = @$f;
515 2773 ▶ next unless defined $v && length $v > $w;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and length $v > $w 2773 0 2773
Condition66%2/3
defined $v and length $v > $w
!ll&&!rl&&r
2527480
MC/DC0%0/2
defined $v and length $v > $w
defined $v length $v > $w
Truth table66%2/3
A and B
A= defined $vB= length $v > $w
ABresult
0X0
100
111
516 0 ▶ return "the " . ($name || 'field') . " '$v' is longer than the $w column"
Branch: 1 branch
BranchTrueFalseTotal
$w == 1 ? : 0 0 0
Condition0%0/2
$name || 'field'
l!l
00
MC/DC0%0/1
$name || 'field'
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
517 . ($w == 1 ? '' : 's') . " the record has for it";
518 }
519 276 return undef;
520 }
521  
522 # _wrap($text, $first, $rest) -- free text in lines of $first characters and
523 # then $rest, as _joined() will put it back together: broken at a blank, which
524 # it restores, and never at a blank after a hyphen, which it would not -- a line
525 # that ends in a hyphen is joined to the next with nothing between. A word too
526 # long for a line is broken after a hyphen of its own for the same reason, and
527 # only one with no hyphen in it is cut where _joined() will put a blank; the
528 # second element returned says whether that happened.
529 530 ▶sub _wrap {
Subroutine _wrap: called CC=12 SCAR=24.9
530 530 my ($text, $first, $rest) = @_;
531 530 (my $t = $text) =~ s/\s+/ /g;
532 530 $t =~ s/\A //;
533 530 $t =~ s/ \z//;
534 530 my ($w, $cut_word, @out) = ($first, 0);
535 530 ▶ while (length $t > $w) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $t > $w) 45 530 575
536 45 my $at;
537 45 ▶ for (my $i = $w; $i > 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 545 4 549
538 545 ▶ next unless substr($t, $i, 1) eq ' ' && substr($t, $i - 1, 1) ne '-';
Branch: 1 branch
BranchTrueFalseTotal
unless substr($t, $i, 1) eq " " and substr($t, $i - 1, 1) ne "-" 504 41 545
Condition100%3/3
substr($t, $i, 1) eq " " and substr($t, $i - 1, 1) ne "-"
!ll&&!rl&&r
503141
MC/DC100%2/2
substr($t, $i, 1) eq " " and substr($t, $i - 1, 1) ne "-"
substr($t, $i, 1) eq " " substr($t, $i - 1, 1) ne "-"
Truth table100%3/3
A and B
A= substr($t, $i, 1) eq " "B= substr($t, $i - 1, 1) ne "-"
ABresult
0X0
100
111
539 41 $at = $i;
540 41 last;
541 }
542 45 ▶ if (defined $at) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $at) { } 41 4 45
543 41 push @out, substr($t, 0, $at);
544 41 $t = substr($t, $at + 1);
545 } else {
546 4 my $at_hyphen;
547 4 ▶ for (my $i = $w - 1; $i > 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 145 2 147
548 145 ▶ next unless substr($t, $i, 1) eq '-' && substr($t, $i + 1, 1) ne ' ';
Branch: 1 branch
BranchTrueFalseTotal
unless substr($t, $i, 1) eq "-" and substr($t, $i + 1, 1) ne " " 143 2 145
Condition66%2/3
substr($t, $i, 1) eq "-" and substr($t, $i + 1, 1) ne " "
!ll&&!rl&&r
14302
MC/DC50%1/2
substr($t, $i, 1) eq "-" and substr($t, $i + 1, 1) ne " "
substr($t, $i, 1) eq "-" substr($t, $i + 1, 1) ne " "
Truth table66%2/3
A and B
A= substr($t, $i, 1) eq "-"B= substr($t, $i + 1, 1) ne " "
ABresult
0X0
100
111
549 2 $at_hyphen = $i + 1;
550 2 last;
551 }
552 4 ▶ $cut_word = 1 unless defined $at_hyphen;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $at_hyphen 2 2 4
553 4 ▶ my $cut = defined $at_hyphen ? $at_hyphen : $w;
Branch: 1 branch
BranchTrueFalseTotal
defined $at_hyphen ? : 2 2 4
554 4 push @out, substr($t, 0, $cut);
555 4 $t = substr($t, $cut);
556 }
557 45 $w = $rest;
558 }
559 530 ▶ push @out, $t if length $t;
Branch: 1 branch
BranchTrueFalseTotal
if length $t 530 0 530
560 530 return (\@out, $cut_word);
561 }
562  
563 # _pdb_text($record, \@segments, \@notes) -- a free-text record over as many
564 # lines as it takes: columns 11-80 of the first, and 12-80 of each continuation,
565 # which carries its number in columns 8-10. Each segment starts a line of its
566 # own, which is how COMPND writes one specification to a line.
567 255 ▶sub _pdb_text {
Subroutine _pdb_text: called CC=6 SCAR=17.9
568 255 my ($rec, $segments, $notes) = @_;
569 255 my @out;
570 255 for my $seg (@$segments) {
571 530 ▶ my ($lines, $cut) = _wrap($seg, @out ? 69 : 70, 69);
Branch: 1 branch
BranchTrueFalseTotal
@out ? : 275 255 530
572 530 ▶ push @$notes, "$rec: a word with no blank or hyphen to break at was broken "
Branch: 1 branch
BranchTrueFalseTotal
if $cut 1 529 530
573 . 'across two lines, and will read back with a blank in it'
574 if $cut;
575 530 for my $l (@$lines) {
576 575 ▶ push @out, @out ? _rec([1, 6, $rec], [8, 3, @out + 1, 'R'], [12, 69, $l])
Branch: 1 branch
BranchTrueFalseTotal
@out ? : 320 255 575
577 : _rec([1, 6, $rec], [11, 70, $l]);
578 }
579 }
580 255 return @out;
581 }
582  
583 # a number into a fixed field: to the format's decimals where that is the same
584 # number, as the archive writes it, and as it stands where it is not and fits
585 357 ▶sub _decimals {
Subroutine _decimals: called CC=5 SCAR=21.7
586 357 my ($v, $d, $w) = @_;
587 357 ▶ return '' unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 357 357
588 357 my $f = sprintf "%.${d}f", $v;
589 357 ▶ return $f if $f == $v && length $f <= $w;
Branch: 1 branch
BranchTrueFalseTotal
if $f == $v and length $f <= $w 357 0 357
Condition33%1/3
$f == $v and length $f <= $w
!ll&&!rl&&r
00357
MC/DC0%0/2
$f == $v and length $f <= $w
$f == $v length $f <= $w
Truth table33%1/3
A and B
A= $f == $vB= length $f <= $w
ABresult
0X0
100
111
590 0 ▶ return "$v" if length "$v" <= $w;
Branch: 1 branch
BranchTrueFalseTotal
if length "$v" <= $w 0 0 0
591 0 return $f;
592 }
593  
594 # _pdb_header($h, \@chains, \@notes) -- the header as PDB records, in the order
595 # the format gives them
596 209 ▶sub _pdb_header {
Subroutine _pdb_header: called CC=66 SCAR=46.7
597 209 my ($h, $chains, $notes) = @_;
598 209 my @l;
599 209 ▶ my $hd = $h->{header} || {};
Condition100%2/2
$h->{'header'} || {}
l!l
2054
MC/DC100%1/1
$h->{'header'} || {}
$h->{'header'}
Truth table100%2/2
A
A= $h->{'header'}
Aresult
11
00
600 209 my $cls = _t($hd->{classification});
601 209 my $date = _pdb_date($hd->{deposit_date});
602 209 my $id = _t($hd->{id_code});
603 push @$notes, "HEADER: the deposition date '$hd->{deposit_date}' is not a date, and is left out"
604 209 ▶ if !length $date && length _t($hd->{deposit_date});
Branch: 1 branch
BranchTrueFalseTotal
if not length $date and length _t($hd->{"deposit_date"}) 5 204 209
Condition100%3/3
not length $date and length _t($hd->{"deposit_date"})
!ll&&!rl&&r
571475
MC/DC100%2/2
not length $date and length _t($hd->{"deposit_date"})
not length $date length _t($hd->{"deposit_date"})
Truth table100%3/3
not(A) and B
A= not length $dateB= length _t($hd->{"deposit_date"})
ABresult
0X0
100
111
605 209 ▶ if (length $cls > 40) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $cls > 40) 0 209 209
606 0 push @$notes, "HEADER: the classification '$cls' is longer than its 40 columns, "
607 . 'and is cut to them';
608 0 $cls = substr($cls, 0, 40);
609 }
610 209 ▶ if (length $id > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $id > 4) 0 209 209
611 0 push @$notes, "HEADER: the id '$id' is longer than its four columns, and is left out";
612 0 $id = '';
613 }
614 209 ▶ push @l, _rec([1, 6, 'HEADER'], [11, 40, $cls], [51, 9, $date], [63, 4, $id])
Branch: 1 branch
BranchTrueFalseTotal
if length $cls or length $date or length $id 81 128 209
Condition83%5/6
length $cls or length $date or length $id
l!l&&r!l&&!r
5724128
length $cls or length $date
l!l&&r!l&&!r
570152
MC/DC66%2/3
length $cls or length $date or length $id
length $cls length $date length $id
Truth table75%3/4
A or B or C
A= length $clsB= length $dateC= length $id
ABCresult
1XX1
01X1
0011
0000
615 if length $cls || length $date || length $id;
616 push @l, _pdb_text('TITLE', [ $h->{title} ], $notes)
617 209 ▶ if defined $h->{title} && $h->{title} =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->{"title"} and $h->{"title"} =~ /\S/ 79 130 209
Condition66%2/3
defined $h->{"title"} and $h->{"title"} =~ /\S/
!ll&&!rl&&r
130079
MC/DC50%1/2
defined $h->{"title"} and $h->{"title"} =~ /\S/
defined $h->{"title"} $h->{"title"} =~ /\S/
Truth table66%2/3
A and B
A= defined $h->{"title"}B= $h->{"title"} =~ /\S/
ABresult
0X0
100
111
618  
619 # COMPND: the polymer entities, which are the ones that claim chains
620 209 my @mol;
621 209 ▶ for my $mid (sort { ($a =~ /\A[0-9]+\z/ && $b =~ /\A[0-9]+\z/) ? $a <=> $b : $a cmp $b }
Branch: 1 branch
BranchTrueFalseTotal
$a =~ /\A[0-9]+\z/ && $b =~ /\A[0-9]+\z/ ? : 178 0 178
Condition33%1/3
$a =~ /\A[0-9]+\z/ and $b =~ /\A[0-9]+\z/
!ll&&!rl&&r
00178
MC/DC0%0/2
$a =~ /\A[0-9]+\z/ and $b =~ /\A[0-9]+\z/
$a =~ /\A[0-9]+\z/ $b =~ /\A[0-9]+\z/
Truth table33%1/3
A and B
A= $a =~ /\A[0-9]+\z/B= $b =~ /\A[0-9]+\z/
ABresult
0X0
100
111
622 209 ▶ keys %{ $h->{compound} || {} }) {
Condition100%2/2
$h->{'compound'} || {}
l!l
2054
MC/DC100%1/1
$h->{'compound'} || {}
$h->{'compound'}
Truth table100%2/2
A
A= $h->{'compound'}
Aresult
11
00
623 156 my $c = $h->{compound}{$mid};
624 156 ▶ next unless @{ $c->{chain} || [] } || $c->{free_text};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$c->{"chain"} or [];} or $c->{"free_text"} 61 95 156
Condition100%5/5
@{$c->{"chain"} or [];} or $c->{"free_text"}
l!l&&r!l&&!r
90561
$c->{'chain'} || []
l!l
1515
MC/DC100%2/2
@{$c->{"chain"} or [];} or $c->{"free_text"}
@{$c->{"chain"} or [];} $c->{"free_text"}
MC/DC100%1/1
$c->{'chain'} || []
$c->{'chain'}
Truth table100%3/3
A or B
A= @{$c->{"chain"} or [];}B= $c->{"free_text"}
ABresult
1X1
011
000
Truth table100%2/2
A
A= $c->{'chain'}
Aresult
11
00
625 95 ▶ if ($c->{free_text}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"free_text"}) 5 90 95
626 5 ▶ push @mol, $c->{molecule} if defined $c->{molecule};
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->{"molecule"} 5 0 5
627 5 next;
628 }
629 90 push @mol, "MOL_ID: $mid;";
630 90 ▶ push @mol, "MOLECULE: $c->{molecule};" if defined $c->{molecule} && length $c->{molecule};
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->{"molecule"} and length $c->{"molecule"} 88 2 90
Condition66%2/3
defined $c->{"molecule"} and length $c->{"molecule"}
!ll&&!rl&&r
2088
MC/DC50%1/2
defined $c->{"molecule"} and length $c->{"molecule"}
defined $c->{"molecule"} length $c->{"molecule"}
Truth table66%2/3
A and B
A= defined $c->{"molecule"}B= length $c->{"molecule"}
ABresult
0X0
100
111
631 90 push @mol, 'CHAIN: ' . join(', ', @{ $c->{chain} }) . ';';
632 90 ▶ push @mol, "FRAGMENT: $c->{fragment};" if defined $c->{fragment} && length $c->{fragment};
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->{"fragment"} and length $c->{"fragment"} 31 59 90
Condition66%2/3
defined $c->{"fragment"} and length $c->{"fragment"}
!ll&&!rl&&r
59031
MC/DC50%1/2
defined $c->{"fragment"} and length $c->{"fragment"}
defined $c->{"fragment"} length $c->{"fragment"}
Truth table66%2/3
A and B
A= defined $c->{"fragment"}B= length $c->{"fragment"}
ABresult
0X0
100
111
633 90 ▶ my $ec = defined $c->{ec_number} ? $c->{ec_number} : $c->{ec};
Branch: 1 branch
BranchTrueFalseTotal
defined $c->{'ec_number'} ? : 0 90 90
634 90 ▶ push @mol, "EC: $ec;" if defined $ec && length $ec;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ec and length $ec 31 59 90
Condition66%2/3
defined $ec and length $ec
!ll&&!rl&&r
59031
MC/DC50%1/2
defined $ec and length $ec
defined $ec length $ec
Truth table66%2/3
A and B
A= defined $ecB= length $ec
ABresult
0X0
100
111
635 }
636 209 ▶ push @l, _pdb_text('COMPND', \@mol, $notes) if @mol;
Branch: 1 branch
BranchTrueFalseTotal
if @mol 60 149 209
637 209 ▶ push @l, _pdb_text('KEYWDS', [ join ', ', @{ $h->{keywords} } ], $notes) if @{ $h->{keywords} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$h->{"keywords"} or [];} 41 168 209
Condition100%2/2
$h->{'keywords'} || []
l!l
2054
MC/DC100%1/1
$h->{'keywords'} || []
$h->{'keywords'}
Truth table100%2/2
A
A= $h->{'keywords'}
Aresult
11
00
638 209 ▶ push @l, _pdb_text('EXPDTA', [ join '; ', @{ $h->{experiment} } ], $notes) if @{ $h->{experiment} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$h->{"experiment"} or [];} 75 134 209
Condition100%2/2
$h->{'experiment'} || []
l!l
2054
MC/DC100%1/1
$h->{'experiment'} || []
$h->{'experiment'}
Truth table100%2/2
A
A= $h->{'experiment'}
Aresult
11
00
639 209 ▶ if (defined $h->{resolution}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h->{"resolution"}) 41 168 209
640 push @l, _rec([1, 6, 'REMARK'], [8, 3, 2, 'R']),
641 _rec([1, 6, 'REMARK'], [8, 3, 2, 'R'],
642 41 [12, 69, sprintf('RESOLUTION. %7s ANGSTROMS.', _decimals($h->{resolution}, 2, 7))]);
643 }
644  
645 # SEQRES, the chains in the order the atoms gave them and then the rest
646 209 my %written = map { ($_ => 1) } @$chains;
647 260 my @order = ((grep { $h->{seqres}{$_} } @$chains),
648 209 ▶ (sort grep { !$written{$_} } keys %{ $h->{seqres} || {} }));
Condition100%2/2
$h->{'seqres'} || {}
l!l
2054
MC/DC100%1/1
$h->{'seqres'} || {}
$h->{'seqres'}
Truth table100%2/2
A
A= $h->{'seqres'}
Aresult
11
00
649 209 for my $cid (@order) {
650 109 ▶ my @res = @{ $h->{seqres}{$cid}{residues} || [] };
Condition50%1/2
$h->{'seqres'}{$cid}{'residues'} || []
l!l
1090
MC/DC0%0/1
$h->{'seqres'}{$cid}{'residues'} || []
$h->{'seqres'}{$cid}{'residues'}
Truth table50%1/2
A
A= $h->{'seqres'}{$cid}{'residues'}
Aresult
11
00
651 109 ▶ next unless @res;
Branch: 1 branch
BranchTrueFalseTotal
unless @res 0 109 109
652 109 my ($long) = grep { length $_ > 3 } @res;
653 109 ▶ my $why = length $cid > 1 ? "the chain id '$cid' is longer than the one column SEQRES has for it"
Branch: 3 branches
BranchTrueFalseTotal
length $cid > 1 ? : 0 109 109
defined $long ? : 0 109 109
@res > 9999 ? : 0 109 109
654 : defined $long ? "the residue name '$long' is longer than SEQRES's three columns"
655 : @res > 9999 ? 'its ' . scalar(@res) . ' residues are more than four columns can count'
656 : undef;
657 109 ▶ if ($why) {
Branch: 1 branch
BranchTrueFalseTotal
if ($why) 0 109 109
658 0 push @$notes, "SEQRES: chain '$cid' is left out: $why";
659 0 next;
660 }
661 109 for my $i (0 .. int($#res / 13)) {
662 159 my @f = ([1, 6, 'SEQRES'], [8, 3, $i + 1, 'R'], [12, 1, $cid], [14, 4, scalar @res, 'R']);
663 159 ▶ my $last = 13 * $i + 12 < $#res ? 13 * $i + 12 : $#res;
Branch: 1 branch
BranchTrueFalseTotal
13 * $i + 12 < $#res ? : 50 109 159
664 159 my $k = 0;
665 159 push @f, [20 + 4 * $k++, 3, $_, 'R'] for @res[13 * $i .. $last];
666 159 push @l, _rec(@f);
667 }
668 }
669  
670 # The bond lengths of SSBOND and LINK are Real(5.2), and an mmCIF file
671 # writes pdbx_dist_value to as many places as its program likes: gemmi
672 # 0.7.5 writes 2.0338. A length is rounded to the two the record has, and
673 # the notes say how many were.
674 209 my $rounded = 0;
675 70 ▶ my $len = sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
676 70 my ($v) = @_;
677 70 my $n = _n($v);
678 70 ▶ return _t($v) unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 70 70
679 70 my $f = _decimals($n, 2, 5);
680 70 ▶ $rounded++ if $f != $n;
Branch: 1 branch
BranchTrueFalseTotal
if $f != $n 0 70 70
681 70 return $f;
682 209 };
683  
684 # A helix's id is a label of up to three characters, often its serial
685 # number, and an mmCIF file can call one anything -- gemmi writes H100 for
686 # the hundredth. One that will not fit is given its serial instead, which
687 # keeps the helix, and the notes say so.
688 209 my $n = 0;
689 209 ▶ for my $x (@{ $h->{helix} || [] }) {
Condition100%2/2
$h->{'helix'} || []
l!l
2054
MC/DC100%1/1
$h->{'helix'} || []
$h->{'helix'}
Truth table100%2/2
A
A= $h->{'helix'}
Aresult
11
00
690 65 my $hid = $x->{id};
691 65 $n++;
692 65 ▶ if (defined $hid && length $hid > 3 && $n < 1000) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hid and length $hid > 3 and $n < 1000) 0 65 65
Condition33%2/6
defined $hid and length $hid > 3 and $n < 1000
!ll&&!rl&&r
6500
defined $hid and length $hid > 3
!ll&&!rl&&r
0650
MC/DC0%0/3
defined $hid and length $hid > 3 and $n < 1000
defined $hid length $hid > 3 $n < 1000
Truth table25%1/4
A and B and C
A= defined $hidB= length $hid > 3C= $n < 1000
ABCresult
0XX0
10X0
1100
1111
693 0 push @$notes, "HELIX: the id '$hid' is longer than its three columns, and is written as $n";
694 0 $hid = $n;
695 }
696 my @f = ([1, 6, 'HELIX'], [8, 3, $n, 'R'], [12, 3, $hid, 'R', 'id'],
697 [16, 3, $x->{init_resname}, 'R', 'residue name'], [20, 1, $x->{init_chain}, '', 'chain id'],
698 [22, 4, $x->{init_resseq}, 'R', 'residue number'],
699 [28, 3, $x->{end_resname}, 'R', 'residue name'], [32, 1, $x->{end_chain}, '', 'chain id'],
700 [34, 4, $x->{end_resseq}, 'R', 'residue number'],
701 65 [39, 2, $x->{class}, 'R', 'class'], [72, 5, $x->{length}, 'R', 'length']);
702 0 ▶ if (my $why = _too_long(@f)) { push @$notes, "HELIX: helix " . _t($x->{id}) . " is left out: $why"; next }
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = _too_long(@f)) 0 65 65
703 65 push @l, _rec(@f);
704 }
705 209 ▶ for my $x (@{ $h->{sheet} || [] }) {
Condition100%2/2
$h->{'sheet'} || []
l!l
2054
MC/DC100%1/1
$h->{'sheet'} || []
$h->{'sheet'}
Truth table100%2/2
A
A= $h->{'sheet'}
Aresult
11
00
706 my @f = ([1, 6, 'SHEET'], [8, 3, $x->{strand}, 'R', 'strand'], [12, 3, $x->{id}, 'R', 'sheet id'],
707 [15, 2, $x->{n_strands}, 'R', 'strand count'],
708 [18, 3, $x->{init_resname}, 'R', 'residue name'], [22, 1, $x->{init_chain}, '', 'chain id'],
709 [23, 4, $x->{init_resseq}, 'R', 'residue number'],
710 [29, 3, $x->{end_resname}, 'R', 'residue name'], [33, 1, $x->{end_chain}, '', 'chain id'],
711 100 [34, 4, $x->{end_resseq}, 'R', 'residue number'], [39, 2, $x->{sense}, 'R', 'sense']);
712 0 ▶ if (my $why = _too_long(@f)) { push @$notes, "SHEET: a strand of sheet " . _t($x->{id}) . " is left out: $why"; next }
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = _too_long(@f)) 0 100 100
713 100 push @l, _rec(@f);
714 }
715 209 $n = 0;
716 209 ▶ for my $x (@{ $h->{ssbond} || [] }) {
Condition100%2/2
$h->{'ssbond'} || []
l!l
2054
MC/DC100%1/1
$h->{'ssbond'} || []
$h->{'ssbond'}
Truth table100%2/2
A
A= $h->{'ssbond'}
Aresult
11
00
717 my @f = ([1, 6, 'SSBOND'], [8, 3, ++$n, 'R'], [12, 3, 'CYS'], [16, 1, $x->{chain1}, '', 'chain id'],
718 [18, 4, $x->{resseq1}, 'R', 'residue number'], [26, 3, 'CYS'],
719 [30, 1, $x->{chain2}, '', 'chain id'], [32, 4, $x->{resseq2}, 'R', 'residue number'],
720 35 [74, 5, $len->($x->{length}), 'R', 'length']);
721 0 ▶ if (my $why = _too_long(@f)) { push @$notes, "SSBOND: a disulfide is left out: $why"; next }
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = _too_long(@f)) 0 35 35
722 35 push @l, _rec(@f);
723 }
724 209 ▶ for my $x (@{ $h->{link} || [] }) {
Condition100%2/2
$h->{'link'} || []
l!l
2054
MC/DC100%1/1
$h->{'link'} || []
$h->{'link'}
Truth table100%2/2
A
A= $h->{'link'}
Aresult
11
00
725 # the atom names as ATOM writes them: four characters from column 13,
726 # fewer from 14
727 35 ▶ my @name = map { my $v = _t($_); length $v && length $v < 4 ? " $v" : $v } @{$x}{qw(name1 name2)};
Branch: 1 branch
BranchTrueFalseTotal
length $v && length $v < 4 ? : 70 0 70
Condition33%1/3
length $v and length $v < 4
!ll&&!rl&&r
0070
MC/DC0%0/2
length $v and length $v < 4
length $v length $v < 4
Truth table33%1/3
A and B
A= length $vB= length $v < 4
ABresult
0X0
100
111
728 my @f = ([13, 4, $name[0], '', 'atom name'], [18, 3, $x->{resname1}, 'R', 'residue name'],
729 [22, 1, $x->{chain1}, '', 'chain id'], [23, 4, $x->{resseq1}, 'R', 'residue number'],
730 [43, 4, $name[1], '', 'atom name'], [48, 3, $x->{resname2}, 'R', 'residue name'],
731 [52, 1, $x->{chain2}, '', 'chain id'], [53, 4, $x->{resseq2}, 'R', 'residue number'],
732 35 [74, 5, $len->($x->{length}), 'R', 'length']);
733 0 ▶ if (my $why = _too_long(@f)) { push @$notes, "LINK: a link is left out: $why"; next }
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = _too_long(@f)) 0 35 35
734 35 push @l, _rec([1, 6, 'LINK'], @f);
735 }
736 209 ▶ push @$notes, "SSBOND, LINK: $rounded bond length" . ($rounded == 1 ? ' was' : 's were')
Branch: 2 branches
BranchTrueFalseTotal
if $rounded 0 209 209
$rounded == 1 ? : 0 0 0
737 . ' rounded to the two decimals the records have for one'
738 if $rounded;
739  
740 209 ▶ my $c = $h->{cryst1} || {};
Condition100%2/2
$h->{'cryst1'} || {}
l!l
2054
MC/DC100%1/1
$h->{'cryst1'} || {}
$h->{'cryst1'}
Truth table100%2/2
A
A= $h->{'cryst1'}
Aresult
11
00
741 209 ▶ if (grep { defined } @{$c}{qw(a b c alpha beta gamma)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_;} @{$c;}{"a", "b", "c", "alpha", "beta", "gamma"}) 41 168 209
742 41 my $sg = _t($c->{sgroup});
743 41 my $z = _t($c->{z});
744 my @f = ([7, 9, _decimals($c->{a}, 3, 9), 'R', 'a'], [16, 9, _decimals($c->{b}, 3, 9), 'R', 'b'],
745 [25, 9, _decimals($c->{c}, 3, 9), 'R', 'c'],
746 [34, 7, _decimals($c->{alpha}, 2, 7), 'R', 'alpha'], [41, 7, _decimals($c->{beta}, 2, 7), 'R', 'beta'],
747 41 [48, 7, _decimals($c->{gamma}, 2, 7), 'R', 'gamma'],
748 [56, 11, $sg, '', 'space group'], [67, 4, $z, 'R', 'Z']);
749 0 ▶ if (my $why = _too_long(@f)) { push @$notes, "CRYST1: the cell is left out: $why" }
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = _too_long(@f)) { } 0 41 41
750 41 else { push @l, _rec([1, 6, 'CRYST1'], @f) }
751 }
752 209 return join '', @l;
753 }
754  
755 # the name of the data block: the entry id, or what structure_info() would call
756 # the file, with what a block name cannot hold taken out
757 200 ▶sub _cif_block_name {
Subroutine _cif_block_name: called CC=6 SCAR=17.9
758 200 my ($h, $file) = @_;
759 my $id = $h && length _t($h->{header}{id_code}) ? _t($h->{header}{id_code})
760 200 ▶ : defined $file ? _id_from({ header => {} }, $file)
Branch: 2 branches
BranchTrueFalseTotal
$h && length _t($h->{'header'}{'id_code'}) ? : 69 131 200
defined $file ? : 86 45 131
Condition100%3/3
$h and length _t($h->{"header"}{"id_code"})
!ll&&!rl&&r
113069
MC/DC100%2/2
$h and length _t($h->{"header"}{"id_code"})
$h length _t($h->{"header"}{"id_code"})
Truth table100%3/3
A and B
A= $hB= length _t($h->{"header"}{"id_code"})
ABresult
0X0
100
111
761 : '';
762 200 ▶ $id = '' unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 200 200
763 200 $id =~ s/[\s#\$'"\[\]]+//g;
764 200 ▶ return length $id ? $id : 'converted';
Branch: 1 branch
BranchTrueFalseTotal
length $id ? : 155 45 200
765 }
766  
767 # _cifq($value) -- a value as an mmCIF file has to write it: bare where it can
768 # be, quoted where it holds a blank or starts like something else, and a text
769 # field where it holds a line end or both quotes followed by a blank. The same
770 # rules as cv_cif_val() in Parser.xs, which writes the atoms.
771 7355 ▶sub _cifq {
Subroutine _cifq: called CC=12 SCAR=28.0
772 7355 my ($v) = @_;
773 7355 ▶ return '?' unless defined $v && length $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and length $v 717 6638 7355
Condition100%3/3
defined $v and length $v
!ll&&!rl&&r
4412766638
MC/DC100%2/2
defined $v and length $v
defined $v length $v
Truth table100%3/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
774 6638 ▶ return "\n;$v\n;" if $v =~ /[\r\n]/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /[\r\n]/ 0 6638 6638
775 6638 ▶ return $v unless $v =~ /\s/ || $v =~ /\A[_#\$'"\[\];]/ || $v eq '.' || $v eq '?'
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /\s/ or $v =~ /\A[_#\$'"\[\];]/ or $v eq "." or $v eq "?" or $v =~ /\A(?:data|save)_/i or $v =~ /\A(?:loop|stop|global)_\z/i 6291 347 6638
Condition66%10/15
$v =~ /\s/ or $v =~ /\A[_#\$'"\[\];]/ or $v eq "." or $v eq "?" or $v =~ /\A(?:data|save)_/i or $v =~ /\A(?:loop|stop|global)_\z/i
l!l&&r!l&&!r
34706291
$v =~ /\s/ or $v =~ /\A[_#\$'"\[\];]/ or $v eq "." or $v eq "?" or $v =~ /\A(?:data|save)_/i
l!l&&r!l&&!r
34706291
$v =~ /\s/ or $v =~ /\A[_#\$'"\[\];]/ or $v eq "." or $v eq "?"
l!l&&r!l&&!r
34706291
$v =~ /\s/ or $v =~ /\A[_#\$'"\[\];]/ or $v eq "."
l!l&&r!l&&!r
34706291
$v =~ /\s/ or $v =~ /\A[_#\$'"\[\];]/
l!l&&r!l&&!r
34706291
MC/DC16%1/6
$v =~ /\s/ or $v =~ /\A[_#\$'"\[\];]/ or $v eq "." or $v eq "?" or $v =~ /\A(?:data|save)_/i or $v =~ /\A(?:loop|stop|global)_\z/i
$v =~ /\s/ $v =~ /\A[_#\$'"\[\];]/ $v eq "." $v eq "?" $v =~ /\A(?:data|save)_/i $v =~ /\A(?:loop|stop|global)_\z/i
Truth table28%2/7
A or B or C or D or E or F
A= $v =~ /\s/B= $v =~ /\A[_#\$'"\[\];]/C= $v eq "."D= $v eq "?"E= $v =~ /\A(?:data|save)_/iF= $v =~ /\A(?:loop|stop|global)_\z/i
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
776 || $v =~ /\A(?:data|save)_/i || $v =~ /\A(?:loop|stop|global)_\z/i;
777 347 ▶ return "'$v'" unless $v =~ /'\s/;
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /'\s/ 347 0 347
778 0 ▶ return "\"$v\"" unless $v =~ /"\s/;
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /"\s/ 0 0 0
779 0 return "\n;$v\n;";
780 }
781  
782 # one category of one row, as tag-value pairs; nothing for a category with no
783 # value in it
784 445 ▶sub _cif_items {
Subroutine _cif_items: called CC=6 SCAR=18.0
785 445 my ($cat, @pairs) = @_;
786 445 my $o = '';
787 445 my $any = 0;
788 445 ▶ while (my ($k, $v) = splice @pairs, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@pairs, 0, 2)) 1092 445 1537
789 1092 ▶ next unless defined $v && length $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and length $v 31 1061 1092
Condition100%3/3
defined $v and length $v
!ll&&!rl&&r
9221061
MC/DC100%2/2
defined $v and length $v
defined $v length $v
Truth table100%3/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
790 1061 $any = 1;
791 1061 my $q = _cifq($v);
792 1061 ▶ $o .= $q =~ /\A\n/ ? "$cat.$k$q\n" : "$cat.$k $q\n";
Branch: 1 branch
BranchTrueFalseTotal
$q =~ /\A\n/ ? : 0 1061 1061
793 }
794 445 ▶ return $any ? "$o#\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
$any ? : 445 0 445
795 }
796  
797 # a category as a loop_, one arrayref of values per row
798 1592 ▶sub _cif_loop {
Subroutine _cif_loop: called CC=2 SCAR=6.9
799 1592 my ($cat, $items, $rows) = @_;
800 1592 ▶ return '' unless @$rows;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rows 1229 363 1592
801 2408 return join('', "loop_\n", map({ "$cat.$_\n" } @$items),
802 363 map({ join(' ', map { _cifq($_) } @$_) . "\n" } @$rows), "#\n");
803 }
804  
805 # the entity_poly type a residue list is, the way the archive spells it
806 89 ▶sub _poly_type {
Subroutine _poly_type: called CC=13 SCAR=27.8
807 89 my ($res) = @_;
808 89 my %t;
809 89 for my $r (@$res) {
810 564 my $k = res_type($r);
811 564 ▶ $k = $r =~ /\AD[ACGTUI]\z/ ? 'dna' : 'rna' if $k eq 'nucleotide';
Branch: 2 branches
BranchTrueFalseTotal
if $k eq "nucleotide" 120 444 564
$r =~ /\AD[ACGTUI]\z/ ? : 120 0 120
812 564 $t{$k}++;
813 }
814 89 ▶ return 'polypeptide(L)' if $t{amino_acid} && keys %t == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $t{"amino_acid"} and keys %t == 1 50 39 89
Condition100%3/3
$t{"amino_acid"} and keys %t == 1
!ll&&!rl&&r
30950
MC/DC100%2/2
$t{"amino_acid"} and keys %t == 1
$t{"amino_acid"} keys %t == 1
Truth table100%3/3
A and B
A= $t{"amino_acid"}B= keys %t == 1
ABresult
0X0
100
111
815 39 ▶ return 'polydeoxyribonucleotide' if $t{dna} && keys %t == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $t{"dna"} and keys %t == 1 30 9 39
Condition66%2/3
$t{"dna"} and keys %t == 1
!ll&&!rl&&r
9030
MC/DC50%1/2
$t{"dna"} and keys %t == 1
$t{"dna"} keys %t == 1
Truth table66%2/3
A and B
A= $t{"dna"}B= keys %t == 1
ABresult
0X0
100
111
816 9 ▶ return 'polyribonucleotide' if $t{rna} && keys %t == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $t{"rna"} and keys %t == 1 0 9 9
Condition33%1/3
$t{"rna"} and keys %t == 1
!ll&&!rl&&r
900
MC/DC0%0/2
$t{"rna"} and keys %t == 1
$t{"rna"} keys %t == 1
Truth table33%1/3
A and B
A= $t{"rna"}B= keys %t == 1
ABresult
0X0
100
111
817 return 'polydeoxyribonucleotide/polyribonucleotide hybrid'
818 9 ▶ if $t{dna} && $t{rna} && keys %t == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $t{"dna"} and $t{"rna"} and keys %t == 2 0 9 9
Condition33%2/6
$t{"dna"} and $t{"rna"} and keys %t == 2
!ll&&!rl&&r
900
$t{"dna"} and $t{"rna"}
!ll&&!rl&&r
900
MC/DC0%0/3
$t{"dna"} and $t{"rna"} and keys %t == 2
$t{"dna"} $t{"rna"} keys %t == 2
Truth table25%1/4
A and B and C
A= $t{"dna"}B= $t{"rna"}C= keys %t == 2
ABCresult
0XX0
10X0
1100
1111
819 9 return 'other';
820 }
821  
822 # _cif_header($h, $id, \@chains, \@notes) -- the header as mmCIF categories
823 199 ▶sub _cif_header {
Subroutine _cif_header: called CC=54 SCAR=41.8
824 199 my ($h, $id, $chains, $notes) = @_;
825 199 ▶ my $hd = $h->{header} || {};
Condition50%1/2
$h->{'header'} || {}
l!l
1990
MC/DC0%0/1
$h->{'header'} || {}
$h->{'header'}
Truth table50%1/2
A
A= $h->{'header'}
Aresult
11
00
826 199 ▶ my $eid = length _t($hd->{id_code}) ? _t($hd->{id_code}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
length _t($hd->{'id_code'}) ? : 69 130 199
827 199 my $o = '';
828 199 ▶ $o .= _cif_items('_entry', id => $eid) if defined $eid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $eid 69 130 199
829 $o .= _cif_items('_struct', entry_id => $id, title => $h->{title})
830 199 ▶ if defined $h->{title} && length $h->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->{"title"} and length $h->{"title"} 63 136 199
Condition66%2/3
defined $h->{"title"} and length $h->{"title"}
!ll&&!rl&&r
136063
MC/DC50%1/2
defined $h->{"title"} and length $h->{"title"}
defined $h->{"title"} length $h->{"title"}
Truth table66%2/3
A and B
A= defined $h->{"title"}B= length $h->{"title"}
ABresult
0X0
100
111
831 $o .= _cif_items('_struct_keywords', entry_id => $id,
832 pdbx_keywords => $hd->{classification},
833 55 ▶ text => join(', ', @{ $h->{keywords} || [] }))
Condition50%1/2
$h->{'keywords'} || []
l!l
550
MC/DC0%0/1
$h->{'keywords'} || []
$h->{'keywords'}
Truth table50%1/2
A
A= $h->{'keywords'}
Aresult
11
00
834 199 ▶ if length _t($hd->{classification}) || @{ $h->{keywords} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if length _t($hd->{"classification"}) or @{$h->{"keywords"} or [];} 55 144 199
Condition80%4/5
length _t($hd->{"classification"}) or @{$h->{"keywords"} or [];}
l!l&&r!l&&!r
514144
$h->{'keywords'} || []
l!l
1480
MC/DC100%2/2
length _t($hd->{"classification"}) or @{$h->{"keywords"} or [];}
length _t($hd->{"classification"}) @{$h->{"keywords"} or [];}
MC/DC0%0/1
$h->{'keywords'} || []
$h->{'keywords'}
Truth table100%3/3
A or B
A= length _t($hd->{"classification"})B= @{$h->{"keywords"} or [];}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $h->{'keywords'}
Aresult
11
00
835 199 my $date = _cif_date($hd->{deposit_date});
836 push @$notes, "HEADER: the deposition date '$hd->{deposit_date}' is not a date, and is left out"
837 199 ▶ if !defined $date && length _t($hd->{deposit_date});
Branch: 1 branch
BranchTrueFalseTotal
if not defined $date and length _t($hd->{"deposit_date"}) 3 196 199
Condition100%3/3
not defined $date and length _t($hd->{"deposit_date"})
!ll&&!rl&&r
511453
MC/DC100%2/2
not defined $date and length _t($hd->{"deposit_date"})
not defined $date length _t($hd->{"deposit_date"})
Truth table100%3/3
not(A) and B
A= not defined $dateB= length _t($hd->{"deposit_date"})
ABresult
0X0
100
111
838 199 ▶ $o .= _cif_items('_pdbx_database_status', entry_id => $id,
Branch: 1 branch
BranchTrueFalseTotal
if defined $date 51 148 199
839 recvd_initial_deposition_date => $date) if defined $date;
840 199 ▶ my @method = @{ $h->{experiment} || [] };
Condition50%1/2
$h->{'experiment'} || []
l!l
1990
MC/DC0%0/1
$h->{'experiment'} || []
$h->{'experiment'}
Truth table50%1/2
A
A= $h->{'experiment'}
Aresult
11
00
841 0 ▶ $o .= @method > 1 ? _cif_loop('_exptl', [qw(entry_id method)], [ map { [ $id, $_ ] } @method ])
Branch: 2 branches
BranchTrueFalseTotal
@method > 1 ? : 0 199 199
@method ? : 63 136 199
842 : @method ? _cif_items('_exptl', entry_id => $id, method => $method[0])
843 : '';
844 199 ▶ if (defined $h->{resolution}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h->{"resolution"}) 36 163 199
845 # the category the archive files it in for the method: a map is not
846 # refined against reflections
847 30 $o .= (grep { /\AELECTRON MICROSCOPY\z/i } @method)
848 ? _cif_items('_em_3d_reconstruction', id => 1, entry_id => $id,
849 resolution => $h->{resolution})
850 : _cif_items('_refine', entry_id => $id, pdbx_refine_id => $method[0],
851 36 ▶ ls_d_res_high => $h->{resolution});
Branch: 1 branch
BranchTrueFalseTotal
grep({/\AELECTRON MICROSCOPY\z/i;} @method) ? : 0 36 36
852 }
853 199 ▶ my $c = $h->{cryst1} || {};
Condition50%1/2
$h->{'cryst1'} || {}
l!l
1990
MC/DC0%0/1
$h->{'cryst1'} || {}
$h->{'cryst1'}
Truth table50%1/2
A
A= $h->{'cryst1'}
Aresult
11
00
854 199 ▶ if (grep { defined } @{$c}{qw(a b c alpha beta gamma)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_;} @{$c;}{"a", "b", "c", "alpha", "beta", "gamma"}) 36 163 199
855 $o .= _cif_items('_cell', entry_id => $id, length_a => $c->{a}, length_b => $c->{b},
856 length_c => $c->{c}, angle_alpha => $c->{alpha}, angle_beta => $c->{beta},
857 36 angle_gamma => $c->{gamma}, Z_PDB => $c->{z});
858 36 $o .= _cif_items('_symmetry', entry_id => $id, 'space_group_name_H-M' => $c->{sgroup});
859 }
860  
861 # The entities. A PDB file has COMPND, whose MOL_IDs are the polymer
862 # entities and name their chains, and SEQRES, a residue list per chain; an
863 # mmCIF file has a residue list per entity. So an entity is a MOL_ID, with
864 # the SEQRES of its first chain that has one, and a chain with a SEQRES that
865 # no MOL_ID names is an entity of its own -- shared with every other such
866 # chain whose residue list is the same, as two copies of one molecule are.
867 199 my (@ent, %claimed);
868 199 my $next = 0;
869 199 my %written = map { ($_ => 1) } @$chains;
870 199 ▶ for my $mid (sort { ($a =~ /\A[0-9]+\z/ && $b =~ /\A[0-9]+\z/) ? $a <=> $b : $a cmp $b }
Branch: 1 branch
BranchTrueFalseTotal
$a =~ /\A[0-9]+\z/ && $b =~ /\A[0-9]+\z/ ? : 100 0 100
Condition33%1/3
$a =~ /\A[0-9]+\z/ and $b =~ /\A[0-9]+\z/
!ll&&!rl&&r
00100
MC/DC0%0/2
$a =~ /\A[0-9]+\z/ and $b =~ /\A[0-9]+\z/
$a =~ /\A[0-9]+\z/ $b =~ /\A[0-9]+\z/
Truth table33%1/3
A and B
A= $a =~ /\A[0-9]+\z/B= $b =~ /\A[0-9]+\z/
ABresult
0X0
100
111
871 199 ▶ keys %{ $h->{compound} || {} }) {
Condition50%1/2
$h->{'compound'} || {}
l!l
1990
MC/DC0%0/1
$h->{'compound'} || {}
$h->{'compound'}
Truth table50%1/2
A
A= $h->{'compound'}
Aresult
11
00
872 110 my $cm = $h->{compound}{$mid};
873 # A COMPND older than MOL_ID names one molecule and no chains, and
874 # _chain_stats() gives it to every chain: here, every chain with a
875 # SEQRES, or every chain written when there is none.
876 my @named = $cm->{free_text}
877 6 ▶ ? (%{ $h->{seqres} || {} } ? (grep { $h->{seqres}{$_} } @$chains,
Condition50%1/2
$h->{'seqres'} || {}
l!l
60
MC/DC0%0/1
$h->{'seqres'} || {}
$h->{'seqres'}
Truth table50%1/2
A
A= $h->{'seqres'}
Aresult
11
00
878 6 sort grep { !$written{$_} } keys %{ $h->{seqres} })
879 : @$chains)
880 110 ▶ : @{ $cm->{chain} || [] };
Branch: 2 branches
BranchTrueFalseTotal
$cm->{'free_text'} ? : 6 104 110
%{$h->{'seqres'} or {};} ? : 6 0 6
Condition50%1/2
$cm->{'chain'} || []
l!l
1040
MC/DC0%0/1
$cm->{'chain'} || []
$cm->{'chain'}
Truth table50%1/2
A
A= $cm->{'chain'}
Aresult
11
00
881 110 my @ch = grep { !$claimed{$_}++ } @named;
882 110 ▶ next unless @ch;
Branch: 1 branch
BranchTrueFalseTotal
unless @ch 30 80 110
883 80 ▶ $next = $mid if $mid =~ /\A[0-9]+\z/ && $mid > $next;
Branch: 1 branch
BranchTrueFalseTotal
if $mid =~ /\A[0-9]+\z/ and $mid > $next 80 0 80
Condition33%1/3
$mid =~ /\A[0-9]+\z/ and $mid > $next
!ll&&!rl&&r
0080
MC/DC0%0/2
$mid =~ /\A[0-9]+\z/ and $mid > $next
$mid =~ /\A[0-9]+\z/ $mid > $next
Truth table33%1/3
A and B
A= $mid =~ /\A[0-9]+\z/B= $mid > $next
ABresult
0X0
100
111
884 80 push @ent, { id => $mid, molecule => $cm->{molecule}, chains => \@ch };
885 }
886 199 my %by_list;
887 199 for my $cid ((grep { $h->{seqres}{$_} } @$chains),
888 95 ▶ (sort grep { !$written{$_} } keys %{ $h->{seqres} || {} })) {
Condition50%1/2
$h->{'seqres'} || {}
l!l
1990
MC/DC0%0/1
$h->{'seqres'} || {}
$h->{'seqres'}
Truth table50%1/2
A
A= $h->{'seqres'}
Aresult
11
00
889 95 ▶ next if $claimed{$cid};
Branch: 1 branch
BranchTrueFalseTotal
if $claimed{$cid} 80 15 95
890 15 ▶ my $list = join ' ', @{ $h->{seqres}{$cid}{residues} || [] };
Condition50%1/2
$h->{'seqres'}{$cid}{'residues'} || []
l!l
150
MC/DC0%0/1
$h->{'seqres'}{$cid}{'residues'} || []
$h->{'seqres'}{$cid}{'residues'}
Truth table50%1/2
A
A= $h->{'seqres'}{$cid}{'residues'}
Aresult
11
00
891 15 ▶ next unless length $list;
Branch: 1 branch
BranchTrueFalseTotal
unless length $list 0 15 15
892 0 ▶ if (my $e = $by_list{$list}) { push @{ $e->{chains} }, $cid; next }
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $by_list{$list}) 0 15 15
893 15 push @ent, $by_list{$list} = { id => ++$next, chains => [ $cid ] };
894 }
895 199 my (@e_rows, @p_rows, @s_rows);
896 199 for my $e (@ent) {
897 # pdbx_strand_id is a comma-separated list, and has no way to name the
898 # chain with no id that an old PDB file's SEQRES can have
899 95 ▶ if (grep { !length } @{ $e->{chains} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not length $_;} @{$$e{"chains"};}) 6 89 95
900 6 push @$notes, 'SEQRES: the chain with no id is left out of entity '
901 . "$e->{id}: pdbx_strand_id cannot name it";
902 6 $e->{chains} = [ grep { length } @{ $e->{chains} } ];
903 }
904 95 ▶ my ($with) = grep { @{ $h->{seqres}{$_}{residues} || [] } } @{ $e->{chains} };
Condition50%1/2
$h->{'seqres'}{$_}{'residues'} || []
l!l
890
MC/DC0%0/1
$h->{'seqres'}{$_}{'residues'} || []
$h->{'seqres'}{$_}{'residues'}
Truth table50%1/2
A
A= $h->{'seqres'}{$_}{'residues'}
Aresult
11
00
905 95 ▶ my @res = $with ? @{ $h->{seqres}{$with}{residues} } : ();
Branch: 1 branch
BranchTrueFalseTotal
$with ? : 89 6 95
906 95 push @e_rows, [ $e->{id}, 'polymer', $e->{molecule} ];
907 95 ▶ push @p_rows, [ $e->{id}, (@res ? _poly_type(\@res) : undef), join(',', @{ $e->{chains} }) ];
Branch: 1 branch
BranchTrueFalseTotal
@res ? : 89 6 95
908 95 my $k = 0;
909 95 push @s_rows, map { [ $e->{id}, ++$k, $_, 'n' ] } @res;
910 }
911 199 $o .= _cif_loop('_entity', [qw(id type pdbx_description)], \@e_rows);
912 199 $o .= _cif_loop('_entity_poly', [qw(entity_id type pdbx_strand_id)], \@p_rows);
913 199 $o .= _cif_loop('_entity_poly_seq', [qw(entity_id num mon_id hetero)], \@s_rows);
914  
915 # HELIX, as the archive writes it: HELX_P and a row id of its own, the
916 # HELIX record's id kept as pdbx_PDB_helix_id. The label_* columns name the
917 # chain as the atoms' label_asym_id does, and the number is '?' for the
918 # same reason the atoms' label_seq_id is.
919 199 my $n = 0;
920 my @h_rows = map { [
921 'HELX_P', 'HELX_P' . ++$n, $_->{id},
922 $_->{init_resname}, $_->{init_chain}, undef, $_->{end_resname}, $_->{end_chain}, undef,
923 $_->{init_resname}, $_->{init_chain}, $_->{init_resseq},
924 $_->{end_resname}, $_->{end_chain}, $_->{end_resseq},
925 $_->{class}, $_->{length},
926 199 ▶ ] } @{ $h->{helix} || [] };
Condition50%1/2
$h->{'helix'} || []
l!l
1990
MC/DC0%0/1
$h->{'helix'} || []
$h->{'helix'}
Truth table50%1/2
A
A= $h->{'helix'}
Aresult
11
00
927 199 $o .= _cif_loop('_struct_conf', [qw(conf_type_id id pdbx_PDB_helix_id
928 beg_label_comp_id beg_label_asym_id beg_label_seq_id
929 end_label_comp_id end_label_asym_id end_label_seq_id
930 beg_auth_comp_id beg_auth_asym_id beg_auth_seq_id
931 end_auth_comp_id end_auth_asym_id end_auth_seq_id
932 pdbx_PDB_helix_class pdbx_PDB_helix_length)], \@h_rows);
933 199 ▶ $o .= _cif_items('_struct_conf_type', id => 'HELX_P') if @h_rows;
Branch: 1 branch
BranchTrueFalseTotal
if @h_rows 36 163 199
934  
935 # SHEET: the strand count goes to _struct_sheet, and each strand's sense
936 # relative to the one before it in its sheet to _struct_sheet_order, which
937 # says it of a pair of strands; the first strand of a sheet has none
938 199 my (@sheets, %n_strands, @order, %prev);
939 199 my %SENSE = ('1' => 'parallel', '-1' => 'anti-parallel');
940 199 ▶ for my $x (@{ $h->{sheet} || [] }) {
Condition50%1/2
$h->{'sheet'} || []
l!l
1990
MC/DC0%0/1
$h->{'sheet'} || []
$h->{'sheet'}
Truth table50%1/2
A
A= $h->{'sheet'}
Aresult
11
00
941 90 my $sh = _t($x->{id});
942 90 ▶ push @sheets, $sh unless exists $n_strands{$sh};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $n_strands{$sh} 36 54 90
943 90 ▶ $n_strands{$sh} = $x->{n_strands} unless defined $n_strands{$sh};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n_strands{$sh} 36 54 90
944 90 ▶ my $sense = defined $x->{sense} ? $SENSE{ _t($x->{sense}) } : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $x->{'sense'} ? : 90 0 90
945 push @order, [ $sh, $prev{$sh}, $x->{strand}, $sense ]
946 90 ▶ if defined $sense && defined $prev{$sh};
Branch: 1 branch
BranchTrueFalseTotal
if defined $sense and defined $prev{$sh} 54 36 90
Condition66%2/3
defined $sense and defined $prev{$sh}
!ll&&!rl&&r
36054
MC/DC50%1/2
defined $sense and defined $prev{$sh}
defined $sense defined $prev{$sh}
Truth table66%2/3
A and B
A= defined $senseB= defined $prev{$sh}
ABresult
0X0
100
111
947 90 $prev{$sh} = $x->{strand};
948 }
949 $o .= _cif_loop('_struct_sheet', [qw(id number_strands)],
950 199 [ map { [ $_, $n_strands{$_} ] } @sheets ]);
951 199 $o .= _cif_loop('_struct_sheet_order', [qw(sheet_id range_id_1 range_id_2 sense)], \@order);
952 $o .= _cif_loop('_struct_sheet_range', [qw(sheet_id id
953 beg_label_comp_id beg_label_asym_id beg_label_seq_id
954 end_label_comp_id end_label_asym_id end_label_seq_id
955 beg_auth_comp_id beg_auth_asym_id beg_auth_seq_id
956 end_auth_comp_id end_auth_asym_id end_auth_seq_id)], [ map { [
957 $_->{id}, $_->{strand},
958 $_->{init_resname}, $_->{init_chain}, undef, $_->{end_resname}, $_->{end_chain}, undef,
959 $_->{init_resname}, $_->{init_chain}, $_->{init_resseq},
960 $_->{end_resname}, $_->{end_chain}, $_->{end_resseq},
961 199 ▶ ] } @{ $h->{sheet} || [] } ]);
Condition50%1/2
$h->{'sheet'} || []
l!l
1990
MC/DC0%0/1
$h->{'sheet'} || []
$h->{'sheet'}
Truth table50%1/2
A
A= $h->{'sheet'}
Aresult
11
00
962  
963 # SSBOND and LINK, which are one category told apart by the bond type
964 199 my ($nd, $nc) = (0, 0);
965 my @conn = ((map { [
966 'disulf' . ++$nd, 'disulf',
967 $_->{chain1}, 'CYS', undef, 'SG', $_->{chain2}, 'CYS', undef, 'SG',
968 $_->{chain1}, $_->{resseq1}, $_->{chain2}, $_->{resseq2}, $_->{length},
969 30 ▶ ] } @{ $h->{ssbond} || [] }), (map { [
Condition50%1/2
$h->{'ssbond'} || []
l!l
1990
MC/DC0%0/1
$h->{'ssbond'} || []
$h->{'ssbond'}
Truth table50%1/2
A
A= $h->{'ssbond'}
Aresult
11
00
970 'covale' . ++$nc, 'covale',
971 $_->{chain1}, $_->{resname1}, undef, $_->{name1},
972 $_->{chain2}, $_->{resname2}, undef, $_->{name2},
973 $_->{chain1}, $_->{resseq1}, $_->{chain2}, $_->{resseq2}, $_->{length},
974 199 ▶ ] } @{ $h->{link} || [] }));
Condition50%1/2
$h->{'link'} || []
l!l
1990
MC/DC0%0/1
$h->{'link'} || []
$h->{'link'}
Truth table50%1/2
A
A= $h->{'link'}
Aresult
11
00
975 199 $o .= _cif_loop('_struct_conn', [qw(id conn_type_id
976 ptnr1_label_asym_id ptnr1_label_comp_id ptnr1_label_seq_id ptnr1_label_atom_id
977 ptnr2_label_asym_id ptnr2_label_comp_id ptnr2_label_seq_id ptnr2_label_atom_id
978 ptnr1_auth_asym_id ptnr1_auth_seq_id ptnr2_auth_asym_id ptnr2_auth_seq_id
979 pdbx_dist_value)], \@conn);
980 199 return $o;
981 }
982  
983 # Views over a parsed structure
984 #
985 # These build what they return. Nothing in the structure points back up at
986 # its parent -- a residue does not hold its chain, an atom does not hold its
987 # residue -- because a hash of hashes with parent links is a cycle, and a
988 # cycle is a leak that no one notices until the tenth thousand file.
989  
990 # structure_atoms($info, $chain?) -- every atom as a flat array of hashes,
991 # each one carrying the chain/residue it came from, in file order.
992 19 ▶sub structure_atoms {
Subroutine structure_atoms: called CC=4 SCAR=13.9
Pod documented
993 19 my ($info, $chain) = @_;
994 19 _check_info($info, 'structure_atoms');
995 15 ▶ my @cids = defined $chain ? ($chain) : @{ $info->{chain_order} };
Branch: 1 branch
BranchTrueFalseTotal
defined $chain ? : 3 12 15
996 15 ▶ $info->{chains}{$_} or die "structure_atoms: no chain '$_'" for @cids;
Branch: 1 branch
BranchTrueFalseTotal
$info->{"chains"}{$_} or die "structure_atoms: no chain '${_}'" 21 2 23
997 # one hash an atom, which is why the copying is atoms_flat() in the XS
998 13 return _structure_atoms($info->{chains}, \@cids);
999 }
1000  
1001 # structure_residues($info, $chain?) -- every residue, in order.
1002 17 ▶sub structure_residues {
Subroutine structure_residues: called CC=4 SCAR=13.9
Pod documented
1003 17 my ($info, $chain) = @_;
1004 17 _check_info($info, 'structure_residues');
1005 13 my @out;
1006 13 ▶ for my $cid (defined $chain ? ($chain) : @{ $info->{chain_order} }) {
Branch: 1 branch
BranchTrueFalseTotal
defined $chain ? : 3 10 13
1007 19 ▶ my $c = $info->{chains}{$cid} or die "structure_residues: no chain '$cid'";
Branch: 1 branch
BranchTrueFalseTotal
my $c = $info->{"chains"}{$cid} or die "structure_residues: no chain '${cid}'" 18 1 19
1008 18 push @out, map { $c->{residues}{$_} } @{ $c->{residue_order} };
1009 }
1010 12 return \@out;
1011 }
1012  
1013 # structure_ligands($info) -- the non-water heterogens, keyed NAME_CHAIN_NUM,
1014 # which is what a binding-site table wants as its row label.
1015 46 ▶sub structure_ligands {
Subroutine structure_ligands: called CC=5 SCAR=16.1
Pod documented
1016 46 my ($info) = @_;
1017 46 _check_info($info, 'structure_ligands');
1018 42 my %lig;
1019 42 for my $cid (@{ $info->{chain_order} }) {
1020 68 my $c = $info->{chains}{$cid};
1021 68 for my $rk (@{ $c->{residue_order} }) {
1022 1073 my $r = $c->{residues}{$rk};
1023 1073 ▶ next unless $r->{type} eq 'ligand' || $r->{type} eq 'ion';
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"type"} eq "ligand" or $r->{"type"} eq "ion" 1017 56 1073
Condition100%3/3
$r->{"type"} eq "ligand" or $r->{"type"} eq "ion"
l!l&&r!l&&!r
30261017
MC/DC100%2/2
$r->{"type"} eq "ligand" or $r->{"type"} eq "ion"
$r->{"type"} eq "ligand" $r->{"type"} eq "ion"
Truth table100%3/3
A or B
A= $r->{"type"} eq "ligand"B= $r->{"type"} eq "ion"
ABresult
1X1
011
000
1024 56 $lig{"$r->{resname}_${cid}_$rk"} = $r;
1025 }
1026 }
1027 42 return \%lig;
1028 }
1029  
1030 # structure_sequences($info_or_file, %opt) -- chain id => single-letter
1031 # sequence, observed. A file name in place of the parsed structure is read
1032 # first, because the sequences are the one view a caller often wants on their
1033 # own, and parsing a file to throw the rest of it away is two lines that read
1034 # as one thought. %opt is then what structure_info() takes; with a structure
1035 # already in hand there is nothing left for options to affect, so passing them
1036 # there is a mistake and is said to be one rather than quietly ignored.
1037 38 ▶sub structure_sequences {
Subroutine structure_sequences: called CC=5 SCAR=16.1
Pod documented
1038 38 my ($info, %opt) = _args('structure_sequences', @_);
1039 38 ▶ if (ref $info) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info) { } 15 23 38
1040 15 ▶ die 'structure_sequences: options apply to reading a file, not to a structure already parsed: '
Branch: 1 branch
BranchTrueFalseTotal
if %opt 1 14 15
1041 . join(', ', sort keys %opt) if %opt;
1042 }
1043 else {
1044 23 ▶ die 'structure_sequences: expected a file name or the hash reference from structure_info()'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info and length $info 3 20 23
Condition100%3/3
defined $info and length $info
!ll&&!rl&&r
2120
MC/DC100%2/2
defined $info and length $info
defined $info length $info
Truth table100%3/3
A and B
A= defined $infoB= length $info
ABresult
0X0
100
111
1045 unless defined $info && length $info;
1046 # the sequence is read off the residues, so neither the atom hashes nor
1047 # the features they feed are wanted: over 30 entries of PDBbind v2020
1048 # this is 0.42 s to the default read's 4.49 s, with the same answer.
1049 # A caller's own atoms or features still wins, coming after.
1050 20 $info = structure_info($info, atoms => 0, features => 0, %opt);
1051 }
1052 33 _check_info($info, 'structure_sequences');
1053 43 return { map { $_ => $info->{chains}{$_}{sequence} }
1054 31 grep { length $info->{chains}{$_}{sequence} } @{ $info->{chain_order} } };
1055 }
1056  
1057 # chain_sequence($info, $chain, $which?) -- one chain's sequence. $which is
1058 # 'observed' (default: the residues that have coordinates) or 'seqres' (what
1059 # the crystallographer put in, disordered tails and all).
1060 9 ▶sub chain_sequence {
Subroutine chain_sequence: called CC=7 SCAR=19.5
Pod documented
1061 9 my ($info, $chain, $which) = @_;
1062 9 _check_info($info, 'chain_sequence');
1063 9 ▶ die 'chain_sequence: no chain given' unless defined $chain;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chain 1 8 9
1064 8 ▶ my $c = $info->{chains}{$chain} or die "chain_sequence: no chain '$chain'";
Branch: 1 branch
BranchTrueFalseTotal
my $c = $info->{"chains"}{$chain} or die "chain_sequence: no chain '${chain}'" 7 1 8
1065 7 ▶ $which = 'observed' unless defined $which;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $which 1 6 7
1066 7 ▶ die "chain_sequence: which must be 'observed' or 'seqres', not '$which'"
Branch: 1 branch
BranchTrueFalseTotal
unless $which eq "observed" or $which eq "seqres" 1 6 7
Condition100%3/3
$which eq "observed" or $which eq "seqres"
l!l&&r!l&&!r
331
MC/DC100%2/2
$which eq "observed" or $which eq "seqres"
$which eq "observed" $which eq "seqres"
Truth table100%3/3
A or B
A= $which eq "observed"B= $which eq "seqres"
ABresult
1X1
011
000
1067 unless $which eq 'observed' || $which eq 'seqres';
1068 6 ▶ return $which eq 'seqres' ? $c->{seqres} : $c->{sequence};
Branch: 1 branch
BranchTrueFalseTotal
$which eq 'seqres' ? : 3 3 6
1069 }
1070  
1071 # structure_summary($info) -- a paragraph a human can read, for STDERR or a log.
1072 9 ▶sub structure_summary {
Subroutine structure_summary: called CC=18 SCAR=29.1
Pod documented
1073 9 my ($info) = @_;
1074 9 _check_info($info, 'structure_summary');
1075 5 my @l;
1076 5 ▶ push @l, sprintf('%s %s', $info->{id} || '????', $info->{title} || '(no title)');
Condition100%4/4
$info->{'id'} || '????'
l!l
41
$info->{'title'} || '(no title)'
l!l
32
MC/DC100%1/1
$info->{'id'} || '????'
$info->{'id'}
MC/DC100%1/1
$info->{'title'} || '(no title)'
$info->{'title'}
Truth table100%2/2
A
A= $info->{'id'}
Aresult
11
00
Truth table100%2/2
A
A= $info->{'title'}
Aresult
11
00
1077 5 ▶ push @l, sprintf(' file %s', $info->{file}) if defined $info->{file};
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"file"} 4 1 5
1078 5 ▶ push @l, sprintf(' method %s', join(', ', @{ $info->{experiment} })) if @{ $info->{experiment} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$info->{"experiment"} or [];} 3 2 5
Condition50%1/2
$info->{'experiment'} || []
l!l
50
MC/DC0%0/1
$info->{'experiment'} || []
$info->{'experiment'}
Truth table50%1/2
A
A= $info->{'experiment'}
Aresult
11
00
1079 5 ▶ push @l, sprintf(' resolution %s A', $info->{resolution}) if defined $info->{resolution};
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"resolution"} 2 3 5
1080 push @l, sprintf(' R / R-free %s / %s',
1081 defined $info->{r_work} ? $info->{r_work} : '-',
1082 defined $info->{r_free} ? $info->{r_free} : '-')
1083 5 ▶ if defined $info->{r_work} || defined $info->{r_free};
Branch: 3 branches
BranchTrueFalseTotal
if defined $info->{"r_work"} or defined $info->{"r_free"} 2 3 5
defined $info->{'r_work'} ? : 2 0 2
defined $info->{'r_free'} ? : 2 0 2
Condition66%2/3
defined $info->{"r_work"} or defined $info->{"r_free"}
l!l&&r!l&&!r
203
MC/DC50%1/2
defined $info->{"r_work"} or defined $info->{"r_free"}
defined $info->{"r_work"} defined $info->{"r_free"}
Truth table66%2/3
A or B
A= defined $info->{"r_work"}B= defined $info->{"r_free"}
ABresult
1X1
011
000
1084 push @l, sprintf(' models %d%s', $info->{n_models},
1085 5 ▶ $info->{n_models} > 1 ? " (chains built from model $info->{model})" : '');
Branch: 1 branch
BranchTrueFalseTotal
$info->{'n_models'} > 1 ? : 1 4 5
1086 push @l, sprintf(' atoms %d (%d hetatm, %d water)',
1087 5 $info->{stats}{n_atoms}, $info->{stats}{n_hetatm}, $info->{stats}{n_water_atoms});
1088 5 for my $cid (@{ $info->{chain_order} }) {
1089 6 my $c = $info->{chains}{$cid};
1090 push @l, sprintf(' chain %-2s %-11s %4d residues, %5d atoms%s',
1091 $cid, $c->{type}, $c->{n_residues}, $c->{n_atoms},
1092 6 ▶ $c->{n_gaps} ? ", $c->{n_gaps} gap" . ($c->{n_gaps} > 1 ? 's' : '') : '');
Branch: 2 branches
BranchTrueFalseTotal
$c->{'n_gaps'} ? : 2 4 6
$c->{'n_gaps'} > 1 ? : 0 2 2
1093 6 ▶ push @l, sprintf(' %s', $c->{sequence}) if length $c->{sequence};
Branch: 1 branch
BranchTrueFalseTotal
if length $c->{"sequence"} 6 0 6
1094 6 ▶ push @l, sprintf(' %s', $c->{molecule}) if defined $c->{molecule};
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->{"molecule"} 4 2 6
1095 }
1096 5 my $lig = structure_ligands($info);
1097 5 ▶ push @l, sprintf(' ligands %s', join(', ', sort keys %$lig)) if %$lig;
Branch: 1 branch
BranchTrueFalseTotal
if %$lig 2 3 5
1098 5 return join("\n", @l) . "\n";
1099 }
1100  
1101 # Physical properties
1102 #
1103 # Everything a structure is asked about after it has been read: how much of it
1104 # the solvent can touch, how big and how heavy it is, which of its aromatic
1105 # rings are stacked, and the numbers a sequence alone answers -- a protein's
1106 # mean hydropathy and aromatic fraction, a nucleic acid's G+C and purine
1107 # fractions.
1108 #
1109 # The first three are one XS call, because all three have to touch every atom
1110 # and the walk that flattens a hash of chains of residues of atoms into
1111 # coordinate arrays is the expensive part; asking for all of them costs one
1112 # walk. The sequence numbers are here rather than there because they read a
1113 # sequence string the chain already carries, which is a few hundred characters
1114 # and no per-atom work at all.
1115 #
1116 # Every number is checked against the implementation it came from, not against
1117 # this one. t/features.t compares with mdtraj 1.11 and Biopython 1.87 -- live
1118 # where mdtraj is installed, and against t/data/features.txt where it is not --
1119 # and t/properties.t covers the parts that are this module's own: the options,
1120 # the call forms, and what each function leaves behind in $info.
1121  
1122 # Kyte, J; Doolittle, R F (1982) "A simple method for displaying the hydropathic
1123 # character of a protein", J Mol Biol 157(1):105-132, the hydropathy index of
1124 # Table 2. Spelled the way Bio::SeqUtils' Python cousin spells it --
1125 # Bio.SeqUtils.ProtParamData.kd of Biopython 1.87 -- which is what
1126 # structure_features's mean is compared against.
1127 #
1128 # The twenty are all of it: there is no value for B, J, O, U, X or Z, and a
1129 # residue whose single-letter code is one of those is left out of both the sum
1130 # and the count rather than scored as something it is not.
1131 24 my %KD = (
1132 A => 1.8, R => -4.5, N => -3.5, D => -3.5, C => 2.5,
1133 Q => -3.5, E => -3.5, G => -0.4, H => -3.2, I => 4.5,
1134 L => 3.8, K => -3.9, M => 1.9, F => 2.8, P => -1.6,
1135 S => -0.8, T => -0.7, W => -0.9, Y => -1.3, V => 4.2,
1136 );
1137  
1138 # Phenylalanine, tryptophan and tyrosine. Aromaticity is their relative
1139 # frequency and nothing else -- Lobry, J R; Gautier, C (1994) Nucleic Acids Res
1140 # 22(15):3174-3180, and Biopython's ProteinAnalysis.aromaticity(), which is
1141 # what it is compared against. Histidine's ring is aromatic and is not in the
1142 # count, because it is not in Lobry's; structure_pi_stacking() does count it,
1143 # because there the question is about the ring rather than about the index.
1144 24 my %AROMATIC = map { $_ => 1 } qw(F W Y);
1145  
1146 # The bases that count towards a nucleic acid chain's composition, and the two
1147 # of them that are the G+C half of it. Which letters count is
1148 # Bio.SeqUtils.gc_fraction() of Biopython 1.87 with its default
1149 # ambiguous => 'remove', which is what these fractions are compared against: it
1150 # divides the C and G by the C, G, A, T and U, so an ambiguous or unknown base
1151 # is in neither half rather than counted as something it is not. That is the
1152 # same rule %KD applies to the amino acids it has no index for, for the same
1153 # reason.
1154 #
1155 # It leaves out I as well -- an inosine is a real base and not an ambiguity, but
1156 # it is not one of the five Biopython counts, and answering a different question
1157 # than the function this is checked against would be the worse trade.
1158 # base_counts is every letter, including those, so a caller can see what the
1159 # fractions left out.
1160 24 my %BASE = map { $_ => 1 } qw(A C G T U);
1161 24 my %GC = map { $_ => 1 } qw(C G);
1162 # adenine and guanine, the two-ring bases. No Biopython function answers this
1163 # one; it is the same five-letter denominator with a different numerator.
1164 24 my %PURINE = map { $_ => 1 } qw(A G);
1165  
1166 # PRODIGY's residue classes and relative-surface denominators, copied from
1167 # prodigy_prot/modules/aa_properties.py of prodigy-prot 2.4.0 (Vangone, A and
1168 # Bonvin, A M J J (2015) eLife 4:e07454), which is what the interface's ic,
1169 # nis and prodigy figures are compared against. Two tables of classes because
1170 # PRODIGY has two: aa_character_ic sorts the residues of a contact, and calls
1171 # cysteine and tyrosine apolar and histidine charged; aa_character_protorp
1172 # sorts the non-interacting surface, and calls all three polar. A = apolar,
1173 # C = charged, P = polar.
1174 24 my %IC_CLASS = (
1175 ALA => 'A', CYS => 'A', GLU => 'C', ASP => 'C', GLY => 'A', PHE => 'A',
1176 ILE => 'A', HIS => 'C', LYS => 'C', MET => 'A', LEU => 'A', ASN => 'P',
1177 GLN => 'P', PRO => 'A', SER => 'P', ARG => 'C', THR => 'P', TRP => 'A',
1178 VAL => 'A', TYR => 'A',
1179 );
1180 24 my %NIS_CLASS = (
1181 ALA => 'A', CYS => 'P', GLU => 'C', ASP => 'C', GLY => 'A', PHE => 'A',
1182 ILE => 'A', HIS => 'P', LYS => 'C', MET => 'A', LEU => 'A', ASN => 'P',
1183 GLN => 'P', PRO => 'A', SER => 'P', ARG => 'C', THR => 'P', TRP => 'P',
1184 VAL => 'A', TYR => 'P',
1185 );
1186 # rel_asa{total}: NACCESS's surface of each residue in an extended ALA-X-ALA
1187 # peptide, angstrom^2. Not the max_asa[] the residues' own rsa divides by
1188 # (Tien et al. 2013): the non-interacting surface is PRODIGY's, and the 5%
1189 # threshold it applies was fitted with these.
1190 24 my %NACCESS_REL = (
1191 ALA => 107.95, CYS => 134.28, ASP => 140.39, GLU => 172.25, PHE => 199.48,
1192 GLY => 80.10, HIS => 182.88, ILE => 175.12, LYS => 200.81, LEU => 178.63,
1193 MET => 194.15, ASN => 143.94, PRO => 136.13, GLN => 178.50, ARG => 238.76,
1194 SER => 116.50, THR => 139.27, VAL => 151.44, TRP => 249.36, TYR => 212.76,
1195 );
1196 # the pair of contact classes, sorted as PRODIGY's analyse_contacts() sorts
1197 # them, and the name it comes back under
1198 24 my %IC_BIN = (
1199 AA => 'apolar_apolar', CC => 'charged_charged', PP => 'polar_polar',
1200 AC => 'charged_apolar', AP => 'apolar_polar', CP => 'charged_polar',
1201 );
1202 # PRODIGY's IC_NIS model, prodigy_prot/modules/models.py of prodigy-prot 2.4.0:
1203 # the coefficients of the contact counts and of the non-interacting surface
1204 # percentages, and the intercept, kcal/mol. R is dg_to_kd()'s, in
1205 # prodigy_prot/modules/utils.py, kcal/(mol K).
1206 24 my %PRODIGY = (
1207 charged_charged => -0.09459, charged_apolar => -0.10007,
1208 polar_polar => 0.19577, apolar_polar => -0.22671,
1209 nis_apolar => 0.18681, nis_charged => 0.13810,
1210 intercept => -15.9433,
1211 );
1212 24 my $PRODIGY_R = 0.0019858775;
1213  
1214 # The pocket's residue classes and charges, as the pocket_block() of
1215 # ~/ui/pepPriML/py/features.pdb.20260806.py has them: its HYDROPHOBIC_RES,
1216 # POLAR_RES, AROMATIC_RES, POS_RES and NEG_RES, and its RESIDUE_CHARGE, which
1217 # gives histidine a tenth of a charge for the share of it protonated at pH 7.
1218 # A class set is not a partition -- tyrosine is aromatic and polar, histidine
1219 # polar and charged, and glycine none of them -- and a modified residue is its
1220 # parent's single-letter code, as the script's parent_resname() makes it.
1221 24 my %POCKET_HYDROPHOBIC = map { $_ => 1 } qw(A V I L M F W P);
1222 24 my %POCKET_POLAR = map { $_ => 1 } qw(S T N Q C Y H);
1223 24 my %POCKET_CHARGED = map { $_ => 1 } qw(R K H D E);
1224 24 my %POCKET_CHARGE = (R => 1, K => 1, H => 0.1, D => -1, E => -1);
1225 # the relative surface alone below which a pocket residue is buried, the
1226 # script's pocket_frac_buried_residues
1227 24 my $POCKET_BURIED = 0.25;
1228  
1229 # The pK values of Bjellqvist et al. (1993) Electrophoresis 14:1023-31 and
1230 # (1994) 15:529-39, as Bio/SeqUtils/IsoelectricPoint.py of Biopython 1.87
1231 # writes them: the side chains, and the termini with the residue-specific
1232 # values that replace the default one when that residue is at the end. In
1233 # Biopython's order, which is the order the partial charges are added up in,
1234 # so that the sum is the same NV.
1235 24 my @PK_POS = ([ Nterm => 7.5 ], [ K => 10.0 ], [ R => 12.0 ], [ H => 5.98 ]);
1236 24 my @PK_NEG = ([ Cterm => 3.55 ], [ D => 4.05 ], [ E => 4.45 ], [ C => 9.0 ], [ Y => 10.0 ]);
1237 24 my %PK_NTERM = (A => 7.59, M => 7.0, S => 6.93, P => 8.36, T => 6.82, V => 7.44, E => 7.7);
1238 24 my %PK_CTERM = (D => 4.55, E => 4.75);
1239  
1240 # The options the three feature functions take, with what they mean and what
1241 # they default to. This table is the one place the defaults are written down:
1242 # the XS carries the same numbers as a fallback, and never sees it, because
1243 # every call below passes the whole merged hash.
1244 #
1245 # The angles are degrees and the distances angstrom, which is what the rest of
1246 # the module is in. mdtraj's are degrees and nanometres; see the note on
1247 # face_distance in structure_pi_stacking's documentation for the one place that
1248 # difference is more than a conversion.
1249 24 my %FEATURE_DEFAULT = (
1250 sasa => 1, # compute the solvent-accessible surface
1251 pi_stacking => 1, # look for stacked aromatic rings
1252 disulfides => 1, # look for SG-SG pairs close enough to be bonded
1253 base_pairs => 1, # look for Watson-Crick and wobble base pairs
1254 base_stacks => 1, # score how far every nearby pair of bases is stacked
1255 interface => 1, # also run the surface on each chain alone, for the buried area
1256 shape => 1, # the gyration tensor and the descriptors built from it
1257 dihedrals => 1, # phi, psi, omega and chi1..chi5, onto each residue
1258 contacts => 1, # which residues touch which
1259 exposure => 1, # half-sphere exposure, onto each amino acid residue
1260 hbonds => 1, # backbone hydrogen bonds, by Kabsch and Sander's energy
1261 secondary => 1, # DSSP secondary structure, onto each residue
1262 # write per-atom, per-residue and per-chain results into $info. The torsion
1263 # angles, the half-sphere exposure and the secondary structure have nowhere
1264 # else to go, so store => 0 does not compute them rather than computing them
1265 # and dropping them; structure_info() always stores.
1266 store => 1,
1267 probe => 1.4, # solvent probe radius, angstrom: mdtraj's 0.14 nm
1268 points => 960, # sphere points per atom; more is more accurate and slower
1269 face_distance => 5.5, # face-to-face: centroid separation, angstrom
1270 face_plane_min => 0, # ... angle between the two ring planes, degrees
1271 face_plane_max => 35,
1272 face_normal_min => 0, # ... a ring's normal against the centroid-to-centroid line
1273 face_normal_max => 33,
1274 edge_distance => 6.5, # edge-to-face: centroid separation, angstrom
1275 edge_plane_min => 50,
1276 edge_plane_max => 90,
1277 edge_normal_min => 0,
1278 edge_normal_max => 30,
1279 edge_radius => 1.5, # ... centroid to where the two planes meet, angstrom
1280 # mdtraj's Topology.create_disulfide_bonds() uses 0.3 nm, and the cutoff is
1281 # the whole of the rule, so it is an option rather than a constant
1282 disulfide_distance => 3.0, # the largest SG-SG separation that is a bond, angstrom
1283 # Bio.PDB.Polypeptide.PPBuilder's `radius': the largest C-to-N separation
1284 # that still means two residues are joined, and so the largest one across
1285 # which a phi or a psi means anything
1286 peptide_bond => 1.8, # angstrom
1287 # the same question for a nucleic acid, and the same answer from the other
1288 # half of gemmi's are_connected(): an O3'-to-P separation under 1.5 times
1289 # the 1.6 A ideal bond, which is the largest one an alpha, an epsilon or a
1290 # zeta may be measured across
1291 phosphodiester_bond => 2.4, # angstrom
1292 # the closest two heavy atoms of two residues may be and still count as a
1293 # contact; 4.5 A is the usual convention and the option is there because
1294 # there is no single right answer
1295 contact_distance => 4.5, # angstrom
1296 # the two halves of the base pair rule, measured in Parser.xs's header
1297 # comment for base_pairs() against the wwPDB's own annotation of forty
1298 # entries: no annotated pair has a longer hydrogen bond than 3.4941 A or
1299 # stands further out of its partner's plane than 2.5408 A, and the nearest
1300 # candidate that is not a pair is at 3.5144 A and 2.6983 A
1301 base_pair_hbond => 3.5, # angstrom: the longest hydrogen bond a pair may have
1302 base_pair_stagger => 2.6, # angstrom: the furthest out of plane it may be
1303 # the two cutoffs of the stacking criteria of Condon et al. (2015), section
1304 # 2.4: bases further apart than the first are not stacked and their angles
1305 # are not computed, and a pair whose overlap angle is past the second is not
1306 # stacked and has no Xi. Both are the paper's, which took the distance from
1307 # CCSD(T) calculations on uracil and adenine dimers and the angle from X-ray
1308 # statistics. The knees of the two ramps between them are the definition
1309 # rather than a threshold, and are constants in Parser.xs.
1310 base_stack_distance => 5.0, # angstrom: the furthest apart two centres of mass may be
1311 base_stack_omega => 50, # degrees: the largest overlap angle that is a stack
1312 # The two sides of the interface: undef to have them worked out, or two
1313 # lists of chain ids and ligand keys. See _partners().
1314 partners => undef,
1315 # the contact cutoff of PRODIGY's calculate_ic() in prodigy-prot 2.4.0,
1316 # d_cutoff, which the ic counts and the prodigy estimate were fitted with
1317 interface_distance => 5.5, # angstrom
1318 # Barlow and Thornton (1983) J Mol Biol 168:867-85: a salt bridge is a
1319 # charged N and a charged O within 4 A
1320 salt_bridge_distance => 4.0, # angstrom
1321 # the heavy-atom hydrogen-bond criterion of features.pdb.20260806.py's
1322 # HBOND_DA_CUTOFF_NM, for structures that have no hydrogens to measure
1323 polar_distance => 3.5, # angstrom
1324 # Gallivan and Dougherty (1999) PNAS 96:9459-64's distance filter, cation
1325 # to ring centroid
1326 cation_pi_distance => 6.0, # angstrom
1327 # the first hydration shell of features.pdb.20260806.py's
1328 # WATER_CONTACT_NM, which a bridging water reaches on both sides
1329 water_distance => 3.5, # angstrom
1330 # features.pdb.20260806.py's pocket_block(): the receptor pocket is every
1331 # receptor atom within POCKET_CUTOFF_NM, 0.6 nm, of any peptide atom, and
1332 # its packing density counts the receptor heavy atoms within 0.8 nm of a
1333 # peptide heavy atom
1334 pocket => 1, # the first partner's pocket around the second
1335 pocket_distance => 6.0, # angstrom
1336 packing_distance => 8.0, # angstrom
1337 # PRODIGY's analyse_nis() acc_threshold: a residue is on the surface when
1338 # at least this fraction of its NACCESS reference area is exposed
1339 nis_threshold => 0.05,
1340 # degrees Celsius, for turning the prodigy estimate into a Kd; PRODIGY's
1341 # default
1342 temperature => 25,
1343 );
1344  
1345 # which of those each function takes. A geometry threshold passed to
1346 # structure_sasa() is a misunderstanding rather than a harmless extra, and the
1347 # same is true the other way round, so each function only knows its own.
1348 24 my @SASA_OPT = qw(store probe points interface);
1349 24 my @PI_OPT = qw(
1350 face_distance face_plane_min face_plane_max face_normal_min face_normal_max
1351 edge_distance edge_plane_min edge_plane_max edge_normal_min edge_normal_max
1352 edge_radius
1353 );
1354 24 my @SS_OPT = qw(store disulfide_distance);
1355 24 my @BP_OPT = qw(store base_pair_hbond base_pair_stagger);
1356 24 my @BS_OPT = qw(store base_stack_distance base_stack_omega);
1357 24 my @TORS_OPT = qw(store peptide_bond phosphodiester_bond);
1358 24 my @CONT_OPT = qw(store contact_distance);
1359 24 my @HB_OPT = qw(peptide_bond);
1360 24 my @IFACE_OPT = qw(
1361 partners interface_distance salt_bridge_distance polar_distance
1362 cation_pi_distance water_distance nis_threshold temperature probe points
1363 pocket pocket_distance packing_distance
1364 );
1365  
1366 # The options that are a switch, in either table. undef is a false value and
1367 # means off, which is what the caller who wrote hydrogens => $keep with $keep
1368 # unset will have meant; every other option takes a value, and undef is not one.
1369 24 my %SWITCH = map { $_ => 1 } qw(
1370 hydrogens waters hetatm atoms features meta anisou dssp
1371 sasa pi_stacking disulfides base_pairs base_stacks interface shape
1372 dihedrals contacts exposure hbonds secondary store pocket
1373 );
1374  
1375 # _no_undef(\%opt, $who, \%default) -- die at an option given as undef that
1376 # needs a value. Without this, model => undef or probe => undef reached a
1377 # comparison and died of 'Use of uninitialized value' in this file, which says
1378 # neither which function was called nor which option was wrong. An option
1379 # whose default is undef -- chains, format -- is not given a value by undef
1380 # either, and is left as not given, which is what undef means there.
1381 2392 ▶sub _no_undef {
Subroutine _no_undef: called CC=5 SCAR=16.1
1382 2392 my ($opt, $who, $default) = @_;
1383 2392 for my $k (sort keys %$opt) {
1384 2132 ▶ next if defined $opt->{$k} || $SWITCH{$k} || !defined $default->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{$k} or $SWITCH{$k} or not defined $default->{$k} 2127 5 2132
Condition100%6/6
defined $opt->{$k} or $SWITCH{$k} or not defined $default->{$k}
l!l&&r!l&&!r
212525
defined $opt->{$k} or $SWITCH{$k}
l!l&&r!l&&!r
212057
MC/DC100%3/3
defined $opt->{$k} or $SWITCH{$k} or not defined $default->{$k}
defined $opt->{$k} $SWITCH{$k} not defined $default->{$k}
Truth table100%4/4
A or B or not(C)
A= defined $opt->{$k}B= $SWITCH{$k}C= not defined $default->{$k}
ABCresult
1XX1
01X1
0011
0000
1385 5 die "$who: $k is undef; leave it out for the default, '$default->{$k}'";
1386 }
1387 2387 return;
1388 }
1389  
1390 766 ▶sub _feature_options {
Subroutine _feature_options: called CC=30 SCAR=34.1
1391 766 my ($opt, $who, $allowed) = @_;
1392 766 my %ok = map { $_ => 1 } @$allowed;
1393 766 for my $k (sort keys %$opt) {
1394 die "$who: unknown option '$k'; known options are: " . join(', ', sort @$allowed)
1395 181 ▶ unless $ok{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $ok{$k} 15 166 181
1396 }
1397 751 _no_undef($opt, $who, \%FEATURE_DEFAULT);
1398 749 my %o = (%FEATURE_DEFAULT, %$opt);
1399 die "$who: probe must be a number and must not be negative, not '$o{probe}'"
1400 749 ▶ unless $o{probe} =~ /\A[0-9]*\.?[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"probe"} =~ /\A[0-9]*\.?[0-9]+\z/ 3 746 749
1401 # the upper bound is memory rather than accuracy: a sphere point is three
1402 # NVs, so ten million of them is 240 MB on a double perl and four times that
1403 # on a quadmath one, for an atom whose area is one number
1404 die "$who: points must be an integer between 1 and 10000000, not '$o{points}'"
1405 746 ▶ unless $o{points} =~ /\A[0-9]+\z/ && $o{points} > 0 && $o{points} <= 10_000_000;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"points"} =~ /\A[0-9]+\z/ and $o{"points"} > 0 and $o{"points"} <= 10000000 3 743 746
Condition100%6/6
$o{"points"} =~ /\A[0-9]+\z/ and $o{"points"} > 0 and $o{"points"} <= 10000000
!ll&&!rl&&r
21743
$o{"points"} =~ /\A[0-9]+\z/ and $o{"points"} > 0
!ll&&!rl&&r
11744
MC/DC100%3/3
$o{"points"} =~ /\A[0-9]+\z/ and $o{"points"} > 0 and $o{"points"} <= 10000000
$o{"points"} =~ /\A[0-9]+\z/ $o{"points"} > 0 $o{"points"} <= 10000000
Truth table100%4/4
A and B and C
A= $o{"points"} =~ /\A[0-9]+\z/B= $o{"points"} > 0C= $o{"points"} <= 10000000
ABCresult
0XX0
10X0
1100
1111
1406 743 for my $k (@PI_OPT) {
1407 die "$who: $k must be a number, not '$o{$k}'"
1408 8165 ▶ unless $o{$k} =~ /\A-?[0-9]*\.?[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{$k} =~ /\A-?[0-9]*\.?[0-9]+\z/ 1 8164 8165
1409 }
1410 die "$who: disulfide_distance must be a number and must not be negative, "
1411 . "not '$o{disulfide_distance}'"
1412 742 ▶ unless $o{disulfide_distance} =~ /\A[0-9]*\.?[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"disulfide_distance"} =~ /\A[0-9]*\.?[0-9]+\z/ 2 740 742
1413 die "$who: peptide_bond must be a positive number, not '$o{peptide_bond}'"
1414 740 ▶ unless $o{peptide_bond} =~ /\A[0-9]*\.?[0-9]+\z/ && $o{peptide_bond} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"peptide_bond"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"peptide_bond"} > 0 3 737 740
Condition100%3/3
$o{"peptide_bond"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"peptide_bond"} > 0
!ll&&!rl&&r
21737
MC/DC100%2/2
$o{"peptide_bond"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"peptide_bond"} > 0
$o{"peptide_bond"} =~ /\A[0-9]*\.?[0-9]+\z/ $o{"peptide_bond"} > 0
Truth table100%3/3
A and B
A= $o{"peptide_bond"} =~ /\A[0-9]*\.?[0-9]+\z/B= $o{"peptide_bond"} > 0
ABresult
0X0
100
111
1415 die "$who: phosphodiester_bond must be a positive number, "
1416 . "not '$o{phosphodiester_bond}'"
1417 unless $o{phosphodiester_bond} =~ /\A[0-9]*\.?[0-9]+\z/
1418 737 ▶ && $o{phosphodiester_bond} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"phosphodiester_bond"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"phosphodiester_bond"} > 0 3 734 737
Condition100%3/3
$o{"phosphodiester_bond"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"phosphodiester_bond"} > 0
!ll&&!rl&&r
21734
MC/DC100%2/2
$o{"phosphodiester_bond"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"phosphodiester_bond"} > 0
$o{"phosphodiester_bond"} =~ /\A[0-9]*\.?[0-9]+\z/ $o{"phosphodiester_bond"} > 0
Truth table100%3/3
A and B
A= $o{"phosphodiester_bond"} =~ /\A[0-9]*\.?[0-9]+\z/B= $o{"phosphodiester_bond"} > 0
ABresult
0X0
100
111
1419 die "$who: contact_distance must be a positive number, not '$o{contact_distance}'"
1420 734 ▶ unless $o{contact_distance} =~ /\A[0-9]*\.?[0-9]+\z/ && $o{contact_distance} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"contact_distance"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"contact_distance"} > 0 0 734 734
Condition33%1/3
$o{"contact_distance"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"contact_distance"} > 0
!ll&&!rl&&r
00734
MC/DC0%0/2
$o{"contact_distance"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"contact_distance"} > 0
$o{"contact_distance"} =~ /\A[0-9]*\.?[0-9]+\z/ $o{"contact_distance"} > 0
Truth table33%1/3
A and B
A= $o{"contact_distance"} =~ /\A[0-9]*\.?[0-9]+\z/B= $o{"contact_distance"} > 0
ABresult
0X0
100
111
1421 die "$who: base_pair_hbond must be a positive number, not '$o{base_pair_hbond}'"
1422 734 ▶ unless $o{base_pair_hbond} =~ /\A[0-9]*\.?[0-9]+\z/ && $o{base_pair_hbond} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"base_pair_hbond"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"base_pair_hbond"} > 0 3 731 734
Condition100%3/3
$o{"base_pair_hbond"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"base_pair_hbond"} > 0
!ll&&!rl&&r
21731
MC/DC100%2/2
$o{"base_pair_hbond"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"base_pair_hbond"} > 0
$o{"base_pair_hbond"} =~ /\A[0-9]*\.?[0-9]+\z/ $o{"base_pair_hbond"} > 0
Truth table100%3/3
A and B
A= $o{"base_pair_hbond"} =~ /\A[0-9]*\.?[0-9]+\z/B= $o{"base_pair_hbond"} > 0
ABresult
0X0
100
111
1423 die "$who: base_pair_stagger must be a number and must not be negative, "
1424 . "not '$o{base_pair_stagger}'"
1425 731 ▶ unless $o{base_pair_stagger} =~ /\A[0-9]*\.?[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"base_pair_stagger"} =~ /\A[0-9]*\.?[0-9]+\z/ 2 729 731
1426 die "$who: base_stack_distance must be a positive number, "
1427 . "not '$o{base_stack_distance}'"
1428 unless $o{base_stack_distance} =~ /\A[0-9]*\.?[0-9]+\z/
1429 729 ▶ && $o{base_stack_distance} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"base_stack_distance"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"base_stack_distance"} > 0 4 725 729
Condition100%3/3
$o{"base_stack_distance"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"base_stack_distance"} > 0
!ll&&!rl&&r
22725
MC/DC100%2/2
$o{"base_stack_distance"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"base_stack_distance"} > 0
$o{"base_stack_distance"} =~ /\A[0-9]*\.?[0-9]+\z/ $o{"base_stack_distance"} > 0
Truth table100%3/3
A and B
A= $o{"base_stack_distance"} =~ /\A[0-9]*\.?[0-9]+\z/B= $o{"base_stack_distance"} > 0
ABresult
0X0
100
111
1430 die "$who: base_stack_omega must be a number between 0 and 180, "
1431 . "not '$o{base_stack_omega}'"
1432 unless $o{base_stack_omega} =~ /\A[0-9]*\.?[0-9]+\z/
1433 725 ▶ && $o{base_stack_omega} <= 180;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"base_stack_omega"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"base_stack_omega"} <= 180 3 722 725
Condition100%3/3
$o{"base_stack_omega"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"base_stack_omega"} <= 180
!ll&&!rl&&r
12722
MC/DC100%2/2
$o{"base_stack_omega"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"base_stack_omega"} <= 180
$o{"base_stack_omega"} =~ /\A[0-9]*\.?[0-9]+\z/ $o{"base_stack_omega"} <= 180
Truth table100%3/3
A and B
A= $o{"base_stack_omega"} =~ /\A[0-9]*\.?[0-9]+\z/B= $o{"base_stack_omega"} <= 180
ABresult
0X0
100
111
1434 722 for my $k (qw(interface_distance salt_bridge_distance polar_distance
1435 cation_pi_distance water_distance pocket_distance packing_distance)) {
1436 die "$who: $k must be a positive number, not '$o{$k}'"
1437 5012 ▶ unless $o{$k} =~ /\A[0-9]*\.?[0-9]+\z/ && $o{$k} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{$k} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{$k} > 0 14 4998 5012
Condition100%3/3
$o{$k} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{$k} > 0
!ll&&!rl&&r
774998
MC/DC100%2/2
$o{$k} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{$k} > 0
$o{$k} =~ /\A[0-9]*\.?[0-9]+\z/ $o{$k} > 0
Truth table100%3/3
A and B
A= $o{$k} =~ /\A[0-9]*\.?[0-9]+\z/B= $o{$k} > 0
ABresult
0X0
100
111
1438 }
1439 die "$who: nis_threshold must be a number between 0 and 1, not '$o{nis_threshold}'"
1440 708 ▶ unless $o{nis_threshold} =~ /\A[0-9]*\.?[0-9]+\z/ && $o{nis_threshold} <= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"nis_threshold"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"nis_threshold"} <= 1 1 707 708
Condition66%2/3
$o{"nis_threshold"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"nis_threshold"} <= 1
!ll&&!rl&&r
01707
MC/DC50%1/2
$o{"nis_threshold"} =~ /\A[0-9]*\.?[0-9]+\z/ and $o{"nis_threshold"} <= 1
$o{"nis_threshold"} =~ /\A[0-9]*\.?[0-9]+\z/ $o{"nis_threshold"} <= 1
Truth table66%2/3
A and B
A= $o{"nis_threshold"} =~ /\A[0-9]*\.?[0-9]+\z/B= $o{"nis_threshold"} <= 1
ABresult
0X0
100
111
1441 # absolute zero, below which there is no Kd to speak of
1442 die "$who: temperature must be a number of degrees Celsius above -273.15, "
1443 . "not '$o{temperature}'"
1444 707 ▶ unless $o{temperature} =~ /\A-?[0-9]*\.?[0-9]+\z/ && $o{temperature} > -273.15;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"temperature"} =~ /\A-?[0-9]*\.?[0-9]+\z/ and $o{"temperature"} > "-273.15" 1 706 707
Condition66%2/3
$o{"temperature"} =~ /\A-?[0-9]*\.?[0-9]+\z/ and $o{"temperature"} > "-273.15"
!ll&&!rl&&r
01706
MC/DC50%1/2
$o{"temperature"} =~ /\A-?[0-9]*\.?[0-9]+\z/ and $o{"temperature"} > "-273.15"
$o{"temperature"} =~ /\A-?[0-9]*\.?[0-9]+\z/ $o{"temperature"} > "-273.15"
Truth table66%2/3
A and B
A= $o{"temperature"} =~ /\A-?[0-9]*\.?[0-9]+\z/B= $o{"temperature"} > "-273.15"
ABresult
0X0
100
111
1445 706 return \%o;
1446 }
1447  
1448 # The properties structure_info() computes on the way past, which is all of
1449 # them. Kept apart from the wrappers below because it is also what decides what
1450 # $info->{features} holds, and so what the wrappers can hand back without doing
1451 # the work a second time.
1452 562 ▶sub _all_features {
Subroutine _all_features: called CC=2 SCAR=6.9
1453 562 my ($info, $who, $partners) = @_;
1454 562 ▶ my $o = _feature_options({ (defined $partners ? (partners => $partners) : ()) }, $who,
Branch: 1 branch
BranchTrueFalseTotal
defined $partners ? : 1 561 562
1455 [ qw(sasa pi_stacking disulfides base_pairs base_stacks shape dihedrals
1456 contacts exposure hbonds secondary),
1457 @SASA_OPT, @PI_OPT, @SS_OPT, @BP_OPT, @BS_OPT, @TORS_OPT, @CONT_OPT,
1458 @HB_OPT, @IFACE_OPT ]);
1459 562 return _features_and_after($info, $o, $who);
1460 }
1461  
1462 # _features_and_after($info, \%o, $who) -- the XS walk, and what the Perl
1463 # makes of it afterwards: the interface is finished and the sequence and
1464 # secondary-structure roll-ups are added. The partners are worked out first,
1465 # because they are what the walk is handed.
1466 607 ▶sub _features_and_after {
Subroutine _features_and_after: called CC=4 SCAR=13.9
1467 607 my ($info, $o, $who) = @_;
1468 607 my $sides;
1469 607 ▶ if ($o->{interface}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"interface"}) 603 4 607
1470 603 $sides = _partners($info, $o->{partners}, $who);
1471 602 ▶ $o = { %$o, sides => [ $sides->{residues}[0], $sides->{residues}[1] ] } if $sides;
Branch: 1 branch
BranchTrueFalseTotal
if $sides 204 398 602
1472 }
1473 606 my $f = _features($info, $o, $who);
1474 604 ▶ _finish_interface($info, $f, $o, $sides) if $f->{interface};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"interface"} 204 400 604
1475 604 _sequence_features($info, $f, $o->{store});
1476 604 _secondary_fractions($info, $f, $o->{store});
1477 604 return $f;
1478 }
1479  
1480 # structure_features($info, %opt) -- the physical properties of a structure.
1481 #
1482 # With no options this is a lookup: structure_info() computed them on the way
1483 # past and left them in $info->{features}, and computing them again would give
1484 # the same answer for the price of the walk. Name any option and it is
1485 # computed again with that option in force.
1486 199 ▶sub structure_features {
Subroutine structure_features: called CC=3 SCAR=11.0
Pod documented
1487 199 my ($info, %opt) = _args('structure_features', @_);
1488 198 _check_info($info, 'structure_features');
1489 195 ▶ return $info->{features} if !%opt && $info->{features};
Branch: 1 branch
BranchTrueFalseTotal
if not %opt and $info->{"features"} 120 75 195
Condition100%3/3
not %opt and $info->{"features"}
!ll&&!rl&&r
705120
MC/DC100%2/2
not %opt and $info->{"features"}
not %opt $info->{"features"}
Truth table100%3/3
not(A) and B
A= not %optB= $info->{"features"}
ABresult
0X0
100
111
1490 75 my $o = _feature_options(\%opt, 'structure_features',
1491 [ qw(sasa pi_stacking disulfides base_pairs base_stacks shape dihedrals
1492 contacts exposure hbonds secondary),
1493 @SASA_OPT, @PI_OPT, @SS_OPT, @BP_OPT, @BS_OPT, @TORS_OPT, @CONT_OPT,
1494 @HB_OPT, @IFACE_OPT ]);
1495 45 return _features_and_after($info, $o, 'structure_features');
1496 }
1497  
1498 # structure_interface($info, %opt) -- what two partners of a complex have
1499 # between them.
1500 #
1501 # A lookup when structure_info() found two partners and no option is named, as
1502 # the other wrappers are. Otherwise the interface alone is computed, with the
1503 # rest of the features off: the surface of the complex is then run whole
1504 # rather than started from the whole structure's, which is the one thing the
1505 # rest of the walk would have saved it.
1506 51 ▶sub structure_interface {
Subroutine structure_interface: called CC=6 SCAR=17.9
Pod documented
1507 51 my ($info, %opt) = _args('structure_interface', @_);
1508 51 _check_info($info, 'structure_interface');
1509 51 ▶ if (!%opt && $info->{features}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %opt and $info->{"features"}) 6 45 51
Condition100%3/3
not %opt and $info->{"features"}
!ll&&!rl&&r
4416
MC/DC100%2/2
not %opt and $info->{"features"}
not %opt $info->{"features"}
Truth table100%3/3
not(A) and B
A= not %optB= $info->{"features"}
ABresult
0X0
100
111
1510 6 ▶ return $info->{features}{interface} if $info->{features}{interface};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"features"}{"interface"} 3 3 6
1511 3 die 'structure_interface: this structure has no two partners to split: '
1512 . 'name them with partners => [ [...], [...] ]';
1513 }
1514 45 my $o = _feature_options(\%opt, 'structure_interface', \@IFACE_OPT);
1515 34 $o->{$_} = 0 for qw(sasa pi_stacking disulfides base_pairs base_stacks shape
1516 dihedrals contacts exposure hbonds secondary store);
1517 34 $o->{interface} = 1;
1518 # the interface's own surface, which sasa => 0 would otherwise switch off
1519 # with the whole structure's
1520 34 $o->{interface_sasa} = 1;
1521 34 ▶ my $sides = _partners($info, $o->{partners}, 'structure_interface')
Branch: 1 branch
BranchTrueFalseTotal
my $sides = _partners($info, $o->{"partners"}, "structure_interface") or die "structure_interface: this structure has no two partners to split: name them with partners => [ [...], [...] ]" 22 2 24
1522 or die 'structure_interface: this structure has no two partners to split: '
1523 . 'name them with partners => [ [...], [...] ]';
1524 22 $o->{sides} = [ $sides->{residues}[0], $sides->{residues}[1] ];
1525 22 my $f = _features($info, $o, 'structure_interface');
1526 22 return _finish_interface($info, $f, $o, $sides);
1527 }
1528  
1529 # structure_sasa($info, %opt) -- the solvent-accessible surface, and nothing else.
1530 35 ▶sub structure_sasa {
Subroutine structure_sasa: called CC=3 SCAR=11.0
Pod documented
1531 35 my ($info, %opt) = _args('structure_sasa', @_);
1532 35 _check_info($info, 'structure_sasa');
1533 32 ▶ return $info->{features}{sasa} if !%opt && $info->{features};
Branch: 1 branch
BranchTrueFalseTotal
if not %opt and $info->{"features"} 13 19 32
Condition100%3/3
not %opt and $info->{"features"}
!ll&&!rl&&r
10913
MC/DC100%2/2
not %opt and $info->{"features"}
not %opt $info->{"features"}
Truth table100%3/3
not(A) and B
A= not %optB= $info->{"features"}
ABresult
0X0
100
111
1534 19 my $o = _feature_options(\%opt, 'structure_sasa', \@SASA_OPT);
1535 14 $o->{sasa} = 1;
1536 14 $o->{pi_stacking} = 0;
1537 14 $o->{disulfides} = 0;
1538 14 $o->{base_pairs} = 0;
1539 14 $o->{base_stacks} = 0;
1540 14 $o->{shape} = 0;
1541 14 $o->{dihedrals} = 0;
1542 14 $o->{contacts} = 0;
1543 14 $o->{exposure} = 0;
1544 14 $o->{hbonds} = 0;
1545 14 $o->{secondary} = 0;
1546 14 return _features($info, $o, 'structure_sasa')->{sasa};
1547 }
1548  
1549 # structure_pi_stacking($info, %opt) -- the stacked pairs of aromatic rings.
1550 14 ▶sub structure_pi_stacking {
Subroutine structure_pi_stacking: called CC=3 SCAR=11.0
Pod documented
1551 14 my ($info, %opt) = _args('structure_pi_stacking', @_);
1552 14 _check_info($info, 'structure_pi_stacking');
1553 11 ▶ return $info->{features}{pi_stacking} if !%opt && $info->{features};
Branch: 1 branch
BranchTrueFalseTotal
if not %opt and $info->{"features"} 2 9 11
Condition100%3/3
not %opt and $info->{"features"}
!ll&&!rl&&r
722
MC/DC100%2/2
not %opt and $info->{"features"}
not %opt $info->{"features"}
Truth table100%3/3
not(A) and B
A= not %optB= $info->{"features"}
ABresult
0X0
100
111
1554 9 my $o = _feature_options(\%opt, 'structure_pi_stacking', \@PI_OPT);
1555 6 $o->{sasa} = 0;
1556 6 $o->{pi_stacking} = 1;
1557 6 $o->{disulfides} = 0;
1558 6 $o->{base_pairs} = 0;
1559 6 $o->{base_stacks} = 0;
1560 6 $o->{shape} = 0;
1561 6 $o->{dihedrals} = 0;
1562 6 $o->{contacts} = 0;
1563 6 $o->{exposure} = 0;
1564 6 $o->{hbonds} = 0;
1565 6 $o->{secondary} = 0;
1566 6 $o->{store} = 0;
1567 6 return _features($info, $o, 'structure_pi_stacking')->{pi_stacking};
1568 }
1569  
1570 # structure_contacts($info, %opt) -- which residues touch which.
1571 7 ▶sub structure_contacts {
Subroutine structure_contacts: called CC=3 SCAR=11.0
Pod documented
1572 7 my ($info, %opt) = _args('structure_contacts', @_);
1573 7 _check_info($info, 'structure_contacts');
1574 4 ▶ return $info->{features}{contacts} if !%opt && $info->{features};
Branch: 1 branch
BranchTrueFalseTotal
if not %opt and $info->{"features"} 2 2 4
Condition100%3/3
not %opt and $info->{"features"}
!ll&&!rl&&r
112
MC/DC100%2/2
not %opt and $info->{"features"}
not %opt $info->{"features"}
Truth table100%3/3
not(A) and B
A= not %optB= $info->{"features"}
ABresult
0X0
100
111
1575 2 my $o = _feature_options(\%opt, 'structure_contacts', \@CONT_OPT);
1576 1 $o->{sasa} = 0;
1577 1 $o->{pi_stacking} = 0;
1578 1 $o->{disulfides} = 0;
1579 1 $o->{base_pairs} = 0;
1580 1 $o->{base_stacks} = 0;
1581 1 $o->{shape} = 0;
1582 1 $o->{dihedrals} = 0;
1583 1 $o->{contacts} = 1;
1584 1 $o->{exposure} = 0;
1585 1 $o->{hbonds} = 0;
1586 1 $o->{secondary} = 0;
1587 1 return _features($info, $o, 'structure_contacts')->{contacts};
1588 }
1589  
1590 # structure_hbonds($info, %opt) -- the backbone hydrogen bonds.
1591 10 ▶sub structure_hbonds {
Subroutine structure_hbonds: called CC=4 SCAR=13.9
Pod documented
1592 10 my ($info, %opt) = _args('structure_hbonds', @_);
1593 10 _check_info($info, 'structure_hbonds');
1594 7 ▶ return $info->{features}{hbonds} if !%opt && $info->{features};
Branch: 1 branch
BranchTrueFalseTotal
if not %opt and $info->{"features"} 3 4 7
Condition100%3/3
not %opt and $info->{"features"}
!ll&&!rl&&r
223
MC/DC100%2/2
not %opt and $info->{"features"}
not %opt $info->{"features"}
Truth table100%3/3
not(A) and B
A= not %optB= $info->{"features"}
ABresult
0X0
100
111
1595 4 my $o = _feature_options(\%opt, 'structure_hbonds', \@HB_OPT);
1596 3 $o->{$_} = 0 for qw(sasa pi_stacking disulfides base_pairs base_stacks shape
1597 dihedrals contacts exposure secondary);
1598 3 $o->{hbonds} = 1;
1599 3 return _features($info, $o, 'structure_hbonds')->{hbonds};
1600 }
1601  
1602 # structure_dssp($info) -- the secondary structure, chain by chain and letter by
1603 # letter. There is nothing to tune, so there are no options: DSSP is the
1604 # hydrogen bonds and the two constants Kabsch and Sander chose for them.
1605 50 ▶sub structure_dssp {
Subroutine structure_dssp: called CC=4 SCAR=13.9
Pod documented
1606 50 my ($info, %opt) = _args('structure_dssp', @_);
1607 50 _check_info($info, 'structure_dssp');
1608 47 ▶ return $info->{features}{dssp} if !%opt && $info->{features};
Branch: 1 branch
BranchTrueFalseTotal
if not %opt and $info->{"features"} 39 8 47
Condition100%3/3
not %opt and $info->{"features"}
!ll&&!rl&&r
2639
MC/DC100%2/2
not %opt and $info->{"features"}
not %opt $info->{"features"}
Truth table100%3/3
not(A) and B
A= not %optB= $info->{"features"}
ABresult
0X0
100
111
1609 8 my $o = _feature_options(\%opt, 'structure_dssp', []);
1610 6 $o->{$_} = 0 for qw(sasa pi_stacking disulfides base_pairs base_stacks shape
1611 dihedrals contacts exposure hbonds);
1612 6 $o->{secondary} = 1;
1613 6 return _features($info, $o, 'structure_dssp')->{dssp};
1614 }
1615  
1616 # structure_disulfides($info, %opt) -- the SG-SG pairs close enough to be bonded.
1617 11 ▶sub structure_disulfides {
Subroutine structure_disulfides: called CC=3 SCAR=11.0
Pod documented
1618 11 my ($info, %opt) = _args('structure_disulfides', @_);
1619 11 _check_info($info, 'structure_disulfides');
1620 8 ▶ return $info->{features}{disulfides} if !%opt && $info->{features};
Branch: 1 branch
BranchTrueFalseTotal
if not %opt and $info->{"features"} 3 5 8
Condition100%3/3
not %opt and $info->{"features"}
!ll&&!rl&&r
413
MC/DC100%2/2
not %opt and $info->{"features"}
not %opt $info->{"features"}
Truth table100%3/3
not(A) and B
A= not %optB= $info->{"features"}
ABresult
0X0
100
111
1621 5 my $o = _feature_options(\%opt, 'structure_disulfides', \@SS_OPT);
1622 4 $o->{sasa} = 0;
1623 4 $o->{pi_stacking} = 0;
1624 4 $o->{disulfides} = 1;
1625 4 $o->{base_pairs} = 0;
1626 4 $o->{base_stacks} = 0;
1627 4 $o->{shape} = 0;
1628 4 $o->{dihedrals} = 0;
1629 4 $o->{contacts} = 0;
1630 4 $o->{exposure} = 0;
1631 4 $o->{hbonds} = 0;
1632 4 $o->{secondary} = 0;
1633 4 return _features($info, $o, 'structure_disulfides')->{disulfides};
1634 }
1635  
1636 # structure_base_pairs($info, %opt) -- the Watson-Crick and wobble base pairs.
1637 37 ▶sub structure_base_pairs {
Subroutine structure_base_pairs: called CC=3 SCAR=11.0
Pod documented
1638 37 my ($info, %opt) = _args('structure_base_pairs', @_);
1639 37 _check_info($info, 'structure_base_pairs');
1640 37 ▶ return $info->{features}{base_pairs} if !%opt && $info->{features};
Branch: 1 branch
BranchTrueFalseTotal
if not %opt and $info->{"features"} 15 22 37
Condition100%3/3
not %opt and $info->{"features"}
!ll&&!rl&&r
19315
MC/DC100%2/2
not %opt and $info->{"features"}
not %opt $info->{"features"}
Truth table100%3/3
not(A) and B
A= not %optB= $info->{"features"}
ABresult
0X0
100
111
1641 22 my $o = _feature_options(\%opt, 'structure_base_pairs', \@BP_OPT);
1642 21 $o->{sasa} = 0;
1643 21 $o->{pi_stacking} = 0;
1644 21 $o->{disulfides} = 0;
1645 21 $o->{base_pairs} = 1;
1646 21 $o->{base_stacks} = 0;
1647 21 $o->{shape} = 0;
1648 21 $o->{dihedrals} = 0;
1649 21 $o->{contacts} = 0;
1650 21 $o->{exposure} = 0;
1651 21 $o->{hbonds} = 0;
1652 21 $o->{secondary} = 0;
1653 21 return _features($info, $o, 'structure_base_pairs')->{base_pairs};
1654 }
1655  
1656 # structure_base_stacks($info, %opt) -- how stacked every nearby pair of bases is.
1657 31 ▶sub structure_base_stacks {
Subroutine structure_base_stacks: called CC=3 SCAR=11.0
Pod documented
1658 31 my ($info, %opt) = _args('structure_base_stacks', @_);
1659 31 _check_info($info, 'structure_base_stacks');
1660 27 ▶ return $info->{features}{base_stacks} if !%opt && $info->{features};
Branch: 1 branch
BranchTrueFalseTotal
if not %opt and $info->{"features"} 12 15 27
Condition100%3/3
not %opt and $info->{"features"}
!ll&&!rl&&r
12312
MC/DC100%2/2
not %opt and $info->{"features"}
not %opt $info->{"features"}
Truth table100%3/3
not(A) and B
A= not %optB= $info->{"features"}
ABresult
0X0
100
111
1661 15 my $o = _feature_options(\%opt, 'structure_base_stacks', \@BS_OPT);
1662 10 $o->{sasa} = 0;
1663 10 $o->{pi_stacking} = 0;
1664 10 $o->{disulfides} = 0;
1665 10 $o->{base_pairs} = 0;
1666 10 $o->{base_stacks} = 1;
1667 10 $o->{shape} = 0;
1668 10 $o->{dihedrals} = 0;
1669 10 $o->{contacts} = 0;
1670 10 $o->{exposure} = 0;
1671 10 $o->{hbonds} = 0;
1672 10 $o->{secondary} = 0;
1673 10 return _features($info, $o, 'structure_base_stacks')->{base_stacks};
1674 }
1675  
1676 #
1677 # Comparing structures
1678 #
1679 # Everything above answers a question about one structure. structure_rmsd()
1680 # is the one that takes two, or twenty: how far apart are these copies of the
1681 # same molecule? The work is in the XS -- pairing the atoms, the superposition
1682 # and the deviation all touch every atom, and an NMR ensemble asks for them
1683 # once per pair of models -- and what is here is deciding what is being
1684 # compared with what.
1685 #
1686 # An argument is a file name or a structure already read, in any mix, and a
1687 # structure read with model => 'all' counts as one per model: that is what
1688 # makes the ensemble case a single call. Two things to compare give the
1689 # number; more than two give the matrix, because with three structures there
1690 # is no one RMSD to hand back.
1691 #
1692 24 my %RMSD_DEFAULT = (
1693 fit => 1, # superpose first; 0 measures the two where they lie
1694 select => 'all', # 'all', 'heavy', 'backbone' or 'ca'
1695 match => 'key', # 'key' = chain, residue and atom name; 'order' = the nth of each
1696 min_atoms => 3, # fewer atoms in common than this and there is no answer
1697 detail => 0, # the whole hash rather than the one number
1698 chain_map => undef, # hashref: what a chain of the second and later structures
1699 # is called in the first
1700 );
1701  
1702 # The options that are about reading a file rather than about the comparison.
1703 # They are structure_info()'s own and mean the same thing here; an argument
1704 # that is already a structure was read without them, so chains is applied to it
1705 # as a filter instead and the rest cannot be.
1706 24 my @RMSD_READ = qw(model altloc hydrogens waters hetatm chains format);
1707  
1708 # structure_rmsd($a, $b, %opt) -- the RMSD of two structures.
1709 # structure_rmsd($a, $b, $c, ..., %opt) -- the matrix of every pair.
1710 # structure_rmsd($ensemble, %opt) -- the matrix over one file's models.
1711 86 ▶sub structure_rmsd {
Subroutine structure_rmsd: called CC=43 SCAR=37.6
Pod documented
1712 86 my @in;
1713 # The structures come first and the options after them, and what separates
1714 # the two is that a structure is a reference or the name of a file that
1715 # exists. A name that does not exist is the mistake it looks like and is
1716 # said to be one below, rather than being read as the first half of an
1717 # option pair and reported as an unknown option.
1718 86 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 208 15 223
1719 208 ▶ last unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 208 208
1720 208 ▶ if (ref $_[0]) { push @in, shift; next }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) 49 159 208
1721 159 ▶ last unless -e $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_[0] 71 88 159
1722 88 push @in, shift;
1723 }
1724 86 ▶ die 'structure_rmsd: nothing to compare; give two structures, two file '
Branch: 1 branch
BranchTrueFalseTotal
unless @in 2 84 86
1725 . 'names, or one file read with model => \'all\'' unless @in;
1726 84 ▶ die "structure_rmsd: '$_[0]' is not a file that exists, and the options "
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 2 82 84
1727 . 'after the structures come in name => value pairs' if @_ % 2;
1728 82 my %opt = @_;
1729 82 for my $k (sort keys %opt) {
1730 die "structure_rmsd: unknown option '$k'; known options are: "
1731 . join(', ', sort (keys %RMSD_DEFAULT, @RMSD_READ))
1732 108 ▶ unless exists $RMSD_DEFAULT{$k} || grep { $_ eq $k } @RMSD_READ;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $RMSD_DEFAULT{$k} or grep {$_ eq $k;} @RMSD_READ 2 106 108
Condition100%3/3
exists $RMSD_DEFAULT{$k} or grep {$_ eq $k;} @RMSD_READ
l!l&&r!l&&!r
71352
MC/DC100%2/2
exists $RMSD_DEFAULT{$k} or grep {$_ eq $k;} @RMSD_READ
exists $RMSD_DEFAULT{$k} grep {$_ eq $k;} @RMSD_READ
Truth table100%3/3
A or B
A= exists $RMSD_DEFAULT{$k}B= grep {$_ eq $k;} @RMSD_READ
ABresult
1X1
011
000
1733 }
1734 71 my %o = (%RMSD_DEFAULT, map { $_ => $opt{$_} }
1735 80 grep { exists $RMSD_DEFAULT{$_} } keys %opt);
1736 80 my %read = map { $_ => $opt{$_} } grep { exists $opt{$_} } @RMSD_READ;
1737  
1738 die "structure_rmsd: select must be 'all', 'heavy', 'backbone' or 'ca', not '$o{select}'"
1739 80 ▶ unless grep { $_ eq $o{select} } qw(all heavy backbone ca);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $o{"select"};} "all", "heavy", "backbone", "ca" 1 79 80
1740 die "structure_rmsd: match must be 'key' or 'order', not '$o{match}'"
1741 79 ▶ unless $o{match} eq 'key' || $o{match} eq 'order';
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"match"} eq "key" or $o{"match"} eq "order" 1 78 79
Condition100%3/3
$o{"match"} eq "key" or $o{"match"} eq "order"
l!l&&r!l&&!r
7531
MC/DC100%2/2
$o{"match"} eq "key" or $o{"match"} eq "order"
$o{"match"} eq "key" $o{"match"} eq "order"
Truth table100%3/3
A or B
A= $o{"match"} eq "key"B= $o{"match"} eq "order"
ABresult
1X1
011
000
1742 die "structure_rmsd: min_atoms must be a whole number of at least 1, not '$o{min_atoms}'"
1743 78 ▶ unless $o{min_atoms} =~ /\A[0-9]+\z/ && $o{min_atoms} >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"min_atoms"} =~ /\A[0-9]+\z/ and $o{"min_atoms"} >= 1 2 76 78
Condition100%3/3
$o{"min_atoms"} =~ /\A[0-9]+\z/ and $o{"min_atoms"} >= 1
!ll&&!rl&&r
1176
MC/DC100%2/2
$o{"min_atoms"} =~ /\A[0-9]+\z/ and $o{"min_atoms"} >= 1
$o{"min_atoms"} =~ /\A[0-9]+\z/ $o{"min_atoms"} >= 1
Truth table100%3/3
A and B
A= $o{"min_atoms"} =~ /\A[0-9]+\z/B= $o{"min_atoms"} >= 1
ABresult
0X0
100
111
1744 76 ▶ if (defined $o{chain_map}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o{"chain_map"}) 5 71 76
1745 die 'structure_rmsd: chain_map must be a hash reference'
1746 5 ▶ unless (reftype($o{chain_map}) || '') eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::reftype($o{"chain_map"}) || "") eq "HASH" 1 4 5
Condition50%1/2
builtin::reftype($o{'chain_map'}) || ''
l!l
50
MC/DC0%0/1
builtin::reftype($o{'chain_map'}) || ''
builtin::reftype($o{'chain_map'})
Truth table50%1/2
A
A= builtin::reftype($o{'chain_map'})
Aresult
11
00
1747 }
1748 75 my $keep;
1749 75 ▶ if (defined $read{chains}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $read{"chains"}) 2 73 75
1750 die 'structure_rmsd: chains must be an array reference'
1751 2 ▶ unless (reftype($read{chains}) || '') eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::reftype($read{"chains"}) || "") eq "ARRAY" 1 1 2
Condition100%2/2
builtin::reftype($read{'chains'}) || ''
l!l
11
MC/DC100%1/1
builtin::reftype($read{'chains'}) || ''
builtin::reftype($read{'chains'})
Truth table100%2/2
A
A= builtin::reftype($read{'chains'})
Aresult
11
00
1752 1 ▶ die 'structure_rmsd: chains is empty' unless @{ $read{chains} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$read{"chains"};} 0 1 1
1753 1 $keep = { map { $_ => 1 } @{ $read{chains} } };
1754 }
1755  
1756 74 my (@sets, @labels);
1757 74 my $nth = 0;
1758 74 my $most_models = 0; # for the message when there turns out to be nothing to compare
1759 74 for my $thing (@in) {
1760 118 my ($info, $name);
1761 118 $nth++;
1762 118 ▶ if (ref $thing) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing) { } 47 71 118
1763 47 _check_info($thing, 'structure_rmsd');
1764 46 $info = $thing;
1765 $name = defined $info->{file} ? $info->{file}
1766 : defined $info->{id} && length $info->{id} ? $info->{id}
1767 46 ▶ : "structure $nth";
Branch: 2 branches
BranchTrueFalseTotal
defined $info->{'file'} ? : 22 24 46
defined $info->{'id'} && length $info->{'id'} ? : 0 24 24
Condition33%1/3
defined $info->{"id"} and length $info->{"id"}
!ll&&!rl&&r
2400
MC/DC0%0/2
defined $info->{"id"} and length $info->{"id"}
defined $info->{"id"} length $info->{"id"}
Truth table33%1/3
A and B
A= defined $info->{"id"}B= length $info->{"id"}
ABresult
0X0
100
111
1768 }
1769 else {
1770 # meta => 0 and features => 0: the header records and the physical
1771 # properties are the expensive half of a read and none of this
1772 # looks at either. atoms => 1 is the default and is said out loud
1773 # because without the atom hashes there is nothing to measure.
1774 71 $info = structure_info($thing, %read,
1775 atoms => 1, features => 0, meta => 0);
1776 71 $name = $thing;
1777 }
1778 $most_models = $info->{n_models}
1779 117 ▶ if ($info->{n_models} || 0) > $most_models;
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"n_models"} || 0) > $most_models 70 47 117
Condition100%2/2
$info->{'n_models'} || 0
l!l
1098
MC/DC100%1/1
$info->{'n_models'} || 0
$info->{'n_models'}
Truth table100%2/2
A
A= $info->{'n_models'}
Aresult
11
00
1780 # read with model => 'all', an ensemble is one structure per model, and
1781 # that is the whole of what makes structure_rmsd($nmr, model => 'all')
1782 # the pairwise matrix over the models
1783 my @models = $info->{models}
1784 106 ? map { [ $_, $info->{models}{$_} ] }
1785 128 sort { $a <=> $b } keys %{ $info->{models} }
1786 : ([ undef, { chains => $info->{chains},
1787 117 ▶ chain_order => $info->{chain_order} } ]);
Branch: 1 branch
BranchTrueFalseTotal
$info->{'models'} ? : 27 90 117
1788 117 for my $m (@models) {
1789 196 my ($num, $set) = @$m;
1790 196 ▶ push @labels, defined $num ? "$name model $num" : $name;
Branch: 1 branch
BranchTrueFalseTotal
defined $num ? : 106 90 196
1791 push @sets, _rmsd_set($set, $keep,
1792 196 ▶ ($nth > 1 ? $o{chain_map} : undef));
Branch: 1 branch
BranchTrueFalseTotal
$nth > 1 ? : 44 152 196
1793 }
1794 }
1795 # One structure is not a comparison. When it is an ensemble read at one
1796 # model, though, the caller almost certainly meant the other thing, and
1797 # saying so is more use than saying it wanted two.
1798 72 ▶ if (@sets < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sets < 2) 3 69 72
1799 3 ▶ die 'structure_rmsd: only one structure to compare'
Branch: 1 branch
BranchTrueFalseTotal
$most_models > 1 ? : 2 1 3
1800 . ($most_models > 1
1801 ? "; it has $most_models models, and reading it with "
1802 . "model => 'all' is what makes them a set to compare"
1803 : '');
1804 }
1805  
1806 69 ▶ my $r = _rmsd(\@sets, { %o, transform => (@sets == 2 && $o{detail}) ? 1 : 0 });
Branch: 1 branch
BranchTrueFalseTotal
@sets == 2 && $o{'detail'} ? : 23 46 69
Condition100%3/3
@sets == 2 and $o{"detail"}
!ll&&!rl&&r
281823
MC/DC100%2/2
@sets == 2 and $o{"detail"}
@sets == 2 $o{"detail"}
Truth table100%3/3
A and B
A= @sets == 2B= $o{"detail"}
ABresult
0X0
100
111
1807 68 ▶ return $r->{rmsd}[0][1] if @sets == 2 && !$o{detail};
Branch: 1 branch
BranchTrueFalseTotal
if @sets == 2 and not $o{"detail"} 17 51 68
Condition100%3/3
@sets == 2 and not $o{"detail"}
!ll&&!rl&&r
282317
MC/DC100%2/2
@sets == 2 and not $o{"detail"}
@sets == 2 not $o{"detail"}
Truth table100%3/3
A and not(B)
A= @sets == 2B= not $o{"detail"}
ABresult
0X0
100
111
1808 my %out = (
1809 labels => \@labels,
1810 n_atoms => $r->{n_atoms},
1811 fit => $o{fit} ? 1 : 0,
1812 select => $o{select},
1813 match => $o{match},
1814 51 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$o{'fit'} ? : 49 2 51
1815 51 ▶ if (@sets == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sets == 2) { } 23 28 51
1816 # two structures have one RMSD and one count, and handing back a 2x2
1817 # matrix of which three cells are known in advance would be a puzzle
1818 23 $out{rmsd} = $r->{rmsd}[0][1];
1819 23 $out{n} = $r->{n}[0][1];
1820 23 ▶ $out{rotation} = $r->{rotation} if $r->{rotation};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"rotation"} 18 5 23
1821 23 ▶ $out{translation} = $r->{translation} if $r->{translation};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"translation"} 18 5 23
1822 }
1823 else {
1824 28 $out{rmsd} = $r->{rmsd};
1825 28 $out{n} = $r->{n};
1826 }
1827 51 return \%out;
1828 }
1829  
1830 # One structure, or one model of one, as the XS wants it: a hash with chains
1831 # and chain_order. chains => filters it, chain_map => renames it.
1832 #
1833 # Both are done by building a new chain_order and, for the rename, a shallow
1834 # copy of each chain hash under its new name. Nothing below this writes to a
1835 # chain and the residues are shared, so the copy is a few dozen scalars per
1836 # chain and no coordinates at all.
1837 196 ▶sub _rmsd_set {
Subroutine _rmsd_set: called CC=7 SCAR=19.5
1838 196 my ($set, $keep, $map) = @_;
1839 196 my @order = @{ $set->{chain_order} };
1840 196 ▶ @order = grep { $keep->{$_} } @order if $keep;
Branch: 1 branch
BranchTrueFalseTotal
if $keep 2 194 196
1841 196 ▶ return { chains => $set->{chains}, chain_order => \@order }
Branch: 1 branch
BranchTrueFalseTotal
unless $map and %$map 193 3 196
Condition66%2/3
$map and %$map
!ll&&!rl&&r
19303
MC/DC50%1/2
$map and %$map
$map %$map
Truth table66%2/3
A and B
A= $mapB= %$map
ABresult
0X0
100
111
1842 unless $map && %$map;
1843 3 my (%chains, %from, @renamed);
1844 3 for my $cid (@order) {
1845 4 ▶ my $to = exists $map->{$cid} ? $map->{$cid} : $cid;
Branch: 1 branch
BranchTrueFalseTotal
exists $map->{$cid} ? : 4 0 4
1846 die "structure_rmsd: chain_map puts both '$from{$to}' and '$cid' "
1847 . "under '$to'; two chains cannot become one chain"
1848 4 ▶ if exists $chains{$to};
Branch: 1 branch
BranchTrueFalseTotal
if exists $chains{$to} 1 3 4
1849 3 $chains{$to} = { %{ $set->{chains}{$cid} }, id => $to };
1850 3 $from{$to} = $cid;
1851 3 push @renamed, $to;
1852 }
1853 2 return { chains => \%chains, chain_order => \@renamed };
1854 }
1855  
1856 # The two sequence-level numbers, per protein chain and over the structure.
1857 #
1858 # Over the observed sequence -- the residues that are actually in the file --
1859 # rather than over SEQRES, because these are properties of the model in front of
1860 # the caller and a residue nobody could see has no coordinates to be a property
1861 # of. chain_sequence($info, $chain, 'seqres') is there for anyone who wants the
1862 # other one.
1863 604 ▶sub _sequence_features {
Subroutine _sequence_features: called CC=26 SCAR=32.6
1864 604 my ($info, $f, $store) = @_;
1865 604 my ($sum, $scored, $arom, $len) = (0, 0, 0, 0);
1866 604 my ($gc, $pur, $counted, $nlen) = (0, 0, 0, 0);
1867 604 my ($charge, $n_charged) = (0, 0);
1868 604 my %bases;
1869 604 for my $cid (@{ $info->{chain_order} }) {
1870 790 my $c = $info->{chains}{$cid};
1871 790 ▶ my $type = $c->{type} || '';
Condition100%2/2
$c->{'type'} || ''
l!l
7891
MC/DC100%1/1
$c->{'type'} || ''
$c->{'type'}
Truth table100%2/2
A
A= $c->{'type'}
Aresult
11
00
1872 790 my $seq = $c->{sequence};
1873 790 ▶ next unless defined $seq && length $seq;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seq and length $seq 47 743 790
Condition100%3/3
defined $seq and length $seq
!ll&&!rl&&r
146743
MC/DC100%2/2
defined $seq and length $seq
defined $seq length $seq
Truth table100%3/3
A and B
A= defined $seqB= length $seq
ABresult
0X0
100
111
1874 743 ▶ if ($type eq 'dna' || $type eq 'rna') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "dna" or $type eq "rna") 272 471 743
Condition100%3/3
$type eq "dna" or $type eq "rna"
l!l&&r!l&&!r
20666471
MC/DC100%2/2
$type eq "dna" or $type eq "rna"
$type eq "dna" $type eq "rna"
Truth table100%3/3
A or B
A= $type eq "dna"B= $type eq "rna"
ABresult
1X1
011
000
1875 272 my ($cgc, $cpur, $cn, %cb) = (0, 0, 0);
1876 272 for my $b (split //, uc $seq) {
1877 1342 $cb{$b}++;
1878 1342 ▶ next unless $BASE{$b};
Branch: 1 branch
BranchTrueFalseTotal
unless $BASE{$b} 0 1342 1342
1879 1342 ▶ $cgc++ if $GC{$b};
Branch: 1 branch
BranchTrueFalseTotal
if $GC{$b} 704 638 1342
1880 1342 ▶ $cpur++ if $PURINE{$b};
Branch: 1 branch
BranchTrueFalseTotal
if $PURINE{$b} 719 623 1342
1881 1342 $cn++;
1882 }
1883 272 $gc += $cgc;
1884 272 $pur += $cpur;
1885 272 $counted += $cn;
1886 272 $nlen += length $seq;
1887 272 $bases{$_} += $cb{$_} for keys %cb;
1888 272 ▶ next unless $store;
Branch: 1 branch
BranchTrueFalseTotal
unless $store 0 272 272
1889 272 $c->{base_counts} = \%cb;
1890 272 ▶ if ($cn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cn) 272 0 272
1891 272 $c->{gc_fraction} = $cgc / $cn;
1892 272 $c->{purine_fraction} = $cpur / $cn;
1893 }
1894 272 next;
1895 }
1896 471 ▶ next unless $type eq 'protein';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "protein" 0 471 471
1897 471 my ($csum, $cn, $ca) = (0, 0, 0);
1898 471 for my $aa (split //, uc $seq) {
1899 7526 ▶ $ca++ if $AROMATIC{$aa};
Branch: 1 branch
BranchTrueFalseTotal
if $AROMATIC{$aa} 790 6736 7526
1900 7526 ▶ next unless exists $KD{$aa};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $KD{$aa} 1 7525 7526
1901 7525 $csum += $KD{$aa};
1902 7525 $cn++;
1903 }
1904 471 $sum += $csum;
1905 471 $scored += $cn;
1906 471 $arom += $ca;
1907 471 $len += length $seq;
1908 471 my ($q, $pi) = _charge_and_pi($seq);
1909 471 $charge += $q;
1910 471 $n_charged++;
1911 471 ▶ next unless $store;
Branch: 1 branch
BranchTrueFalseTotal
unless $store 5 466 471
1912 466 ▶ $c->{hydropathy} = $csum / $cn if $cn;
Branch: 1 branch
BranchTrueFalseTotal
if $cn 465 1 466
1913 466 $c->{aromatic_fraction} = $ca / length $seq;
1914 466 $c->{charge} = $q;
1915 466 $c->{isoelectric_point} = $pi;
1916 }
1917 604 ▶ $f->{hydropathy} = $sum / $scored if $scored;
Branch: 1 branch
BranchTrueFalseTotal
if $scored 445 159 604
1918 604 ▶ $f->{aromatic_fraction} = $arom / $len if $len;
Branch: 1 branch
BranchTrueFalseTotal
if $len 446 158 604
1919 604 $f->{n_aromatic} = $arom;
1920 604 $f->{sequence_length} = $len;
1921 # the sum of the protein chains' net charges at pH 7, each chain its own
1922 # molecule with its own two termini; there is no isoelectric point of the
1923 # whole, since a complex does not focus as one sequence
1924 604 ▶ $f->{charge} = $charge if $n_charged;
Branch: 1 branch
BranchTrueFalseTotal
if $n_charged 446 158 604
1925 # the nucleic half, and only when there is one: a structure with no nucleic
1926 # acid in it gets no gc_fraction rather than a zero that would read as a
1927 # chain of nothing but A and T
1928 604 ▶ if ($nlen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nlen) 250 354 604
1929 250 ▶ $f->{gc_fraction} = $gc / $counted if $counted;
Branch: 1 branch
BranchTrueFalseTotal
if $counted 250 0 250
1930 250 ▶ $f->{purine_fraction} = $pur / $counted if $counted;
Branch: 1 branch
BranchTrueFalseTotal
if $counted 250 0 250
1931 250 $f->{n_gc} = $gc;
1932 250 $f->{nucleotide_length} = $nlen;
1933 250 $f->{base_counts} = \%bases;
1934 }
1935 604 return $f;
1936 }
1937  
1938 # _partners($info, $spec, $who) -- the two sides of the interface, as residues.
1939 #
1940 # $spec is what the caller wrote -- two entries, each a chain id, a ligand key
1941 # as structure_ligands() writes it (NAME_CHAIN_NUMBER), or a list of those --
1942 # or undef, and then the split is worked out:
1943 #
1944 # two or more polymer chains the shortest against all the others, which is
1945 # a peptide against its receptor; a tie goes to
1946 # the chain later in the file
1947 # one polymer chain the ligand with the most heavy atoms against
1948 # it; a tie goes to the one earlier in the file
1949 # neither no interface, and undef back
1950 #
1951 # which is a guess, and says so in the documentation: an antibody's two chains
1952 # against an antigen, or a drug against a protein that also holds a glycerol
1953 # molecule bigger than it, is a structure whose partners have to be named.
1954 #
1955 # A chain named as a partner is its amino acids and nucleotides, modified ones
1956 # included, and nothing else in it: a ligand, an ion or a water that happens to
1957 # carry the chain's letter is not part of the polymer. A cap peptide-bonded
1958 # to the chain is part of it already; a cofactor that should be is named by its
1959 # key alongside the chain, and a residue named twice, in either way, is on its
1960 # side once. PRODIGY takes the chain without its HETATM residues at all, which
1961 # is the same thing for the twenty standard residues it accepts.
1962 #
1963 # Returns { partners => [ [names], [names] ], residues => [ [hashes], [hashes] ] }.
1964 637 ▶sub _partners {
Subroutine _partners: called CC=35 SCAR=35.6
1965 637 my ($info, $spec, $who) = @_;
1966 637 ▶ my $chains = $info->{chains} || {};
Condition50%1/2
$info->{'chains'} || {}
l!l
6370
MC/DC0%0/1
$info->{'chains'} || {}
$info->{'chains'}
Truth table50%1/2
A
A= $info->{'chains'}
Aresult
11
00
1967 637 ▶ my @order = @{ $info->{chain_order} || [] };
Condition100%2/2
$info->{'chain_order'} || []
l!l
6352
MC/DC100%1/1
$info->{'chain_order'} || []
$info->{'chain_order'}
Truth table100%2/2
A
A= $info->{'chain_order'}
Aresult
11
00
1968 637 my %poly_type = (amino_acid => 1, nucleotide => 1);
1969 # A chain's amino acids and nucleotides, and the residues the table does
1970 # not know that are peptide-bonded into them: an ACE or NH2 cap, or a
1971 # non-standard amino acid such as 3fe7's PM3, is part of the peptide it
1972 # caps, and a drug that only shares the chain's letter is not. Bonded is
1973 # gemmi's test, as asm_bonded() in the XS applies it, asked of each such residue and the
1974 # residues either side of it in the chain until nothing more joins.
1975 #
1976 # Worked out once per chain and kept: the split below asks it of the same
1977 # chain several times over, each time walking the chain and testing bonds.
1978 637 my %polymer_of;
1979 2002 ▶ my $polymer = sub {
Subroutine __ANON__: called CC=15 SCAR=27.1
1980 2002 my ($cid) = @_;
1981 2002 ▶ return $polymer_of{$cid} if $polymer_of{$cid};
Branch: 1 branch
BranchTrueFalseTotal
if $polymer_of{$cid} 1167 835 2002
1982 835 my $c = $chains->{$cid};
1983 835 my @res = map { $c->{residues}{$_} } @{ $c->{residue_order} };
1984 835 ▶ my @in = map { $poly_type{ $_->{type} || '' } ? 1 : 0 } @res;
Branch: 1 branch
BranchTrueFalseTotal
$poly_type{$_->{'type'} or ''} ? : 10367 5445 15812
Condition100%2/2
$_->{'type'} || ''
l!l
158111
MC/DC100%1/1
$_->{'type'} || ''
$_->{'type'}
Truth table100%2/2
A
A= $_->{'type'}
Aresult
11
00
1985 835 my $grew = 1;
1986 835 ▶ while ($grew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grew) 851 835 1686
1987 851 $grew = 0;
1988 851 for my $k (0 .. $#res) {
1989 15958 ▶ next if $in[$k] || ($res[$k]{type} || '') ne 'ligand';
Branch: 1 branch
BranchTrueFalseTotal
if $in[$k] or ($res[$k]{"type"} || "") ne "ligand" 15775 183 15958
Condition100%5/5
$in[$k] or ($res[$k]{"type"} || "") ne "ligand"
l!l&&r!l&&!r
105135262183
$res[$k]{'type'} || ''
l!l
54441
MC/DC100%2/2
$in[$k] or ($res[$k]{"type"} || "") ne "ligand"
$in[$k] $res[$k]{'type'}
Truth table100%3/3
A or B
A= $in[$k]B= $res[$k]{'type'}
ABresult
1X1
011
000
1990 183 ▶ next unless ($k > 0 && $in[$k - 1] && _peptide_linked($res[$k - 1], $res[$k]))
Branch: 1 branch
BranchTrueFalseTotal
unless $k > 0 and $in[$k - 1] and _peptide_linked($res[$k - 1], $res[$k]) or $k < $#res and $in[$k + 1] and _peptide_linked($res[$k], $res[$k + 1]) 166 17 183
Condition93%14/15
$k > 0 and $in[$k - 1] and _peptide_linked($res[$k - 1], $res[$k]) or $k < $#res and $in[$k + 1] and _peptide_linked($res[$k], $res[$k + 1])
l!l&&r!l&&!r
215166
$k > 0 and $in[$k - 1] and _peptide_linked($res[$k - 1], $res[$k])
!ll&&!rl&&r
341472
$k > 0 and $in[$k - 1]
!ll&&!rl&&r
322149
$k < $#res and $in[$k + 1] and _peptide_linked($res[$k], $res[$k + 1])
!ll&&!rl&&r
166015
$k < $#res and $in[$k + 1]
!ll&&!rl&&r
2514115
MC/DC83%5/6
$k > 0 and $in[$k - 1] and _peptide_linked($res[$k - 1], $res[$k]) or $k < $#res and $in[$k + 1] and _peptide_linked($res[$k], $res[$k + 1])
$k > 0 $in[$k - 1] _peptide_linked($res[$k - 1], $res[$k]) $k < $#res $in[$k + 1] _peptide_linked($res[$k], $res[$k + 1])
Truth table53%7/13
A and B and C or D and E and F
A= $k > 0B= $in[$k - 1]C= _peptide_linked($res[$k - 1], $res[$k])D= $k < $#resE= $in[$k + 1]F= _peptide_linked($res[$k], $res[$k + 1])
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
1991 || ($k < $#res && $in[$k + 1] && _peptide_linked($res[$k], $res[$k + 1]));
1992 17 $in[$k] = $grew = 1;
1993 }
1994 }
1995 835 return $polymer_of{$cid} = [ map { $res[$_] } grep { $in[$_] } 0 .. $#res ];
1996 637 };
1997 637 my (@names, @res);
1998 637 ▶ if (defined $spec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec) 22 615 637
1999 22 ▶ die "$who: partners must be an array reference of two partners"
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::reftype($spec) || "") eq "ARRAY" and @$spec == 2 3 19 22
Condition100%5/5
(builtin::reftype($spec) || "") eq "ARRAY" and @$spec == 2
!ll&&!rl&&r
1219
builtin::reftype($spec) || ''
l!l
211
MC/DC100%2/2
(builtin::reftype($spec) || "") eq "ARRAY" and @$spec == 2
builtin::reftype($spec) @$spec == 2
Truth table100%3/3
A and B
A= builtin::reftype($spec)B= @$spec == 2
ABresult
0X0
100
111
2000 unless (reftype($spec) || '') eq 'ARRAY' && @$spec == 2;
2001 19 my $lig;
2002 19 for my $i (0, 1) {
2003 37 ▶ my @want = ref $spec->[$i] ? @{ $spec->[$i] } : ($spec->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
ref $spec->[$i] ? : 33 4 37
2004 37 ▶ die "$who: partner " . ($i + 1) . ' is empty' unless @want;
Branch: 1 branch
BranchTrueFalseTotal
unless @want 1 36 37
2005 36 for my $w (@want) {
2006 39 ▶ die "$who: partner " . ($i + 1) . ' names an undefined chain or ligand'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $w 1 38 39
2007 unless defined $w;
2008 38 ▶ if ($chains->{$w}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chains->{$w}) { } 29 9 38
2009 29 my $r = $polymer->($w);
2010 29 ▶ die "$who: chain '$w' has no amino acid or nucleotide in it; name "
Branch: 1 branch
BranchTrueFalseTotal
unless @$r 1 28 29
2011 . 'what is in it by the keys structure_ligands() gives'
2012 unless @$r;
2013 28 push @{ $res[$i] }, @$r;
2014 } else {
2015 9 ▶ $lig ||= structure_ligands($info);
Condition66%2/3
$lig ||= structure_ligands($info)
l!l&&r!l&&!r
180
MC/DC0%0/2
$lig ||= structure_ligands($info)
$lig structure_ligands($info)
Truth table66%2/3
A ||= B
A= $ligB= structure_ligands($info)
ABresult
1X1
011
000
2016 die "$who: partner '$w' is neither a chain nor a ligand key; the "
2017 6 . 'chains are ' . join(', ', map { "'$_'" } @order)
2018 . ', and structure_ligands() has the ligand keys'
2019 9 ▶ unless $lig->{$w};
Branch: 1 branch
BranchTrueFalseTotal
unless $lig->{$w} 3 6 9
2020 6 push @{ $res[$i] }, $lig->{$w};
2021 }
2022 34 push @{ $names[$i] }, $w;
2023 }
2024 31 my %once;
2025 31 $res[$i] = [ grep { !$once{"$_"}++ } @{ $res[$i] } ];
2026 31 my %said;
2027 31 $names[$i] = [ grep { !$said{$_}++ } @{ $names[$i] } ];
2028 }
2029 13 my %seen = map { ($_ => 1) } map { "$_" } @{ $res[0] };
2030 13 for (@{ $res[1] }) {
2031 die "$who: the two partners share residue $_->{resname} $_->{chain} $_->{key}"
2032 175 ▶ if $seen{"$_"};
Branch: 1 branch
BranchTrueFalseTotal
if $seen{"$_"} 2 173 175
2033 }
2034 11 return { partners => \@names, residues => \@res };
2035 }
2036 615 my @poly = grep { @{ $polymer->($_) } } @order;
2037 615 ▶ if (@poly >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@poly >= 2) 199 416 615
2038 199 my $short;
2039 199 for my $cid (@poly) {
2040 $short = $cid if !defined $short
2041 400 ▶ || @{ $polymer->($cid) } <= @{ $polymer->($short) };
Branch: 1 branch
BranchTrueFalseTotal
if not defined $short or @{&$polymer($cid);} <= @{&$polymer($short);} 398 2 400
Condition100%3/3
not defined $short or @{&$polymer($cid);} <= @{&$polymer($short);}
l!l&&r!l&&!r
1991992
MC/DC100%2/2
not defined $short or @{&$polymer($cid);} <= @{&$polymer($short);}
not defined $short @{&$polymer($cid);} <= @{&$polymer($short);}
Truth table100%3/3
not(A) or B
A= not defined $shortB= @{&$polymer($cid);} <= @{&$polymer($short);}
ABresult
1X1
011
000
2042 }
2043 199 my @rest = grep { $_ ne $short } @poly;
2044 return {
2045 partners => [ \@rest, [ $short ] ],
2046 199 residues => [ [ map { @{ $polymer->($_) } } @rest ], $polymer->($short) ],
2047 };
2048 }
2049 416 ▶ return undef unless @poly == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @poly == 1 54 362 416
2050 # a cap or a non-standard residue bonded into the chain is part of the
2051 # first partner already, and cannot be the second
2052 362 my $side1 = $polymer->($poly[0]);
2053 362 my %taken = map { ("$_" => 1) } @$side1;
2054 362 my ($best, $best_n);
2055 362 for my $cid (@order) {
2056 375 my $c = $chains->{$cid};
2057 375 for my $rk (@{ $c->{residue_order} }) {
2058 5502 my $r = $c->{residues}{$rk};
2059 5502 ▶ next unless ($r->{type} || '') eq 'ligand' && !$taken{"$r"};
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"type"} || "") eq "ligand" and not $taken{"$r"} 5485 17 5502
Condition80%4/5
($r->{"type"} || "") eq "ligand" and not $taken{"$r"}
!ll&&!rl&&r
54701517
$r->{'type'} || ''
l!l
55020
MC/DC50%1/2
($r->{"type"} || "") eq "ligand" and not $taken{"$r"}
$r->{'type'} not $taken{"$r"}
Truth table66%2/3
A and not(B)
A= $r->{'type'}B= not $taken{"$r"}
ABresult
0X0
100
111
2060 my $n = grep {
2061 72 my $e = $r->{atoms}{$_}{element};
2062 72 ▶ !defined $e || ($e ne 'H' && $e ne 'D')
Condition33%2/6
!defined($e) || $e ne 'H' && $e ne 'D'
l!l&&r!l&&!r
0720
$e ne "H" and $e ne "D"
!ll&&!rl&&r
0072
MC/DC0%0/3
!defined($e) || $e ne 'H' && $e ne 'D'
!defined($e) $e ne "H" $e ne "D"
Truth table25%1/4
not(A) || B and C
A= !defined($e)B= $e ne "H"C= $e ne "D"
ABCresult
1XX1
0111
00X0
0100
2063 17 ▶ } @{ $r->{atom_order} || [] };
Condition50%1/2
$r->{'atom_order'} || []
l!l
170
MC/DC0%0/1
$r->{'atom_order'} || []
$r->{'atom_order'}
Truth table50%1/2
A
A= $r->{'atom_order'}
Aresult
11
00
2064 17 ▶ next unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 17 17
2065 17 ▶ ($best, $best_n) = ("$r->{resname}_${cid}_$rk", $n)
Branch: 1 branch
BranchTrueFalseTotal
if not defined $best_n or $n > $best_n 16 1 17
Condition66%2/3
not defined $best_n or $n > $best_n
l!l&&r!l&&!r
1601
MC/DC50%1/2
not defined $best_n or $n > $best_n
not defined $best_n $n > $best_n
Truth table66%2/3
not(A) or B
A= not defined $best_nB= $n > $best_n
ABresult
1X1
011
000
2066 if !defined $best_n || $n > $best_n;
2067 }
2068 }
2069 362 ▶ return undef unless defined $best;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $best 346 16 362
2070 return {
2071 partners => [ [ $poly[0] ], [ $best ] ],
2072 16 residues => [ $side1, [ structure_ligands($info)->{$best} ] ],
2073 };
2074 }
2075  
2076 # _finish_interface($info, $f, \%o, $sides) -- what the XS measured, made into
2077 # what a caller reads: the residues of each side that take part, PRODIGY's
2078 # classes and estimate, and the ring and disulfide pairs that cross, taken out
2079 # of the whole-structure lists rather than looked for twice.
2080 226 ▶sub _finish_interface {
Subroutine _finish_interface: called CC=33 SCAR=35.0
2081 226 my ($info, $f, $o, $sides) = @_;
2082 226 my $raw = $f->{interface};
2083 226 my %on; # "chain\0key" => 0 or 1: which side a residue is on
2084 226 for my $i (0, 1) {
2085 452 $on{"$_->{chain}\0$_->{key}"} = $i for @{ $sides->{residues}[$i] };
2086 }
2087 226 my (%n_ct, %ic);
2088 226 $ic{$_} = 0 for values %IC_BIN;
2089 226 for my $c (@{ $raw->{contacts} }) {
2090 1298 $n_ct{"$c->{chain1}\0$c->{residue1}"}++;
2091 1298 $n_ct{"$c->{chain2}\0$c->{residue2}"}++;
2092 1298 my ($x, $y) = ($IC_CLASS{ $c->{resname1} }, $IC_CLASS{ $c->{resname2} });
2093 1298 ▶ next unless defined $x && defined $y;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x and defined $y 260 1038 1298
Condition100%3/3
defined $x and defined $y
!ll&&!rl&&r
224361038
MC/DC100%2/2
defined $x and defined $y
defined $x defined $y
Truth table100%3/3
A and B
A= defined $xB= defined $y
ABresult
0X0
100
111
2094 1038 $ic{ $IC_BIN{ join '', sort $x, $y } }++;
2095 }
2096 # with sasa => 0 there are no surfaces, and an interface residue is one
2097 # that touches the other side
2098 226 my $surf = exists $raw->{residue_sasa};
2099 226 my (@taking, %nis, $n_nis, $side_amino);
2100 226 my @buried = (0, 0);
2101 226 for my $i (0, 1) {
2102 452 my $list = $sides->{residues}[$i];
2103 452 for my $e (0 .. $#$list) {
2104 4630 my $r = $list->[$e];
2105 4630 ▶ my $n = $n_ct{"$r->{chain}\0$r->{key}"} || 0;
Condition100%2/2
$n_ct{"$r->{'chain'}\000$r->{'key'}"} || 0
l!l
10613569
MC/DC100%1/1
$n_ct{"$r->{'chain'}\000$r->{'key'}"} || 0
$n_ct{"$r->{'chain'}\000$r->{'key'}"}
Truth table100%2/2
A
A= $n_ct{"$r->{'chain'}\000$r->{'key'}"}
Aresult
11
00
2106 4630 ▶ $side_amino->[$i]++ if ($r->{type} || '') eq 'amino_acid';
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"type"} || "") eq "amino_acid" 3845 785 4630
Condition50%1/2
$r->{'type'} || ''
l!l
46300
MC/DC0%0/1
$r->{'type'} || ''
$r->{'type'}
Truth table50%1/2
A
A= $r->{'type'}
Aresult
11
00
2107 my %one = (chain => $r->{chain}, residue => $r->{key}, resname => $r->{resname},
2108 4630 n_contacts => $n);
2109 4630 ▶ if ($surf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($surf) { } 4564 66 4630
2110 4564 my $area = $raw->{residue_sasa}[$i][$e];
2111 4564 my $alone = $raw->{residue_sasa_alone}[$i][$e];
2112 4564 $buried[$i] += $alone - $area;
2113 4564 ▶ if (my $cls = $NIS_CLASS{ $r->{resname} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cls = $NIS_CLASS{$r->{"resname"}}) 3641 923 4564
2114 3641 ▶ if ($area / $NACCESS_REL{ $r->{resname} } >= $o->{nis_threshold}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($area / $NACCESS_REL{$r->{"resname"}} >= $o->{"nis_threshold"}) 3277 364 3641
2115 3277 $nis{$cls}++;
2116 3277 $n_nis++;
2117 }
2118 }
2119 4564 ▶ next unless $n || $alone > $area;
Branch: 1 branch
BranchTrueFalseTotal
unless $n or $alone > $area 3481 1083 4564
Condition100%3/3
$n or $alone > $area
l!l&&r!l&&!r
1036473481
MC/DC100%2/2
$n or $alone > $area
$n $alone > $area
Truth table100%3/3
A or B
A= $nB= $alone > $area
ABresult
1X1
011
000
2120 1083 @one{qw(sasa sasa_alone buried)} = ($area, $alone, $alone - $area);
2121 } else {
2122 66 ▶ next unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 41 25 66
2123 }
2124 1108 push @{ $taking[$i] }, \%one;
2125 }
2126 }
2127 408 ▶ my $cross = sub {
Subroutine __ANON__: called CC=4 SCAR=15.9
2128 408 my ($list) = @_;
2129 return [ grep {
2130 266 my ($a, $b) = ($on{"$_->{chain1}\0$_->{residue1}"}, $on{"$_->{chain2}\0$_->{residue2}"});
2131 266 ▶ defined $a && defined $b && $a != $b
Condition33%2/6
defined $a && defined $b && $a != $b
!ll&&!rl&&r
02660
defined $a and defined $b
!ll&&!rl&&r
00266
MC/DC0%0/3
defined $a && defined $b && $a != $b
defined $a defined $b $a != $b
Truth table25%1/4
A and B && C
A= defined $aB= defined $bC= $a != $b
ABCresult
0XX0
10X0
1100
1111
2132 408 ▶ } @{ $list || [] } ];
Condition50%1/2
$list || []
l!l
4080
MC/DC0%0/1
$list || []
$list
Truth table50%1/2
A
A= $list
Aresult
11
00
2133 226 };
2134 my %out = (
2135 partners => $sides->{partners},
2136 452 ▶ n_residues => [ map { scalar @{ $sides->{residues}[$_] } } 0, 1 ],
Branch: 5 branches
BranchTrueFalseTotal
$surf ? : 225 1 226
exists $f->{'pi_stacking'} ? : 204 22 226
exists $f->{'disulfides'} ? : 204 22 226
exists $raw->{'min_distance'} ? : 78 148 226
exists $raw->{'com_distance'} ? : 226 0 226
Condition100%4/4
$taking[0] || []
l!l
78148
$taking[1] || []
l!l
78148
MC/DC100%1/1
$taking[0] || []
$taking[0]
MC/DC100%1/1
$taking[1] || []
$taking[1]
Truth table100%2/2
A
A= $taking[0]
Aresult
11
00
Truth table100%2/2
A
A= $taking[1]
Aresult
11
00
2137 n_atoms => $raw->{n_atoms},
2138 residues => [ $taking[0] || [], $taking[1] || [] ],
2139 contacts => $raw->{contacts},
2140 n_atom_contacts => $raw->{n_atom_contacts},
2141 ic => \%ic,
2142 ($surf ? (
2143 sasa => { complex => $raw->{sasa_complex}, alone => $raw->{sasa_alone} },
2144 buried => {
2145 total => $raw->{buried_apolar} + $raw->{buried_polar},
2146 apolar => $raw->{buried_apolar},
2147 polar => $raw->{buried_polar},
2148 side => \@buried,
2149 },
2150 ) : ()),
2151 salt_bridges => $raw->{salt_bridges},
2152 polar_contacts => $raw->{polar_contacts},
2153 cation_pi => $raw->{cation_pi},
2154 bridging_waters => $raw->{bridging_waters},
2155 bfactor => { mean => $raw->{bfactor_mean}, interface => $raw->{bfactor_interface} },
2156 # computed on this walk only when it was the whole-structure one; the
2157 # interface alone asks for neither and has neither
2158 (exists $f->{pi_stacking} ? (pi_stacking => $cross->($f->{pi_stacking})) : ()),
2159 (exists $f->{disulfides} ? (disulfides => $cross->($f->{disulfides})) : ()),
2160 (exists $raw->{min_distance} ? (min_distance => $raw->{min_distance}) : ()),
2161 226 (exists $raw->{com_distance} ? (com_distance => $raw->{com_distance}) : ()),
2162 );
2163 226 ▶ $out{pocket} = _pocket($sides->{residues}[0], $raw) if $raw->{pocket_atoms};
Branch: 1 branch
BranchTrueFalseTotal
if $raw->{"pocket_atoms"} 223 3 226
2164 # The non-interacting surface is PRODIGY's: every residue of either side
2165 # whose surface in the complex is at least nis_threshold of its NACCESS
2166 # reference, sorted by class. It is over the whole complex, interface
2167 # included, as analyse_nis() has it, and not only the residues away from
2168 # the interface that the name suggests.
2169 226 ▶ if ($n_nis) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_nis) 202 24 226
2170 202 ▶ $out{nis} = { map { ($_->[1] => ($nis{ $_->[0] } || 0) / $n_nis) }
Condition100%2/2
$nis{$_->[0]} || 0
l!l
429177
MC/DC100%1/1
$nis{$_->[0]} || 0
$nis{$_->[0]}
Truth table100%2/2
A
A= $nis{$_->[0]}
Aresult
11
00
2171 [ A => 'apolar' ], [ C => 'charged' ], [ P => 'polar' ] };
2172 }
2173 # PRODIGY is fitted on protein-protein complexes and refuses a structure
2174 # with no contact between the two, so the estimate is only made for two
2175 # sides that are both protein and touch
2176 226 ▶ if ($out{nis} && @{ $raw->{contacts} } && $side_amino->[0] && $side_amino->[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out{"nis"} and @{$raw->{"contacts"};} and $side_amino->[0] and $side_amino->[1]) 36 190 226
Condition100%9/9
$out{"nis"} and @{$raw->{"contacts"};} and $side_amino->[0] and $side_amino->[1]
!ll&&!rl&&r
1731736
$out{"nis"} and @{$raw->{"contacts"};} and $side_amino->[0]
!ll&&!rl&&r
171253
$out{"nis"} and @{$raw->{"contacts"};}
!ll&&!rl&&r
2414755
MC/DC100%4/4
$out{"nis"} and @{$raw->{"contacts"};} and $side_amino->[0] and $side_amino->[1]
$out{"nis"} @{$raw->{"contacts"};} $side_amino->[0] $side_amino->[1]
Truth table100%5/5
A and B and C and D
A= $out{"nis"}B= @{$raw->{"contacts"};}C= $side_amino->[0]D= $side_amino->[1]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2177 36 my $dg = $PRODIGY{intercept};
2178 36 $dg += $PRODIGY{$_} * $ic{$_} for qw(charged_charged charged_apolar polar_polar apolar_polar);
2179 36 $dg += $PRODIGY{nis_apolar} * 100 * $out{nis}{apolar};
2180 36 $dg += $PRODIGY{nis_charged} * 100 * $out{nis}{charged};
2181 $out{prodigy} = {
2182 dg => $dg,
2183 kd => exp($dg / ($PRODIGY_R * ($o->{temperature} + 273.15))),
2184 temperature => $o->{temperature},
2185 36 };
2186 }
2187 226 return $f->{interface} = \%out;
2188 }
2189  
2190 # _pocket(\@first, $raw) -- the first partner's pocket around the second, from
2191 # what iface_compute() tallied per residue of the first list: its atoms in the
2192 # pocket, their surface in the first partner alone, and the residue's whole
2193 # relative surface alone. The composition is over the pocket's amino acids
2194 # with one of the twenty letters, as %KD is, so a cap or a ligand named into
2195 # the first partner is in the atom and residue counts and the surface but is
2196 # not scored as an amino acid it is not.
2197 223 ▶sub _pocket {
Subroutine _pocket: called CC=23 SCAR=31.4
2198 223 my ($first, $raw) = @_;
2199 223 my ($n_atoms, @res, %chains, @aa, @rsa) = (0);
2200 223 my $surf = exists $raw->{pocket_sasa};
2201 223 my %sasa = (total => 0, hydrophobic => 0, polar => 0);
2202 223 for my $e (0 .. $#$first) {
2203 3359 ▶ my $n = $raw->{pocket_atoms}[$e] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $n = $raw->{"pocket_atoms"}[$e] or next 629 2730 3359
2204 629 my $r = $first->[$e];
2205 my $one = ($r->{type} || '') eq 'amino_acid' && exists $KD{ $r->{one} // '' }
2206 629 ▶ ? $r->{one} : undef;
Branch: 1 branch
BranchTrueFalseTotal
($r->{'type'} || '') eq 'amino_acid' && exists $KD{$r->{'one'} // ''} ? : 538 91 629
Condition57%4/7
($r->{"type"} || "") eq "amino_acid" and exists $KD{$r->{"one"} // ""}
!ll&&!rl&&r
910538
$r->{'type'} || ''
l!l
6290
$r->{"one"} // ""
l!l
5380
MC/DC0%0/2
($r->{"type"} || "") eq "amino_acid" and exists $KD{$r->{"one"} // ""}
$r->{'type'} exists $KD{$r->{"one"} // ""}
MC/DC0%0/1
$r->{"one"} // ""
$r->{"one"}
Truth table33%1/3
A and B
A= $r->{'type'}B= exists $KD{$r->{"one"} // ""}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $r->{"one"}
Aresult
11
00
2207 my %one = (chain => $r->{chain}, residue => $r->{key}, resname => $r->{resname},
2208 629 n_atoms => $n);
2209 629 $n_atoms += $n;
2210 629 $chains{ $r->{chain} } = 1;
2211 629 ▶ push @aa, $one if defined $one;
Branch: 1 branch
BranchTrueFalseTotal
if defined $one 538 91 629
2212 629 ▶ if ($surf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($surf) 611 18 629
2213 611 my $a = $raw->{pocket_sasa}[$e];
2214 611 $one{sasa_alone} = $a;
2215 611 $sasa{total} += $a;
2216 611 ▶ $sasa{ defined $one && $POCKET_HYDROPHOBIC{$one} ? 'hydrophobic' : 'polar' } += $a;
Branch: 1 branch
BranchTrueFalseTotal
defined $one && $POCKET_HYDROPHOBIC{$one} ? : 230 381 611
Condition100%3/3
defined $one and $POCKET_HYDROPHOBIC{$one}
!ll&&!rl&&r
91290230
MC/DC100%2/2
defined $one and $POCKET_HYDROPHOBIC{$one}
defined $one $POCKET_HYDROPHOBIC{$one}
Truth table100%3/3
A and B
A= defined $oneB= $POCKET_HYDROPHOBIC{$one}
ABresult
0X0
100
111
2217 611 my $rel = $raw->{pocket_rsa}[$e];
2218 611 ▶ if (defined $one && defined $rel) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $one and defined $rel) 520 91 611
Condition66%2/3
defined $one and defined $rel
!ll&&!rl&&r
910520
MC/DC50%1/2
defined $one and defined $rel
defined $one defined $rel
Truth table66%2/3
A and B
A= defined $oneB= defined $rel
ABresult
0X0
100
111
2219 520 $one{rsa_alone} = $rel;
2220 520 push @rsa, $rel;
2221 }
2222 }
2223 629 push @res, \%one;
2224 }
2225 223 my %p = (n_atoms => $n_atoms, n_residues => scalar @res,
2226 n_chains => scalar keys %chains, residues => \@res);
2227 223 ▶ $p{packing_density} = $raw->{pocket_packing} if exists $raw->{pocket_packing};
Branch: 1 branch
BranchTrueFalseTotal
if exists $raw->{"pocket_packing"} 223 0 223
2228 223 ▶ return \%p unless @res;
Branch: 1 branch
BranchTrueFalseTotal
unless @res 150 73 223
2229 73 ▶ $p{sasa} = \%sasa if $surf;
Branch: 1 branch
BranchTrueFalseTotal
if $surf 72 1 73
2230 73 ▶ if (@aa) {
Branch: 1 branch
BranchTrueFalseTotal
if (@aa) 49 24 73
2231 49 my ($kd, $kd_max, $charge) = (0, undef, 0);
2232 49 for (@aa) {
2233 538 $kd += $KD{$_};
2234 538 ▶ $kd_max = $KD{$_} if !defined $kd_max || $KD{$_} > $kd_max;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $kd_max or $KD{$_} > $kd_max 114 424 538
Condition100%3/3
not defined $kd_max or $KD{$_} > $kd_max
l!l&&r!l&&!r
4965424
MC/DC100%2/2
not defined $kd_max or $KD{$_} > $kd_max
not defined $kd_max $KD{$_} > $kd_max
Truth table100%3/3
not(A) or B
A= not defined $kd_maxB= $KD{$_} > $kd_max
ABresult
1X1
011
000
2235 538 ▶ $charge += $POCKET_CHARGE{$_} || 0;
Condition100%2/2
$POCKET_CHARGE{$_} || 0
l!l
173365
MC/DC100%1/1
$POCKET_CHARGE{$_} || 0
$POCKET_CHARGE{$_}
Truth table100%2/2
A
A= $POCKET_CHARGE{$_}
Aresult
11
00
2236 }
2237 49 $p{charge} = $charge;
2238 49 $p{hydropathy} = $kd / @aa;
2239 49 $p{hydropathy_max} = $kd_max;
2240 49 $p{aromatic_fraction} = (grep { $AROMATIC{$_} } @aa) / @aa;
2241 49 $p{hydrophobic_fraction} = (grep { $POCKET_HYDROPHOBIC{$_} } @aa) / @aa;
2242 49 $p{polar_fraction} = (grep { $POCKET_POLAR{$_} } @aa) / @aa;
2243 49 $p{charged_fraction} = (grep { $POCKET_CHARGED{$_} } @aa) / @aa;
2244 }
2245 73 ▶ if (@rsa) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rsa) 48 25 73
2246 48 my $sum = 0;
2247 48 $sum += $_ for @rsa;
2248 48 $p{rsa} = $sum / @rsa;
2249 48 $p{buried_fraction} = (grep { $_ < $POCKET_BURIED } @rsa) / @rsa;
2250 }
2251 73 return \%p;
2252 }
2253  
2254 # _bjellqvist_charge(\%count, $pos, $neg, $ph) -- the net charge of a sequence
2255 # at a pH, by Henderson-Hasselbalch over Bio.SeqUtils.IsoelectricPoint's pK
2256 # tables: charge_at_pH() of Biopython 1.87, term for term and in its order.
2257 8949 ▶sub _bjellqvist_charge {
Subroutine _bjellqvist_charge: called CC=3 SCAR=11.0
2258 8949 my ($count, $pos, $neg, $ph) = @_;
2259 8949 my ($p, $n) = (0.0, 0.0);
2260 8949 $p += $count->{ $_->[0] } * (1.0 / (10 ** ($ph - $_->[1]) + 1.0)) for @$pos;
2261 8949 $n += $count->{ $_->[0] } * (1.0 / (10 ** ($_->[1] - $ph) + 1.0)) for @$neg;
2262 8949 return $p - $n;
2263 }
2264  
2265 # _charge_and_pi($seq) -- the net charge at pH 7 and the isoelectric point of a
2266 # protein sequence, Biopython's IsoelectricPoint(seq).charge_at_pH(7.0) and
2267 # .pi(). pi() is a bisection written as recursion; this is the same bisection,
2268 # from the same starting bracket and to the same width, written as a loop, so
2269 # every pH it tries is the one Biopython tried.
2270 471 ▶sub _charge_and_pi {
Subroutine _charge_and_pi: called CC=7 SCAR=19.5
2271 471 my ($seq) = @_;
2272 471 $seq = uc $seq;
2273 471 my %count = map { ($_ => 0) } qw(K R H D E C Y);
2274 471 ▶ for my $aa (split //, $seq) { $count{$aa}++ if exists $count{$aa} }
Branch: 1 branch
BranchTrueFalseTotal
if exists $count{$aa} 2520 5006 7526
2275 471 @count{qw(Nterm Cterm)} = (1.0, 1.0);
2276 471 my ($first, $last) = (substr($seq, 0, 1), substr($seq, -1));
2277 471 my @pos = map { [ @$_ ] } @PK_POS;
2278 471 my @neg = map { [ @$_ ] } @PK_NEG;
2279 471 ▶ $pos[0][1] = $PK_NTERM{$first} if exists $PK_NTERM{$first};
Branch: 1 branch
BranchTrueFalseTotal
if exists $PK_NTERM{$first} 292 179 471
2280 471 ▶ $neg[0][1] = $PK_CTERM{$last} if exists $PK_CTERM{$last};
Branch: 1 branch
BranchTrueFalseTotal
if exists $PK_CTERM{$last} 2 469 471
2281 # Biopython's starting bracket: 4.05 is below a sequence of nothing but
2282 # aspartate and 12 above one of nothing but arginine; 0.0001 is its width
2283 471 my ($ph, $lo, $hi) = (7.775, 4.05, 12);
2284 471 while (1) {
2285 8478 my $q = _bjellqvist_charge(\%count, \@pos, \@neg, $ph);
2286 8478 ▶ last unless $hi - $lo > 0.0001;
Branch: 1 branch
BranchTrueFalseTotal
unless $hi - $lo > "0.0001" 471 8007 8478
2287 8007 ▶ if ($q > 0.0) { $lo = $ph } else { $hi = $ph }
Branch: 1 branch
BranchTrueFalseTotal
if ($q > 0.0) { } 3462 4545 8007
2288 8007 $ph = ($lo + $hi) / 2;
2289 }
2290 471 return (_bjellqvist_charge(\%count, \@pos, \@neg, 7.0), $ph);
2291 }
2292  
2293 # _secondary_fractions($info, $f, $store) -- the three-state share of each
2294 # chain's assigned residues, from the dssp roll-up: H is the three helices
2295 # (H, G, I), E the strand and the bridge (E, B), C the rest -- ss_simple's
2296 # reduction, counted rather than read off every residue. A chain with no
2297 # assigned residue gets none, as it has no key in the roll-up.
2298 604 ▶sub _secondary_fractions {
Subroutine _secondary_fractions: called CC=10 SCAR=23.0
2299 604 my ($info, $f, $store) = @_;
2300 604 ▶ my $d = $f->{dssp} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $d = $f->{"dssp"} or return 602 2 604
2301 602 my %three = (H => 'H', G => 'H', I => 'H', E => 'E', B => 'E');
2302 602 my %all = (H => 0, E => 0, C => 0);
2303 602 my $n_all = 0;
2304 602 for my $cid (sort keys %$d) {
2305 385 my %n = (H => 0, E => 0, C => 0);
2306 385 my $tot = 0;
2307 385 for my $letter (keys %{ $d->{$cid} }) {
2308 756 my $k = scalar @{ $d->{$cid}{$letter} };
2309 756 ▶ $n{ $three{$letter} || 'C' } += $k;
Condition100%2/2
$three{$letter} || 'C'
l!l
179577
MC/DC100%1/1
$three{$letter} || 'C'
$three{$letter}
Truth table100%2/2
A
A= $three{$letter}
Aresult
11
00
2310 756 $tot += $k;
2311 }
2312 385 ▶ next unless $tot;
Branch: 1 branch
BranchTrueFalseTotal
unless $tot 0 385 385
2313 385 $all{$_} += $n{$_} for keys %n;
2314 385 $n_all += $tot;
2315 1140 $info->{chains}{$cid}{ss_fraction} = { map { ($_ => $n{$_} / $tot) } keys %n }
2316 385 ▶ if $store && $info->{chains}{$cid};
Branch: 1 branch
BranchTrueFalseTotal
if $store and $info->{"chains"}{$cid} 380 5 385
Condition66%2/3
$store and $info->{"chains"}{$cid}
!ll&&!rl&&r
50380
MC/DC50%1/2
$store and $info->{"chains"}{$cid}
$store $info->{"chains"}{$cid}
Truth table66%2/3
A and B
A= $storeB= $info->{"chains"}{$cid}
ABresult
0X0
100
111
2317 }
2318 602 ▶ $f->{ss_fraction} = { map { ($_ => $all{$_} / $n_all) } keys %all } if $n_all;
Branch: 1 branch
BranchTrueFalseTotal
if $n_all 368 234 602
2319 602 return;
2320 }
2321  
2322 # Options and format detection
2323  
2324 1206 ▶sub _options {
Subroutine _options: called CC=8 SCAR=20.8
2325 1206 my ($opt, $who) = @_;
2326 1206 for my $k (sort keys %$opt) {
2327 die "$who: unknown option '$k'; known options are: " . join(', ', sort keys %DEFAULT)
2328 1520 ▶ unless exists $DEFAULT{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $DEFAULT{$k} 2 1518 1520
2329 }
2330 1204 _no_undef($opt, $who, \%DEFAULT);
2331 1202 my %o = (%DEFAULT, %$opt);
2332 die "$who: altloc must be 'first' or 'highest', not '$o{altloc}'"
2333 1202 ▶ unless $o{altloc} eq 'first' || $o{altloc} eq 'highest';
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"altloc"} eq "first" or $o{"altloc"} eq "highest" 1 1201 1202
Condition100%3/3
$o{"altloc"} eq "first" or $o{"altloc"} eq "highest"
l!l&&r!l&&!r
119741
MC/DC100%2/2
$o{"altloc"} eq "first" or $o{"altloc"} eq "highest"
$o{"altloc"} eq "first" $o{"altloc"} eq "highest"
Truth table100%3/3
A or B
A= $o{"altloc"} eq "first"B= $o{"altloc"} eq "highest"
ABresult
1X1
011
000
2334 # features is a switch here and not the option hash structure_features()
2335 # takes: `features => { sasa => 0 }` is a true value, so every feature would
2336 # be computed, the surface included, and the caller told nothing. That is
2337 # the ignored option the check above exists for, spelled with a real name.
2338 die "$who: features is 1 or 0 here; the per-feature options are "
2339 1201 ▶ . "structure_features(\$info, ...)'s" if ref $o{features};
Branch: 1 branch
BranchTrueFalseTotal
if ref $o{"features"} 2 1199 1201
2340 # features => 1 with atoms => 0 computes nothing and says nothing, because
2341 # features is on by default and a caller reading for residues should not
2342 # have to turn it off too. dssp is off by default, so asking for it with
2343 # nothing to compute it from is a request that cannot be met.
2344 die "$who: dssp needs the atoms, and this read has atoms => 0"
2345 1199 ▶ if $o{dssp} && !$o{atoms};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"dssp"} and not $o{"atoms"} 3 1196 1199
Condition100%3/3
$o{"dssp"} and not $o{"atoms"}
!ll&&!rl&&r
1138583
MC/DC100%2/2
$o{"dssp"} and not $o{"atoms"}
$o{"dssp"} not $o{"atoms"}
Truth table100%3/3
A and not(B)
A= $o{"dssp"}B= not $o{"atoms"}
ABresult
0X0
100
111
2346 1196 _model_and_chains(\%o, $who);
2347 1191 return \%o;
2348 }
2349  
2350 # _model_and_chains(\%o, $who) -- the model and chains options, which
2351 # structure_info() and convert() both hand to the XS parse and so both have to
2352 # give it something it can hold
2353 1632 ▶sub _model_and_chains {
Subroutine _model_and_chains: called CC=11 SCAR=24.0
2354 1632 my ($o, $who) = @_;
2355 1632 ▶ if (defined $o->{chains}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o->{"chains"}) 61 1571 1632
2356 die "$who: chains must be an array reference"
2357 61 ▶ unless (reftype($o->{chains}) || '') eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::reftype($o->{"chains"}) || "") eq "ARRAY" 2 59 61
Condition100%2/2
builtin::reftype($o->{'chains'}) || ''
l!l
592
MC/DC100%1/1
builtin::reftype($o->{'chains'}) || ''
builtin::reftype($o->{'chains'})
Truth table100%2/2
A
A= builtin::reftype($o->{'chains'})
Aresult
11
00
2358 59 ▶ die "$who: chains is empty" unless @{ $o->{chains} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$o->{"chains"};} 2 57 59
2359 }
2360 # 0 is a model number and not a mistake: an ensemble numbered from 0 is
2361 # unusual and legal, which is why the XS takes a negative number rather than
2362 # zero as its "every model" sentinel. The message said positive and the
2363 # test has always accepted 0; it is the message that was wrong.
2364 1628 ▶ if (defined $o->{model} && $o->{model} ne 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o->{"model"} and $o->{"model"} ne "all") 921 707 1628
Condition66%2/3
defined $o->{"model"} and $o->{"model"} ne "all"
!ll&&!rl&&r
0707921
MC/DC50%1/2
defined $o->{"model"} and $o->{"model"} ne "all"
defined $o->{"model"} $o->{"model"} ne "all"
Truth table66%2/3
A and B
A= defined $o->{"model"}B= $o->{"model"} ne "all"
ABresult
0X0
100
111
2365 die "$who: model must be a whole number or 'all', not '$o->{model}'"
2366 921 ▶ unless $o->{model} =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"model"} =~ /\A[0-9]+\z/ 2 919 921
2367 # And one the parse can hold. '9223372036854775808' passed the pattern
2368 # and wrapped to a negative IV on its way in, which is the parse's "every
2369 # model": one model asked for, all of them handed back. Compared as
2370 # digits, because as numbers the two ends of the range round together.
2371 919 (my $digits = $o->{model}) =~ s/\A0+(?=[0-9])//;
2372 919 my $max = ~0 >> 1; # IV_MAX, whatever the width of this perl's IV
2373 919 ▶ die "$who: model $o->{model} is larger than any model number this perl can hold ($max)"
Branch: 1 branch
BranchTrueFalseTotal
if length $digits > length $max or length $digits == length $max and $digits gt $max 3 916 919
Condition100%6/6
length $digits > length $max or length $digits == length $max and $digits gt $max
l!l&&r!l&&!r
12916
length $digits == length $max and $digits gt $max
!ll&&!rl&&r
91422
MC/DC100%3/3
length $digits > length $max or length $digits == length $max and $digits gt $max
length $digits > length $max length $digits == length $max $digits gt $max
Truth table100%4/4
A or B and C
A= length $digits > length $maxB= length $digits == length $maxC= $digits gt $max
ABCresult
1XX1
0111
00X0
0100
2374 if length($digits) > length($max)
2375 || (length($digits) == length($max) && $digits gt $max);
2376 }
2377 1623 return;
2378 }
2379  
2380 # the options the XS parser understands, which are the ones that let it throw
2381 # a line away before it has built a single SV for it
2382 1185 ▶sub _xs_options {
Subroutine _xs_options: called CC=6 SCAR=17.9
2383 1185 my ($o) = @_;
2384 return {
2385 model => ($o->{model} eq 'all' ? -1 : $o->{model}),
2386 # when atoms are wanted, the parse builds the atom hashes itself; see
2387 # the note in the XS about not building every atom twice. When they
2388 # are not, it builds the four columns _assemble() in the XS still reads
2389 # and none of the others.
2390 atom_hashes => $o->{atoms} ? 1 : 0,
2391 slim => $o->{atoms} ? 0 : 1,
2392 # and files them into their residues, which is where altloc is decided
2393 altloc_highest => $o->{altloc} eq 'highest' ? 1 : 0,
2394 hydrogens => $o->{hydrogens},
2395 waters => $o->{waters},
2396 hetatm => $o->{hetatm},
2397 meta => $o->{meta},
2398 anisou => $o->{anisou},
2399 1185 ▶ (defined $o->{chains} ? (chains => { map { $_ => 1 } @{ $o->{chains} } }) : ()),
Branch: 5 branches
BranchTrueFalseTotal
$o->{'model'} eq 'all' ? : 281 904 1185
$o->{'atoms'} ? : 1141 44 1185
$o->{'atoms'} ? : 1141 44 1185
$o->{'altloc'} eq 'highest' ? : 4 1181 1185
defined $o->{'chains'} ? : 36 1149 1185
2400 };
2401 }
2402  
2403 # the format a caller named, under the name it is filed under here
2404 528 ▶sub _alias {
Subroutine _alias: called CC=2 SCAR=6.9
2405 528 my ($fmt) = @_;
2406 528 $fmt = lc $fmt;
2407 528 ▶ return exists $ALIAS{$fmt} ? $ALIAS{$fmt} : $fmt;
Branch: 1 branch
BranchTrueFalseTotal
exists $ALIAS{$fmt} ? : 523 5 528
2408 }
2409  
2410 1110 ▶sub _detect_format {
Subroutine _detect_format: called CC=2 SCAR=6.9
2411 1110 my ($file) = @_;
2412 1110 my $fmt = _format_of_name($file);
2413 1110 ▶ return defined $fmt ? $fmt : _sniff_format(_head($file));
Branch: 1 branch
BranchTrueFalseTotal
defined $fmt ? : 1101 9 1110
2414 }
2415  
2416 # the format a file name says, or undef where it says none; convert() asks it
2417 # of the file it is about to write, which has no records yet to sniff
2418 1186 ▶sub _format_of_name {
Subroutine _format_of_name: called CC=5 SCAR=16.1
2419 1186 my ($file) = @_;
2420 1186 my $name = $file;
2421 1186 $name =~ s/\.(gz|bz2|z)\z//i;
2422 1186 ▶ return 'pdb' if $name =~ /\.(pdb|ent|pdb\d+)\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\.(pdb|ent|pdb\d+)\z/i 740 446 1186
2423 446 ▶ return 'mmcif' if $name =~ /\.(cif|mmcif|pdbx)\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\.(cif|mmcif|pdbx)\z/i 432 14 446
2424 14 ▶ return 'mol2' if $name =~ /\.mol2\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\.mol2\z/i 3 11 14
2425 11 ▶ return 'sdf' if $name =~ /\.(sdf|mol)\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\.(sdf|mol)\z/i 1 10 11
2426 10 return undef;
2427 }
2428  
2429 # when the name says nothing, the first few records do
2430 336 ▶sub _sniff_format {
Subroutine _sniff_format: called CC=5 SCAR=16.1
2431 336 my ($text) = @_;
2432 336 ▶ return 'mmcif' if $text =~ /^(?:data_|loop_|_atom_site\.)/m;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /^(?:data_|loop_|_atom_site\.)/m 130 206 336
2433 206 ▶ return 'pdb' if $text =~ /^(?:HEADER|ATOM |HETATM|MODEL |REMARK|CRYST1|SEQRES|EXPDTA|TITLE )/m;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /^(?:HEADER|ATOM |HETATM|MODEL |REMARK|CRYST1|SEQRES|EXPDTA|TITLE )/m 197 9 206
2434 9 ▶ return 'mol2' if $text =~ /^\@<TRIPOS>/m;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /^\@<TRIPOS>/m 2 7 9
2435 7 ▶ return 'sdf' if $text =~ /^\s*M END\s*$/m;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /^\s*M END\s*$/m 1 6 7
2436 6 return 'unknown';
2437 }
2438  
2439 9 ▶sub _head {
Subroutine _head: called CC=1 SCAR=0.0
2440 9 my ($file) = @_;
2441 9 my $text = _slurp_maybe_compressed($file, 8192);
2442 9 return $text;
2443 }
2444  
2445 # .gz and .bz2 are worth handling here: a directory of a few thousand
2446 # structures is usually kept compressed, and unpacking into a temporary file
2447 # first is both slower and something the caller then has to clean up.
2448 #
2449 # Both decompressors are IO::Compress, which is in core on every perl this
2450 # module installs on -- Bunzip2 joined it in 5.10.1, which is why that is the
2451 # minimum -- but which some vendors package apart from perl, so each is loaded
2452 # when a file needs it rather than asked of every installer.
2453 # The suffix is the whole of the rule: a file is unpacked because it is named
2454 # as compressed, and its name is what says how.
2455 my %UNPACK = (
2456 gz => { class => 'IO::Uncompress::Gunzip', verb => 'gunzip',
2457 what => 'gzipped',
2458 24 ▶ error => sub { no warnings 'once'; $IO::Uncompress::Gunzip::GunzipError } },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
2459 bz2 => { class => 'IO::Uncompress::Bunzip2', verb => 'bunzip2',
2460 what => 'compressed with bzip2',
2461 24 ▶ error => sub { no warnings 'once'; $IO::Uncompress::Bunzip2::Bunzip2Error } },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
2462 24 );
2463  
2464 # the key in %UNPACK that a file name asks for, or undef for a plain file
2465 1260 ▶sub _compression {
Subroutine _compression: called CC=2 SCAR=6.9
2466 1260 my ($file) = @_;
2467 1260 ▶ return $file =~ /\.(gz|bz2)\z/i ? lc $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$file =~ /\.(gz|bz2)\z/i ? : 120 1140 1260
2468 }
2469  
2470 73 ▶sub _slurp_maybe_compressed {
Subroutine _slurp_maybe_compressed: called CC=16 SCAR=28.9
2471 73 my ($file, $limit) = @_;
2472 73 ▶ if (my $kind = _compression($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $kind = _compression($file)) 62 11 73
2473 62 my $u = $UNPACK{$kind};
2474 62 (my $pm = "$u->{class}.pm") =~ s{::}{/}g;
2475 62 ▶ eval { require $pm; 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $pm; 1 } } or die qq[Chem::Structure::Parser: '${file}' is $u->{"what"} but $u->{"class"} is not installed: $@] 62 0 62
2476 or die "Chem::Structure::Parser: '$file' is $u->{what} but $u->{class} is not installed: $@";
2477 # MultiStream, because bgzip and `cat a.gz b.gz' both write a file of
2478 # several gzip members, and without it the reader stops at the end of the
2479 # first: mini.pdb split in two came back as 38 lines and no atoms, where
2480 # zcat gives the whole file. pbzip2 and `cat a.bz2 b.bz2' do the same to
2481 # bzip2 streams, and bzcat reads all of them too.
2482 my $z = $u->{class}->new($file, MultiStream => 1)
2483 62 ▶ or die "Chem::Structure::Parser: cannot $u->{verb} '$file': " . $u->{error}->();
Branch: 1 branch
BranchTrueFalseTotal
my $z = $u->{"class"}->new($file, "MultiStream", 1) or die qq[Chem::Structure::Parser: cannot $u->{"verb"} '${file}': ] . $u->{"error"}->() 55 7 62
2484 55 my ($text, $buf) = ('', '');
2485 # read() returns 0 at the end of the stream and a negative number on
2486 # error, so a `> 0' loop reads a truncated or corrupt archive as a short
2487 # file: half of mini.pdb.gz came back as a structure with no atoms in it
2488 # and nothing said so. That is the failure autodie existed to stop, on a
2489 # method autodie never covered, so it is checked here.
2490 55 while (1) {
2491 101 my $n = $z->read($buf, 65536);
2492 101 ▶ die "Can't read from '$file': '" . $z->error . "'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n and $n >= 0 5 96 101
Condition66%2/3
defined $n and $n >= 0
!ll&&!rl&&r
0596
MC/DC50%1/2
defined $n and $n >= 0
defined $n $n >= 0
Truth table66%2/3
A and B
A= defined $nB= $n >= 0
ABresult
0X0
100
111
2493 unless defined $n && $n >= 0;
2494 96 ▶ last if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 46 50 96
2495 50 $text .= $buf;
2496 50 ▶ last if defined $limit && length($text) >= $limit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $limit and length $text >= $limit 4 46 50
Condition66%2/3
defined $limit and length $text >= $limit
!ll&&!rl&&r
4604
MC/DC50%1/2
defined $limit and length $text >= $limit
defined $limit length $text >= $limit
Truth table66%2/3
A and B
A= defined $limitB= length $text >= $limit
ABresult
0X0
100
111
2497 }
2498 $z->close
2499 50 ▶ or die "Can't close '$file': '" . $z->error . "'";
Branch: 1 branch
BranchTrueFalseTotal
$z->close or die "Can't close '${file}': '" . $z->error . q['] 50 0 50
2500 50 return $text;
2501 }
2502 11 ▶ open my $fh, '<:raw', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or die "Can't open '${file}' with mode '<:raw': '$!'" 11 0 11
2503 or die "Can't open '$file' with mode '<:raw': '$!'";
2504 11 my $text = '';
2505 11 ▶ if (defined $limit) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $limit) { } 9 2 11
2506 # 0 is a short file rather than a failure, so it is defined() that says
2507 # which happened
2508 9 ▶ defined(read $fh, $text, $limit)
Branch: 1 branch
BranchTrueFalseTotal
defined read($fh, $text, $limit) or die "Can't read from '${file}': '$!'" 9 0 9
2509 or die "Can't read from '$file': '$!'";
2510 } else {
2511 # readline in slurp mode returns undef for an empty file and for a read
2512 # that failed alike, and readline is not a builtin autodie covered, so
2513 # $! is what tells the two apart -- cleared first, because it is only
2514 # meaningful where something set it. An I/O error read as an empty
2515 # string is a structure with no atoms and nothing said so.
2516 2 local $/;
2517 2 $! = 0;
2518 2 $text = <$fh>;
2519 2 ▶ unless (defined $text) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 2 2
2520 0 ▶ die "Can't read from '$file': '$!'" if $!;
Branch: 1 branch
BranchTrueFalseTotal
if $! 0 0 0
2521 0 $text = '';
2522 }
2523 }
2524 11 ▶ close $fh or die "Can't close '$file': '$!'";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Can't close '${file}': '$!'" 11 0 11
2525 11 return $text;
2526 }
2527  
2528 #
2529 # The readers
2530 #
2531 # There is one of these per format and they differ only in which XS parser
2532 # they call, because the parsers agree about what they hand back. Keeping
2533 # them as two named subs rather than one closure is so that %READER reads as a
2534 # list of formats and the die message above can name them.
2535 #
2536  
2537 548 ▶sub _read_pdb { return _read($XS{pdb}, @_) }
Subroutine _read_pdb: called CC=1 SCAR=0.0
2538 258 ▶sub _read_cif { return _read($XS{mmcif}, @_) }
Subroutine _read_cif: called CC=1 SCAR=0.0
2539  
2540 806 ▶sub _read {
Subroutine _read: called CC=2 SCAR=6.9
2541 806 my ($xs, $file, $o) = @_;
2542 806 my $p;
2543 806 ▶ if (_compression($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_compression($file)) { } 55 751 806
2544 55 my $text = _slurp_maybe_compressed($file, undef);
2545 43 $p = $xs->{string}->($text, _xs_options($o));
2546 43 $p = _retry_model($p, $o, $xs->{string}, $text);
2547 } else {
2548 751 $p = $xs->{file}->($file, _xs_options($o));
2549 749 $p = _retry_model($p, $o, $xs->{file}, $file);
2550 }
2551 792 return _build_structure($p, $o, $file);
2552 }
2553  
2554 # An NMR ensemble whose models are numbered from 0, or a file whose only model
2555 # is MODEL 7, would otherwise come back empty for the default model => 1. The
2556 # parse says which model numbers it saw, so ask again for the first real one
2557 # rather than handing back a structure with no atoms in it.
2558 #
2559 # A file with no MODEL records has one model and it is model 1 -- that is what
2560 # the parse read its atoms under -- so it is the fall-back for that file as
2561 # model 0 is for the ensemble numbered from 0. Without it the rule held for an
2562 # ensemble and not for the crystal structures that are most of the archive:
2563 # model => 2 of a file with no MODEL records handed back a structure with no
2564 # atoms and no chains and said nothing, which is the answer this exists to
2565 # prevent. Nothing is read twice to get it: the model the caller asked for is
2566 # already in the list for every file that was emptied by something else -- a
2567 # chains or waters option, or a file with no coordinates at all -- and those
2568 # return here untouched.
2569 1168 ▶sub _retry_model {
Subroutine _retry_model: called CC=5 SCAR=16.1
2570 1168 my ($p, $o, $parse, $src) = @_;
2571 1168 ▶ return $p if $p->{n_atoms} || $o->{model} eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $p->{"n_atoms"} or $o->{"model"} eq "all" 1115 53 1168
Condition100%3/3
$p->{"n_atoms"} or $o->{"model"} eq "all"
l!l&&r!l&&!r
11051053
MC/DC100%2/2
$p->{"n_atoms"} or $o->{"model"} eq "all"
$p->{"n_atoms"} $o->{"model"} eq "all"
Truth table100%3/3
A or B
A= $p->{"n_atoms"}B= $o->{"model"} eq "all"
ABresult
1X1
011
000
2572 53 ▶ my $nums = @{ $p->{model_numbers} } ? $p->{model_numbers} : [ 1 ];
Branch: 1 branch
BranchTrueFalseTotal
@{$p->{'model_numbers'};} ? : 10 43 53
2573 53 ▶ return $p if grep { $_ == $o->{model} } @$nums;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == $o->{"model"};} @$nums 38 15 53
2574 15 my $x = _xs_options($o);
2575 15 $x->{model} = $nums->[0];
2576 15 my $q = $parse->($src, $x);
2577 15 $q->{requested_model} = $nums->[0];
2578 15 return $q;
2579 }
2580  
2581 1168 ▶sub _build_structure {
Subroutine _build_structure: called CC=18 SCAR=29.0
2582 1168 my ($p, $o, $file) = @_;
2583 1168 ▶ my $fmt = $p->{format} || 'pdb';
Condition50%1/2
$p->{'format'} || 'pdb'
l!l
11680
MC/DC0%0/1
$p->{'format'} || 'pdb'
$p->{'format'}
Truth table50%1/2
A
A= $p->{'format'}
Aresult
11
00
2584 my $info = {
2585 file => $file,
2586 format => $fmt,
2587 model => (defined $p->{requested_model} ? $p->{requested_model}
2588 : $o->{model} eq 'all' ? 'all' : $o->{model}),
2589 n_models => $p->{n_models},
2590 # The counts and extremes come straight from the parse. They have to
2591 # touch every atom, and the parse is already reading every atom, so
2592 # doing them there costs nothing and doing them again here would cost
2593 # more than the parse itself.
2594 stats => {
2595 n_atoms => $p->{n_atoms},
2596 n_hetatm => 0,
2597 # Every ATOM/HETATM record the file has, which is not what n_atoms
2598 # counts: that one is what came back, after the model selection and
2599 # the hydrogens, waters, hetatm and chains options have had their
2600 # say, and this one is what was there to be filtered. The two are
2601 # equal for a single-model file read with the defaults and are not
2602 # for anything else -- an NMR ensemble read at its default model => 1
2603 # returns a twentieth of its atoms and is not a twentieth of a file.
2604 # total_atoms == n_atoms + n_skipped, always, in both formats.
2605 total_atoms => $p->{n_atom_records} + $p->{n_hetatm_records},
2606 n_hydrogens => $p->{n_hydrogens},
2607 n_water_atoms => $p->{n_water_atoms},
2608 n_atom_records => $p->{n_atom_records},
2609 n_hetatm_records => $p->{n_hetatm_records},
2610 n_anisou => $p->{n_anisou},
2611 n_skipped => $p->{n_skipped},
2612 n_lines => $p->{n_lines},
2613 elements => $p->{elements},
2614 bfactor => $p->{bfactor_stats},
2615 bbox => $p->{bbox},
2616 center => $p->{center},
2617 },
2618 1168 ▶ };
Branch: 2 branches
BranchTrueFalseTotal
defined $p->{'requested_model'} ? : 15 1153 1168
$o->{'model'} eq 'all' ? : 281 872 1153
2619  
2620 # the one place the two formats are read differently, and the reason it is
2621 # the only one: everything below works off $info, which is the same shape
2622 # whichever of these filled it in
2623 1168 ▶ if ($o->{meta}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"meta"}) 1092 76 1168
2624 1092 ▶ $fmt eq 'mmcif' ? _parse_cif_meta($info, $p) : _parse_meta($info, $p->{meta} || {});
Branch: 1 branch
BranchTrueFalseTotal
$fmt eq 'mmcif' ? : 389 703 1092
Condition50%1/2
$p->{'meta'} || {}
l!l
7030
MC/DC0%0/1
$p->{'meta'} || {}
$p->{'meta'}
Truth table50%1/2
A
A= $p->{'meta'}
Aresult
11
00
2625 }
2626  
2627 # the runs the parse read, gathered into models of chains of residues, each
2628 # chain rolled up into its sequence, type and gaps; assemble() in the XS
2629 1168 ▶ my $by_model = _assemble($p, $o->{atoms} ? 1 : 0, $info->{stats});
Branch: 1 branch
BranchTrueFalseTotal
$o->{'atoms'} ? : 1124 44 1168
2630 # Nothing reads the parse after this, and it would otherwise live until the
2631 # caller's read returned -- through the features below, which are most of a
2632 # default read's peak. Its atoms are referenced from their residues now, so
2633 # what goes is the per-run arrays and the list of atoms: 4fqr's default read
2634 # peaked at 221 MB with them and 209 MB without.
2635 1168 %$p = ();
2636 1168 my @models = sort { $a <=> $b } keys %$by_model;
2637 1168 ▶ my $main = $o->{model} eq 'all' ? (@models ? $models[0] : 1) : $info->{model};
Branch: 2 branches
BranchTrueFalseTotal
$o->{'model'} eq 'all' ? : 281 887 1168
@models ? : 271 10 281
2638 1168 ▶ $main = $models[0] if @models && !exists $by_model->{$main};
Branch: 1 branch
BranchTrueFalseTotal
if @models and not exists $by_model->{$main} 0 1168 1168
Condition66%2/3
@models and not exists $by_model->{$main}
!ll&&!rl&&r
4811200
MC/DC0%0/2
@models and not exists $by_model->{$main}
@models not exists $by_model->{$main}
Truth table66%2/3
A and not(B)
A= @modelsB= not exists $by_model->{$main}
ABresult
0X0
100
111
2639  
2640 1168 ▶ my $sel = $by_model->{$main} || { chains => {}, chain_order => [] };
Condition100%2/2
$by_model->{$main} || {'chains', {}, 'chain_order', []}
l!l
112048
MC/DC100%1/1
$by_model->{$main} || {'chains', {}, 'chain_order', []}
$by_model->{$main}
Truth table100%2/2
A
A= $by_model->{$main}
Aresult
11
00
2641 1168 $info->{chains} = $sel->{chains};
2642 1168 $info->{chain_order} = $sel->{chain_order};
2643 1168 ▶ if ($o->{model} eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"model"} eq "all") 281 887 1168
2644 281 $info->{models} = $by_model;
2645 281 $info->{model} = $main;
2646 }
2647  
2648 1168 _chain_stats($info);
2649 1168 $info->{id} = _id_from($info, $file);
2650  
2651 # The physical properties, computed on the way past.
2652 #
2653 # They are on by default because a structure's surface, size and contacts
2654 # are as much a part of what it *is* as its sequence, and a caller who has
2655 # to know to ask for them mostly does not. What that costs is real and is
2656 # measured in notes.txt: reading a structure goes from about 279,000 atoms a
2657 # second to about 43,600, which is 6.4 times the cost. The largest part is
2658 # the solvent-accessible surfaces, at 960 sphere points per atom -- with
2659 # sasa => 0 the rest together come to 3.4x the read. features => 0 is the
2660 # way back to the old speed, and is what to reach for when reading a
2661 # directory for its headers or its sequences.
2662 #
2663 # atoms => 0 turns them off on its own rather than dying: it is the
2664 # documented way to read a file for its residues without its coordinates,
2665 # structure_sequences() passes it, and a fast path that started dying would
2666 # be a worse answer than one that quietly has nothing to compute from.
2667 $info->{features} = _all_features($info, 'structure_info', $o->{partners})
2668 1168 ▶ if $o->{features} && $o->{atoms};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"features"} and $o->{"atoms"} 562 606 1168
Condition100%3/3
$o->{"features"} and $o->{"atoms"}
!ll&&!rl&&r
59313562
MC/DC100%2/2
$o->{"features"} and $o->{"atoms"}
$o->{"features"} $o->{"atoms"}
Truth table100%3/3
A and B
A= $o->{"features"}B= $o->{"atoms"}
ABresult
0X0
100
111
2669  
2670 # dssp => 1 lifts the secondary structure roll-up out of the features and
2671 # puts it where a caller who wants that and not the rest will look for it.
2672 # It is the same hash, not a copy: structure_dssp() hands back the same one.
2673 # With features => 0 it is computed on its own, which is the cheap way to
2674 # the secondary structure: it used to leave nothing at {dssp} and say
2675 # nothing, which read as a structure with no secondary structure in it.
2676 1167 ▶ if ($o->{dssp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"dssp"}) 58 1109 1167
2677 58 ▶ $info->{dssp} = $info->{features} ? $info->{features}{dssp} : structure_dssp($info);
Branch: 1 branch
BranchTrueFalseTotal
$info->{'features'} ? : 54 4 58
2678 }
2679  
2680 1167 return $info;
2681 }
2682  
2683 # the largest separation of a carbonyl carbon from the next residue's nitrogen
2684 # that is a peptide bond: gemmi 0.7.0 polyheur.hpp, have_peptide_bond(), 1.5
2685 # times 1.341 A. CSP_LINK_CN in Parser.xs is the same bound, for the residues
2686 # assemble() decides are free of their polymer.
2687 24 my $PEPTIDE_CN = 1.341 * 1.5;
2688  
2689 # _peptide_linked($a, $b) -- whether $a's carbonyl carbon is bonded to $b's
2690 # nitrogen, for residues whose type says nothing about it
2691 164 ▶sub _peptide_linked {
Subroutine _peptide_linked: called CC=5 SCAR=16.1
2692 164 my ($a, $b) = @_;
2693 164 my ($c, $n) = ($a->{atoms}{C}, $b->{atoms}{N});
2694 164 ▶ return 0 unless $c && $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $c and $n 143 21 164
Condition100%3/3
$c and $n
!ll&&!rl&&r
114221
MC/DC100%2/2
$c and $n
$c $n
Truth table100%3/3
A and B
A= $cB= $n
ABresult
0X0
100
111
2695 21 ▶ return 0 if grep { !defined } @$c{qw(x y z)}, @$n{qw(x y z)};
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} @$c{"x", "y", "z"}, @$n{"x", "y", "z"} 0 21 21
2696 21 my $d2 = ($c->{x} - $n->{x}) ** 2 + ($c->{y} - $n->{y}) ** 2 + ($c->{z} - $n->{z}) ** 2;
2697 21 ▶ return $d2 < $PEPTIDE_CN ** 2 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$d2 < $PEPTIDE_CN ** 2 ? : 17 4 21
2698 }
2699  
2700 # SEQRES, COMPND and SOURCE all describe chains; fold them in once the chains
2701 # exist, so that everything about a chain is in one place
2702 1168 ▶sub _chain_stats {
Subroutine _chain_stats: called CC=17 SCAR=28.3
2703 1168 my ($info) = @_;
2704 # The free-text COMPND of an old file names no chains, so there was no
2705 # chain to file it under when the header was read and there is one now: the
2706 # entry is the one molecule and every chain in it is that molecule. This is
2707 # the only place a chain is added to entity_of_chain, because it is the only
2708 # entity that could not say for itself which chains it means.
2709 1168 ▶ if (($info->{compound}{1} || {})->{free_text} && !%{ $info->{entity_of_chain} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (+($info->{"compound"}{1} || {})->{"free_text"} and not %{$info->{"entity_of_chain"};}) 6 1162 1168
Condition80%4/5
+($info->{"compound"}{1} || {})->{"free_text"} and not %{$info->{"entity_of_chain"};}
!ll&&!rl&&r
116206
$info->{'compound'}{'1'} || {}
l!l
341827
MC/DC50%1/2
+($info->{"compound"}{1} || {})->{"free_text"} and not %{$info->{"entity_of_chain"};}
$info->{'compound'}{'1'} not %{$info->{"entity_of_chain"};}
Truth table66%2/3
A and not(B)
A= $info->{'compound'}{'1'}B= not %{$info->{"entity_of_chain"};}
ABresult
0X0
100
111
2710 6 ▶ my $s = $info->{source}{1} || {};
Condition100%2/2
$info->{'source'}{'1'} || {}
l!l
42
MC/DC100%1/1
$info->{'source'}{'1'} || {}
$info->{'source'}{'1'}
Truth table100%2/2
A
A= $info->{'source'}{'1'}
Aresult
11
00
2711 $info->{entity_of_chain}{$_} = {
2712 mol_id => 1,
2713 molecule => $info->{compound}{1}{molecule},
2714 organism => $s->{organism_scientific},
2715 6 } for @{ $info->{chain_order} };
2716 }
2717 # Every model's chains, not only the main model's: with model => 'all' each
2718 # model is its own set of chains, and the header describes all of them alike.
2719 # 2ll7 read that way had CALMODULIN and its 148-residue SEQRES on model 1's
2720 # chain A and nothing on the other nineteen. The main model is one of the
2721 # models, so walking the models covers it.
2722 my @sets = $info->{models}
2723 479 ? map { $info->{models}{$_} } sort { $a <=> $b } keys %{ $info->{models} }
2724 1168 ▶ : ({ chains => $info->{chains}, chain_order => $info->{chain_order} });
Branch: 1 branch
BranchTrueFalseTotal
$info->{'models'} ? : 281 887 1168
2725 1168 for my $set (@sets) {
2726 1366 for my $cid (@{ $set->{chain_order} }) {
2727 1718 my $c = $set->{chains}{$cid};
2728 1718 ▶ if (my $s = $info->{seqres}{$cid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = $info->{"seqres"}{$cid}) 753 965 1718
2729 753 $c->{seqres} = $s->{sequence};
2730 753 $c->{seqres_length} = $s->{length};
2731 753 ▶ $c->{n_missing} = $s->{length} - $c->{n_polymer} if defined $s->{length};
Branch: 1 branch
BranchTrueFalseTotal
if defined $s->{"length"} 753 0 753
2732 }
2733 1718 ▶ if (my $e = $info->{entity_of_chain}{$cid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $info->{"entity_of_chain"}{$cid}) 631 1087 1718
2734 631 $c->{mol_id} = $e->{mol_id};
2735 631 ▶ $c->{molecule} = $e->{molecule} if defined $e->{molecule};
Branch: 1 branch
BranchTrueFalseTotal
if defined $e->{"molecule"} 593 38 631
2736 631 ▶ $c->{organism} = $e->{organism} if defined $e->{organism};
Branch: 1 branch
BranchTrueFalseTotal
if defined $e->{"organism"} 395 236 631
2737 631 ▶ $c->{fragment} = $e->{fragment} if defined $e->{fragment};
Branch: 1 branch
BranchTrueFalseTotal
if defined $e->{"fragment"} 209 422 631
2738 631 ▶ $c->{ec} = $e->{ec} if defined $e->{ec};
Branch: 1 branch
BranchTrueFalseTotal
if defined $e->{"ec"} 208 423 631
2739 }
2740 1718 ▶ $c->{dbref} = $info->{dbref}{$cid} if $info->{dbref}{$cid};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"dbref"}{$cid} 391 1327 1718
2741 }
2742 }
2743 1168 return $info;
2744 }
2745  
2746 1254 ▶sub _id_from {
Subroutine _id_from: called CC=4 SCAR=13.9
2747 1254 my ($info, $file) = @_;
2748 1254 ▶ return $info->{header}{id_code} if length($info->{header}{id_code} || '');
Branch: 1 branch
BranchTrueFalseTotal
if length($info->{"header"}{"id_code"} || "") 436 818 1254
Condition100%2/2
$info->{'header'}{'id_code'} || ''
l!l
436818
MC/DC100%1/1
$info->{'header'}{'id_code'} || ''
$info->{'header'}{'id_code'}
Truth table100%2/2
A
A= $info->{'header'}{'id_code'}
Aresult
11
00
2749 818 ▶ return undef unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 272 546 818
2750 546 my ($base) = $file =~ m{([^/\\]+)\z};
2751 546 $base =~ s/\.(gz|bz2|z)\z//i;
2752 # every suffix _detect_format() reads a format from: '2abc.pdbx' came back
2753 # as the id 2ABC.PDBX
2754 546 $base =~ s/\.(pdb|ent|cif|mmcif|pdbx)\z//i;
2755 546 $base =~ s/\.ent\z//i;
2756 # The archive's own name for an entry is pdb1abc.ent, and the prefix is not
2757 # part of the id. Only that: a file called pdbfixer_output.pdb came back as
2758 # FIXER_OUTPUT, the prefix taken off a name that never had one.
2759 546 $base =~ s/\Apdb(?=[0-9][0-9a-z]{3}\z)//i;
2760 546 return uc $base;
2761 }
2762  
2763 #
2764 # Header records
2765 #
2766 # Every one of these is a fixed-column record too, but there are only a few
2767 # dozen lines of them in a file, they are irregular, and they are where a new
2768 # quirk turns up every few hundred structures. That is Perl's job, not C's.
2769 #
2770 # The keys a parsed structure always has, whatever was in the file and
2771 # whichever format it was in. Set before either reader runs, so that a caller
2772 # can read $info->{resolution} without first asking whether the file was an
2773 # mmCIF, and get undef for "the file does not say" in both.
2774 1496 ▶sub _meta_defaults {
Subroutine _meta_defaults: called CC=5 SCAR=16.1
2775 1496 my ($info) = @_;
2776 1496 $info->{$_} = undef for qw(title resolution r_work r_free);
2777 1496 $info->{$_} = [] for qw(keywords experiment authors);
2778 1496 $info->{$_} = {} for qw(header compound source seqres het hetnam formul
2779 remarks dbref entity_of_chain cryst1 journal
2780 modres);
2781 # seqadv was missing from this list, so a file with no SEQADV -- every mmCIF
2782 # file, and any PDB file without one -- had no key at all where every other
2783 # list is an empty one
2784 1496 $info->{$_} = [] for qw(helix sheet ssbond link cispep revdat site conect
2785 seqadv);
2786 1496 return $info;
2787 }
2788  
2789 # _het_names($info) -- hetnam and formul, which the README's tree has always
2790 # listed and nothing ever filled: each heterogen's name and its formula, keyed by
2791 # its id, read off the het hash after either reader has filled that. The same
2792 # text stays in the het hash, where it is beside the rest of what is known
2793 # about the heterogen; these are the two flat lookups a caller who wants only
2794 # the name reaches for.
2795 1496 ▶sub _het_names {
Subroutine _het_names: called CC=4 SCAR=13.9
2796 1496 my ($info) = @_;
2797 1496 for my $id (keys %{ $info->{het} }) {
2798 695 my $h = $info->{het}{$id};
2799 695 ▶ $info->{hetnam}{$id} = $h->{name} if defined $h->{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->{"name"} 553 142 695
2800 695 ▶ $info->{formul}{$id} = $h->{formula} if defined $h->{formula};
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->{"formula"} 693 2 695
2801 }
2802 1496 return $info;
2803 }
2804  
2805 903 ▶sub _parse_meta {
Subroutine _parse_meta: called CC=96 SCAR=45.7
2806 903 my ($info, $meta) = @_;
2807 903 _meta_defaults($info);
2808  
2809 903 ▶ if (my $h = $meta->{HEADER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $h = $meta->{"HEADER"}) 345 558 903
2810 345 my $l = $h->[0];
2811 $info->{header} = {
2812 345 classification => _c($l, 10, 40),
2813 deposit_date => _c($l, 50, 9),
2814 id_code => _c($l, 62, 4),
2815 };
2816 }
2817 # The entry id, for _untail(): the text records of an old file end in it, and
2818 # it is the only thing that tells the stationery from the text. Every field
2819 # read past column 72 goes through it -- the text records, REVDAT's record
2820 # list, the REMARKs, the comments of SEQADV and MODRES, HETNAM, HETSYN and
2821 # FORMUL, and the SSBOND and LINK lengths -- because each of them came back
2822 # with the id on the end otherwise: pdb1gdr's first revision touched
2823 # '1GDR 6' and its REMARK 2 read '1GDR 44'.
2824 903 my $eid = $info->{header}{id_code};
2825  
2826 # a record that is not in the file reads as undef, not as an empty string:
2827 # "there was no TITLE" and "the TITLE was blank" are different answers
2828 903 ▶ $info->{title} = $meta->{TITLE} ? _joined($meta->{TITLE}, 10, $eid) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'TITLE'} ? : 324 579 903
2829 903 ▶ $info->{caveat} = _joined($meta->{CAVEAT}, 19, $eid) if $meta->{CAVEAT};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"CAVEAT"} 1 902 903
2830 903 $info->{keywords} = [ grep { length } map { _t($_) } split /,/, _joined($meta->{KEYWDS}, 10, $eid) ];
2831 903 $info->{experiment} = [ grep { length } map { _t($_) } split /;/, _joined($meta->{EXPDTA}, 10, $eid) ];
2832 903 $info->{authors} = [ grep { length } map { _t($_) } split /,/, _joined($meta->{AUTHOR}, 10, $eid) ];
2833 903 ▶ $info->{model_type} = _joined($meta->{MDLTYP}, 10, $eid) if $meta->{MDLTYP};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"MDLTYP"} 1 902 903
2834 903 ▶ $info->{obsolete} = _joined($meta->{OBSLTE}, 10, $eid) if $meta->{OBSLTE};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"OBSLTE"} 1 902 903
2835 903 ▶ $info->{split} = [ split ' ', _joined($meta->{SPLIT}, 10, $eid) ] if $meta->{SPLIT};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"SPLIT"} 1 902 903
2836  
2837 903 $info->{compound} = _mol_records($meta->{COMPND}, 10, 'molecule', $eid);
2838 903 $info->{source} = _mol_records($meta->{SOURCE}, 10, 'organism_scientific', $eid);
2839 903 _entities($info);
2840  
2841 # A revision that touched more records than one line has room for goes on
2842 # to a second line, which carries the revision number again, a continuation
2843 # number in columns 11-12, and nothing but the record names: no date, no id
2844 # and no type. It is the same revision, not another one with no date, and
2845 # the names it lists belong to it. 1a37's revision 5 is written that way;
2846 # 1,789 PDBbind entries have at least one.
2847 903 ▶ for my $l (@{ $meta->{REVDAT} || [] }) {
Condition100%2/2
$meta->{'REVDAT'} || []
l!l
145758
MC/DC100%1/1
$meta->{'REVDAT'} || []
$meta->{'REVDAT'}
Truth table100%2/2
A
A= $meta->{'REVDAT'}
Aresult
11
00
2848 425 my $prev = $info->{revdat}[-1];
2849 425 ▶ if (length _c($l, 10, 2) && $prev && $prev->{num} eq _c($l, 7, 3)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length _c($l, 10, 2) and $prev and $prev->{"num"} eq _c($l, 7, 3)) 140 285 425
Condition66%4/6
length _c($l, 10, 2) and $prev and $prev->{"num"} eq _c($l, 7, 3)
!ll&&!rl&&r
2850140
length _c($l, 10, 2) and $prev
!ll&&!rl&&r
2850140
MC/DC33%1/3
length _c($l, 10, 2) and $prev and $prev->{"num"} eq _c($l, 7, 3)
length _c($l, 10, 2) $prev $prev->{"num"} eq _c($l, 7, 3)
Truth table50%2/4
A and B and C
A= length _c($l, 10, 2)B= $prevC= $prev->{"num"} eq _c($l, 7, 3)
ABCresult
0XX0
10X0
1100
1111
2850 140 $prev->{what} = _rejoin($prev->{what}, _c(_untail($l, $eid), 39));
2851 140 next;
2852 }
2853 285 push @{ $info->{revdat} }, {
2854 num => _c($l, 7, 3),
2855 date => _c($l, 13, 9),
2856 id => _c($l, 23, 4),
2857 type => _c($l, 31, 1),
2858 what => _c(_untail($l, $eid), 39),
2859 };
2860 }
2861  
2862 # JRNL sub-records live in columns 13-16 and continue across lines
2863 903 ▶ for my $l (@{ $meta->{JRNL} || [] }) {
Condition100%2/2
$meta->{'JRNL'} || []
l!l
145758
MC/DC100%1/1
$meta->{'JRNL'} || []
$meta->{'JRNL'}
Truth table100%2/2
A
A= $meta->{'JRNL'}
Aresult
11
00
2864 868 my $sub = lc _c($l, 12, 4);
2865 868 ▶ next unless length $sub;
Branch: 1 branch
BranchTrueFalseTotal
unless length $sub 1 867 868
2866 867 my $text = _c(_untail($l, $eid), 19);
2867 $info->{journal}{$sub} = length($info->{journal}{$sub} || '')
2868 867 ▶ ? _rejoin($info->{journal}{$sub}, $text)
Branch: 1 branch
BranchTrueFalseTotal
length($info->{'journal'}{$sub} || '') ? : 149 718 867
Condition100%2/2
$info->{'journal'}{$sub} || ''
l!l
149718
MC/DC100%1/1
$info->{'journal'}{$sub} || ''
$info->{'journal'}{$sub}
Truth table100%2/2
A
A= $info->{'journal'}{$sub}
Aresult
11
00
2869 : $text;
2870 }
2871 290 $info->{journal}{auth} = [ grep { length } map { _t($_) } split /,/, $info->{journal}{auth} ]
2872 903 ▶ if defined $info->{journal}{auth};
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"journal"}{"auth"} 145 758 903
2873  
2874 # REMARKs are kept whole, by number: there are hundreds of kinds and the
2875 # useful ones are pulled out below. Anything not pulled out is still there.
2876 903 ▶ for my $l (@{ $meta->{REMARK} || [] }) {
Condition100%2/2
$meta->{'REMARK'} || []
l!l
215688
MC/DC100%1/1
$meta->{'REMARK'} || []
$meta->{'REMARK'}
Truth table100%2/2
A
A= $meta->{'REMARK'}
Aresult
11
00
2877 2547 my $n = _c($l, 7, 3);
2878 2547 ▶ next unless length $n;
Branch: 1 branch
BranchTrueFalseTotal
unless length $n 1 2546 2547
2879 2546 push @{ $info->{remarks}{$n} }, _c(_untail($l, $eid), 11);
2880 }
2881 903 ▶ for my $l (@{ $info->{remarks}{2} || [] }) {
Condition100%2/2
$info->{'remarks'}{'2'} || []
l!l
211692
MC/DC100%1/1
$info->{'remarks'}{'2'} || []
$info->{'remarks'}{'2'}
Truth table100%2/2
A
A= $info->{'remarks'}{'2'}
Aresult
11
00
2882 419 ▶ $info->{resolution} = $1 + 0 if $l =~ /RESOLUTION\.\s+($NUM)\s+ANGSTROM/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /RESOLUTION\.\s+($NUM)\s+ANGSTROM/ 210 209 419
2883 }
2884 # REMARK 3 says it too, as the high resolution limit of the refinement, and
2885 # that is the one to fall back on: a file written by a refinement program
2886 # rather than by the archive often has REMARK 3 and no REMARK 2 at all, and
2887 # 5cvz_final.pdb reads as a structure of no resolution otherwise. It is
2888 # also the same number the mmCIF reader already takes from
2889 # _refine.ls_d_res_high, so the two formats answer alike. Anchored, because
2890 # REMARK 3 also carries 'BIN RESOLUTION RANGE HIGH', which is a bin and not
2891 # the structure.
2892 903 ▶ if (!defined $info->{resolution}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info->{"resolution"}) 693 210 903
2893 693 ▶ for my $l (@{ $info->{remarks}{3} || [] }) {
Condition100%2/2
$info->{'remarks'}{'3'} || []
l!l
3690
MC/DC100%1/1
$info->{'remarks'}{'3'} || []
$info->{'remarks'}{'3'}
Truth table100%2/2
A
A= $info->{'remarks'}{'3'}
Aresult
11
00
2894 13 ▶ next unless $l =~ /\ARESOLUTION RANGE HIGH\b[^:]*:\s*($NUM)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ /\ARESOLUTION RANGE HIGH\b[^:]*:\s*($NUM)/ 12 1 13
2895 1 $info->{resolution} = $1 + 0;
2896 1 last;
2897 }
2898 }
2899 # anchored, because REMARK 3 also carries 'BIN FREE R VALUE' and
2900 # 'ESTIMATED ERROR OF FREE R VALUE', which are not the R-free. A value of
2901 # NULL -- what an unrefined or pre-R-free structure has -- stays undef.
2902 903 ▶ for my $l (@{ $info->{remarks}{3} || [] }) {
Condition100%2/2
$info->{'remarks'}{'3'} || []
l!l
187716
MC/DC100%1/1
$info->{'remarks'}{'3'} || []
$info->{'remarks'}{'3'}
Truth table100%2/2
A
A= $info->{'remarks'}{'3'}
Aresult
11
00
2903 $info->{r_work} = $1 + 0 if !defined $info->{r_work}
2904 848 ▶ && $l =~ /\AR VALUE\s+\(WORKING SET\)\s*:\s*($NUM)/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $info->{"r_work"} and $l =~ /\AR VALUE\s+\(WORKING SET\)\s*:\s*($NUM)/ 170 678 848
Condition100%3/3
not defined $info->{"r_work"} and $l =~ /\AR VALUE\s+\(WORKING SET\)\s*:\s*($NUM)/
!ll&&!rl&&r
339339170
MC/DC100%2/2
not defined $info->{"r_work"} and $l =~ /\AR VALUE\s+\(WORKING SET\)\s*:\s*($NUM)/
not defined $info->{"r_work"} $l =~ /\AR VALUE\s+\(WORKING SET\)\s*:\s*($NUM)/
Truth table100%3/3
not(A) and B
A= not defined $info->{"r_work"}B= $l =~ /\AR VALUE\s+\(WORKING SET\)\s*:\s*($NUM)/
ABresult
0X0
100
111
2905 $info->{r_free} = $1 + 0 if !defined $info->{r_free}
2906 848 ▶ && $l =~ /\AFREE R VALUE\s*:\s*($NUM)/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $info->{"r_free"} and $l =~ /\AFREE R VALUE\s*:\s*($NUM)/ 170 678 848
Condition100%3/3
not defined $info->{"r_free"} and $l =~ /\AFREE R VALUE\s*:\s*($NUM)/
!ll&&!rl&&r
169509170
MC/DC100%2/2
not defined $info->{"r_free"} and $l =~ /\AFREE R VALUE\s*:\s*($NUM)/
not defined $info->{"r_free"} $l =~ /\AFREE R VALUE\s*:\s*($NUM)/
Truth table100%3/3
not(A) and B
A= not defined $info->{"r_free"}B= $l =~ /\AFREE R VALUE\s*:\s*($NUM)/
ABresult
0X0
100
111
2907 }
2908 # A structure refined with SHELXL writes its R values twice, once for all
2909 # the data and once for F > 4 sigma(F), and neither line is spelled like the
2910 # two above: 'R VALUE (WORKING SET, NO CUTOFF)' and 'FREE R VALUE (NO
2911 # CUTOFF)'. The no-cutoff pair is the one the archive files as the R-work
2912 # and R-free: the mmCIF of 1c5c has 0.2529 as _refine.ls_R_factor_R_free and
2913 # 0.1934 as _pdbx_refine.R_factor_obs_no_cutoff, where its PDB file has 0.253
2914 # and 0.193 on those lines and 0.243 and 0.186 on the F > 4 sigma(F) ones.
2915 # 81 PDBbind entries had neither number without this.
2916 903 ▶ for my $l (@{ $info->{remarks}{3} || [] }) {
Condition100%2/2
$info->{'remarks'}{'3'} || []
l!l
187716
MC/DC100%1/1
$info->{'remarks'}{'3'} || []
$info->{'remarks'}{'3'}
Truth table100%2/2
A
A= $info->{'remarks'}{'3'}
Aresult
11
00
2917 $info->{r_work} = $1 + 0 if !defined $info->{r_work}
2918 848 ▶ && $l =~ /\AR VALUE\s+\(WORKING SET,\s*NO CUTOFF\)\s*:\s*($NUM)/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $info->{"r_work"} and $l =~ /\AR VALUE\s+\(WORKING SET,\s*NO CUTOFF\)\s*:\s*($NUM)/ 1 847 848
Condition100%3/3
not defined $info->{"r_work"} and $l =~ /\AR VALUE\s+\(WORKING SET,\s*NO CUTOFF\)\s*:\s*($NUM)/
!ll&&!rl&&r
6871601
MC/DC100%2/2
not defined $info->{"r_work"} and $l =~ /\AR VALUE\s+\(WORKING SET,\s*NO CUTOFF\)\s*:\s*($NUM)/
not defined $info->{"r_work"} $l =~ /\AR VALUE\s+\(WORKING SET,\s*NO CUTOFF\)\s*:\s*($NUM)/
Truth table100%3/3
not(A) and B
A= not defined $info->{"r_work"}B= $l =~ /\AR VALUE\s+\(WORKING SET,\s*NO CUTOFF\)\s*:\s*($NUM)/
ABresult
0X0
100
111
2919 $info->{r_free} = $1 + 0 if !defined $info->{r_free}
2920 848 ▶ && $l =~ /\AFREE R VALUE\s+\(NO CUTOFF\)\s*:\s*($NUM)/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $info->{"r_free"} and $l =~ /\AFREE R VALUE\s+\(NO CUTOFF\)\s*:\s*($NUM)/ 1 847 848
Condition100%3/3
not defined $info->{"r_free"} and $l =~ /\AFREE R VALUE\s+\(NO CUTOFF\)\s*:\s*($NUM)/
!ll&&!rl&&r
6861611
MC/DC100%2/2
not defined $info->{"r_free"} and $l =~ /\AFREE R VALUE\s+\(NO CUTOFF\)\s*:\s*($NUM)/
not defined $info->{"r_free"} $l =~ /\AFREE R VALUE\s+\(NO CUTOFF\)\s*:\s*($NUM)/
Truth table100%3/3
not(A) and B
A= not defined $info->{"r_free"}B= $l =~ /\AFREE R VALUE\s+\(NO CUTOFF\)\s*:\s*($NUM)/
ABresult
0X0
100
111
2921 }
2922 903 ▶ for my $l (@{ $info->{remarks}{200} || [] }) {
Condition100%2/2
$info->{'remarks'}{'200'} || []
l!l
170733
MC/DC100%1/1
$info->{'remarks'}{'200'} || []
$info->{'remarks'}{'200'}
Truth table100%2/2
A
A= $info->{'remarks'}{'200'}
Aresult
11
00
2923 340 ▶ $info->{temperature} = $1 + 0 if $l =~ /TEMPERATURE\s+\(KELVIN\)\s*:\s*($NUM)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /TEMPERATURE\s+\(KELVIN\)\s*:\s*($NUM)/ 170 170 340
2924 340 ▶ $info->{ph} = $1 + 0 if $l =~ /\bPH\s*:\s*($NUM)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\bPH\s*:\s*($NUM)/ 170 170 340
2925 }
2926 903 ▶ $info->{biological_assembly} = $info->{remarks}{350} if $info->{remarks}{350};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"remarks"}{350} 0 903 903
2927  
2928 # SEQRES -- what was in the crystal, as opposed to what was modelled
2929 #
2930 # Thirteen residues to a line, columns 20 to 70, and no further: a file old
2931 # enough to keep the entry id in columns 73-80 has '1GDR 81' sitting there,
2932 # and reading to the end of the line makes two more residues out of it.
2933 # pdb1gdr's 140-residue chain comes back 162 long that way, with an X every
2934 # thirteenth place, which is a wrong sequence rather than a missing one.
2935 903 ▶ for my $l (@{ $meta->{SEQRES} || [] }) {
Condition100%2/2
$meta->{'SEQRES'} || []
l!l
335568
MC/DC100%1/1
$meta->{'SEQRES'} || []
$meta->{'SEQRES'}
Truth table100%2/2
A
A= $meta->{'SEQRES'}
Aresult
11
00
2936 695 my $cid = _c($l, 11, 1);
2937 695 my $n = _c($l, 13, 4);
2938 695 my @res = split ' ', _c($l, 19, 51);
2939 695 ▶ my $s = $info->{seqres}{$cid} ||= { chain => $cid, length => ($n =~ /\A\d+\z/ ? $n + 0 : undef), residues => [] };
Branch: 1 branch
BranchTrueFalseTotal
$n =~ /\A\d+\z/ ? : 524 1 525
Condition100%2/2
$info->{"seqres"}{$cid} ||= {"chain", $cid, "length", $n =~ /\A\d+\z/ ? $n + 0 : undef, "residues", []}
l!l
170525
MC/DC100%1/1
$info->{"seqres"}{$cid} ||= {"chain", $cid, "length", $n =~ /\A\d+\z/ ? $n + 0 : undef, "residues", []}
$info->{"seqres"}{$cid}
Truth table100%2/2
A
A= $info->{"seqres"}{$cid}
Aresult
11
00
2940 695 push @{ $s->{residues} }, @res;
2941 }
2942 903 for my $cid (keys %{ $info->{seqres} }) {
2943 525 my $s = $info->{seqres}{$cid};
2944 525 ▶ $s->{sequence} = join '', map { my $o = res1($_); length $o ? $o : 'X' } @{ $s->{residues} };
Branch: 1 branch
BranchTrueFalseTotal
length $o ? : 5698 40 5738
2945 525 ▶ $s->{length} = scalar @{ $s->{residues} } unless defined $s->{length};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s->{"length"} 1 524 525
2946 }
2947  
2948 903 ▶ for my $l (@{ $meta->{DBREF} || [] }) {
Condition100%2/2
$meta->{'DBREF'} || []
l!l
140763
MC/DC100%1/1
$meta->{'DBREF'} || []
$meta->{'DBREF'}
Truth table100%2/2
A
A= $meta->{'DBREF'}
Aresult
11
00
2949 140 my $cid = _c($l, 12, 1);
2950 140 push @{ $info->{dbref}{$cid} }, {
2951 chain => $cid,
2952 seq_begin => _c($l, 14, 4),
2953 seq_end => _c($l, 20, 4),
2954 database => _c($l, 26, 6),
2955 accession => _c($l, 33, 8),
2956 db_id => _c($l, 42, 12),
2957 db_begin => _c($l, 55, 5),
2958 db_end => _c($l, 62, 5),
2959 };
2960 }
2961 # An accession or database id too long for DBREF's columns -- a UniProt
2962 # accession of ten characters, an id like A0A2B6C295_BACAN -- is written as
2963 # a DBREF1 and DBREF2 pair instead: the first line the chain's range and the
2964 # database, the second the accession and the database's range. They are
2965 # always written one after the other, so the n-th of each are a pair.
2966 # Columns from the wwPDB format v3.3 and Bio.SeqIO.PdbIO of Biopython 1.87,
2967 # which reads them the same way. 232 PDBbind entries have them and no
2968 # DBREF at all, so without this they had no cross-references.
2969 903 ▶ my @dbref2 = @{ $meta->{DBREF2} || [] };
Condition100%2/2
$meta->{'DBREF2'} || []
l!l
142761
MC/DC100%1/1
$meta->{'DBREF2'} || []
$meta->{'DBREF2'}
Truth table100%2/2
A
A= $meta->{'DBREF2'}
Aresult
11
00
2970 903 ▶ for my $l (@{ $meta->{DBREF1} || [] }) {
Condition100%2/2
$meta->{'DBREF1'} || []
l!l
142761
MC/DC100%1/1
$meta->{'DBREF1'} || []
$meta->{'DBREF1'}
Truth table100%2/2
A
A= $meta->{'DBREF1'}
Aresult
11
00
2971 143 my $cid = _c($l, 12, 1);
2972 143 my $m = shift @dbref2;
2973 # a DBREF2 for another chain is not this one's second half, and
2974 # pairing it anyway would file one chain's accession under another
2975 143 ▶ undef $m if defined $m && _c($m, 12, 1) ne $cid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $m and _c($m, 12, 1) ne $cid 1 142 143
Condition66%2/3
defined $m and _c($m, 12, 1) ne $cid
!ll&&!rl&&r
01421
MC/DC50%1/2
defined $m and _c($m, 12, 1) ne $cid
defined $m _c($m, 12, 1) ne $cid
Truth table66%2/3
A and B
A= defined $mB= _c($m, 12, 1) ne $cid
ABresult
0X0
100
111
2976 143 push @{ $info->{dbref}{$cid} }, {
2977 chain => $cid,
2978 seq_begin => _c($l, 14, 4),
2979 seq_end => _c($l, 20, 4),
2980 database => _c($l, 26, 6),
2981 accession => _c($m, 18, 22),
2982 db_id => _c($l, 47, 20),
2983 db_begin => _c($m, 45, 10),
2984 db_end => _c($m, 57, 10),
2985 };
2986 }
2987 903 ▶ for my $l (@{ $meta->{SEQADV} || [] }) {
Condition100%2/2
$meta->{'SEQADV'} || []
l!l
142761
MC/DC100%1/1
$meta->{'SEQADV'} || []
$meta->{'SEQADV'}
Truth table100%2/2
A
A= $meta->{'SEQADV'}
Aresult
11
00
2988 142 push @{ $info->{seqadv} }, {
2989 resname => _c($l, 12, 3),
2990 chain => _c($l, 16, 1),
2991 resseq => _c($l, 18, 4),
2992 database => _c($l, 24, 4),
2993 accession => _c($l, 29, 9),
2994 db_res => _c($l, 39, 3),
2995 db_seq => _c($l, 43, 5),
2996 comment => _c(_untail($l, $eid), 49),
2997 };
2998 }
2999 903 ▶ for my $l (@{ $meta->{MODRES} || [] }) {
Condition100%2/2
$meta->{'MODRES'} || []
l!l
141762
MC/DC100%1/1
$meta->{'MODRES'} || []
$meta->{'MODRES'}
Truth table100%2/2
A
A= $meta->{'MODRES'}
Aresult
11
00
3000 141 my $r = _c($l, 12, 3);
3001 141 ▶ $info->{modres}{$r} ||= {
Condition50%1/2
$info->{"modres"}{$r} ||= {"resname", $r, "standard", _c($l, 24, 3), "comment", _c(_untail($l, $eid), 29)}
l!l
0141
MC/DC0%0/1
$info->{"modres"}{$r} ||= {"resname", $r, "standard", _c($l, 24, 3), "comment", _c(_untail($l, $eid), 29)}
$info->{"modres"}{$r}
Truth table50%1/2
A
A= $info->{"modres"}{$r}
Aresult
11
00
3002 resname => $r,
3003 standard => _c($l, 24, 3),
3004 comment => _c(_untail($l, $eid), 29),
3005 };
3006 }
3007  
3008 # heterogens: HET gives the instances, HETNAM/FORMUL name them
3009 903 ▶ for my $l (@{ $meta->{HET} || [] }) {
Condition100%2/2
$meta->{'HET'} || []
l!l
141762
MC/DC100%1/1
$meta->{'HET'} || []
$meta->{'HET'}
Truth table100%2/2
A
A= $meta->{'HET'}
Aresult
11
00
3010 281 my $id = _c($l, 7, 3);
3011 281 push @{ $info->{het}{$id}{instances} }, {
3012 chain => _c($l, 12, 1),
3013 resseq => _c($l, 13, 4),
3014 icode => _c($l, 17, 1),
3015 natoms => _c($l, 20, 5),
3016 };
3017 281 $info->{het}{$id}{het_id} = $id;
3018 }
3019 903 ▶ for my $l (@{ $meta->{HETNAM} || [] }) {
Condition100%2/2
$meta->{'HETNAM'} || []
l!l
142761
MC/DC100%1/1
$meta->{'HETNAM'} || []
$meta->{'HETNAM'}
Truth table100%2/2
A
A= $meta->{'HETNAM'}
Aresult
11
00
3020 282 my $id = _c($l, 11, 3);
3021 282 my $t = _c(_untail($l, $eid), 15);
3022 282 $info->{het}{$id}{het_id} = $id;
3023 282 $info->{het}{$id}{name} = _rejoin($info->{het}{$id}{name}, $t);
3024 }
3025 903 ▶ for my $l (@{ $meta->{HETSYN} || [] }) {
Condition100%2/2
$meta->{'HETSYN'} || []
l!l
1902
MC/DC100%1/1
$meta->{'HETSYN'} || []
$meta->{'HETSYN'}
Truth table100%2/2
A
A= $meta->{'HETSYN'}
Aresult
11
00
3026 1 my $id = _c($l, 11, 3);
3027 1 $info->{het}{$id}{synonym} = _rejoin($info->{het}{$id}{synonym}, _c(_untail($l, $eid), 15));
3028 }
3029 903 ▶ for my $l (@{ $meta->{FORMUL} || [] }) {
Condition100%2/2
$meta->{'FORMUL'} || []
l!l
142761
MC/DC100%1/1
$meta->{'FORMUL'} || []
$meta->{'FORMUL'}
Truth table100%2/2
A
A= $meta->{'FORMUL'}
Aresult
11
00
3030 422 my $id = _c($l, 12, 3);
3031 422 $info->{het}{$id}{het_id} = $id;
3032 422 $info->{het}{$id}{formula} = _rejoin($info->{het}{$id}{formula}, _c(_untail($l, $eid), 19));
3033 422 ▶ $info->{het}{$id}{water} = 1 if _c($l, 18, 1) eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if _c($l, 18, 1) eq "*" 140 282 422
3034 }
3035  
3036 903 ▶ for my $l (@{ $meta->{HELIX} || [] }) {
Condition100%2/2
$meta->{'HELIX'} || []
l!l
209694
MC/DC100%1/1
$meta->{'HELIX'} || []
$meta->{'HELIX'}
Truth table100%2/2
A
A= $meta->{'HELIX'}
Aresult
11
00
3037 # the length is a number or nothing. A file that keeps its entry id in
3038 # columns 73-80 puts '1GDR' where the length goes, and a caller adding
3039 # lengths up has no way to tell that from a length. Empty rather than
3040 # undef, because empty is what every other column of a short record
3041 # gives and a helix should not answer two ways about the same absence.
3042 281 my $hlen = _c($l, 71, 5);
3043 281 ▶ $hlen = '' unless defined _n($hlen);
Branch: 1 branch
BranchTrueFalseTotal
unless defined _n($hlen) 91 190 281
3044 281 push @{ $info->{helix} }, {
3045 id => _c($l, 11, 3),
3046 init_resname => _c($l, 15, 3),
3047 init_chain => _c($l, 19, 1),
3048 init_resseq => _c($l, 21, 4),
3049 end_resname => _c($l, 27, 3),
3050 end_chain => _c($l, 31, 1),
3051 end_resseq => _c($l, 33, 4),
3052 class => _c($l, 38, 2),
3053 length => $hlen,
3054 };
3055 }
3056 903 ▶ for my $l (@{ $meta->{SHEET} || [] }) {
Condition100%2/2
$meta->{'SHEET'} || []
l!l
209694
MC/DC100%1/1
$meta->{'SHEET'} || []
$meta->{'SHEET'}
Truth table100%2/2
A
A= $meta->{'SHEET'}
Aresult
11
00
3057 471 push @{ $info->{sheet} }, {
3058 strand => _c($l, 7, 3),
3059 id => _c($l, 11, 3),
3060 n_strands => _c($l, 14, 2),
3061 init_resname => _c($l, 17, 3),
3062 init_chain => _c($l, 21, 1),
3063 init_resseq => _c($l, 22, 4),
3064 end_resname => _c($l, 28, 3),
3065 end_chain => _c($l, 32, 1),
3066 end_resseq => _c($l, 33, 4),
3067 sense => _c($l, 38, 2),
3068 };
3069 }
3070 903 ▶ for my $l (@{ $meta->{SSBOND} || [] }) {
Condition100%2/2
$meta->{'SSBOND'} || []
l!l
192711
MC/DC100%1/1
$meta->{'SSBOND'} || []
$meta->{'SSBOND'}
Truth table100%2/2
A
A= $meta->{'SSBOND'}
Aresult
11
00
3071 192 push @{ $info->{ssbond} }, {
3072 chain1 => _c($l, 15, 1),
3073 resseq1 => _c($l, 17, 4),
3074 chain2 => _c($l, 29, 1),
3075 resseq2 => _c($l, 31, 4),
3076 length => _c(_untail($l, $eid), 73, 5),
3077 };
3078 }
3079 903 ▶ for my $l (@{ $meta->{LINK} || [] }) {
Condition100%2/2
$meta->{'LINK'} || []
l!l
191712
MC/DC100%1/1
$meta->{'LINK'} || []
$meta->{'LINK'}
Truth table100%2/2
A
A= $meta->{'LINK'}
Aresult
11
00
3080 191 push @{ $info->{link} }, {
3081 name1 => _c($l, 12, 4), resname1 => _c($l, 17, 3),
3082 chain1 => _c($l, 21, 1), resseq1 => _c($l, 22, 4),
3083 name2 => _c($l, 42, 4), resname2 => _c($l, 47, 3),
3084 chain2 => _c($l, 51, 1), resseq2 => _c($l, 52, 4),
3085 length => _c(_untail($l, $eid), 73, 5),
3086 };
3087 }
3088 # SITE -- the residues of each site, four to a line and as many lines as the
3089 # site needs, every line carrying the site's id and its residue count again.
3090 # Columns from the wwPDB format v3.3: the id in 12-14, the count in 16-17,
3091 # and each residue eleven columns after the one before it, from 19 -- name,
3092 # a blank, chain, number in four columns, insertion code. site was in the
3093 # keys a structure always has and nothing filled it, so a file with SITE
3094 # records read the same as one without.
3095 903 my %site_at;
3096 903 ▶ for my $l (@{ $meta->{SITE} || [] }) {
Condition100%2/2
$meta->{'SITE'} || []
l!l
1902
MC/DC100%1/1
$meta->{'SITE'} || []
$meta->{'SITE'}
Truth table100%2/2
A
A= $meta->{'SITE'}
Aresult
11
00
3097 2 my $id = _c($l, 11, 3);
3098 2 ▶ next unless length $id;
Branch: 1 branch
BranchTrueFalseTotal
unless length $id 0 2 2
3099 2 my $s = $site_at{$id};
3100 2 ▶ unless ($s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s) 1 1 2
3101 1 $s = $site_at{$id} = { id => $id, n_residues => _c($l, 15, 2), residues => [] };
3102 1 push @{ $info->{site} }, $s;
3103 }
3104 2 for my $k (0 .. 3) {
3105 8 my $at = 18 + 11 * $k;
3106 8 my $rn = _c($l, $at, 3);
3107 8 ▶ next unless length $rn;
Branch: 1 branch
BranchTrueFalseTotal
unless length $rn 3 5 8
3108 5 push @{ $s->{residues} }, {
3109 resname => $rn,
3110 chain => _c($l, $at + 4, 1),
3111 resseq => _c($l, $at + 5, 4),
3112 icode => _c($l, $at + 9, 1),
3113 };
3114 }
3115 }
3116 903 ▶ for my $l (@{ $meta->{CISPEP} || [] }) {
Condition100%2/2
$meta->{'CISPEP'} || []
l!l
140763
MC/DC100%1/1
$meta->{'CISPEP'} || []
$meta->{'CISPEP'}
Truth table100%2/2
A
A= $meta->{'CISPEP'}
Aresult
11
00
3117 140 push @{ $info->{cispep} }, {
3118 resname1 => _c($l, 11, 3), chain1 => _c($l, 15, 1),
3119 resseq1 => _c($l, 17, 4),
3120 resname2 => _c($l, 25, 3), chain2 => _c($l, 29, 1),
3121 resseq2 => _c($l, 31, 4),
3122 angle => _c($l, 53, 6),
3123 };
3124 }
3125 903 ▶ if (my $c = $meta->{CRYST1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $meta->{"CRYST1"}) 210 693 903
3126 210 my $l = $c->[0];
3127 $info->{cryst1} = {
3128 210 a => _n(_c($l, 6, 9)), b => _n(_c($l, 15, 9)),
3129 c => _n(_c($l, 24, 9)), alpha => _n(_c($l, 33, 7)),
3130 beta => _n(_c($l, 40, 7)), gamma => _n(_c($l, 47, 7)),
3131 sgroup => _c($l, 55, 11),
3132 z => _c($l, 66, 4),
3133 };
3134 }
3135 903 ▶ for my $l (@{ $meta->{CONECT} || [] }) {
Condition100%2/2
$meta->{'CONECT'} || []
l!l
141762
MC/DC100%1/1
$meta->{'CONECT'} || []
$meta->{'CONECT'}
Truth table100%2/2
A
A= $meta->{'CONECT'}
Aresult
11
00
3136 710 my @s = grep { length } map { _t($_) }
3137 142 map { _c($l, $_, 5) } (6, 11, 16, 21, 26);
3138 142 ▶ push @{ $info->{conect} }, \@s if @s > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @s > 1 141 1 142
3139 }
3140 903 ▶ if (my $n = $meta->{NUMMDL}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $n = $meta->{"NUMMDL"}) 207 696 903
3141 207 my $v = _c($n->[0], 10, 4);
3142 207 ▶ $info->{n_models_declared} = $v + 0 if $v =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /\A\d+\z/ 207 0 207
3143 }
3144 903 _het_names($info);
3145 903 $info->{records} = { map { $_ => scalar @{ $meta->{$_} } } keys %$meta };
3146 903 return $info;
3147 }
3148  
3149 # COMPND and SOURCE are "TOKEN: value;" lists broken into MOL_ID groups
3150 1806 ▶sub _mol_records {
Subroutine _mol_records: called CC=12 SCAR=24.9
3151 1806 my ($lines, $from, $free_key, $entry_id) = @_;
3152 1806 ▶ return {} unless $lines;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines 1431 375 1806
3153 375 my $text = _joined($lines, $from, $entry_id);
3154 375 my %mol;
3155 375 my $id = 1;
3156 # A ';' ends a specification only where the next thing is another TOKEN: or
3157 # the end of the record, past any stray ';' a depositor doubled it with. One
3158 # inside a value is part of the value: 3iaw's molecule is "[GLY51;AIB51']
3159 # 'COVALENT DIMER' HIV-1 PROTEASE", and splitting on every ';' made it
3160 # '[GLY51'. Biopython 1.85's parse_pdb_header gives the whole name, as it
3161 # does for 3ka2's "[L-ALA51;GLY51']HIV-1 PROTEASE".
3162 375 for my $piece (split /;[;\s]*(?=\z|[A-Z0-9_][A-Z0-9_ ]*:)/, $text) {
3163 3047 ▶ next unless $piece =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $piece =~ /\S/ 0 3047 3047
3164 3047 my ($k, $v) = $piece =~ /\A\s*([A-Z0-9_ ]+?)\s*:\s*(.*)\z/;
3165 3047 ▶ next unless defined $k;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 21 3026 3047
3166 3026 $k = lc $k;
3167 3026 $k =~ s/\s+/_/g;
3168 3026 $v = _t($v);
3169 3026 ▶ if ($k eq 'mol_id') {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "mol_id") 686 2340 3026
3170 686 $id = $v;
3171 686 $mol{$id}{mol_id} = $v;
3172 686 next;
3173 }
3174 2340 ▶ $mol{$id}{mol_id} = $id unless exists $mol{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $mol{$id} 2 2338 2340
3175 2340 ▶ if ($k eq 'chain') {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq 'chain') { } 407 1933 2340
3176 407 $mol{$id}{chain} = [ grep { length } map { _t($_) } split /,/, $v ];
3177 } else {
3178 1933 ▶ $mol{$id}{$k} = exists $mol{$id}{$k} ? "$mol{$id}{$k} $v" : $v;
Branch: 1 branch
BranchTrueFalseTotal
exists $mol{$id}{$k} ? : 1 1932 1933
3179 }
3180 }
3181 # A file older than the MOL_ID convention writes the record as free text --
3182 # 'COMPND GAMMA DELTA RESOLVASE', 'SOURCE (ESCHERICHIA COLI)' -- and a
3183 # reader that knows only about 'MOLECULE:' throws away the one thing the
3184 # record says. There is no chain list in that form because there was
3185 # nothing to distinguish: the whole entry is the one molecule, which is what
3186 # free_text says and what _chain_stats() does with it.
3187 375 ▶ if (!%mol && $free_key && $text =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %mol and $free_key and $text =~ /\S/) 21 354 375
Condition66%4/6
not %mol and $free_key and $text =~ /\S/
!ll&&!rl&&r
354021
not %mol and $free_key
!ll&&!rl&&r
354021
MC/DC33%1/3
not %mol and $free_key and $text =~ /\S/
not %mol $free_key $text =~ /\S/
Truth table50%2/4
not(A) and B and C
A= not %molB= $free_keyC= $text =~ /\S/
ABCresult
0XX0
10X0
1100
1111
3188 21 my $v = _t($text);
3189 21 $v =~ s/\A\((.*)\)\z/$1/; # SOURCE used to parenthesise the organism
3190 21 %mol = (1 => { mol_id => 1, $free_key => $v, free_text => 1 });
3191 }
3192 375 return \%mol;
3193 }
3194  
3195 # one flat record per chain, so a chain hash can say what molecule it is
3196 1496 ▶sub _entities {
Subroutine _entities: called CC=9 SCAR=22.2
3197 1496 my ($info) = @_;
3198 1496 my %by_chain;
3199 # In MOL_ID order, and the first to name a chain keeps it. A file that puts
3200 # one chain under two MOL_IDs is malformed, and the chain used to take
3201 # whichever the hash walked last -- one molecule under one PERL_HASH_SEED and
3202 # the other under the next. No PDBbind v2020 entry does it.
3203 978 ▶ my @ids = sort { ($a =~ /\A[0-9]+\z/ && $b =~ /\A[0-9]+\z/) ? $a <=> $b : $a cmp $b }
Branch: 1 branch
BranchTrueFalseTotal
$a =~ /\A[0-9]+\z/ && $b =~ /\A[0-9]+\z/ ? : 978 0 978
Condition33%1/3
$a =~ /\A[0-9]+\z/ and $b =~ /\A[0-9]+\z/
!ll&&!rl&&r
00978
MC/DC0%0/2
$a =~ /\A[0-9]+\z/ and $b =~ /\A[0-9]+\z/
$a =~ /\A[0-9]+\z/ $b =~ /\A[0-9]+\z/
Truth table33%1/3
A and B
A= $a =~ /\A[0-9]+\z/B= $b =~ /\A[0-9]+\z/
ABresult
0X0
100
111
3204 1496 keys %{ $info->{compound} };
3205 1496 for my $id (@ids) {
3206 1056 my $c = $info->{compound}{$id};
3207 1056 ▶ my $s = $info->{source}{$id} || {};
Condition100%2/2
$info->{'source'}{$id} || {}
l!l
419637
MC/DC100%1/1
$info->{'source'}{$id} || {}
$info->{'source'}{$id}
Truth table100%2/2
A
A= $info->{'source'}{$id}
Aresult
11
00
3208 1056 ▶ for my $cid (@{ $c->{chain} || [] }) {
Condition100%2/2
$c->{'chain'} || []
l!l
103917
MC/DC100%1/1
$c->{'chain'} || []
$c->{'chain'}
Truth table100%2/2
A
A= $c->{'chain'}
Aresult
11
00
3209 748 ▶ next if $by_chain{$cid};
Branch: 1 branch
BranchTrueFalseTotal
if $by_chain{$cid} 1 747 748
3210 $by_chain{$cid} = {
3211 mol_id => $id,
3212 molecule => $c->{molecule},
3213 fragment => $c->{fragment},
3214 ec => $c->{ec_number} || $c->{ec},
3215 organism => $s->{organism_scientific},
3216 taxid => $s->{organism_taxid},
3217 expressed_in => $s->{expression_system},
3218 747 ▶ };
Condition66%2/3
$c->{'ec_number'} || $c->{'ec'}
l!l&&r!l&&!r
0283464
MC/DC50%1/2
$c->{'ec_number'} || $c->{'ec'}
$c->{'ec_number'} $c->{'ec'}
Truth table66%2/3
A || B
A= $c->{'ec_number'}B= $c->{'ec'}
ABresult
1X1
011
000
3219 }
3220 }
3221 1496 $info->{entity_of_chain} = \%by_chain;
3222 1496 return $info;
3223 }
3224  
3225 #
3226 # mmCIF header categories
3227 #
3228 # The same facts, filed differently. A PDB file says the resolution on a
3229 # REMARK 2 line and an mmCIF file says it in _refine.ls_d_res_high, and a
3230 # caller who wants to know the resolution should not have to care which. So
3231 # this fills in the same $info keys _parse_meta() fills in, from the
3232 # categories that carry the same information.
3233 #
3234 # Where a fact exists in one format and not the other it is left alone rather
3235 # than invented: an mmCIF file has no REMARK records, so $info->{remarks} stays
3236 # empty, and reading it gets the same "nothing there" a PDB file with no
3237 # remarks would give.
3238 #
3239 # Identifiers are the auth_* ones throughout -- pdbx_strand_id, auth_asym_id --
3240 # because those are the chain ids the coordinates were read under and the ones
3241 # the PDB record carried. Using label_asym_id here would file the annotations
3242 # under chains that the chains hash does not have.
3243 #
3244  
3245 593 ▶sub _parse_cif_meta {
Subroutine _parse_cif_meta: called CC=26 SCAR=33.2
3246 593 my ($info, $p) = @_;
3247 593 _meta_defaults($info);
3248 593 ▶ my $cif = $p->{cif} || {};
Condition50%1/2
$p->{'cif'} || {}
l!l
5930
MC/DC0%0/1
$p->{'cif'} || {}
$p->{'cif'}
Truth table50%1/2
A
A= $p->{'cif'}
Aresult
11
00
3249 593 ▶ my $loops = $p->{cif_loops} || {};
Condition50%1/2
$p->{'cif_loops'} || {}
l!l
5930
MC/DC0%0/1
$p->{'cif_loops'} || {}
$p->{'cif_loops'}
Truth table50%1/2
A
A= $p->{'cif_loops'}
Aresult
11
00
3250  
3251 593 my $id = _cif1($p, '_entry', 'id');
3252 $info->{header} = {
3253 593 ▶ classification => _cif1($p, '_struct_keywords', 'pdbx_keywords'),
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 241 352 593
3254 deposit_date => _cif1($p, '_pdbx_database_status', 'recvd_initial_deposition_date'),
3255 id_code => defined $id ? uc $id : '',
3256 };
3257 # The data_ block name is deliberately not a key of its own. It is usually
3258 # the entry id, which $info->{id} already has, and where it is not -- a file
3259 # written by a simulation program calls its block 'cell' -- it is worse than
3260 # the file name _id_from() falls back to. A key only one of the two formats
3261 # could ever fill in is a key a caller has to test the format for.
3262  
3263 593 $info->{title} = _cif1($p, '_struct', 'title');
3264 593 ▶ $info->{keywords} = [ grep { length } map { _t($_) }
Condition100%2/2
_cif1($p, '_struct_keywords', 'text') || ''
l!l
138455
MC/DC100%1/1
_cif1($p, '_struct_keywords', 'text') || ''
_cif1($p, '_struct_keywords', 'text')
Truth table100%2/2
A
A= _cif1($p, '_struct_keywords', 'text')
Aresult
11
00
3265 split /,/, (_cif1($p, '_struct_keywords', 'text') || '') ];
3266 231 ▶ $info->{experiment} = [ grep { defined && length }
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
00231
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3267 593 map { $_->{method} } @{ _cif_rows($p, '_exptl') } ];
3268 132 ▶ $info->{authors} = [ grep { defined && length }
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
00132
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3269 593 map { $_->{name} } @{ _cif_rows($p, '_audit_author') } ];
3270  
3271 # resolution: refined structures say so in _refine; the others say it
3272 # wherever their method says it
3273 593 for my $where ([ '_refine', 'ls_d_res_high' ],
3274 [ '_reflns', 'd_resolution_high' ],
3275 [ '_em_3d_reconstruction', 'resolution' ]) {
3276 1529 my $v = _cifn($p, @$where);
3277 1529 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 1404 125 1529
3278 125 $info->{resolution} = $v;
3279 125 last;
3280 }
3281 # a SHELXL refinement leaves ls_R_factor_R_work as '?' and files the
3282 # working-set R as the no-cutoff one in _pdbx_refine; see _parse_meta
3283 593 $info->{r_work} = _cifn($p, '_refine', 'ls_r_factor_r_work');
3284 $info->{r_work} = _cifn($p, '_pdbx_refine', 'r_factor_obs_no_cutoff')
3285 593 ▶ unless defined $info->{r_work};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info->{"r_work"} 497 96 593
3286 593 $info->{r_free} = _cifn($p, '_refine', 'ls_r_factor_r_free');
3287 593 $info->{temperature} = _cifn($p, '_diffrn', 'ambient_temp');
3288 593 $info->{ph} = _cifn($p, '_exptl_crystal_grow', 'ph');
3289 593 my $nmr = _cifn($p, '_pdbx_nmr_ensemble', 'conformers_submitted_total_number');
3290 593 ▶ $info->{n_models_declared} = $nmr if defined $nmr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $nmr 37 556 593
3291  
3292 # the paper. 'primary' is the entry's own citation; anything else in the
3293 # category is a reference it cites.
3294 593 my @cites = @{ _cif_rows($p, '_citation') };
3295 593 ▶ my ($cite) = ((grep { ($_->{id} || '') eq 'primary' } @cites), @cites);
Condition50%1/2
$_->{'id'} || ''
l!l
720
MC/DC0%0/1
$_->{'id'} || ''
$_->{'id'}
Truth table50%1/2
A
A= $_->{'id'}
Aresult
11
00
3296 593 ▶ if ($cite) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cite) 71 522 593
3297 71 my %j;
3298 71 ▶ $j{titl} = $cite->{title} if defined $cite->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $cite->{"title"} 71 0 71
3299 71 ▶ $j{pmid} = $cite->{pdbx_database_id_pubmed} if defined $cite->{pdbx_database_id_pubmed};
Branch: 1 branch
BranchTrueFalseTotal
if defined $cite->{"pdbx_database_id_pubmed"} 67 4 71
3300 71 ▶ $j{doi} = $cite->{pdbx_database_id_doi} if defined $cite->{pdbx_database_id_doi};
Branch: 1 branch
BranchTrueFalseTotal
if defined $cite->{"pdbx_database_id_doi"} 66 5 71
3301 284 ▶ my @ref = grep { defined && length }
Condition66%2/3
defined $_ && length $_
!ll&&!rl&&r
140270
MC/DC50%1/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3302 71 @{$cite}{qw(journal_abbrev journal_volume page_first year)};
3303 71 ▶ $j{ref} = join ' ', @ref if @ref;
Branch: 1 branch
BranchTrueFalseTotal
if @ref 71 0 71
3304 71 my $cid = $cite->{id};
3305 133 my @auth = map { $_->{name} }
3306 134 ▶ grep { !defined $cid || !defined $_->{citation_id} || $_->{citation_id} eq $cid }
Condition50%3/6
!(defined $cid && defined $_->{'citation_id'}) || $_->{'citation_id'} eq $cid
l!l&&r!l&&!r
01331
defined $cid && defined $_->{'citation_id'}
!ll&&!rl&&r
00134
MC/DC33%1/3
!(defined $cid && defined $_->{'citation_id'}) || $_->{'citation_id'} eq $cid
defined $cid defined $_->{'citation_id'} $_->{'citation_id'} eq $cid
Truth table50%2/4
not(A && B) || C
A= defined $cidB= defined $_->{'citation_id'}C= $_->{'citation_id'} eq $cid
ABCresult
0XX1
10X1
1111
1100
3307 71 @{ _cif_rows($p, '_citation_author') };
3308 71 ▶ $j{auth} = [ grep { defined && length } @auth ] if @auth;
Branch: 1 branch
BranchTrueFalseTotal
if @auth 67 4 71
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
00133
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3309 71 $info->{journal} = \%j;
3310 }
3311  
3312 593 ▶ if (my @cell = grep { defined } map { _cifn($p, '_cell', $_) }
Branch: 1 branch
BranchTrueFalseTotal
if (my(@cell) = grep({defined $_;} map({_cifn($p, "_cell", $_);} "length_a", "length_b", "length_c", "angle_alpha", "angle_beta", "angle_gamma"))) 126 467 593
3313 qw(length_a length_b length_c angle_alpha angle_beta angle_gamma)) {
3314 $info->{cryst1} = {
3315 126 ▶ a => _cifn($p, '_cell', 'length_a'),
Branch: 1 branch
BranchTrueFalseTotal
if @cell 126 0 126
3316 b => _cifn($p, '_cell', 'length_b'),
3317 c => _cifn($p, '_cell', 'length_c'),
3318 alpha => _cifn($p, '_cell', 'angle_alpha'),
3319 beta => _cifn($p, '_cell', 'angle_beta'),
3320 gamma => _cifn($p, '_cell', 'angle_gamma'),
3321 sgroup => _cif1($p, '_symmetry', 'space_group_name_h-m'),
3322 z => _cif1($p, '_cell', 'z_pdb'),
3323 } if @cell;
3324 }
3325  
3326 593 _cif_entities($info, $p);
3327 593 _cif_seqres($info, $p);
3328 593 _cif_het($info, $p);
3329 593 _cif_annotations($info, $p);
3330 593 _het_names($info);
3331  
3332 # what the file actually contained, by category, which is the mmCIF answer
3333 # to the question $info->{records} answers for a PDB file
3334 593 my %rec = map { $_ => scalar @{ $loops->{$_} } } keys %$loops;
3335 593 for my $tag (keys %$cif) {
3336 4401 my ($cat) = $tag =~ /\A([^.]+)/;
3337 4401 ▶ $rec{$cat} ||= 1;
Condition100%2/2
$rec{$cat} ||= 1
l!l
26611740
MC/DC100%1/1
$rec{$cat} ||= 1
$rec{$cat}
Truth table100%2/2
A
A= $rec{$cat}
Aresult
11
00
3338 }
3339 593 $info->{records} = \%rec;
3340 593 return $info;
3341 }
3342  
3343 # the entities, and which chains they are
3344 #
3345 # COMPND and SOURCE in a PDB file are one _entity plus one _entity_src_* here,
3346 # so they are put back into the shape _entities() already knows how to turn
3347 # into a per-chain record.
3348 593 ▶sub _cif_entities {
Subroutine _cif_entities: called CC=23 SCAR=31.4
3349 593 my ($info, $p) = @_;
3350  
3351 # Only the polymer entities claim chains, which is the rule COMPND follows:
3352 # a chain is the molecule its polymer is, and the ligands, ions and waters
3353 # sitting in it are not what it is. They share the chain id -- the zinc in
3354 # chain A is written as chain A -- so a non-polymer entity that claimed its
3355 # chains here would take the chain's name over from the protein, and
3356 # whichever entity happened to be looked at last would win. Where the
3357 # ligands are is $info->{het}, which is where a PDB file keeps it too.
3358 593 my %chains_of;
3359 593 for my $r (@{ _cif_rows($p, '_entity_poly') }) {
3360 343 ▶ next unless defined $r->{entity_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"entity_id"} 0 343 343
3361 340 ▶ $chains_of{ $r->{entity_id} } = [ grep { length } map { _t($_) }
Condition100%2/2
$r->{'pdbx_strand_id'} || ''
l!l
3394
MC/DC100%1/1
$r->{'pdbx_strand_id'} || ''
$r->{'pdbx_strand_id'}
Truth table100%2/2
A
A= $r->{'pdbx_strand_id'}
Aresult
11
00
3362 343 split /,/, ($r->{pdbx_strand_id} || '') ];
3363 }
3364  
3365 593 my (%compound, %source);
3366 593 for my $r (@{ _cif_rows($p, '_entity') }) {
3367 630 my $e = $r->{id};
3368 630 ▶ next unless defined $e;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 0 630 630
3369 $compound{$e} = {
3370 mol_id => $e,
3371 molecule => $r->{pdbx_description},
3372 chain => $chains_of{$e} || [],
3373 type => $r->{type},
3374 630 ▶ };
Condition100%2/2
$chains_of{$e} || []
l!l
341289
MC/DC100%1/1
$chains_of{$e} || []
$chains_of{$e}
Truth table100%2/2
A
A= $chains_of{$e}
Aresult
11
00
3375 630 ▶ $compound{$e}{ec} = $r->{pdbx_ec} if defined $r->{pdbx_ec};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"pdbx_ec"} 96 534 630
3376 # COMPND's FRAGMENT, which _entities() hands on to the chain
3377 630 ▶ $compound{$e}{fragment} = $r->{pdbx_fragment} if defined $r->{pdbx_fragment};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"pdbx_fragment"} 96 534 630
3378 }
3379 # an entity that only shows up in _entity_poly still has to have a record,
3380 # or its chains lose their molecule name
3381 593 for my $e (keys %chains_of) {
3382 343 ▶ $compound{$e} ||= { mol_id => $e, chain => $chains_of{$e} };
Condition100%2/2
$compound{$e} ||= {"mol_id", $e, "chain", $chains_of{$e}}
l!l
3412
MC/DC100%1/1
$compound{$e} ||= {"mol_id", $e, "chain", $chains_of{$e}}
$compound{$e}
Truth table100%2/2
A
A= $compound{$e}
Aresult
11
00
3383 }
3384  
3385 # One row per source, and an entity can have more than one: 1shz's chimera
3386 # is seven segments, rat and mouse by turns, seven rows of _entity_src_gen
3387 # that its PDB file writes as 'ORGANISM_SCIENTIFIC: RATTUS NORVEGICUS, MUS
3388 # MUSCULUS'. So the distinct values are joined the way SOURCE joins them,
3389 # in the order they first turn up. Each category is only read for an entity the one before it had
3390 # nothing for: an engineered entity's natural source is not its source.
3391 #
3392 # A chemically synthesised entity -- SOURCE's 'SYNTHETIC: YES' -- still
3393 # names the organism its sequence came from, on the same ORGANISM_SCIENTIFIC
3394 # line a natural one uses: 1avp's adenovirus peptide cofactor.
3395 593 my @from = (
3396 [ '_entity_src_gen', pdbx_gene_src_scientific_name => 'pdbx_gene_src_ncbi_taxonomy_id',
3397 pdbx_host_org_scientific_name => undef ],
3398 [ '_entity_src_nat', pdbx_organism_scientific => 'pdbx_ncbi_taxonomy_id' ],
3399 [ '_pdbx_entity_src_syn', organism_scientific => 'ncbi_taxonomy_id', undef, 'YES' ],
3400 );
3401 593 for my $f (@from) {
3402 1779 my ($cat, $org, $tax, $host, $syn) = @$f;
3403 1779 my (%mine, %seen);
3404 1779 for my $r (@{ _cif_rows($p, $cat) }) {
3405 137 my $e = $r->{entity_id};
3406 137 ▶ next unless defined $e;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 0 137 137
3407 137 ▶ next if $source{$e} && !$mine{$e};
Branch: 1 branch
BranchTrueFalseTotal
if $source{$e} and not $mine{$e} 1 136 137
Condition100%3/3
$source{$e} and not $mine{$e}
!ll&&!rl&&r
13421
MC/DC100%2/2
$source{$e} and not $mine{$e}
$source{$e} not $mine{$e}
Truth table100%3/3
A and not(B)
A= $source{$e}B= not $mine{$e}
ABresult
0X0
100
111
3408 136 ▶ my $s = $source{$e} ||= { mol_id => $e };
Condition100%2/2
$source{$e} ||= {"mol_id", $e}
l!l
2134
MC/DC100%1/1
$source{$e} ||= {"mol_id", $e}
$source{$e}
Truth table100%2/2
A
A= $source{$e}
Aresult
11
00
3409 136 $mine{$e} = 1;
3410 136 ▶ $s->{synthetic} = $syn if defined $syn;
Branch: 1 branch
BranchTrueFalseTotal
if defined $syn 66 70 136
3411 136 my %add = (organism_scientific => $r->{$org}, organism_taxid => $r->{$tax});
3412 136 ▶ $add{expression_system} = $r->{$host} if defined $host;
Branch: 1 branch
BranchTrueFalseTotal
if defined $host 69 67 136
3413 136 for my $k (keys %add) {
3414 341 ▶ next unless defined $add{$k} && !$seen{$e}{$k}{ $add{$k} }++;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $add{$k} and not $seen{$e}{$k}{$add{$k}}++ 4 337 341
Condition66%2/3
defined $add{$k} and not $seen{$e}{$k}{$add{$k}}++
!ll&&!rl&&r
04337
MC/DC50%1/2
defined $add{$k} and not $seen{$e}{$k}{$add{$k}}++
defined $add{$k} not $seen{$e}{$k}{$add{$k}}++
Truth table66%2/3
A and not(B)
A= defined $add{$k}B= not $seen{$e}{$k}{$add{$k}}++
ABresult
0X0
100
111
3415 337 ▶ $s->{$k} = defined $s->{$k} ? "$s->{$k}, $add{$k}" : $add{$k};
Branch: 1 branch
BranchTrueFalseTotal
defined $s->{$k} ? : 2 335 337
3416 }
3417 }
3418 }
3419  
3420 593 $info->{compound} = \%compound;
3421 593 $info->{source} = \%source;
3422 593 _entities($info);
3423 593 return $info;
3424 }
3425  
3426 # SEQRES
3427 #
3428 # _entity_poly_seq is the residue list, one row per position, per entity;
3429 # _entity_poly says which chains an entity was crystallised as. A chain's
3430 # seqres is therefore its entity's list, and two chains of the same entity get
3431 # the same one -- which is what a PDB file writes out twice.
3432 593 ▶sub _cif_seqres {
Subroutine _cif_seqres: called CC=17 SCAR=28.5
3433 593 my ($info, $p) = @_;
3434 593 my (%res_of, %seen);
3435 593 for my $r (@{ _cif_rows($p, '_entity_poly_seq') }) {
3436 2163 ▶ next unless defined $r->{entity_id} && defined $r->{mon_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"entity_id"} and defined $r->{"mon_id"} 0 2163 2163
Condition33%1/3
defined $r->{"entity_id"} and defined $r->{"mon_id"}
!ll&&!rl&&r
002163
MC/DC0%0/2
defined $r->{"entity_id"} and defined $r->{"mon_id"}
defined $r->{"entity_id"} defined $r->{"mon_id"}
Truth table33%1/3
A and B
A= defined $r->{"entity_id"}B= defined $r->{"mon_id"}
ABresult
0X0
100
111
3437 # A position modelled as two residues at once -- microheterogeneity,
3438 # _entity_poly_seq.hetero 'y' -- has a row for each, under one num.
3439 # SEQRES names the first of them and nothing else, and so does this:
3440 # 1ejg's crambin, PRO/SER at 22 and LEU/ILE at 25, is 46 residues long
3441 # from either file rather than 48 from this one.
3442 2163 ▶ next if defined $r->{num} && $seen{ $r->{entity_id} }{ $r->{num} }++;
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"num"} and $seen{$r->{"entity_id"}}{$r->{"num"}}++ 2 2161 2163
Condition66%2/3
defined $r->{"num"} and $seen{$r->{"entity_id"}}{$r->{"num"}}++
!ll&&!rl&&r
021612
MC/DC50%1/2
defined $r->{"num"} and $seen{$r->{"entity_id"}}{$r->{"num"}}++
defined $r->{"num"} $seen{$r->{"entity_id"}}{$r->{"num"}}++
Truth table66%2/3
A and B
A= defined $r->{"num"}B= $seen{$r->{"entity_id"}}{$r->{"num"}}++
ABresult
0X0
100
111
3443 2161 push @{ $res_of{ $r->{entity_id} } }, $r->{mon_id};
3444 }
3445 593 for my $r (@{ _cif_rows($p, '_entity_poly') }) {
3446 343 my $e = $r->{entity_id};
3447 343 ▶ next unless defined $e;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 0 343 343
3448 343 ▶ my @chains = grep { length } map { _t($_) } split /,/, ($r->{pdbx_strand_id} || '');
Condition100%2/2
$r->{'pdbx_strand_id'} || ''
l!l
3394
MC/DC100%1/1
$r->{'pdbx_strand_id'} || ''
$r->{'pdbx_strand_id'}
Truth table100%2/2
A
A= $r->{'pdbx_strand_id'}
Aresult
11
00
3449 343 ▶ next unless @chains;
Branch: 1 branch
BranchTrueFalseTotal
unless @chains 4 339 343
3450 339 my $residues = $res_of{$e};
3451 339 my $seq;
3452 339 ▶ if ($residues) {
Branch: 1 branch
BranchTrueFalseTotal
if ($residues) { } 337 2 339
3453 337 ▶ $seq = join '', map { my $o = res1($_); length $o ? $o : 'X' } @$residues;
Branch: 1 branch
BranchTrueFalseTotal
length $o ? : 2142 19 2161
3454 }
3455 else {
3456 # a file with no _entity_poly_seq still carries the sequence as a
3457 # string; the residue names are what is lost, not the sequence
3458 2 ▶ my $one = $r->{pdbx_seq_one_letter_code_can} || $r->{pdbx_seq_one_letter_code};
Condition66%2/3
$r->{'pdbx_seq_one_letter_code_can'} || $r->{'pdbx_seq_one_letter_code'}
l!l&&r!l&&!r
101
MC/DC50%1/2
$r->{'pdbx_seq_one_letter_code_can'} || $r->{'pdbx_seq_one_letter_code'}
$r->{'pdbx_seq_one_letter_code_can'} $r->{'pdbx_seq_one_letter_code'}
Truth table66%2/3
A || B
A= $r->{'pdbx_seq_one_letter_code_can'}B= $r->{'pdbx_seq_one_letter_code'}
ABresult
1X1
011
000
3459 2 ▶ next unless defined $one;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $one 1 1 2
3460 1 $seq = $one;
3461 1 $seq =~ s/\s+//g;
3462 1 $seq =~ s/\([^)]*\)/X/g; # a modified residue, spelled out in brackets
3463 }
3464 338 for my $cid (@chains) {
3465 338 ▶ $info->{seqres}{$cid} = {
Branch: 2 branches
BranchTrueFalseTotal
$residues ? : 337 1 338
$residues ? : 337 1 338
3466 chain => $cid,
3467 residues => ($residues ? [ @$residues ] : []),
3468 sequence => $seq,
3469 length => ($residues ? scalar @$residues : length $seq),
3470 };
3471 }
3472 }
3473 593 return $info;
3474 }
3475  
3476 # heterogens
3477 #
3478 # _chem_comp describes every residue in the file, standard ones included;
3479 # $info->{het} is what HET/HETNAM/FORMUL describe, which is the rest.
3480 593 ▶sub _cif_het {
Subroutine _cif_het: called CC=22 SCAR=34.6
3481 593 my ($info, $p) = @_;
3482 593 for my $r (@{ _cif_rows($p, '_chem_comp') }) {
3483 272 my $cid = $r->{id};
3484 272 ▶ next unless defined $cid && length $cid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cid and length $cid 0 272 272
Condition33%1/3
defined $cid and length $cid
!ll&&!rl&&r
00272
MC/DC0%0/2
defined $cid and length $cid
defined $cid length $cid
Truth table33%1/3
A and B
A= defined $cidB= length $cid
ABresult
0X0
100
111
3485 272 ▶ next if _standard_res($cid);
Branch: 1 branch
BranchTrueFalseTotal
if _standard_res($cid) 1 271 272
3486 271 ▶ my $h = $info->{het}{$cid} ||= { het_id => $cid };
Condition50%1/2
$info->{"het"}{$cid} ||= {"het_id", $cid}
l!l
0271
MC/DC0%0/1
$info->{"het"}{$cid} ||= {"het_id", $cid}
$info->{"het"}{$cid}
Truth table50%1/2
A
A= $info->{"het"}{$cid}
Aresult
11
00
3487 271 ▶ $h->{name} = $r->{name} if defined $r->{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"name"} 271 0 271
3488 271 ▶ $h->{formula} = $r->{formula} if defined $r->{formula};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"formula"} 271 0 271
3489 271 ▶ $h->{synonym} = $r->{pdbx_synonyms} if defined $r->{pdbx_synonyms};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"pdbx_synonyms"} 1 270 271
3490 271 ▶ $h->{water} = 1 if $cid eq 'HOH' || $cid eq 'DOD' || $cid eq 'WAT';
Branch: 1 branch
BranchTrueFalseTotal
if $cid eq "HOH" or $cid eq "DOD" or $cid eq "WAT" 67 204 271
Condition66%4/6
$cid eq "HOH" or $cid eq "DOD" or $cid eq "WAT"
l!l&&r!l&&!r
670204
$cid eq "HOH" or $cid eq "DOD"
l!l&&r!l&&!r
670204
MC/DC33%1/3
$cid eq "HOH" or $cid eq "DOD" or $cid eq "WAT"
$cid eq "HOH" $cid eq "DOD" $cid eq "WAT"
Truth table50%2/4
A or B or C
A= $cid eq "HOH"B= $cid eq "DOD"C= $cid eq "WAT"
ABCresult
1XX1
01X1
0011
0000
3491 }
3492 593 for my $r (@{ _cif_rows($p, '_pdbx_nonpoly_scheme') }) {
3493 265 my $cid = $r->{mon_id};
3494 265 ▶ next unless defined $cid && length $cid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cid and length $cid 0 265 265
Condition33%1/3
defined $cid and length $cid
!ll&&!rl&&r
00265
MC/DC0%0/2
defined $cid and length $cid
defined $cid length $cid
Truth table33%1/3
A and B
A= defined $cidB= length $cid
ABresult
0X0
100
111
3495 265 ▶ my $h = $info->{het}{$cid} ||= { het_id => $cid };
Condition100%2/2
$info->{"het"}{$cid} ||= {"het_id", $cid}
l!l
2641
MC/DC100%1/1
$info->{"het"}{$cid} ||= {"het_id", $cid}
$info->{"het"}{$cid}
Truth table100%2/2
A
A= $info->{"het"}{$cid}
Aresult
11
00
3496 265 ▶ push @{ $h->{instances} }, {
Branch: 1 branch
BranchTrueFalseTotal
defined $r->{'pdb_ins_code'} ? : 0 265 265
3497 chain => $r->{pdb_strand_id},
3498 resseq => $r->{pdb_seq_num},
3499 265 icode => (defined $r->{pdb_ins_code} ? $r->{pdb_ins_code} : ''),
3500 };
3501 }
3502 593 for my $r (@{ _cif_rows($p, '_pdbx_struct_mod_residue') }) {
3503 67 ▶ my $cid = $r->{auth_comp_id} || $r->{label_comp_id};
Condition33%1/3
$r->{'auth_comp_id'} || $r->{'label_comp_id'}
l!l&&r!l&&!r
6700
MC/DC0%0/2
$r->{'auth_comp_id'} || $r->{'label_comp_id'}
$r->{'auth_comp_id'} $r->{'label_comp_id'}
Truth table33%1/3
A || B
A= $r->{'auth_comp_id'}B= $r->{'label_comp_id'}
ABresult
1X1
011
000
3504 67 ▶ next unless defined $cid && length $cid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cid and length $cid 0 67 67
Condition33%1/3
defined $cid and length $cid
!ll&&!rl&&r
0067
MC/DC0%0/2
defined $cid and length $cid
defined $cid length $cid
Truth table33%1/3
A and B
A= defined $cidB= length $cid
ABresult
0X0
100
111
3505 $info->{modres}{$cid} ||= {
3506 resname => $cid,
3507 standard => $r->{parent_comp_id},
3508 comment => $r->{details},
3509 67 ▶ };
Condition50%1/2
$info->{"modres"}{$cid} ||= {"resname", $cid, "standard", $r->{"parent_comp_id"}, "comment", $r->{"details"}}
l!l
067
MC/DC0%0/1
$info->{"modres"}{$cid} ||= {"resname", $cid, "standard", $r->{"parent_comp_id"}, "comment", $r->{"details"}}
$info->{"modres"}{$cid}
Truth table50%1/2
A
A= $info->{"modres"}{$cid}
Aresult
11
00
3510 }
3511 593 return $info;
3512 }
3513  
3514 # secondary structure, bonds and database cross-references
3515 593 ▶sub _cif_annotations {
Subroutine _cif_annotations: called CC=38 SCAR=39.5
3516 593 my ($info, $p) = @_;
3517  
3518 593 for my $r (@{ _cif_rows($p, '_struct_conf') }) {
3519 142 ▶ next unless ($r->{conf_type_id} || '') =~ /\AHELX/i;
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"conf_type_id"} || "") =~ /\AHELX/i 0 142 142
Condition50%1/2
$r->{'conf_type_id'} || ''
l!l
1420
MC/DC0%0/1
$r->{'conf_type_id'} || ''
$r->{'conf_type_id'}
Truth table50%1/2
A
A= $r->{'conf_type_id'}
Aresult
11
00
3520 142 ▶ push @{ $info->{helix} }, {
Branch: 1 branch
BranchTrueFalseTotal
defined $r->{'pdbx_pdb_helix_id'} ? : 141 1 142
3521 # the id the HELIX record carried, AA or 1; $r->{id} is
3522 # HELX_P1, a name the mmCIF file made up for the row
3523 id => (defined $r->{pdbx_pdb_helix_id} ? $r->{pdbx_pdb_helix_id} : $r->{id}),
3524 init_resname => _cif_auth($r, 'beg', 'comp_id'),
3525 init_chain => _cif_auth($r, 'beg', 'asym_id'),
3526 init_resseq => _cif_auth($r, 'beg', 'seq_id'),
3527 end_resname => _cif_auth($r, 'end', 'comp_id'),
3528 end_chain => _cif_auth($r, 'end', 'asym_id'),
3529 end_resseq => _cif_auth($r, 'end', 'seq_id'),
3530 class => $r->{pdbx_pdb_helix_class},
3531 length => $r->{pdbx_pdb_helix_length},
3532 142 };
3533 }
3534 # SHEET carries each sheet's strand count on every strand, and each
3535 # strand's sense relative to the strand before it: 0 for the first, 1
3536 # parallel, -1 antiparallel. mmCIF keeps the count in _struct_sheet and
3537 # the sense in _struct_sheet_order, as a pair of range ids and a word.
3538 593 my (%n_strands, %sense);
3539 593 for my $r (@{ _cif_rows($p, '_struct_sheet') }) {
3540 125 ▶ $n_strands{ $r->{id} } = $r->{number_strands} if defined $r->{id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"id"} 125 0 125
3541 }
3542 593 my %SENSE = ('parallel' => '1', 'anti-parallel' => '-1');
3543 593 for my $r (@{ _cif_rows($p, '_struct_sheet_order') }) {
3544 137 ▶ next unless defined $r->{sheet_id} && defined $r->{range_id_2};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"sheet_id"} and defined $r->{"range_id_2"} 0 137 137
Condition33%1/3
defined $r->{"sheet_id"} and defined $r->{"range_id_2"}
!ll&&!rl&&r
00137
MC/DC0%0/2
defined $r->{"sheet_id"} and defined $r->{"range_id_2"}
defined $r->{"sheet_id"} defined $r->{"range_id_2"}
Truth table33%1/3
A and B
A= defined $r->{"sheet_id"}B= defined $r->{"range_id_2"}
ABresult
0X0
100
111
3545 # undef where the file does not say, which is still not a first strand
3546 137 ▶ $sense{ $r->{sheet_id} }{ $r->{range_id_2} } = $SENSE{ lc($r->{sense} || '') };
Condition50%1/2
$r->{'sense'} || ''
l!l
1370
MC/DC0%0/1
$r->{'sense'} || ''
$r->{'sense'}
Truth table50%1/2
A
A= $r->{'sense'}
Aresult
11
00
3547 }
3548 593 for my $r (@{ _cif_rows($p, '_struct_sheet_range') }) {
3549 262 my ($sh, $st) = @{$r}{qw(sheet_id id)};
3550 262 my $sense;
3551 262 ▶ if (defined $sh && defined $st) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sh and defined $st) 262 0 262
Condition33%1/3
defined $sh and defined $st
!ll&&!rl&&r
00262
MC/DC0%0/2
defined $sh and defined $st
defined $sh defined $st
Truth table33%1/3
A and B
A= defined $shB= defined $st
ABresult
0X0
100
111
3552 # the first strand of a sheet is the one nothing is ordered after
3553 262 ▶ $sense = exists $sense{$sh}{$st} ? $sense{$sh}{$st} : '0';
Branch: 1 branch
BranchTrueFalseTotal
exists $sense{$sh}{$st} ? : 137 125 262
3554 }
3555 262 ▶ push @{ $info->{sheet} }, {
Branch: 1 branch
BranchTrueFalseTotal
defined $sh ? : 262 0 262
3556 strand => $st,
3557 id => $sh,
3558 262 n_strands => (defined $sh ? $n_strands{$sh} : undef),
3559 sense => $sense,
3560 init_resname => _cif_auth($r, 'beg', 'comp_id'),
3561 init_chain => _cif_auth($r, 'beg', 'asym_id'),
3562 init_resseq => _cif_auth($r, 'beg', 'seq_id'),
3563 end_resname => _cif_auth($r, 'end', 'comp_id'),
3564 end_chain => _cif_auth($r, 'end', 'asym_id'),
3565 end_resseq => _cif_auth($r, 'end', 'seq_id'),
3566 };
3567 }
3568  
3569 # SSBOND and LINK are one category here, told apart by the bond type
3570 593 for my $r (@{ _cif_rows($p, '_struct_conn') }) {
3571 246 ▶ my $type = lc($r->{conn_type_id} || '');
Condition50%1/2
$r->{'conn_type_id'} || ''
l!l
2460
MC/DC0%0/1
$r->{'conn_type_id'} || ''
$r->{'conn_type_id'}
Truth table50%1/2
A
A= $r->{'conn_type_id'}
Aresult
11
00
3572 246 ▶ if ($type eq 'disulf') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "disulf") 122 124 246
3573 122 push @{ $info->{ssbond} }, {
3574 chain1 => _cif_ptnr($r, 1, 'asym_id'),
3575 resseq1 => _cif_ptnr($r, 1, 'seq_id'),
3576 chain2 => _cif_ptnr($r, 2, 'asym_id'),
3577 resseq2 => _cif_ptnr($r, 2, 'seq_id'),
3578 length => $r->{pdbx_dist_value},
3579 122 };
3580 122 next;
3581 }
3582 124 ▶ next if $type eq 'hydrog';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "hydrog" 1 123 124
3583 123 push @{ $info->{link} }, {
3584 name1 => $r->{ptnr1_label_atom_id}, resname1 => _cif_ptnr($r, 1, 'comp_id'),
3585 chain1 => _cif_ptnr($r, 1, 'asym_id'), resseq1 => _cif_ptnr($r, 1, 'seq_id'),
3586 name2 => $r->{ptnr2_label_atom_id}, resname2 => _cif_ptnr($r, 2, 'comp_id'),
3587 chain2 => _cif_ptnr($r, 2, 'asym_id'), resseq2 => _cif_ptnr($r, 2, 'seq_id'),
3588 length => $r->{pdbx_dist_value},
3589 123 };
3590 }
3591  
3592 593 for my $r (@{ _cif_rows($p, '_struct_mon_prot_cis') }) {
3593 66 push @{ $info->{cispep} }, {
3594 resname1 => $r->{auth_comp_id}, chain1 => $r->{auth_asym_id},
3595 resseq1 => $r->{auth_seq_id},
3596 resname2 => $r->{pdbx_auth_comp_id_2}, chain2 => $r->{pdbx_auth_asym_id_2},
3597 resseq2 => $r->{pdbx_auth_seq_id_2},
3598 angle => $r->{pdbx_omega_angle},
3599 66 };
3600 }
3601  
3602 593 my %db;
3603 593 for my $r (@{ _cif_rows($p, '_struct_ref') }) {
3604 132 ▶ next unless defined $r->{id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"id"} 0 132 132
3605 132 $db{ $r->{id} } = $r;
3606 }
3607 593 for my $r (@{ _cif_rows($p, '_struct_ref_seq') }) {
3608 132 my $cid = $r->{pdbx_strand_id};
3609 132 ▶ next unless defined $cid && length $cid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cid and length $cid 0 132 132
Condition33%1/3
defined $cid and length $cid
!ll&&!rl&&r
00132
MC/DC0%0/2
defined $cid and length $cid
defined $cid length $cid
Truth table33%1/3
A and B
A= defined $cidB= length $cid
ABresult
0X0
100
111
3610 132 ▶ my $ref = (defined $r->{ref_id} && $db{ $r->{ref_id} }) || {};
Condition40%2/5
defined $r->{'ref_id'} && $db{$r->{'ref_id'}} || {}
l!l
1320
defined $r->{"ref_id"} and $db{$r->{"ref_id"}}
!ll&&!rl&&r
00132
MC/DC0%0/2
defined $r->{'ref_id'} && $db{$r->{'ref_id'}} || {}
defined $r->{"ref_id"} $db{$r->{"ref_id"}}
Truth table33%1/3
A and B
A= defined $r->{"ref_id"}B= $db{$r->{"ref_id"}}
ABresult
111
0X0
100
3611 132 ▶ push @{ $info->{dbref}{$cid} }, {
Branch: 1 branch
BranchTrueFalseTotal
defined $r->{'pdbx_db_accession'} ? : 132 0 132
3612 chain => $cid,
3613 seq_begin => $r->{pdbx_auth_seq_align_beg},
3614 seq_end => $r->{pdbx_auth_seq_align_end},
3615 database => $ref->{db_name},
3616 accession => (defined $r->{pdbx_db_accession} ? $r->{pdbx_db_accession} : $ref->{pdbx_db_accession}),
3617 db_id => $ref->{db_code},
3618 db_begin => $r->{db_align_beg},
3619 db_end => $r->{db_align_end},
3620 132 };
3621 }
3622  
3623 # SEQADV is _struct_ref_seq_dif, a row per difference from the database
3624 # sequence. The fields are the PDB reader's, and so is the empty string for
3625 # one the file leaves '?', which is what a blank SEQADV column reads as.
3626 593 for my $r (@{ _cif_rows($p, '_struct_ref_seq_dif') }) {
3627 1 push @{ $info->{seqadv} }, {
3628 resname => _t($r->{mon_id}),
3629 chain => _t($r->{pdbx_pdb_strand_id}),
3630 resseq => _t($r->{pdbx_auth_seq_num}),
3631 database => _t($r->{pdbx_seq_db_name}),
3632 accession => _t($r->{pdbx_seq_db_accession_code}),
3633 db_res => _t($r->{db_mon_id}),
3634 db_seq => _t($r->{pdbx_seq_db_seq_num}),
3635 1 comment => _t($r->{details}),
3636 };
3637 }
3638  
3639 # SITE is two categories here: _struct_site, a row per site with its residue
3640 # count, and _struct_site_gen, a row per residue of a site. Auth names
3641 # first, as everywhere in this reader, and a site that only the residues
3642 # name is still a site, counted from them.
3643 593 my %site_at;
3644 593 for my $r (@{ _cif_rows($p, '_struct_site') }) {
3645 1 ▶ next unless defined $r->{id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"id"} 0 1 1
3646 1 push @{ $info->{site} }, $site_at{ $r->{id} } = {
3647 1 id => $r->{id}, n_residues => _t($r->{pdbx_num_residues}), residues => [],
3648 };
3649 }
3650 593 for my $r (@{ _cif_rows($p, '_struct_site_gen') }) {
3651 5 my $id = $r->{site_id};
3652 5 ▶ next unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 5 5
3653 5 my $s = $site_at{$id};
3654 5 ▶ unless ($s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s) 0 5 5
3655 0 $s = $site_at{$id} = { id => $id, n_residues => '', residues => [] };
3656 0 push @{ $info->{site} }, $s;
3657 }
3658 5 push @{ $s->{residues} }, {
3659 resname => _t(_cif_named($r, 'comp_id')),
3660 chain => _t(_cif_named($r, 'asym_id')),
3661 resseq => _t(_cif_named($r, 'seq_id')),
3662 5 icode => _t($r->{pdbx_auth_ins_code}),
3663 };
3664 }
3665 593 for my $s (@{ $info->{site} }) {
3666 0 ▶ $s->{n_residues} = scalar @{ $s->{residues} } unless length $s->{n_residues};
Branch: 1 branch
BranchTrueFalseTotal
unless length $s->{"n_residues"} 0 1 1
3667 }
3668  
3669 593 for my $r (@{ _cif_rows($p, '_pdbx_audit_revision_history') }) {
3670 2 push @{ $info->{revdat} }, {
3671 num => $r->{ordinal},
3672 date => $r->{revision_date},
3673 id => $info->{header}{id_code},
3674 type => $r->{data_content_type},
3675 2 };
3676 }
3677 593 return $info;
3678 }
3679  
3680 # reading the parsed categories
3681  
3682 # _cif_rows($p, $category) -- a category as a list of rows, whether it was
3683 # written as a loop_ or, having only one row, as a run of plain tags. The
3684 # format allows both for the same category and files use both, so asking for
3685 # the rows has to work either way.
3686 #
3687 # The two are folded together once, on the first call, rather than on each:
3688 # reading the header asks for forty-odd categories and a real entry has
3689 # several hundred plain tags, so doing it per call would walk the lot forty
3690 # times over to answer forty questions.
3691 27418 ▶sub _cif_rows {
Subroutine _cif_rows: called CC=8 SCAR=20.9
3692 27418 my ($p, $cat) = @_;
3693 27418 ▶ my $by_cat = $p->{_by_category} ||= do {
Condition66%2/3
$p->{"_by_category"} ||= do { my %c; while (() = each %{$p->{"cif"} or {};}) { do { my $dot = index($tag, "."); () = $dot < 0 ? ($tag, $tag) : (substr($tag, 0, $dot), substr($tag, $dot + 1)); +($c{$k} ||= [{}])->[0]{$item} = $val }; } ; %c = (%c, %{$p->{"cif_loops"} or {};}); \%c }
l!l&&r!l&&!r
268255930
MC/DC0%0/2
$p->{"_by_category"} ||= do { my %c; while (() = each %{$p->{"cif"} or {};}) { do { my $dot = index($tag, "."); () = $dot < 0 ? ($tag, $tag) : (substr($tag, 0, $dot), substr($tag, $dot + 1)); +($c{$k} ||= [{}])->[0]{$item} = $val }; } ; %c = (%c, %{$p->{"cif_loops"} or {};}); \%c }
$p->{"_by_category"} do { my %c; while (() = each %{$p->{"cif"} or {};}) { do { my $dot = index($tag, "."); () = $dot < 0 ? ($tag, $tag) : (substr($tag, 0, $dot), substr($tag, $dot + 1)); +($c{$k} ||= [{}])->[0]{$item} = $val }; } ; %c = (%c, %{$p->{"cif_loops"} or {};}); \%c }
Truth table66%2/3
A ||= B
A= $p->{"_by_category"}B= do { my %c; while (() = each %{$p->{"cif"} or {};}) { do { my $dot = index($tag, "."); () = $dot < 0 ? ($tag, $tag) : (substr($tag, 0, $dot), substr($tag, $dot + 1)); +($c{$k} ||= [{}])->[0]{$item} = $val }; } ; %c = (%c, %{$p->{"cif_loops"} or {};}); \%c }
ABresult
1X1
011
000
3694 593 my %c;
3695 593 ▶ while (my ($tag, $val) = each %{ $p->{cif} || {} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$p->{"cif"} or {};}) 4401 593 4994
Condition50%1/2
$p->{'cif'} || {}
l!l
49940
MC/DC0%0/1
$p->{'cif'} || {}
$p->{'cif'}
Truth table50%1/2
A
A= $p->{'cif'}
Aresult
11
00
3696 4401 my $dot = index($tag, '.');
3697 # a core CIF tag has no category half, and is its own category
3698 4401 ▶ my ($k, $item) = $dot < 0 ? ($tag, $tag)
Branch: 1 branch
BranchTrueFalseTotal
$dot < 0 ? : 2 4399 4401
3699 : (substr($tag, 0, $dot), substr($tag, $dot + 1));
3700 4401 ▶ ($c{$k} ||= [ {} ])->[0]{$item} = $val;
Condition100%2/2
$c{$k} ||= [{}]
l!l
26611740
MC/DC100%1/1
$c{$k} ||= [{}]
$c{$k}
Truth table100%2/2
A
A= $c{$k}
Aresult
11
00
3701 }
3702 # a loop_ is the category, where there is one: a file that wrote both
3703 # meant the loop, since that is the one that can hold what it holds
3704 593 ▶ %c = (%c, %{ $p->{cif_loops} || {} });
Condition50%1/2
$p->{'cif_loops'} || {}
l!l
5930
MC/DC0%0/1
$p->{'cif_loops'} || {}
$p->{'cif_loops'}
Truth table50%1/2
A
A= $p->{'cif_loops'}
Aresult
11
00
3705 593 \%c;
3706 };
3707 27418 ▶ return $by_cat->{$cat} || [];
Condition100%2/2
$by_cat->{$cat} || []
l!l
580321615
MC/DC100%1/1
$by_cat->{$cat} || []
$by_cat->{$cat}
Truth table100%2/2
A
A= $by_cat->{$cat}
Aresult
11
00
3708 }
3709  
3710 # one item from a category that has one row, which is most of them
3711 12522 ▶sub _cif1 {
Subroutine _cif1: called CC=4 SCAR=13.9
3712 12522 my ($p, $cat, $item) = @_;
3713 12522 my $rows = _cif_rows($p, $cat);
3714 12522 ▶ return undef unless @$rows;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rows 9202 3320 12522
3715 3320 my $v = $rows->[0]{$item};
3716 3320 ▶ return defined $v && length $v ? $v : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v && length $v ? : 3147 173 3320
Condition66%2/3
defined $v and length $v
!ll&&!rl&&r
17303147
MC/DC50%1/2
defined $v and length $v
defined $v length $v
Truth table66%2/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
3717 }
3718  
3719 # the same, as a number. '?' and '.' already came back as undef; what is left
3720 # to guard against is a field holding text where a number belongs.
3721 9305 ▶sub _cifn {
Subroutine _cifn: called CC=2 SCAR=6.9
3722 9305 my $v = _cif1(@_);
3723 9305 ▶ return defined $v ? _n($v) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 1992 7313 9305
3724 }
3725  
3726 # auth_* first, then label_*: the same rule the coordinates were read under,
3727 # so an annotation and the chain it annotates agree about the chain's name
3728 2424 ▶sub _cif_auth {
Subroutine _cif_auth: called CC=4 SCAR=13.9
3729 2424 my ($r, $which, $item) = @_;
3730 2424 for my $k ("${which}_auth_$item", "${which}_label_$item") {
3731 2510 ▶ return $r->{$k} if defined $r->{$k} && length $r->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{$k} and length $r->{$k} 2338 172 2510
Condition66%2/3
defined $r->{$k} and length $r->{$k}
!ll&&!rl&&r
17202338
MC/DC50%1/2
defined $r->{$k} and length $r->{$k}
defined $r->{$k} length $r->{$k}
Truth table66%2/3
A and B
A= defined $r->{$k}B= length $r->{$k}
ABresult
0X0
100
111
3732 }
3733 86 return undef;
3734 }
3735  
3736 1226 ▶sub _cif_ptnr {
Subroutine _cif_ptnr: called CC=4 SCAR=13.9
3737 1226 my ($r, $n, $item) = @_;
3738 1226 for my $k ("ptnr${n}_auth_$item", "ptnr${n}_label_$item") {
3739 1292 ▶ return $r->{$k} if defined $r->{$k} && length $r->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{$k} and length $r->{$k} 1220 72 1292
Condition66%2/3
defined $r->{$k} and length $r->{$k}
!ll&&!rl&&r
7201220
MC/DC50%1/2
defined $r->{$k} and length $r->{$k}
defined $r->{$k} length $r->{$k}
Truth table66%2/3
A and B
A= defined $r->{$k}B= length $r->{$k}
ABresult
0X0
100
111
3740 }
3741 6 return undef;
3742 }
3743  
3744 # the same, for a category that names its columns auth_$item and label_$item
3745 15 ▶sub _cif_named {
Subroutine _cif_named: called CC=4 SCAR=16.9
3746 15 my ($r, $item) = @_;
3747 15 for my $k ("auth_$item", "label_$item") {
3748 15 ▶ return $r->{$k} if defined $r->{$k} && length $r->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{$k} and length $r->{$k} 15 0 15
Condition33%1/3
defined $r->{$k} and length $r->{$k}
!ll&&!rl&&r
0015
MC/DC0%0/2
defined $r->{$k} and length $r->{$k}
defined $r->{$k} length $r->{$k}
Truth table33%1/3
A and B
A= defined $r->{$k}B= length $r->{$k}
ABresult
0X0
100
111
3749 }
3750 0 return undef;
3751 }
3752  
3753 # small helpers
3754  
3755 12155 ▶sub _t {
Subroutine _t: called CC=2 SCAR=6.9
3756 12155 my ($s) = @_;
3757 12155 ▶ return '' unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 797 11358 12155
3758 11358 $s =~ s/\A\s+//;
3759 11358 $s =~ s/\s+\z//;
3760 11358 return $s;
3761 }
3762  
3763 # _c($line, $from, $length) -- the trimmed contents of a fixed field, clipped
3764 # to what the line actually has. Records in real files are right-trimmed, so
3765 # any field can begin past the end of its line, and that is not damage: it is
3766 # a field the depositor left empty. Every fixed-column read below goes
3767 # through this rather than through substr() directly, because a bare substr()
3768 # dies on 15 of the 10,116 entries in PDBbind v2020 -- a SHEET record with no
3769 # sense field on it is enough.
3770 37202 ▶sub _c {
Subroutine _c: called CC=4 SCAR=13.9
3771 37202 my ($line, $from, $length) = @_;
3772 37202 ▶ return '' if !defined $line || $from >= length $line;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $line or $from >= length $line 826 36376 37202
Condition100%3/3
not defined $line or $from >= length $line
l!l&&r!l&&!r
382336376
MC/DC100%2/2
not defined $line or $from >= length $line
not defined $line $from >= length $line
Truth table100%3/3
not(A) or B
A= not defined $lineB= $from >= length $line
ABresult
1X1
011
000
3773 36376 ▶ my $s = defined $length ? substr($line, $from, $length) : substr($line, $from);
Branch: 1 branch
BranchTrueFalseTotal
defined $length ? : 27653 8723 36376
3774 36376 $s =~ s/\A\s+//;
3775 36376 $s =~ s/\s+\z//;
3776 36376 return $s;
3777 }
3778  
3779 # _n($field) -- a numeric field as a number, or undef where it is not one.
3780 #
3781 # The pattern spells a number rather than "digits and dots", which is what it
3782 # used to say: [\d.]+ also matches '1.2.3' and a lone '.', neither of which is
3783 # something Perl will add. Under warnings FATAL => 'all' that is not a wrong
3784 # answer but a dead read -- a CRYST1 whose cell edge is written '1.2.3' took
3785 # the whole structure down with "Argument isn't numeric in addition". Fields
3786 # of that shape are in the archive: 5m04 writes its pH as '5.4.-5.8'. A field
3787 # that is not a number is now the undef it always meant. '1.' and '.5' still
3788 # read as numbers, as they always did and as Perl does.
3789 3603 ▶sub _n {
Subroutine _n: called CC=2 SCAR=6.9
3790 3603 my $v = _t($_[0]);
3791 3603 ▶ return $v =~ /\A[-+]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][-+]?[0-9]+)?\z/
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /\A[-+]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][-+]?[0-9]+)?\z/ ? : 3511 92 3603
3792 ? $v + 0 : undef;
3793 }
3794  
3795 # continuation records: text from column $from on, glued back together. A
3796 # hyphen at the end of a line is a real hyphen in the middle of a word --
3797 # KEYWDS breaks "COMPLEX (HORMONE-" / "RECEPTOR)" across lines -- so it joins
3798 # without a space; anything else takes one.
3799 3412 ▶sub _joined {
Subroutine _joined: called CC=5 SCAR=16.2
3800 3412 my ($lines, $from, $id) = @_;
3801 3412 ▶ return '' unless $lines && @$lines;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines and @$lines 2051 1361 3412
Condition66%2/3
$lines and @$lines
!ll&&!rl&&r
205101361
MC/DC50%1/2
$lines and @$lines
$lines @$lines
Truth table66%2/3
A and B
A= $linesB= @$lines
ABresult
0X0
100
111
3802 1361 my $out = '';
3803 1361 for my $l (@$lines) {
3804 4400 my $t = _c(_untail($l, $id), $from);
3805 4400 ▶ next unless length $t;
Branch: 1 branch
BranchTrueFalseTotal
unless length $t 0 4400 4400
3806 4400 $out = _rejoin($out, $t);
3807 }
3808 1361 return $out;
3809 }
3810  
3811 # The text records run to the end of the line, and in a file old enough to keep
3812 # its entry id in columns 73-80 the end of the line is '1GDR 3'. Given the id
3813 # the HEADER carried, a line whose columns 73-80 hold nothing but that id and a
3814 # line number is cut there: 'GAMMA DELTA RESOLVASE' is the compound and the id
3815 # is the stationery. Nothing else is cut -- a modern file uses those columns
3816 # for text, and text is not the entry id followed by a number -- so a title that
3817 # runs to column 80 is left alone.
3818 9609 ▶sub _untail {
Subroutine _untail: called CC=7 SCAR=19.7
3819 9609 my ($line, $id) = @_;
3820 9609 ▶ return $line unless defined $line && defined $id && length $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line and defined $id and length $id 52 9557 9609
Condition66%4/6
defined $line and defined $id and length $id
!ll&&!rl&&r
5209557
defined $line and defined $id
!ll&&!rl&&r
0529557
MC/DC33%1/3
defined $line and defined $id and length $id
defined $line defined $id length $id
Truth table50%2/4
A and B and C
A= defined $lineB= defined $idC= length $id
ABCresult
0XX0
10X0
1100
1111
3821 9557 ▶ return $line unless length($line) > 72 && $id =~ /\A\w{1,4}\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line > 72 and $id =~ /\A\w{1,4}\z/ 8005 1552 9557
Condition66%2/3
length $line > 72 and $id =~ /\A\w{1,4}\z/
!ll&&!rl&&r
800501552
MC/DC50%1/2
length $line > 72 and $id =~ /\A\w{1,4}\z/
length $line > 72 $id =~ /\A\w{1,4}\z/
Truth table66%2/3
A and B
A= length $line > 72B= $id =~ /\A\w{1,4}\z/
ABresult
0X0
100
111
3822 1552 ▶ return substr($line, 72) =~ /\A\s*\Q$id\E(?:\s+\d+)?\s*\z/i
Branch: 1 branch
BranchTrueFalseTotal
substr($line, 72) =~ /\A\s*\Q$id\E(?:\s+\d+)?\s*\z/i ? : 1011 541 1552
3823 ? substr($line, 0, 72)
3824 : $line;
3825 }
3826  
3827 5394 ▶sub _rejoin {
Subroutine _rejoin: called CC=4 SCAR=13.9
3828 5394 my ($have, $add) = @_;
3829 5394 ▶ return $add unless defined $have && length $have;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $have and length $have 2066 3328 5394
Condition100%3/3
defined $have and length $have
!ll&&!rl&&r
70513613328
MC/DC100%2/2
defined $have and length $have
defined $have length $have
Truth table100%3/3
A and B
A= defined $haveB= length $have
ABresult
0X0
100
111
3830 3328 ▶ return $have . $add if $have =~ /-\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $have =~ /-\z/ 171 3157 3328
3831 3157 return "$have $add";
3832 }
3833  
3834 624 ▶sub _check_info {
Subroutine _check_info: called CC=5 SCAR=16.1
3835 624 my ($info, $who) = @_;
3836 die "$who: expected the hash reference from structure_info()"
3837 624 ▶ unless defined $info && (reftype($info) || '') eq 'HASH' && exists $info->{chains};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info and (builtin::reftype($info) || "") eq "HASH" and exists $info->{"chains"} 44 580 624
Condition100%8/8
defined $info and (builtin::reftype($info) || "") eq "HASH" and exists $info->{"chains"}
!ll&&!rl&&r
3113580
defined $info and (builtin::reftype($info) || "") eq "HASH"
!ll&&!rl&&r
1219593
builtin::reftype($info) || ''
l!l
6075
MC/DC100%3/3
defined $info and (builtin::reftype($info) || "") eq "HASH" and exists $info->{"chains"}
defined $info builtin::reftype($info) exists $info->{"chains"}
Truth table100%4/4
A and B and C
A= defined $infoB= builtin::reftype($info)C= exists $info->{"chains"}
ABCresult
0XX0
10X0
1100
1111
3838 580 return 1;
3839 }
3840  
3841 #
3842 # Help
3843 #
3844 # h() prints a function's own documentation, in the spirit of R's ?function.
3845 # The text is this file's POD, read at run time, so the help and the shipped
3846 # documentation cannot drift apart.
3847 #
3848 7 ▶sub h {
Subroutine h: called CC=4 SCAR=13.9
Pod documented
3849 7 my ($what) = @_;
3850 7 my $name = _help_name($what);
3851 7 my $sec = _pod_sections();
3852 7 ▶ if (defined $name && $sec->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and $sec->{$name}) 5 2 7
Condition100%3/3
defined $name and $sec->{$name}
!ll&&!rl&&r
115
MC/DC100%2/2
defined $name and $sec->{$name}
defined $name $sec->{$name}
Truth table100%3/3
A and B
A= defined $nameB= $sec->{$name}
ABresult
0X0
100
111
3853 5 print STDOUT $sec->{$name};
3854 5 return $name;
3855 }
3856 2 print STDOUT "Chem::Structure::Parser $VERSION\n\nDocumented functions:\n";
3857 2 print STDOUT " $_\n" for sort keys %$sec;
3858 2 print STDOUT "\nCall h('structure_info') for one of them.\n";
3859 2 return undef;
3860 }
3861  
3862 7 ▶sub _help_name {
Subroutine _help_name: called CC=3 SCAR=11.0
3863 7 my ($what) = @_;
3864 7 ▶ return undef unless defined $what;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $what 1 6 7
3865 6 my $r = ref $what;
3866 6 ▶ if ($r eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($r eq "CODE") 1 5 6
3867 1 require B;
3868 1 my $gv = B::svref_2object($what)->GV;
3869 1 return $gv->NAME;
3870 }
3871 5 my $n = "$what"; # a glob stringifies as *Chem::Structure::Parser::res1
3872 5 $n =~ s/\A\*//;
3873 5 $n =~ s/\A.*:://;
3874 5 return $n;
3875 }
3876  
3877 7 ▶sub _pod_sections {
Subroutine _pod_sections: called CC=14 SCAR=27.5
3878 7 my %sec;
3879 # Only the functions. The POD is generated from README.md, whose '# Changes'
3880 # section writes each release as '## 0.01 2026-08-21 CDT' -- a =head2 like
3881 # any other, which listed the version number among the documented functions
3882 # until this filtered on the export list.
3883 7 my %exported = map { $_ => 1 } @EXPORT_OK;
3884 7 my $self = __FILE__;
3885 7 ▶ open my $fh, '<', $self
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self or die "Can't open '${self}' with mode '<': '$!'" 7 0 7
3886 or die "Can't open '$self' with mode '<': '$!'";
3887 7 my ($in, $name);
3888 7 ▶ while (my $l = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = readline $fh)) 54124 7 54131
3889 54124 ▶ if ($l =~ /\A=head2\s+(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A=head2\s+(\S+)/) 189 53935 54124
3890 189 $name = $1;
3891 189 $name =~ s/\(.*//;
3892 0 ▶ if (!$exported{$name}) { $in = 0; $name = undef; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($exported{$name}) 0 189 189
3893 189 $in = 1;
3894 189 $sec{$name} = '';
3895 189 next;
3896 }
3897 53935 ▶ if ($l =~ /\A=head[12]\b/ || $l =~ /\A=cut/) { $in = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A=head[12]\b/ or $l =~ /\A=cut/) 91 53844 53935
Condition66%2/3
$l =~ /\A=head[12]\b/ or $l =~ /\A=cut/
l!l&&r!l&&!r
91053844
MC/DC50%1/2
$l =~ /\A=head[12]\b/ or $l =~ /\A=cut/
$l =~ /\A=head[12]\b/ $l =~ /\A=cut/
Truth table66%2/3
A or B
A= $l =~ /\A=head[12]\b/B= $l =~ /\A=cut/
ABresult
1X1
011
000
3898 # A subsection of a function -- '### Options' in README.md, '=head3
3899 # Options' here -- prints as its own title and not as the POD command
3900 # that carries it.
3901 53844 ▶ if ($l =~ /\A=head[3-9]\s+(\S.*?)\s*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A=head[3-9]\s+(\S.*?)\s*\z/) 315 53529 53844
3902 315 ▶ $sec{$name} .= "$1\n" if $in && defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if $in and defined $name 315 0 315
Condition33%1/3
$in and defined $name
!ll&&!rl&&r
00315
MC/DC0%0/2
$in and defined $name
$in defined $name
Truth table33%1/3
A and B
A= $inB= defined $name
ABresult
0X0
100
111
3903 315 next;
3904 }
3905 53529 ▶ $sec{$name} .= $l if $in && defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if $in and defined $name 21560 31969 53529
Condition66%2/3
$in and defined $name
!ll&&!rl&&r
31969021560
MC/DC50%1/2
$in and defined $name
$in defined $name
Truth table66%2/3
A and B
A= $inB= defined $name
ABresult
0X0
100
111
3906 }
3907 7 ▶ close $fh or die "Can't close '$self': '$!'";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Can't close '${self}': '$!'" 7 0 7
3908 7 s/\A\n+//, s/\n+\z/\n/ for values %sec;
3909 7 return \%sec;
3910 }
3911  
3912 24 1;
3913  
3914 __END__
↑ Summary Parser.xs »