def self.new_bp(record)
seq_name = record[:SEQ_NAME]
seq = record[:SEQ]
- type = record[:SEQ_TYPE]
+ type = record[:SEQ_TYPE].to_sym if record[:SEQ_TYPE]
qual = record[:SCORES]
self.new(seq_name, seq, type, qual)
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
+ when :dna then alph = DNA
+ when :rna then alph = RNA
+ when :protein then alph = PROTEIN
else
raise SeqError, "Unknown sequence type: #{type}"
end
raise SeqError, "Guess failed: sequence is nil" if self.seq.nil?
case self.seq[0 ... 100].downcase
- when /[flpqie]/ then return "protein"
- when /[u]/ then return "rna"
- else return "dna"
+ when /[flpqie]/ then return :protein
+ when /[u]/ then return :rna
+ else return :dna
end
end
# Method that returns true is a given sequence type is DNA.
def is_dna?
- self.type == 'dna'
+ self.type == :dna
end
# Method that returns true is a given sequence type is RNA.
def is_rna?
- self.type == 'rna'
+ self.type == :rna
end
# Method that returns true is a given sequence type is protein.
def is_protein?
- self.type == 'protein'
+ self.type == :protein
end
# Method to transcribe DNA to RNA.
def to_rna
raise SeqError, "Cannot transcribe 0 length sequence" if self.length == 0
raise SeqError, "Cannot transcribe sequence type: #{self.type}" unless self.is_dna?
- self.type = 'rna'
+ self.type = :rna
self.seq.tr!('Tt','Uu')
end
def to_dna
raise SeqError, "Cannot reverse-transcribe 0 length sequence" if self.length == 0
raise SeqError, "Cannot reverse-transcribe sequence type: #{self.type}" unless self.is_rna?
-
- self.type = 'dna'
+ self.type = :dna
self.seq.tr!('Uu','Tt')
end
# Method to translate a DNA sequence to protein.
def translate!(trans_tab = 11)
- raise SeqError, "Sequence type must be 'dna' - not #{self.type}" unless self.type == 'dna'
+ raise SeqError, "Sequence type must be 'dna' - not #{self.type}" unless self.type == :dna
raise SeqError, "Sequence length must be a multiplum of 3 - was: #{self.length}" unless (self.length % 3) == 0
case trans_tab
self.seq = protein
self.qual = nil
- self.type = "protein"
+ self.type = :protein
self
end
def generate(length, type)
raise SeqError, "Cannot generate sequence length < 1: #{length}" if length <= 0
- case type.downcase
- when "dna"
- alph = DNA
- when "rna"
- alph = RNA
- when "protein"
- alph = PROTEIN
+ case type
+ when :dna then alph = DNA
+ when :rna then alph = RNA
+ when :protein then alph = PROTEIN
else
raise SeqError, "Unknown sequence type: #{type}"
end
seq_new = Array.new(length) { alph[rand(alph.size)] }.join("")
self.seq = seq_new
- self.type = type.downcase
+ self.type = type
seq_new
end