Hello,

I have a file with the data as shown below:

ATOM 2 CA ARG A 1 6.324 32.707 50.379
ATOM 13 CA THR A 2 5.197 32.618 46.826
ATOM 20 CA ASP A 3 4.020 36.132 46.259
ATOM 28 CA CYS A 4 7.131 38.210 45.919

I am a beginner in perl and i wrote a program to retrieve the last three columns and putting them in an array in order to calculate the distance

open (IN, "out.pl");
my $file = ' ';
while (<IN>) {
chomp($file);
my @array = /\d+\.\d+\s+\d+\.\d+\s+\d+\.\d+/
.....
am stuck.
for(#calculate distance){

}
}
close (IN);


I would like to know the script to match the three columns and putting them in an array and writng a for loop to calculate the distance between the four atoms given in the file.

Thank you,

open (IN, "filename.pdb") or die "$!";
while (my $line = <IN>) {
   chomp($line);
   my @array = (split(/\s+/,$line))[6,7,8];
   print "@array\n";
}
close (IN);

Look into perls math operators for the distance calculations. The above just shows an example of how to get the last three columns from a line with 9 columns of varying length data seperated by spaces.

Thank you so much.. that really helped me solve the problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.