Tuesday, 20 August 2013

if value lies between two values than add another value to corresponding line

if value lies between two values than add another value to corresponding line

This is a description of my problem: I have two text files (here $variants
and $annotation). I want to check if the value from column 2 in $variants
lies between the values from column 2 and 3 in $annotation. If this is
true than the value from column 1 in $annotation should be added to a new
column in $variants.
This is how my script looks like for the moment
my %hash1=();
while(<$annotation>){
my @column = split(/\t/); #split on tabs
my $keyfield = $column[1] && $column[2]; #I need to remember values
from two columns here. How do I do that?
}
while(<$variants>){
my @column=split(/\t/); #split on tabs
my $keyfield = $column[1];
if ($hash1{$keyfield} >= #so the value in column[1] should be between
the values from column[1] & [2] in $annotation
push #if true then add values from column[0] in $annotation to new
column in $variants
}
So my biggest problems are how to remember two values in a file using
hashes and how to put a value from one file to a column in another file.
Could someone help me with this?

No comments:

Post a Comment