Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
April 2nd, 2013, 10:42 AM
 kapab07
Registered User

Join Date: Mar 2013
Posts: 12
Time spent in forums: 1 h 38 m 24 sec
Reputation 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
April 2nd, 2013, 10:50 AM
 ManiacDan
Sarcky

Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 10,499
Time spent in forums: 2 Months 3 Weeks 5 Days 8 h 27 m 58 sec
Reputation Power: 6300
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.
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Last edited by ManiacDan : April 2nd, 2013 at 10:57 AM.

#3
April 2nd, 2013, 12:40 PM
 kapab07
Registered User

Join Date: Mar 2013
Posts: 12
Time spent in forums: 1 h 38 m 24 sec
Reputation Power: 0
Quote:
 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
April 2nd, 2013, 12:55 PM
 FishMonger
Contributing User

Join Date: Apr 2009
Posts: 1,794
Time spent in forums: 1 Month 3 Weeks 22 h 41 m 35 sec
Reputation Power: 1206
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
April 2nd, 2013, 02:08 PM
 ManiacDan
Sarcky

Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 10,499
Time spent in forums: 2 Months 3 Weeks 5 Days 8 h 27 m 58 sec
Reputation Power: 6300
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.

 Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Distance between consecutive residue