X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=code_ruby%2Flib%2Fmaasha%2Fseq.rb;h=a2d5bbac3462d44401d0e1d97a70101f1b7d3af4;hb=a30677c14f1738f6a76e8c12f2e732cdef9958d6;hp=fd83ba3282d28c561358fb9383c18e324d9a7ed4;hpb=545eed9d7927e2c59a7c7d3c919aa8d8bed18c86;p=biopieces.git diff --git a/code_ruby/lib/maasha/seq.rb b/code_ruby/lib/maasha/seq.rb index fd83ba3..a2d5bba 100644 --- a/code_ruby/lib/maasha/seq.rb +++ b/code_ruby/lib/maasha/seq.rb @@ -93,7 +93,7 @@ class Seq type = record[:SEQ_TYPE].to_sym if record[:SEQ_TYPE] qual = record[:SCORES] - self.new(seq_name, seq, type, qual) + self.new(seq_name: seq_name, seq: seq, type: type, qual: qual) end # Class method that generates all possible oligos of a specifed length and type. @@ -125,19 +125,19 @@ class Seq oligos end - # Initialize a sequence object with the following arguments: - # - seq_name: Name of the sequence. - # - seq: The sequence. - # - type: The sequence type - DNA, RNA, or protein - # - qual: An Illumina type quality scores string. - def initialize(seq_name = nil, seq = nil, type = nil, qual = nil) - @seq_name = seq_name - @seq = seq - @type = type - @qual = qual + # Initialize a sequence object with the following options: + # - :seq_name Name of the sequence. + # - :seq The sequence. + # - :type The sequence type - DNA, RNA, or protein + # - :qual An Illumina type quality scores string. + def initialize(options = {}) + @seq_name = options[:seq_name] + @seq = options[:seq] + @type = options[:type] + @qual = options[:qual] - if @qual - raise SeqError, "Sequence length and score length mismatch: #{@seq.length} != #{@qual.length}" if @seq.length != @qual.length + if @qual and @seq.length != @qual.length + raise SeqError, "Sequence length and score length mismatch: #{@seq.length} != #{@qual.length}" end end @@ -343,7 +343,12 @@ class Seq # Method to reverse the sequence. def reverse - Seq.new(self.seq_name, self.seq.reverse, self.type, self.qual ? self.qual.reverse : self.qual) + Seq.new( + seq_name: self.seq_name, + seq: self.seq.reverse, + type: self.type, + qual: (self.qual ? self.qual.reverse : self.qual) + ) end # Method to reverse the sequence. @@ -357,10 +362,11 @@ class Seq def complement raise SeqError, "Cannot complement 0 length sequence" if self.length == 0 - entry = Seq.new - entry.seq_name = self.seq_name - entry.type = self.type - entry.qual = self.qual + entry = Seq.new( + seq_name: self.seq_name, + type: self.type, + qual: self.qual + ) if self.is_dna? entry.seq = self.seq.tr('AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'TCGAAYRWSKMDHBVNtcgaayrwskmdhbvn') @@ -424,7 +430,12 @@ class Seq # Method to return a new Seq object with shuffled sequence. def shuffle - Seq.new(self.seq_name, self.seq.split('').shuffle!.join, self.type, self.qual) + Seq.new( + seq_name: self.seq_name, + seq: self.seq.split('').shuffle!.join, + type: self.type, + qual: self.qual + ) end # Method to shuffle a sequence randomly inline. @@ -491,7 +502,7 @@ class Seq seq_name = self.seq_name.nil? ? nil : self.seq_name.dup - Seq.new(seq_name, seq, self.type, qual) + Seq.new(seq_name: seq_name, seq: seq, type: self.type, qual: qual) end # Method that replaces a sequence with a subsequence from a given start position