match data with another value in another file

Reply

Join Date: Oct 2008
Posts: 1
Reputation: mishel is an unknown quantity at this point 
Solved Threads: 0
mishel mishel is offline Offline
Newbie Poster

match data with another value in another file

 
0
  #1
Oct 6th, 2008
hi,

I got this program from one of forums:

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

its something like this:
-------------------------------------------------------------------------
open(IN, "/path/outModified.pl") or die "$!";

while (my $line = <IN>) {
chomp($line);
my @array = (split (/\s+/, $line))[6, 7, 8];
# print "@array\n";
push @points, [ @array ];
}

close(IN);

print '@points : ', Dumper \@points;

open my $out_file, '>', "/path/dist_modified.pl" or die "cannot open: $!\n";

for my $i1 ( 0 .. $#points -1 ){
my ( $x1, $y1, $z1 ) = @{ $points[$i1] };
for my $i2 ( 1 .. $#points){
my ( $x2, $y2, $z2 ) = @{ $points[$i2] };
my $dist = sqrt(($x2 - $x1)**2 + ($y2 - $y1)**2 + ($z2 - $z1)**2);
print $out_file "153L.pdb: the distance between CA $i1 and CA $i2 = $dist\n";
}
}
close $out_file or die "cannot close file: $!\n";
========================================
Thanks to Shawnhcorey and KevinR.

my doubt is, if i have to compare the $dist with another file in the directory which has the data:

col1 col2
1 2.69
2 2.97032
3 3.25064
4 3.53096
5 3.81128
6 4.0916
7 4.37192

can I match the value of $dist with the column 2(col2) with its nearest higher value and retrieve the column1(col1) corresponding to it? I dont know how to write this in perl. Can you help...

To make it clear, if the value of $dist = 2.84, then the program should search for second row in the file [2 2.97032] and print only 2. that is the first column.it this possible. I think i have to use regular expressions?? or pattern matching??
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 57
Reputation: mitchems is an unknown quantity at this point 
Solved Threads: 2
mitchems's Avatar
mitchems mitchems is offline Offline
Junior Poster in Training

Re: match data with another value in another file

 
0
  #2
Feb 5th, 2009
  1. open(FILE,"<test.txt");
  2. $compare=$ARGV[0]; # this takes the compare on the command line
  3. while(<FILE>){
  4. chomp;
  5. $x++;
  6. next if($x==1); #this skips the label at the top
  7. ($n,$value)=split(/\s/);
  8. print "$n\n" if($compare>$last_value && $compare<=$value);
  9. $last_value=$value;
  10. }
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: match data with another value in another file

 
0
  #3
Feb 5th, 2009
mishel Offline
Newbie Poster
What does the community think of mishel?
Community Reputation Points: 10
Reputation-Altering Power: 0
How helpful is mishel at solving threads?
Solved Threads Replied To: 0
Last Activity: Oct 6th, 2008

I'm eager to help too, but posting code for a person that has not been here for months is probably something I wouldn't do. Its your decision though.

Welcome to DaniWeb, good to have another perl person around.
Last edited by KevinADC; Feb 5th, 2009 at 1:32 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 57
Reputation: mitchems is an unknown quantity at this point 
Solved Threads: 2
mitchems's Avatar
mitchems mitchems is offline Offline
Junior Poster in Training

Re: match data with another value in another file

 
0
  #4
Feb 5th, 2009
Thanks for the welcome. I was just looking through threads in which no one had posted an answer and wasn't looking at activity. I just joined Daniweb this week, because I had a system problem and posted in another forum. I appreciated the help so much I thought I'd come to the area where I have the most experience (which is perl - I've been using perl - probably poorly at times - for about 15 years). Just trying to give back a bit.

Mitchems
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: match data with another value in another file

 
0
  #5
Feb 5th, 2009
Awesome, I hope to see you around.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC