QCons.pm

filter: Statementstmt 100% 74 / 74 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod n/a totaltotal 98.9% 95 / 96 CC 7 SCAR 7.9
CC
7
Cov
99%
_parse_by_atom
5.0
_build__result
2.0
_parse_by_residue
2.0
CRAP 2.2
↑ Summary QCons/Types.pm »
1 package Bio::Tools::Run::QCons;
2 {
3 2 $Bio::Tools::Run::QCons::VERSION = '0.112990'; # TRIAL
4 }
5  
6 # ABSTRACT: Run Qcons to analyze protein-protein contacts
7  
8 2 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Capture::Tiny 'capture_merged';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Bio::Tools::Run::QCons::Types 'Executable';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 has 'program_name' => (
16 is => 'ro',
17 isa => 'Executable',
18 default => 'Qcontacts',
19 );
20  
21 2 has file => (
22 is => 'ro',
23 isa => 'Str',
24 required => 1,
25 );
26  
27 2 has chains => (
28 is => 'ro',
29 isa => 'ArrayRef[Str]',
30 required => 1,
31 );
32  
33 2 has probe_radius => (
34 is => 'ro',
35 isa => 'Num',
36 default => 1.4,
37 );
38  
39 2 has _result => ( is => 'ro', lazy_build => 1 );
40  
41 2 has [qw(residue_contacts atom_contacts)] => (
42 is => 'ro',
43 lazy_build => 1,
44 );
45  
46 1 ▶sub _build_residue_contacts {
Subroutine _build_residue_contacts: called CC=1 SCAR=0.0
47 1 return $_[0]->_result->{by_residue};
48 }
49  
50 1 ▶sub _build_atom_contacts {
Subroutine _build_atom_contacts: called CC=1 SCAR=0.0
51 1 return $_[0]->_result->{by_atom};
52 }
53  
54 2 has verbose => (
55 is => 'rw',
56 isa => 'Bool',
57 default => 0,
58 );
59  
60 2 has _temp_dir => (
61 is => 'ro',
62 isa => 'File::Temp::Dir',
63 lazy_build => 1,
64 );
65  
66 1 ▶sub _build__temp_dir {
Subroutine _build__temp_dir: called CC=1 SCAR=0.0
67 1 require File::Temp;
68  
69 1 return File::Temp->newdir();
70 }
71  
72 1 ▶sub _build__result {
Subroutine _build__result: called CC=2 SCAR=6.9
73  
74 # Run Qcontacts with the set parameters, and return
75 # an array with the contact information.
76  
77 1 my $self = shift;
78 1 my $arguments;
79 1 my $executable = $self->program_name;
80  
81 $self->_arguments->{-prefOut} =
82 1 File::Spec->catfile( $self->_temp_dir->dirname, '' );
83  
84 1 ▶ my $output = capture_merged {
Subroutine __ANON__: called CC=1 SCAR=0.0
85 1 system( $executable, %{ $self->_arguments } )
86 1 };
87  
88 1 ▶ warn $output if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 1 1
89  
90 1 my @contacts_by_atom = $self->_parse_by_atom();
91 1 my @contacts_by_residue = $self->_parse_by_residue();
92  
93 1 return { by_atom => \@contacts_by_atom, by_residue => \@contacts_by_residue };
94 }
95  
96 2 has _arguments => (
97 is => 'ro',
98 init_arg => undef,
99 lazy_build => 1,
100 );
101  
102 # Private methods
103  
104 1 ▶sub _parse_by_residue {
Subroutine _parse_by_residue: called CC=2 SCAR=6.9
105  
106 # Qcontacts outputs two files. This subroutine parses
107 # the file that outputs residue-residue contacts.
108  
109 1 my $self = shift;
110 1 my @contacts;
111  
112 # Get the path to the output file.
113 my $filename =
114 1 File::Spec->catfile( $self->_arguments->{-prefOut}, '-by-res.vor' );
115  
116 1 open( my $fh, '<', $filename );
117  
118 # Parse the file line by line, each line corresponds to a
119 # contact.
120 1 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 48 1 49
121 48 my @fields = split( /\s+/, $line );
122  
123 48 my %contact = (
124 res1 => {
125 number => $fields[1],
126 name => $fields[2],
127 },
128 res2 => {
129 number => $fields[5],
130 name => $fields[6],
131 },
132 area => $fields[8],
133 );
134 48 push @contacts, \%contact;
135 }
136  
137 1 return @contacts;
138 }
139  
140 1 ▶sub _parse_by_atom {
Subroutine _parse_by_atom: called CC=5 SCAR=16.1
141  
142 # Qcontacts outputs two files. This subroutine parses
143 # the file that outputs atom-atom contacts.
144  
145 1 my $self = shift;
146 1 my @contacts;
147  
148 # Get the path to the output file.
149 my $filename =
150 1 File::Spec->catfile( $self->_arguments->{-prefOut}, '-by-atom.vor' );
151  
152  
153 1 open( my $fh, '<', $filename );
154 # Parse the file line by line, each line corresponds to a
155 # contact.
156  
157 1 my $meaning_for = {
158  
159 # What each parsed field means, depending on the contact
160 # type (fields[1])
161  
162 # contact type => { field number => meaning }
163 V => { 13 => 'area' },
164 H => { 13 => 'area', 14 => 'angle', 15 => 'Rno' },
165 S => {
166 13 => 'area',
167 15 => 'dGhb',
168 17 => 'dGip',
169 18 => 'angle',
170 19 => 'Rno'
171 },
172 I => { 13 => 'area', 14 => 'Rno' },
173 };
174  
175 1 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 233 1 234
176 233 my @fields = split( ' ', $line );
177 233 my %contact = (
178 atom1 => {
179 number => $fields[5],
180 name => $fields[6],
181 res_name => $fields[3],
182 res_number => $fields[2],
183 },
184 atom2 => {
185 number => $fields[11],
186 name => $fields[12],
187 res_name => $fields[9],
188 res_number => $fields[8],
189 },
190 type => $fields[1],
191 area => $fields[8],
192 );
193  
194 # I can't wait for Perl 6's junctions.
195 233 foreach my $type ( keys %$meaning_for ) {
196 932 ▶ if ( $type eq $fields[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $fields[1]) 233 699 932
197 233 foreach my $field ( keys %{ $meaning_for->{$type} } ) {
198  
199 # I just realized that there's parameter in the 'S' type
200 # that has a ')' sticked to it, remove it.
201 239 $fields[$field] =~ s/\)//g;
202 239 $contact{ $meaning_for->{$type}{$field} }
203 = $fields[$field];
204 }
205 }
206 }
207  
208 233 push @contacts, \%contact;
209 }
210  
211 1 return @contacts;
212  
213 }
214  
215 1 ▶sub _build__arguments {
Subroutine _build__arguments: called CC=1 SCAR=0.0
216 1 my $self = shift;
217 return {
218 1 -c1 => ${ $self->chains }[0],
219 1 -c2 => ${ $self->chains }[1],
220 -i => $self->file,
221 -probe => $self->probe_radius,
222 };
223 }
224  
225 2 1;
226  
227  
228 =pod
229  
230 =head1 NAME
231  
232 Bio::Tools::Run::QCons - Run Qcons to analyze protein-protein contacts
233  
234 =head1 VERSION
235  
236 version 0.112990
237  
238 =head1 SYNOPSIS
239  
240 my $q = Bio::Tools::Run::QCons->new(
241 file => $pdbfile,
242 chains => [$chain1, $chain2],
243 );
244  
245 my $contacts_by_atom = $q->atom_contacts;
246 my $contacts_by_residue = $q->residue_contacts;
247  
248 =head1 DESCRIPTION
249  
250 This module implements a wrapper for the QCons application. QCons
251 itself is an implementation of the Polyhedra algorithm for the
252 prediction of protein-protein contacts. From the program's web page
253 (L<http://tsailab.tamu.edu/QCons/>):
254  
255 "QContacts allows for a fast and accurate analysis of protein binding
256 interfaces. Given a PDB file [...] and the interacting chains of
257 interest, QContacts will provide a graphical representation of the
258 residues in contact. The contact map will not only indicate the
259 contacts present between the two proteins, but will also indicate
260 whether the contact is a packing interaction, hydrogen bond, ion pair
261 or salt bridge (hydrogen-bonded ion pair). Contact maps allow for easy
262 visualization and comparison of protein-protein interactions."
263  
264 For a thorough description of the algorithm, its limitations and a
265 comparison with several others, refer to Fischer, T. et. al: Assessing
266 methods for identifying pair-wise atomic contacts across binding
267 interfaces, J. Struc. Biol., vol 153, p. 103-112, 2006.
268  
269 =head1 ATTRIBUTES
270  
271 =head2 file
272  
273 Gets or sets the file with the protein structures to analyze. The file
274 format should be PDB.
275  
276 Required.
277  
278 =head2 chains
279  
280 chains => ['A', 'B'];
281  
282 Gets or sets the chain IDs of the subunits whose contacts the program
283 will calculate. It takes an array reference of two strings as
284 argument.
285  
286 Required.
287  
288 =head2 probe_radius($radius);
289  
290 Gets or sets the probe radius that the program uses to calculate the
291 exposed and buried surfaces. It defaults to 1.4 Angstroms, and unless
292 you have a really strong reason to change this, you should refrain
293 from doing it.
294  
295 =head2 verbose
296  
297 Output debugging information to C<STDERR>. Off by default.
298  
299 =head2 program_name
300  
301 The name of the executable. Defaults to 'Qcontacts', but it can be set
302 to anything at construction time:
303  
304 my $q = Bio::Tools::Run::QCons->new(
305 program_name => 'qcons',
306 file => $pdbfile,
307 chains => [$chain1, $chain2]
308 );
309  
310 Notice that if the binary is not on your PATH environment variable, you
311 should give C<program_name> a full path to it.
312  
313 =head2 atom_contacts
314  
315 Return an array reference with the information of every atom-atom
316 contact found.
317  
318 The structure of the array reference is as follows:
319  
320 $by_atom = [
321 {
322 'area' => '0.400',
323 'type' => 'V',
324 'atom2' => {
325 'number' => '461',
326 'res_name' => 'SER',
327 'res_number' => '59',
328 'name' => 'OG'
329 },
330 'atom1' => {
331 'number' => '2226',
332 'res_name' => 'ASN',
333 'res_number' => '318',
334 'name' => 'CB'
335 }
336 },
337 ]
338  
339 This corresponds to the information of one contact. Here, 'atom1'
340 refers to the atom belonging to the first of the two polypeptides
341 given to the 'chains' method; 'atom2' refers to the second. The fields
342 'number' and 'name' refer to the atom's number and name, respectively.
343 The fields 'res_name' and 'res_number' indicate the atom's parent
344 residue name and residue id. 'type' indicates one of the five
345 non-covalent bonds that the program predicts:
346  
347 =head2 residue_contacts
348  
349 Returns an array reference with the information of every residue-residue
350 contact found.
351  
352 The structure of the array is organized as follows:
353  
354 $by_res = [
355 {
356 'area' => '20.033',
357 'res1' => {
358 'number' => '318',
359 'name' => 'ASN'
360 },
361 'res2' => {
362 'number' => '59',
363 'name' => 'SER'
364 }
365 },
366 ]
367  
368 Here, bond type is obviously not given since the contact can possibly
369 involve more than one atom-atom contact type. 'res1' and 'res2'
370 correspond to the residues of the first and second chain ID given,
371 respectively. 'area' is the sum of every atom-atom contact that the
372 residue pair has. Their names (as three-letter residue names) and
373 number are given as hashrefs.
374  
375 =begin :list
376  
377 * B<V:> Van der Waals (packing interaction)
378  
379 * B<I:> Ion pair
380  
381 * B<S:> Salt bridge (hydrogen-bonded ion pair)
382  
383 * B<H:> Hydrogen bond (hydrogen-bonded ion pair)
384  
385 =end :list
386  
387 Every bond type has the 'area' attribute, which indicates the surface
388 (in square Angstroms) of the interaction. In addition, all N-O
389 contacts (I, S and H) have a 'Rno' value that represents the N-O
390 distance. Directional contacts (S and H) also have an 'angle' feature
391 that indicates the contact angle. For salt bridges, estimations of the
392 free energy of hydrogen bond (dGhb) and free energy of ionic pair
393 (dGip) are also given.
394  
395 =head1 THANKS
396  
397 To Chad Davis for prodding me to dust off and release this module to the CPAN.
398  
399 =head1 AUTHOR
400  
401 Bruno Vecchi <vecchi.b gmail.com>
402  
403 =head1 COPYRIGHT AND LICENSE
404  
405 This software is copyright (c) 2011 by Bruno Vecchi.
406  
407 This is free software; you can redistribute it and/or modify it under
408 the same terms as the Perl 5 programming language system itself.
409  
410 =cut
411  
412  
413 __END__
↑ Summary QCons/Types.pm »