[BioRuby] Bio::Sequence forces a DNA sequence to lowercase?

Adam Kraut adamnkraut at gmail.com
Fri Feb 1 15:39:45 UTC 2008


Oops! I sent this solution directly to Gordon rather than the bioruby list.
Here's the original message I sent in case anyone else is interested.

Hi Gordon,

I grepped for the string method called downcase in the Sequence class and
noticed,

# Nucleic Acid sequences are *always* all lowercase in bioruby
def initialize(str)
    super
    self.downcase !
    self.tr!(" \t\n\r",'')
  end

When you call NA.new("atgcATGcaaaa"), your string is converted to lowercase
and white space is stripped.  One way you might work around this is to
simply open up the class and redefine the constructor.  Since Ruby classes
are open, you can redefine the Sequence class on the fly if you'd like.


seq = Bio::Sequence::NA.new("atgcATGcaaaa") # => "atgcatgcaaaa"

class Bio::Sequence::NA

  def initialize(str) # !> method redefined; discarding old initialize
    super
    self.tr!(" \t\n\r",'')
  end

end

seq2 = Bio::Sequence::NA.new("atgcATGcaaaa") # => "atgcATGcaaaa"

I am also new to Bioruby so there may be a more fitting solution that's
already been discussed.

Best Regards,
Adam



More information about the BioRuby mailing list