February 9th, 2013, 04:56 PM
Hello im new to programming i need help
what i am trying to do is to compare a set of coordinates from one file to another set of coordinates from many different files. i am having trouble doing this please can some 1 help me here is what i have done so far which compares 2 sets. i want to be able to change the first part to cycle through all files i have in a directory.
#$dir = "/net/klab2/u2/home/fmohammad/GFP2/run1";
#opendir (DIR, $dir) or die $!;
#@one = readdir (DIR);
#foreach $file (@one)
$initialfile2 = "UM_802_R203E112_1GFL_clean_gfp_5.pdb";
open FILETWO, "$initialfile2" or die "cannot open $initialfile2 for read\n";
while ($line2 = <FILETWO>)
if ($oneeq "C4")
if ($oneeq "C1")
if ($oneeq "C13")
$initialfile = "1GFL.pdb";
open FILEONE, "$initialfile" or die "cannot open $initialfile for read\n";
while ($line = <FILEONE>)
if ($twoeq "479")
if ($twoeq "484")
if ($twoeq "496")
$part1 = ((($xC1 - $xS)**2) + (($yC1 - $yS)**2) + (($zC1 - $zS)**2));
$part2 = ((($xC4 - $xY)**2) + (($yC4 - $yY)**2) + (($zC4 - $zY)**2));
$part3 = ((($xC13 - $xG)**2) + (($yC13 - $yG)**2) + (($zC13 - $zG)**2));
$sum = $part1 + $part2 + $part3;
$sum1 = $sum / 3;
$rmsd = sqrt ($sum1);
February 10th, 2013, 06:38 AM
Unless I missed something, what you have commented out at the top of your program should happily iterate over each file in the directory, which I assume is what you want to do. Please tell us where you think you have a problem.
The only thing you might want to add is to discard entries starting with a dot or, better, to test with the -f file test operator that the entry you will use next is a plain file (not a directory or something else).
Also take a look at the glob function, which can make your iteration simpler, because it returns a list of files with their path (which readdir gives you only the filenames).
Last edited by Laurent_R; February 10th, 2013 at 06:43 AM.