[BioRuby] Beautiful code for Bioinformatics

Pjotr Prins pjotr.public14 at thebird.nl
Tue Feb 14 02:19:50 EST 2012


New programming languages are great. It is a form of evolution :).
You should try to learn a language every year.

The Clojure fan-boys have been quiet here - that is another one.
Personally I looked a Go, and did not like it that much (apart from
Go-routines). It is a bit over its hype now, so we can see what
happens.

Programming languages, nevertheless, do not solve the problem of
programming. Never believe the person who tells you that all problems
will be solved by programming language X. I know people who stick with
C++ and are extremely productive, mostly because they have very rich
libraries. I think they could do better with D, in the really long
term. But who am I to suggest that? And I know people who are
extremely productive with Ruby. Go figure.

Pj.

On Tue, Feb 14, 2012 at 02:33:04PM +1000, Mic wrote:
>    Hi,
>    Did anyone try out
>    * GO: [1]http://en.wikipedia.org/wiki/Go_(programming_language)
>    * Rust: [2]http://en.wikipedia.org/wiki/Rust_(programming_language)
>    * Vala: [3]http://en.wikipedia.org/wiki/Vala_(programming_language)
> 
>    On Mon, Feb 13, 2012 at 8:46 PM, Raoul Bonnal <[4]bonnal at ingm.org> wrote:
> 
>      Yeah, I was thinking the exact same thing.
> 
>      This kind of documentation will be of great help!!! I'm thinking about
>      teaching Ruby @ Uni.
> 
>      What I missed from the previous email is:
>      Beautiful code come from coders but that is not enough, working with
>      people
>      in this ML I found that the quality of code and its beauty increase only
>      if
>      you chat/talk with people and you are available to accept critics and
>      contributes.
> 
>      Another tab ? ;-)
> 
>      On 13/02/12 11.34, "Pjotr Prins" <[5]pjotr.public14 at thebird.nl> wrote:
> 
>      > Excellent.
>      >
>      > May I propose that at least the other half of the authors of the
>      > Biogem paper send in an example of beautiful code? We can compile
>      > these snippets on a special page on one of the websites (or both).
>      > That will help courses, 'newbies' and even 'die hard' Perl users, such
>      > as Yoda, to see what this Ruby thing is about.
>      >
>      > Maybe it is time for a 'Bioinformatics Ruby Academy'. Ruby rules. Herh
>      > herh herh.
>      >
>      > Pj.
>      >
>      > On Mon, Feb 13, 2012 at 11:06:03AM +0100, Francesco Strozzi wrote:
>      >> Some code I particularly liked comes from the BioNGS Wrapper library
>      (by
>      >> Raoul). The gem is in development and I'm contributing to it so I
>      could
>      >> look at the code from a very close perspective!
>      >>
>      >> [6]https://gist.github.com/1815501
>      >>
>      >> What is interesting is the use of an internal DSL which makes the
>      code
>      >> particularly expressive and readable, and writing a wrapper becomes
>      only a
>      >> matter of defining the options that the command line binary expects.
>      The
>      >> library is quite large and includes also methods to define aliases
>      for the
>      >> options.
>      >> This module makes use also of the powerful Thor gem (used in Rails)
>      to
>      >> create and define tasks that can be used to launch the binaries and
>      to
>      >> include them in larger workflows and pipelines.
>      >> Now let's say you want to turn your freshly new wrapped binary into a
>      >> mighty Thor taks, all you need to do is:
>      >>
>      >> [7]https://gist.github.com/1815523
>      >>
>      >> The amazing part is that the parameters passed to the block works
>      like
>      >> arguments definition for the Thor task itself. The code that makes
>      this
>      >> possible behind the scenes is here:
>      >>
>      >> [8]https://gist.github.com/1815481
>      >>
>      >> It checks also if the number of arguments passed are equal to the
>      arguments
>      >> of the block. If not, it raises an error to the user as he/she is
>      calling
>      >> the task with the wrong number of arguments. To understand every part
>      you
>      >> need to know a bit the way the Thor library defines tasks (more here:
>      >> [9]https://github.com/wycats/thor) but the code here in BioNGS
>      definitely
>      >> worth a look!
>      >>
>      >> P.S. I'm diving into Scala too :-). I took the Odersky book few
>      months ago
>      >> and now I'm about to start looking in details at this new programming
>      >> language. Easy and powerful parallelism is the new goal we need to
>      achieve
>      >> to keep up with the big data era.
>      >>
>      >> Cheers
>      >>
>      >> On Mon, Feb 13, 2012 at 08:54, Pjotr Prins
>      <[10]pjotr.public14 at thebird.nl>wrote:
>      >>
>      >>> OK, here another candidate for the price of beautiful code:
>      >>>
>      >>>
>      >>>
>      [11]https://github.com/trevor/bioruby-restriction_enzyme/blob/master/lib/bio/uti
>      >>> l/restriction_enzyme/range/sequence_range/calculated_cuts.rb
>      >>>
>      >>> Trevor has implemented some hairy logic into the RE code. I mean
>      >>> hairy, that if it were done by someone else it would become
>      spaghetti
>      >>> code (plenty of examples there in the real world!). You can see,
>      that
>      >>> even when choosing sensible names, and explaining the code with good
>      >>> comments, it may still be hard to understand! But I think
>      >>>
>      >>>  def add_cuts_from_cut_ranges(cut_ranges)
>      >>>
>      >>> pretty much sums it up :). Still, it is beautiful, because it is
>      hard
>      >>> to think of doing it better. The Ruby code is short and self
>      >>> explanatory and RE library has almost become a DSL for cutting
>      >>> sequences using restriction enzymes. That is beautiful.
>      >>>
>      >>> Pj.
>      >>>
>      >>> On Sat, Feb 11, 2012 at 11:27:44PM +0300, George Githinji wrote:
>      >>>> Hi All
>      >>>> Beauty is in the eyes of the beholder!
>      >>>> The Bio-Alignment plugin can  read and interconvert a nucleotide
>      >>>> alignment to an amino acid alignment.  I liked the simplicity of
>      how
>      >>>> PJ has implemented the codon to amino acid conversion helper method
>      >>>> while taking care of the gaps or undefined aa translations.
>      >>>>
>      >>>>       # lazily convert to Amino acid (once only)
>      >>>>       def to_aa
>      >>>>         aa = translate
>      >>>>         if not aa
>      >>>>           if gap?
>      >>>>             return '-'
>      >>>>           elsif undefined?
>      >>>>             return 'X'
>      >>>>           else
>      >>>>             raise 'What?'
>      >>>>           end
>      >>>>         end
>      >>>>         aa
>      >>>>       end
>      >>>>
>      >>>> This method does not have any ruby 'magic' and is self documenting.
>      >>>> The gap? and undefined? methods are implemented as simple one line
>      >>>> standalone methods.
>      >>>>
>      >>>> Again I like this simple 'trick' of getting an array of codons from
>      a
>      >>>> sequence in the codonsequence class.
>      >>>>
>      >>>> seq.scan(/\S\S\S/) #gets an array of codons
>      >>>>
>      >>>> The longer alternative would be to create a bio::sequence::NA
>      object
>      >>>> and iterate
>      >>>> seq = Bio::Sequence::NA.new("blahahahha")
>      >>>> seq.window_search(3, 3) do |subseq|
>      >>>>   puts subseq
>      >>>> end
>      >>>>
>      >>>> It seems more intuitive to represent a sequence as an array of
>      codon
>      >>>> objects. In this way the codons have some state and can carry
>      >>>> 'luggage'. getting the string representation of the sequence is as
>      >>>> simple as
>      >>>> def to_s
>      >>>>  @seq.map { |codon| codon.to_s }.join(' ')
>      >>>> end
>      >>>>
>      >>>> To be more DRY, the to_nt method in the same class could be aliased
>      >>>> from the to_s method
>      >>>>
>      >>>> It seems the bio-plugins are a rich source of tricks and great
>      >>> learning.... !
>      >>>>
>      >>>>
>      >>>> On Sat, Feb 11, 2012 at 10:08 PM, Peter Cock
>      <[12]p.j.a.cock at googlemail.com>
>      >>> wrote:
>      >>>>> On Sat, Feb 11, 2012 at 5:46 PM, Pjotr Prins <
>      >>> [13]pjotr.public14 at thebird.nl> wrote:
>      >>>>>> Correct me if I am wrong, but has everyone moved across to
>      BioPython
>      >>>>>> now? Or even to the dark side?
>      >>>>>>
>      >>>>>> Pj.
>      >>>>>
>      >>>>> I haven't noticed any BioRuby developers posting on the Biopython
>      >>>>> mailing lists recently - but you'd be welcome ;)
>      >>>>>
>      >>>>> On a related topic, my first BioRuby pull request was merged, so
>      >>>>> there is a little direct cross project contribution going on :)
>      >>>>>
>      >>>>>
>      >>>
>      [14]https://github.com/bioruby/bioruby/commit/f33abf9bbd90c3c1e320f06447fdb54ffd
>      >>> 094c5d
>      >>>>>
>      >>>>> Peter
>      >>>>> _______________________________________________
>      >>>>> BioRuby Project - [15]http://www.bioruby.org/
>      >>>>> BioRuby mailing list
>      >>>>> [16]BioRuby at lists.open-bio.org
>      >>>>> [17]http://lists.open-bio.org/mailman/listinfo/bioruby
>      >>>>
>      >>>>
>      >>>>
>      >>>> --
>      >>>> ---------------
>      >>>> Sincerely
>      >>>> George
>      >>>> Skype: george_g2
>      >>>> Blog: [18]http://biorelated.wordpress.com/
>      >>>> Twitter: [19]http://twitter.com/#!/george_l
>      >>>>
>      >>> _______________________________________________
>      >>> BioRuby Project - [20]http://www.bioruby.org/
>      >>> BioRuby mailing list
>      >>> [21]BioRuby at lists.open-bio.org
>      >>> [22]http://lists.open-bio.org/mailman/listinfo/bioruby
>      >>>
>      >>
>      >>
>      >>
>      >> --
>      >>
>      >> Francesco
>      >> _______________________________________________
>      >> BioRuby Project - [23]http://www.bioruby.org/
>      >> BioRuby mailing list
>      >> [24]BioRuby at lists.open-bio.org
>      >> [25]http://lists.open-bio.org/mailman/listinfo/bioruby
>      >>
>      > _______________________________________________
>      > BioRuby Project - [26]http://www.bioruby.org/
>      > BioRuby mailing list
>      > [27]BioRuby at lists.open-bio.org
>      > [28]http://lists.open-bio.org/mailman/listinfo/bioruby
> 
>      _______________________________________________
>      BioRuby Project - [29]http://www.bioruby.org/
>      BioRuby mailing list
>      [30]BioRuby at lists.open-bio.org
>      [31]http://lists.open-bio.org/mailman/listinfo/bioruby
> 
> References
> 
>    Visible links
>    1. http://en.wikipedia.org/wiki/Go_(programming_language)
>    2. http://en.wikipedia.org/wiki/Rust_(programming_language)
>    3. http://en.wikipedia.org/wiki/Vala_(programming_language)
>    4. mailto:bonnal at ingm.org
>    5. mailto:pjotr.public14 at thebird.nl
>    6. https://gist.github.com/1815501
>    7. https://gist.github.com/1815523
>    8. https://gist.github.com/1815481
>    9. https://github.com/wycats/thor
>   10. mailto:pjotr.public14 at thebird.nl
>   11. https://github.com/trevor/bioruby-restriction_enzyme/blob/master/lib/bio/uti
>   12. mailto:p.j.a.cock at googlemail.com
>   13. mailto:pjotr.public14 at thebird.nl
>   14. https://github.com/bioruby/bioruby/commit/f33abf9bbd90c3c1e320f06447fdb54ffd
>   15. http://www.bioruby.org/
>   16. mailto:BioRuby at lists.open-bio.org
>   17. http://lists.open-bio.org/mailman/listinfo/bioruby
>   18. http://biorelated.wordpress.com/
>   19. http://twitter.com/#!/george_l
>   20. http://www.bioruby.org/
>   21. mailto:BioRuby at lists.open-bio.org
>   22. http://lists.open-bio.org/mailman/listinfo/bioruby
>   23. http://www.bioruby.org/
>   24. mailto:BioRuby at lists.open-bio.org
>   25. http://lists.open-bio.org/mailman/listinfo/bioruby
>   26. http://www.bioruby.org/
>   27. mailto:BioRuby at lists.open-bio.org
>   28. http://lists.open-bio.org/mailman/listinfo/bioruby
>   29. http://www.bioruby.org/
>   30. mailto:BioRuby at lists.open-bio.org
>   31. http://lists.open-bio.org/mailman/listinfo/bioruby


More information about the BioRuby mailing list