### Thread: Distance between consecutive residue

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
12
Rep Power
0

#### Distance between consecutive residue

Good morning,
I have some problems adding a subroutine to calculate the distance between consecutive residue. Here is my script:

#!/usr/bin/perl

use strict;
use Data:umper;

my @points = ();
my \$atname;
my \$X;
my \$Y;
my \$Z;
my \$resid;
my \$dist;
open(FILE,\$ARGV[0]);

my @file = <FILE>;

foreach my \$l (@file){
chomp(\$l);
if (\$l=~/^ATOM/ && \$l=~/H01/ || \$l=~/H03/){
my @line = split (/\s+/,\$l);
\$atname = \$line[-1];
\$resid = \$line[5];
\$X = \$line[6];
\$Y = \$line[7];
\$Z = \$line[8];

print "\$atname \$resid \$X \$Y \$Z \n";
push @points, [\$X, \$Y, \$Z];
}
}
close;

After getting the H01 and H03 for each residue, I would like to calculate the distance between H01(residue1) and H03(residue2), H01(residue2) and H03(residue3), .....

Can some one help? Thanks a lot.
2. You aren't exactly being clear since \$H1 and \$H3 aren't variables in your code, but rather unrelated preg_match conditions.

The new user guide contains tips on code formatting and asking good questions.

PHP Code:
``` my \$prev = 0; foreach my \$l (@file){   chomp(\$l);   if (\$l=~/^ATOM/ && \$l=~/H01/ || \$l=~/H03/){     my @line = split (/\s+/,\$l);     \$atname = \$line[-1];     \$resid = \$line[5];     \$X = \$line[6];     \$Y = \$line[7];     \$Z = \$line[8];          /*whatever you're talking about with h01 and h03, put them here.  \$prev is whatever that variable is you're referencing. */          if ( \$prev != 0 {       my \$delta = \$prev - \$X;     } else {       my \$delta = 0;     }          \$prev = \$X;     print "\$atname \$resid \$X \$Y \$Z \$delta \n";     push @points, [\$X, \$Y, \$Z];   } }  ```
Edit: Also, your logical conditions are wrong, you're not understanding operator precedence, and your IF doesn't do what you think.
Last edited by ManiacDan; April 2nd, 2013 at 09:57 AM.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
12
Rep Power
0
Originally Posted by ManiacDan
You aren't exactly being clear since \$H1 and \$H3 aren't variables in your code, but rather unrelated preg_match conditions.

The new user guide contains tips on code formatting and asking good questions.

PHP Code:
``` my \$prev = 0; foreach my \$l (@file){   chomp(\$l);   if (\$l=~/^ATOM/ && \$l=~/H01/ || \$l=~/H03/){     my @line = split (/\s+/,\$l);     \$atname = \$line[-1];     \$resid = \$line[5];     \$X = \$line[6];     \$Y = \$line[7];     \$Z = \$line[8];          /*whatever you're talking about with h01 and h03, put them here.  \$prev is whatever that variable is you're referencing. */          if ( \$prev != 0 {       my \$delta = \$prev - \$X;     } else {       my \$delta = 0;     }          \$prev = \$X;     print "\$atname \$resid \$X \$Y \$Z \$delta \n";     push @points, [\$X, \$Y, \$Z];   } }  ```
Edit: Also, your logical conditions are wrong, you're not understanding operator precedence, and your IF doesn't do what you think.
I am sorry my questions are not clear.
I have a pdb file containing many residues. Each residue has H, C, O, N, P. I am supposed to read, print, and calculate the distance between H01 and H03 of consecutive residue knowing their coordinates. My script can read the coordinates and I would like to add script to calculate the distance between consecutive H01 (residue1) and H03(residue2), H03(residue2) and H01(residue3), ....
Thanks for the helps
4. No Profile Picture
Contributing User
Devshed Regular (2000 - 2499 posts)

Join Date
Apr 2009
Posts
2,008
Rep Power
1226
We are not biologists so we don't know to "calculate the distance between consecutive H01 (residue1) and H03(residue2), H03(residue2) and H01(residue3)".

If you can provide the required algorithm, we should be able to help you with the perl syntax.

You may want to look at this thread, which appears to be the same question probably from one of your classmates.
5. Yeah, this reminds me of the guy who asked us how to calculate solar panel efficiency.

While I write algorithms all day long, I don't know all the algorithms ever off the top of my head.