]> git.donarmstrong.com Git - biopieces.git/commitdiff
added generate_oligos method to seq.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 1 Feb 2011 12:53:36 +0000 (12:53 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 1 Feb 2011 12:53:36 +0000 (12:53 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1242 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/Maasha/lib/seq.rb

index a61e761eb01aefba1eb7b45009a204e645689008..08c90ea538e9963808903476631324caa7afc788 100644 (file)
@@ -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