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

    Join Date
    Mar 2013
    Posts
    12
    Rep Power
    0

    Calculating rmsd


    Hi I need some help with this perl script to calculate rmsd of a pdb file. Here is the scipt;

    #!/usr/bin/perl- W
    use strict;
    use warnings;

    print ($ARG[0]);
    open(FILE, $ARG[0]) || die "$!\n";
    $fn=0;
    while(chomp($line=<FILE>)){
    open('~/path/to/file',$line)||die "$!\n";
    $cn=0;
    While(chomp($l=<~/path/to/file>)){
    $resid=substr($l, 22, 4);
    $resid=~s/ //g;
    $atname=substr($l,12,4);
    if ($resid>38 && $resid<41 && $l=~/^ATOM/ && !($atname=~/ N /|| $atname=~/ CA / || $atname=~/ C / || $atname=~/ O / || $atnam=~/ CB /)){
    $posX{$fn}{resid}{$atname}=sudstr($l, 30, 8);
    }
    }
    close ('~/path/to/file');
    $fn++;
    }



    I am getting the following errors:
    Global symbol "$ARG" require explicit package name at line 5
    " " "$fn" at line 7
    "$line" at line 8
    "$line" at line 9
    "$cn" at line 10
    "$l" at line 11
    BEGIN not safe after errors--compilation aborted at line 11.

    Please can someone help me figure out what I am doing wrong? I am new using perl about a week ago. Help me.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    837
    Rep Power
    496
    The arguments passed to the script are in the @ARGV array, not @ARG.

    So it should be:

    Perl Code:
    print ($ARGV[0]);
    open(FILE, $ARGV[0]) || die "$!\n";


    When you use the strict pragma (and it is good that you do it), you have to explicitly declare your variables (usually with the my function), so you should have, for example:

    Perl Code:
    my $fn = 0;
    while (chomp (my $line = <FILE>)){ # ...


    Same thing for the $l variable. As for the $cn variable, you don't seem to use it anywhere, so you could probably remove the line where you set $cn to 0.

    There are a number of stylistic comments that I could add, but at least the corrections suggested should allow you to compile your program.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    837
    Rep Power
    496
    I was happy to see on another forum (Perl Gurus) that you used my suggestions for correcting your script before asking your next question (at least, I know that you have used my suggestions), but I would be even more satisfied if you took the time to thank me for my answer and the help I provided.

    Oh, well, I am old school, maybe, thanking people for their help is probably has-been by now?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Posts
    22
    Rep Power
    0
    And also I particularly find your code hard to read and I storngly suggest use the code around your code for readability and possibly get better response. I'm not sure if the forum has some sort of enformce mechanism to check if code tag are in place before posting.

    perl Code:
     
    #!/usr/bin/perl- W


    And also this should produce a problem complaining about there is not bianry called perl-. That should rather be

    perl Code:
     
    #! /usr/bin/perl -w


    ssharish2005
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    837
    Rep Power
    496
    The -w is actually useless, since there is the "use warnings"' pragma just a couple of lines below.

    Comments on this post

    • ssharish2005 agrees
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Posts
    22
    Rep Power
    0
    I do agree with it. I read articale a while back again in one of the forum that the scoping applies to where the warning flag were raised. That if you had -w places at the top; the interpretor would apply the warning for all of the sub modules but not only for the module currently under execution with contrast to "use warning".

    But however I couldn't agree to it or even get a chance to test it myself.

    ssharish2005
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    12
    Rep Power
    0

    I appreciate your help


    Originally Posted by Laurent_R
    I was happy to see on another forum (Perl Gurus) that you used my suggestions for correcting your script before asking your next question (at least, I know that you have used my suggestions), but I would be even more satisfied if you took the time to thank me for my answer and the help I provided.

    Oh, well, I am old school, maybe, thanking people for their help is probably has-been by now?
    To Laurent_R
    Do not be offended. I really appreciate your helps. And thanks to everyone who took time to look at my scripts.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    12
    Rep Power
    0
    Originally Posted by ssharish2005
    I do agree with it. I read articale a while back again in one of the forum that the scoping applies to where the warning flag were raised. That if you had -w places at the top; the interpretor would apply the warning for all of the sub modules but not only for the module currently under execution with contrast to "use warning".

    But however I couldn't agree to it or even get a chance to test it myself.

    ssharish2005
    Thanks a lot
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    12
    Rep Power
    0

    Hi Laurent_R


    Originally Posted by Laurent_R
    I was happy to see on another forum (Perl Gurus) that you used my suggestions for correcting your script before asking your next question (at least, I know that you have used my suggestions), but I would be even more satisfied if you took the time to thank me for my answer and the help I provided.

    Oh, well, I am old school, maybe, thanking people for their help is probably has-been by now?
    I try to rewrite my script in order to get x,y,z coordinates from pdb file then calculate the distance between them. Here the script and the errors messages. Please help.

    #!/usr/bin/perl

    use strict;
    use warnings;

    print($ARGV[0]);
    open(FILE,$ARGV[0]) || die "$!\n";
    my $fn=0;
    while(chomp(my $line=<FILE>)){
    OPEN('~/pdb_data/00?pdb100d.pdb',$line) || die "$!\n";
    my $cn=0;
    while(chomp(my $l=<'~/pdb_data/00/pdb100d.pdb'>)){
    my $resid=substr($l, 8, 3);
    $resid=~s/ //g;
    my $atname=substr($l, 66, 2);
    if($resid==0 && $resid<876 && $l=~/^ATOM/ && !($atname=~/ H /)){
    my $posX{$fn}{$resid}{$atname}=substr($l, 27, 6);
    my $posY{$fn}{$resid}{$atname}=substr($l, 33, 6);
    my $posZ{$fn}{$resid}{$atname}=substr($l, 42, 6);
    $cn++;
    }
    }
    close( '~/pdb_data/00/pdb100d.pdb');
    $fn++;
    }

    print "$fn\n";
    close(FILE);
    for($i=0; $i<$fn-1; $i++){
    for($j=$i+1; $j<$fn; $j++){
    my $dist_1=0;
    my $cn=0;
    for($resid==0; $resid<876;$resdi++){
    $dist_1=($posX{$i}{$resid}{$k} - posX{$j}{$resid}{$k})**2 + ($posY{$i}{$resid}{$k} - $posY{$j}{$resid}{$k})**2 + ($posZ{$i}{$resid}{$k} - posZ{$j}{$resid}{$k})**2;
    $cn++;
    }
    $dist=sqrt($dist_1)
    printf"%d %d %.2f\n",$i,$j,$dist;
    }
    }

    Here are the errors message:

    syntax error at H_coord.pl line 17, near "$posX{"
    syntax error at H_coord.pl line 17, near "}="
    syntax error at H_coord.pl line 18, near "$posY{"
    Global symbol "$resid" requires explicit package name at H_coord.pl line 18.
    Global symbol "$atname" requires explicit package name at H_coord.pl line 18.
    syntax error at H_coord.pl line 18, near "}="
    Global symbol "$l" requires explicit package name at H_coord.pl line 18.
    syntax error at H_coord.pl line 19, near "$posZ{"
    Global symbol "$resid" requires explicit package name at H_coord.pl line 19.
    Global symbol "$atname" requires explicit package name at H_coord.pl line 19.
    syntax error at H_coord.pl line 19, near "}="
    H_coord.pl has too many errors.

    Thanks in advance.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    837
    Rep Power
    496
    Originally Posted by ssharish2005
    I do agree with it. I read articale a while back again in one of the forum that the scoping applies to where the warning flag were raised. That if you had -w places at the top; the interpretor would apply the warning for all of the sub modules but not only for the module currently under execution with contrast to "use warning".
    Yes, and this is the problem with the -w flag: it activates warnings even in code that you did not write (such as a module, for example) and that may have been written with other standards. Also, with use warnings, you can silence some of the specific warnings, which can be useful sometimes.

    In brief, use warnings gives you a much better control. It is usually admitted for good practices that the -w is still there for compatibility reasons but should no longer be used in new code; use warnings should be used instead.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    837
    Rep Power
    496
    You need to declare your three hashes earlier, near the top of your script.

    Perl Code:
    my (%posX, %posY, %posZ);


    The change the relevant lines as follows:

    Code:
    $posX{$fn}{$resid}{$atname} = substr($l, 27, 6);
    $posY{$fn}{$resid}{$atname} = substr($l, 33, 6);
    $posZ{$fn}{$resid}{$atname} = substr($l, 42, 6);
    I think it will probably remove most of the other errors (unless I missed something else).
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    12
    Rep Power
    0
    Originally Posted by Laurent_R
    You need to declare your three hashes earlier, near the top of your script.

    Perl Code:
    my (%posX, %posY, %posZ);


    The change the relevant lines as follows:

    Code:
    $posX{$fn}{$resid}{$atname} = substr($l, 27, 6);
    $posY{$fn}{$resid}{$atname} = substr($l, 33, 6);
    $posZ{$fn}{$resid}{$atname} = substr($l, 42, 6);
    I think it will probably remove most of the other errors (unless I missed something else).
    I appreciate your time to answers my questions. Be blessed.

IMN logo majestic logo threadwatch logo seochat tools logo