DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Perl (http://www.daniweb.com/forums/forum112.html)
-   -   How to retrieve three columns using perl (http://www.daniweb.com/forums/thread148387.html)

annie_singh Sep 30th, 2008 2:23 pm
How to retrieve three columns using perl
 
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,

KevinADC Sep 30th, 2008 2:39 pm
Re: How to retrieve three columns using perl
 
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.

annie_singh Oct 1st, 2008 5:53 am
Re: How to retrieve three columns using perl
 
Thank you so much.. that really helped me solve the problem

KevinADC Oct 1st, 2008 2:35 pm
Re: How to retrieve three columns using perl
 
Yea, sure it did:

http://www.perlguru.com/gforum.cgi?post=32920


All times are GMT -4. The time now is 10:13 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC