in reply to Sliding window perl program

Untested code illustrating the algorithm described in my post above:
# opening file 1 # ... my %hash; while (my $line1=<TR>) { chomp($line1); my @ar = split(/\t/,$line1); $hash{$ar[1]} = $ar[3]; } close TR; open my $SC, "<", $file2 or die "Error blah blah... $!"; while (my $line2 = <$SC>) { my ($id, $val) = split /\t/, $line2; my $val_file1 = $hash{$id}; if ( $val > $val_file1 - $margin and $val < $val_file1 + $margin) +{ # print out something } } close $SC;
BTW, I basically kept your syntax almost unchanged for the first part and tried to improve it in accordance to good practices in the second part. Take a look at the differences.

Replies are listed 'Best First'.
Re^2: Sliding window perl program
by genome (Novice) on Oct 21, 2015 at 18:02 UTC
    Hi, This program is for sliding window. I want to count the number of entries of file 2 , lies between the variable range (100 size window with 50 size slid) of sliding window from +500 to the -500 of 650. That is because I put a for loop of 100 increment and then tries to increase the $up number 50. i.e. 150-250

    200-300

    250-350

    ...

    ...

    ...

    1100-1150

    I hope u understand the question.

      Well, since you insist on sliding windows, it appears that I missed your requirement, sorry about that. But I still really don't understand what you want.

      Perhaps a more detailed example of your input and desired output would help.

        Hi, Here is the explanation of task I want to perform. 1. match the value of column 2 of file 1 with the value of column 1 of file 2 (i.e. chr11). and then fetch all lines of file2 which have chr11 value.

        2. make the varables -500 and +500 of value 4 of file 1 (i.e. 650). From 150 to 1150 select a sliding window of 50 with window size 100. i.e. 150-250, 200-300, 250-350, 300-400....1050-1150.

        3. Count the lines of file2, on the basis of value in the second column of file2, which lies in these windows....

        4. For this examples... The answer should be

        150 250 0

        250 350 0

        350 450 0

        450 550 0

        550 650 5

        650 750 1

        750 850 0

        850 950 0

        950 1050 0

        1050 1150 0

        1150 1250 0