[BioRuby] Beautiful code for Bioinformatics

George Githinji georgkam at gmail.com
Sat Feb 11 20:27:44 UTC 2012


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 <p.j.a.cock at googlemail.com> wrote:
> On Sat, Feb 11, 2012 at 5:46 PM, Pjotr Prins <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 :)
>
> https://github.com/bioruby/bioruby/commit/f33abf9bbd90c3c1e320f06447fdb54ffd094c5d
>
> Peter
> _______________________________________________
> BioRuby Project - http://www.bioruby.org/
> BioRuby mailing list
> BioRuby at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioruby



-- 
---------------
Sincerely
George
Skype: george_g2
Blog: http://biorelated.wordpress.com/
Twitter: http://twitter.com/#!/george_l



More information about the BioRuby mailing list