Debian Codegraph @

applications/bed/starch/test/original_data/src/jumble_duplicate_coords.pl

raw
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use Data::Dumper;
6
7 #
8 # input: sorted BED with possible duplicate coordinates
9 # output: possibly modified BED with nonredundant coordinates
10 #
11
12 my $max_coord = 100000000;
13
14 my $input;
15 while(<>) {
16 chomp;
17 my ($chr, $start, $stop, $id, $score, $strand) = split("\t", $_);
18 my $key = "$chr:$start:$stop";
19 my $value = "$_\n";
20 if (defined $input->{$key}) {
21 my $randomStart = 0;
22 my $randomStop = 1;
23 my $test_key = $key;
24 while (defined $input->{$test_key}) {
25 $randomStart = int(rand($max_coord));
26 $randomStop = $randomStart + int(rand($max_coord));
27 $test_key = "$chr:$randomStart:$randomStop";
28 }
29 my $new_value = join("\t", ($chr, $randomStart, $randomStop, $id, $score, $strand))."\n";
30 $input->{$test_key} = $new_value;
31 }
32 else {
33 $input->{$key} = $value;
34 }
35 }
36
37 foreach my $posKey (keys %{$input}) {
38 print $input->{$posKey};
39 }