#1
  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. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    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 != {
          
    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.
    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

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. 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 != {
          
    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
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    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.
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    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.
    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

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo