I have two input files :-

File 1

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 +
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.

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

550 650 602 <p> 600 700 602 <p>
But where is the count of 612,613, 614 etc.. these numbers are in the rage.

In reply to Sliding window perl program by genome

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.