Created
February 6, 2009 16:30
-
-
Save drio/59475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Generate random genomes: | |
# | |
# Creates a random genome with the number of contig you specify. | |
# You can pass the number of characters per line and the max size | |
# of the contigs. | |
# | |
class RandomGenome | |
# + hr: root string for the headers | |
# + nc: number of contigs to generate | |
# + ls: number of characters on each line | |
# + ml: maximun size, in lines, of each contig | |
def initialize(hr, nc, ls, ml) | |
@header_root, @n_contigs, @l_size, @max_c_lines = [hr, nc, ls, ml] | |
end | |
def generate | |
(1..@n_contigs).each do |cn| | |
puts ">#{@header_root}_#{cn}\n" | |
(1..my_rand).each do |ln| | |
puts (1..@l_size).map {|n| rand_n }.join | |
end | |
end | |
end | |
protected | |
def my_rand | |
r = rand(@max_c_lines) | |
r == 0 ? my_rand : r | |
end | |
def rand_n | |
%w(A C G T N)[rand(5)] | |
end | |
end | |
# | |
# Main | |
# | |
RandomGenome.new("original", 2, 72, 4).generate | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment