943,544 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 1148
  • Perl RSS
Sep 30th, 2008
0

How to retrieve three columns using perl

Expand Post »
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,
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
annie_singh is offline Offline
6 posts
since Sep 2008
Sep 30th, 2008
0

Re: How to retrieve three columns using perl

Perl Syntax (Toggle Plain Text)
  1. open (IN, "filename.pdb") or die "$!";
  2. while (my $line = <IN>) {
  3. chomp($line);
  4. my @array = (split(/\s+/,$line))[6,7,8];
  5. print "@array\n";
  6. }
  7. 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.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Oct 1st, 2008
0

Re: How to retrieve three columns using perl

Thank you so much.. that really helped me solve the problem
Reputation Points: 10
Solved Threads: 0
Newbie Poster
annie_singh is offline Offline
6 posts
since Sep 2008
Oct 1st, 2008
0

Re: How to retrieve three columns using perl

Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: convert XYZ co-ordinates to distance in pdb file
Next Thread in Perl Forum Timeline: Need guidance in converting Perl code to Java code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC