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 4chr 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
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|----| |----| |-----| |-----|
I make the script but It's not work well :TSSD_ID Start position End position Count overlapped ID_1 XXXXX XXXXXX 54
what should i do?! :(#!/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"; }}
In reply to Help the counting! by g-alone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |