File: random_segments.pl

package info (click to toggle)
gbrowse 2.56%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,104 kB
  • sloc: perl: 50,765; sh: 227; sql: 62; makefile: 50; ansic: 27
file content (50 lines) | stat: -rwxr-xr-x 1,061 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl

use strict;
use constant FLEN => 10000;
use constant SLEN => 50000;
use constant FNUM => 15;

my $fclass  = shift || "Match";
my $fprefix = shift || 'seg';

# open STDOUT,"|sort -k4,4n" or die;

for (1..FNUM) {
  my $start  = int(rand(SLEN));
  my $end    = $start + int(rand(FLEN));
  $end       = SLEN if $end > SLEN;
  my $strand = rand(1) > 0.5 ? '+' : '-';
  my $name   = sprintf("$fprefix%02d",$_);

  my @rows = <<END;
ctgA	example	match	$start	$end	.	$strand	.	$fclass $name
END
;

  my ($seg_start,$seg_end,$last_start,$last_end);
  $seg_start = $start;
  do {
    $seg_end = $seg_start + int(rand(500));
    $seg_end = $end if $seg_end > $end;
  push @rows,<<END;
ctgA	example	similarity	$seg_start	$seg_end	.	$strand	.	$fclass $name
END
;
    $last_end   = $seg_end;
    $last_start = $seg_start;
    $seg_start = $seg_end + int(rand(500));
  } until ($seg_start > $end);

  if ($last_end < $end) {
    $rows[-1] = <<END;
ctgA	example	similarity	$last_start	$end	.	$strand	.	$fclass $name
END
;
  }

  print @rows;

}

close STDOUT;