Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 9th, 2013, 03:56 PM
fahadm89 fahadm89 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 1 fahadm89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 32 sec
Reputation Power: 0
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.

#!/usr/bin/perl -w

#$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>)
{
chomp $line2;

@one=split(/\s+/, $line2);

if ($one[0]=~m/^HETATM/)
{
if ($one[2]eq "C4")
{
$xC4=$one[6];
$yC4=$one[7];
$zC4=$one[8];
}

if ($one[2]eq "C1")
{
$xC1=$one[6];
$yC1=$one[7];
$zC1=$one[8];
}

if ($one[2]eq "C13")
{
$xC13=$one[6];
$yC13=$one[7];
$zC13=$one[8];
}
}
}
close FILETWO;

$initialfile = "1GFL.pdb";
open FILEONE, "$initialfile" or die "cannot open $initialfile for read\n";
while ($line = <FILEONE>)
{
chomp $line;

@two=split(/\s+/, $line);

if ($two[0]=~m/^ATOM/)
{
if ($two[1]eq "479")
{
$xS=$two[6];
$yS=$two[7];
$zS=$two[8];
}

if ($two[1]eq "484")
{
$xY=$two[6];
$yY=$two[7];
$zY=$two[8];
}

if ($two[1]eq "496")
{
$xG=$two[6];
$yG=$two[7];
$zG=$two[8];
}
}
}
close FILEONE;

$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);
print"$rmsd\n";
#}

Reply With Quote
  #2  
Old February 10th, 2013, 05:38 AM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 509 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 19 h 39 m 4 sec
Reputation Power: 385
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 05:43 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Hello im new to programming i need help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap