File: randpat.pl

package info (click to toggle)
murasaki 1.68.6-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,928 kB
  • ctags: 3,100
  • sloc: cpp: 16,010; perl: 8,365; makefile: 186
file content (71 lines) | stat: -rwxr-xr-x 1,952 bytes parent folder | download | duplicates (5)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl

#Copyright (C) 2006-2008 Keio University
#(Kris Popendorf) <comp@bio.keio.ac.jp> (2006)
#
#This file is part of Murasaki.
#
#Murasaki is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#Murasaki is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with Murasaki.  If not, see <http://www.gnu.org/licenses/>.

use Getopt::Std;
use List::Util shuffle;

$Getopt::Std::STANDARD_HELP_VERSION=true;
getopts('chs:t:n');
if($opt_h){HELP_MESSAGE();exit(0);}

srand($opt_s) if defined($opt_s);

my $repeats=$opt_t ? $opt_t:1;

($weight,$length,$file)=@ARGV;
($weight,$length,$file)=($1,$2,$length) if $weight=~m/(\d+)\D(\d+)/;
$zeros=$length-$weight;

if($file){
  open(OF,">>$file");
  select OF;
}

print "Weight: $weight\nLength: $length\n" unless $opt_c;

for my $i (1..$repeats){
  $pat=join("",1,
	    shuffle((map {1} (1..$weight-2)),(map {0} (1..$zeros))),
	    1);

  print $pat;
}continue{print "\n" if $i < $repeats}

print "\n" unless $opt_n;

sub main::HELP_MESSAGE(){
  print <<ENDTEXT
Usage: $0 [-c] <weight> <length>
  -c specifies "clean output" ie only the pattern
  -n suppress the final newline
  -s specifies seed for random number generator
  -t specifies the number of patterns to generate

As an alternative to specifying <weight> <length> and you can also use
the Murasaki format of <weight>:<length>.

A neat trick for scripts is to use geneparse.pl to generate this for you.
 eg: ./murasaki -p`./geneparse.pl -m -f -e -c seq/humanY.fa`
ENDTEXT
    ;
}
  
  sub main::VERSION_MESSAGE(){
  }