genome has asked for the wisdom of the Perl Monks concerning the following question:
File 1
I want to count the number of entries in the second column of second file within 500+ (up) and 500- (down) to the number medntioned in the second column of first file.CTSC chr11 - 650 E RAB38 chr11 - 87883123 E + 12 2 INTRACHR-SS-OGO-0GAP inframe-shift file 2 chr11 602 63889087 HWI-ST216_106:3:67:14628:181851 - chr11 613 69889087 HWI-ST216_106:3:24:16406:176388 + chr11 614 80889087 HWI-ST216_106:3:21:13731:105239 + chr11 643 94888888 HWI-ST216_111:5:22:3149:116167 + chr11 678 98889079 HWI-ST216_106:3:5:18058:57952 + chr11 612 108888887 HWI-ST216_106:3:8:5578:44855 + chr5 612 63889087 HWI-ST216_106:3:67:14628:181851 - chr3 88033200 69889087 HWI-ST216_106:3:24:16406:176388 + chr2 88033345 80889087 HWI-ST216_106:3:21:13731:105239 + chr1 88033376 94888888 HWI-ST216_111:5:22:3149:116167 + chr6 88034000 98889079 HWI-ST216_106:3:5:18058:57952 + chr7 88034123 108888887 HWI-ST216_106:3:8:5578:44855 +
For this, I made an script, but does not giving the desired result:-
#!/usr/bin/perl -w $file1=$ARGV[0]; #First file $file2=$ARGV[1]; #second file open(TR,$file1); while ($line1=<TR>) { chomp($line1); @ar1 = split(/\t/,$line1); chomp($ar1[1]);chomp($ar1[3]); $up = $ar1[3]-500; $dn = $ar1[3]+500; open(SC,$file2); while ($line2=<SC>) { chomp($line2); @array2 = split (/\t/, $line2); if ($ar1[1] eq $array2[0]) { for ($mm=$up;$mm<=$dn;$mm+=100) { $gt = $up+100; $c ='0'; if (($array2[1]> $up) && ($array2[1] < $gt)) { print "$up\t$gt\t$array2[1]\n"; $c++; } $up=$up+50; } } } }
Result produced is
But where is the count of 612,613, 614 etc.. these numbers are in the rage.550 650 602 <p> 600 700 602 <p>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sliding window perl program
by GotToBTru (Prior) on Oct 20, 2015 at 19:51 UTC | |
by genome (Novice) on Oct 20, 2015 at 20:15 UTC | |
by hippo (Archbishop) on Oct 20, 2015 at 21:42 UTC | |
|
Re: Sliding window perl program
by Laurent_R (Canon) on Oct 20, 2015 at 20:57 UTC | |
by genome (Novice) on Oct 21, 2015 at 18:02 UTC | |
by Laurent_R (Canon) on Oct 21, 2015 at 23:18 UTC | |
by genome (Novice) on Oct 22, 2015 at 14:27 UTC | |
by Laurent_R (Canon) on Oct 22, 2015 at 18:56 UTC | |
by Laurent_R (Canon) on Oct 22, 2015 at 21:20 UTC | |
|
Re: Sliding window perl program
by Laurent_R (Canon) on Oct 20, 2015 at 20:37 UTC | |
|
Re: Sliding window perl program
by LanX (Saint) on Oct 20, 2015 at 19:51 UTC | |
by genome (Novice) on Oct 20, 2015 at 20:14 UTC | |
by u65 (Chaplain) on Oct 20, 2015 at 20:37 UTC |