Hey all, I am a PERL newbie trying to create a script to calculate the distance between all HIS/ASP residues and a single Zinc atom embedded into a protein.

#!/usr/bin/perl -W use strict; use warnings; #subroutines for calculations sub distanceAB { my $distance = 0; my $Ax = substr($_[0], 30, 8) + 0; my $Ay = substr($_[0], 38, 8) + 0; my $Az = substr($_[0], 46, 8) + 0; my $Bx = substr($_[1], 30, 8) + 0; my $By = substr($_[1], 38, 8) + 0; my $Bz = substr($_[1], 46, 8) + 0; $distance = sqrt(($Ax - $Bx)**2 + ($Ay - $By)**2 + ($Az - $Bz) +**2); return sprintf("%4.2f", $distance); } #open files for calculations and modify distance cutoff for target res +idues my $input=$ARGV[0]; my $num = 0; my $i = 0; open IN, "<$input" or die "can't open .pdb"; my @pdblines = (); while (<IN>) { for ( @pdblines) { #chomp $pdbline; if (my $pdbline =~ /ZN1 LG1 X/) { my $ZNline = $pdbline; next; } #find xyz coordinates for other atoms and store in array if (my $pdbline =~ /^ATOM.*(OD2 ASP|NE2 HIS)/) { my $Atomline = $pdbline; my $resname = substr($pdbline, 16, 3); my $resnumber = substr($pdbline, 22, 3); #calculate Zn to each atom distance my $Zndistance=distanceAB(my $ZNline, $Atomline); if (my $Zndistance < 2.5) { print "$Zndistance \n"; print "$resname $resnumber \n"; print "Coordinator $num \n"; } } ++$num; } }

When I run the code, I get a lot of "Use of initialized value" errors, such as

Use of uninitialized value $Znx in array element at ./getRESZNdistance.pl line 58, <IN> line 2863.

Use of uninitialized value $Znz in array element at ./getRESZNdistance.pl line 58, <IN> line 2863.

Basically when the script encounters lines that do not contain /OD2 ASP/ or /NE2 HIS/ it runs into an error from what I can see.

Any suggestions?


In reply to calculate distance between atoms and a target atom by mishimakaz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.