Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I want to find out how much sequence is covered within a particular range. For example range 1...1524 is reported with 6 positions 46, 403, 800, 832, 1008, 1407 where there is an overlap between 800 and 832. The output should give (150+150+32+118+32+150+150) = 782 With my script I am trying to create an array which stores 1 to 1524. Making the array 1 if it contains the position+150 else the array is set to 0. But there is a problem with the loop I think which is not giving the correct output. Any help or idea will be appreciated. My script is:seq.txt position range seq 46 1..1524 ----------------- 832 1..1524 ----------------- 1008 1..1524 ----------------- 1407 1..1524 ----------------- 2360 2052..3260 ------------------ 2967 2052..3260 ------------------ 403 1..1524 ----------------- 800 1..1524 ----------------- 2986 2052..3260 ------------------ 3170 2052..3260 ------------------
use strict; use warnings; my $i; my $j; my $seq; open my $m, '<', 'count_try.txt' or die 'Cannot open count_try.txt'; while ($seq = <$m>) { chomp $seq; my (@range) = split(/\t/, $seq); my ($fm, $to) = split(/\.\./, $range[1]); my $r = $range[0]; for ($i = $fm; $i <= $to; $i++) { $j = $r + 150; if ($i >= $r and $i <= $j) {$range[$i] = 1;} else {$range[$i] = 0;} print $range[$i]."\t"; } } close $m;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: find the coverage of sequence in a particular range
by choroba (Cardinal) on May 20, 2016 at 12:47 UTC | |
Re: find the coverage of sequence in a particular range
by GotToBTru (Prior) on May 20, 2016 at 12:40 UTC | |
Re: find the coverage of sequence in a particular range
by oiskuu (Hermit) on May 20, 2016 at 20:53 UTC | |
by Anonymous Monk on May 23, 2016 at 06:10 UTC | |
by hippo (Archbishop) on May 23, 2016 at 08:03 UTC |