[BioPython] Off-topic: BioRuby

Andrew Dalke dalke@acm.org
Thu, 22 Mar 2001 21:11:21 -0700


Johann Visagie:
>Everyone noticed that Python's closest competitor now has a Bio* project?
>:-)

Perhaps Python is Ruby's closest competitor, but Ruby's
closest competitor (IMHO, of course) is Perl.  It doesn't
have what is to me one of the prime fetures of Python -
readability.

Briefly, since I don't want to get into detail, I'm
looking at http://bioruby.org/ftp/bio/sequence.rb and
wonder why 'downcase!' doesn't take a parens.

class NAseq < Sequence

  def initialize(str)
    if str
      super.downcase!
      super.tr!('u', 't')
    end
  end

I think it's because the '!' is a hint that this is
a method call and not a method reference followed by
a call, which is what Python does.

But then what does

    str = self.reverse
    str.tr!('atgc', 'tacg')

do?  How does 'self' differ from 'super'?  Why isn't
there a '!' at the end of reverse.

I do admit I like this method:

  def pikachu
    self.tr("atgc", "pika") # joke, of cource :-)
  end

It also uses Perlisms like /./ for pattern match, tr
for character translation and automatic initialization
of variables.

OTOH, it uses Smalltalk style code blocks all over,
like:

    self.scan(/./) do |b|
      count[b] += 1
    end

where the self.scan returns an iterator and each
value is used to call the code block, kinda like

  f = lambda b: count[b] += 1
  for x in self.scan(/./):
    apply(f, x)

But that's one of the things I don't like about
Smalltalk.  They generalized it so that integers
implement a lot of methods.  I don't recall the
syntax, but in a Ruby-like style you can do

  5 do
    print 'Hello, world'
 end

This is because 5 implements the iterator protocol
when passed a code block.

 I find explicit loops easier to follow, as in

  for b in str:
     count[b] += 1

or based on the referenced code

  for c in str:
    count[c] += 1

(Trust me, this was briefly :)

                    Andrew
                    dalke@acm.org