From 25b8db93da78454b13fcbb5b1ee064feee2fc8fa Mon Sep 17 00:00:00 2001 From: martinahansen Date: Tue, 1 Feb 2011 12:53:36 +0000 Subject: [PATCH] added generate_oligos method to seq.rb git-svn-id: http://biopieces.googlecode.com/svn/trunk@1242 74ccb610-7750-0410-82ae-013aeee3265d --- code_ruby/Maasha/lib/seq.rb | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/code_ruby/Maasha/lib/seq.rb b/code_ruby/Maasha/lib/seq.rb index a61e761..08c90ea 100644 --- a/code_ruby/Maasha/lib/seq.rb +++ b/code_ruby/Maasha/lib/seq.rb @@ -38,6 +38,35 @@ class SeqError < StandardError; end class Seq attr_accessor :seq_name, :seq, :type, :qual + # Method that generates all possible oligos of a specifed length and type. + def self.generate_oligos(length, type) + raise SeqError, "Cannot generate negative oligo length: #{length}" if length <= 0 + + case type.downcase + when /dna/ then alph = DNA + when /rna/ then alph = RNA + when /protein/ then alph = PROTEIN + else + raise SeqError, "Unknown sequence type: #{type}" + end + + oligos = [""] + + (1 .. length).each do + list = [] + + oligos.each do |oligo| + alph.each do |char| + list << oligo + char + end + end + + oligos = list + end + + oligos + end + # Initialize a sequence object with the following arguments: # - seq_name: Name of the sequence. # - seq: The sequence. @@ -171,7 +200,7 @@ class Seq end end - # Method that generates a random sequence of a given length. + # Method that generates a random sequence of a given length and type. def generate(length,type) raise SeqError, "Cannot generate negative sequence length: #{length}" if length <= 0 -- 2.39.5