I have input file with these kind of data :
chr start end chr21 9411509 9411529 chr21 9411510 9411529 chr21 9411509 9411529 chr21 9411569 9411589 chr21 9411571 9411591 chr21 9411572 9411592 chr21 9411573 9411593 chr21 9411575 9411595 chr21 9411578 9411598
I want to have output which counting the number of overlapped between 1st position in start and end position with 2bp overlap : Imagine the start pos of the clusters are and end of them could have over lap with 2bp like the pic at the bottom and it counts 4
|-----| |-----| |-----| |------|
and if it does not have overlap like : do not count it and give each of them one ID which are not overlapped
|----| |----| |-----| |-----|
and get output like this
TSSD_ID Start position End position Count overlapped ID_1 XXXXX XXXXXX 54
I make the script but It's not work well :
#!/usr/bin/perl -w use strict; use warnings; my $data = <>; my $tol = 2; my @chr; my @start; my @end; my @count; my @strand; while ( $data = (<>) ) { my ( $chr, $start, $end, $info, $cnt, $strand, $start2, $end2, $color, $cnt2, $length , $zero ) = split( "\t", $data ); push( @chr, $chr); push (@start, $start); push (@end, $end); push (@strand, $strand); } my $cl1length = @start; my $cl2length = @end; print "TSSD_ID \t Start \t End \t Count\t Strand \n" ; foreach ( my $i =0 ; $i < $cl1length ; $i = $i++) { for ( my $i = 1 ; $i < $cl1length ; $i++ ) { my $ID = 1; my $count = 0; for (my $j = 0 ; $j < $cl2length ; $j++) { if ( $tol < ( $start[$i] - $start[$i+1] ) ) { $ID++; } if ($start[$i]-$start[$j] == 0) { $count++;}} print "ID_$ID \t $chr[$i] \t $start[$i] \t $end[$i] $count \t $st +rand[$i] \n"; }}
what should i do?! :(

In reply to Help the counting! by g-alone

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.