From: martinahansen Date: Thu, 13 Oct 2011 09:23:37 +0000 (+0000) Subject: added Class method Seq.new_bp to seq.rb X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=bcffd8fb4326ae75ae63c23598558f2ede1da716;p=biopieces.git added Class method Seq.new_bp to seq.rb git-svn-id: http://biopieces.googlecode.com/svn/trunk@1559 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/lib/maasha/seq.rb b/code_ruby/lib/maasha/seq.rb index a724339..2919cfc 100644 --- a/code_ruby/lib/maasha/seq.rb +++ b/code_ruby/lib/maasha/seq.rb @@ -46,7 +46,18 @@ class Seq attr_accessor :seq_name, :seq, :type, :qual - # Method that generates all possible oligos of a specifed length and type. + # Class method to instantiate a new Sequence object given + # a Biopiece record. + def self.new_bp(record) + seq_name = record[:SEQ_NAME] + seq = record[:SEQ] + type = record[:SEQ_TYPE] + qual = record[:SCORES] + + self.new(seq_name, seq, type, qual) + end + + # Class 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 diff --git a/code_ruby/test/maasha/test_seq.rb b/code_ruby/test/maasha/test_seq.rb index cda1f94..78a6543 100755 --- a/code_ruby/test/maasha/test_seq.rb +++ b/code_ruby/test/maasha/test_seq.rb @@ -14,6 +14,15 @@ class TestSeq < Test::Unit::TestCase # dna.seq = "A\tT\r\tC\nG " # assert_equal(dna.seq, "ATCG") # end + + def test_Seq_new_bp_returns_correctly + record = {:SEQ_NAME => "test", :SEQ => "ATCG", :SEQ_TYPE => "dna", :SCORES => "hhhh"} + seq = Seq.new_bp(record) + assert_equal("test", seq.seq_name) + assert_equal("ATCG", seq.seq) + assert_equal("dna", seq.type) + assert_equal("hhhh", seq.qual) + end def test_Seq_is_dna_with_no_sequence_type_returns_false assert(@entry.is_dna? == false)