Bioruby mini-series: The Sequence class

Bioruby is a bioinformatics ruby package for analysis of biological sequences. In my quest to become a bioruby guru i have decided to poke the bioruby API and all available tutorials to better understand this fantastic library written by the bioruby team of developers. My journey will be logged here as the bioruby mini series. We start with an introductory overview of the sequence class.

To use the library you need to have a ruby interpreter installed , preferably ruby 1.8.5 and above . To install bioruby as a gem, do:
sudo gem install bio

This will install Bioruby version 1.1.0 and it comes with its own shell as well.

Type bioruby on the command prompt and you will see this:


Loading config (/.bioruby/shell/session/config) … done
Loading object (/.bioruby/shell/session/object) … done
Loading history (/.bioruby/shell/session/history) … done

. . . B i o R u b y i n t h e s h e l l . . .

Version : BioRuby 1.1.0 / Ruby 1.8.6

bioruby>

Now we ready to rock and roll! I dug in to the API and extracted some useful information for us.

The Bio::Sequence class

This is the primary sequence class and deals with sequence translation and transformations. It inherits from ruby’s string class which means that you can use ruby’s string methods with the Bio::Sequence class just like you would with a string.

The Bio::Sequence class object is a wrapper around the actual sequence and it is represented as either a Bio::Sequence::NA or a Bio::Sequence::AA. and responds to all the methods that are defined for both NA and AA classes. This class has the following methods:

  • auto – This will guess the type of sequence provided and return the appropriate Bio:Sequence class for the given string, either a Bio::Sequence::AA or a Bio::Sequence::NA
  • new – Creates a new Bio::Sequence object. It does not initialize the object in to any of the bioruby objects. It returns a string.
  • aa – Will transform your current Bio::Sequence object to a Bio::Sequence::AA object. It will change your current object i.e it will transform a Bio::Sequence::NA to a Bio::Sequence::AA which is undesirable. So it needs to be used only when you are sure of the type of sequence you are working with.
  • na – works the same as the aa method above but the returned object is a Bio::Sequence::NA
  • output – It returns a string with the current Bio::Sequence object formatted with the given style. The supported styles are fasta, genbank and embl. The style argument is passed as a ruby symbol eg :fasta
  • to_s – it returns the sequence as a string leaving the original sequence unaltered. The to_str is an alias for this method

Bio::Sequence::NA class

This class wraps a nucleic acid sequence. It provides a number of methods to work with a DNA sequence as demonstrated in the example below.

Dr Optimist has finally finished his long awaited sequencing project code named Sikwensi. The nucleic acid sequence for a chromosome for which he won’t reveal any further details is shown below.
“gacagatggacatggactagagctgct”

He calls his trusted ruby programmer to help analyze the sequence and tear it base by base. The guy gets to work.

require ‘bio’

bio_seq = Bio::Sequence.auto( ‘gacagatggacatggactagagctgct’) #=> bio_seq is now a Bio::Sequence::NA object

#get the number of codons in the sequence

bio_seq.window_search(3,3) {|codon| puts codon}

# complemental sequence

bio_seq.complement (Bio::Sequence::NA object)

# gets subsequence of positions 4 to 14
bio_seq.subseq(4,14) # he thinks the subsequence is interesting and worth
extracting!

bio_seq.gc_percent #what is the gc content?

bio_seq.composition # nucleic acid compositions (returns a Hash)

bio_seq.translate # translation ( returns a Bio::Sequence::AA object)
bio_seq.translate(2) # translation from frame 2 (The default is frame 1)
bio_seq.translate(1,11) # using codon table No.11 (bacteria)
bio_seq.translate.codes # shows three-letter codes ( returns an Array)
bio_seq.translate.names # shows amino acid names (returns an Array)
bio_seq.translate.composition # amino acid compositions (returns a Hash)
bio_seq.translate.molecular_weight # calculating molecular weight (returns Float)

bio_seq.complement.translate # translation of complemental strand

A tutorial written by Katayama Toshiaki can be found here and translated to English by Naohisa Goto. (Thank you guys!)

A Ruby algorithms resource

Ruby quiz resourceAn algorithm is a procedure to accomplish a specific task. They solve general well specified problems and are the ideas behind computer programs.

Rubyquiz is an interesting repository for ruby programs that implement queit interesting algorithms. Even though the programs may not have anything to do with biology, some of the algorithms definitely do. It is a good place to a find a start point for your ruby algorithm implementation. Browsing the different sets of problems can give a lot of insight on how to approach some common programming problems eg. writing an inference engine, a hidden markov chain , dictionary matcher etc

The site has about 147 quizzes as of this writing. Take a look!

PlasmoDB 5.4 released

PlasmodbThe ApiDB team have announced a new release of the Plasmodb database version 5.4. The database hosts genomic and proteomic data for different species of the parasitic eukaryote Plasmodium, which is the causative agent for malaria. It brings together data provided by numerous laboratories worldwide. From an email sent to registered database users,

New data in the new release include:

  • A slightly modified reference genome for P. falciparum
  • P. berghei gametocyte proteomics data
  • Many additional P. falciparum SNPs
  • Additional ESTs
  • Expression profiling data for antigenic and adherent variants of P. falciparum 3D7
  • User comments submitted prior to June 2007 have now been incorporated into the official annotation.

A brief list of new features include:

  • faster loading of Gene and Genome Browser pages.
  • Improved synteny views in the Genome Browser.
  • Browser views of rodent malaria genomes colored to indicate chromosomes.
  • Gene page links to various external data sources (including PlasmoMAP, TDRtargets, UCSC P. falciparum genome browser, Ontology-based Pattern Identification and literature databases).
  • More convenient access to help … please click the “Ask us a Question” link on the left of every page, or the “Contact Us” at bottom to report problems or suggest improvements to the database.

Many thanks to the Plasmodb team and the entire ApiDB team for the the recent improvements and for the new datasets.

A ruby micro review

ruby logoRuby is a reflective, dynamic, object-oriented programming language, created by Yukihiro Matsumoto and released to the public in 1995. It is an extremely pragmatic language, less concerned with formalities and more concerned with ease of development and valid results. You will see Agile principles running through ruby and particularly with rails. Most of all TDD and BDD concepts / philosophies have been implemented for ruby developers. Ruby differs from most programming languages by syntax, culture, grammar and customs. It has more in common with LISP and Smalltalk than with most languages such as C++ and PHP.

If you can program in languages such as Perl, PHP, C or Pascal, using and learning ruby is quite easy, but the problem solving pespectives that ruby uses may throw you out at first.

The so popular and hyped ruby on rails DSL (domain specific language) is a framework for developing web applications and currently powers hundreds of large websites around the world.

Bioruby is an excellent bioinformatics library for ruby. Though not highly documented like its sister, bioperl, efforts are been made to improve its level of documentation. The bioruby community is also really nice and friendly. Not a single question that i have posted on the mailing list goes unanswered.

Hundreds of libraries for performing different tasks have been written for ruby , packaged as gems and hosted at rubyforge

So far my favorite ruby editor is the netbeans IDE, whose currently release is in beta 2. The final release is slated for 3rd of Dec 2007. (Am waiting!). It features auto completion, syntax highlighting among other cool things that makes programming a joy. It also comes bundled with the jruby release, a java implementation of ruby that is starting to rock the world, so you can choose to use either native ruby or jruby, the choice is all yours!

Ruby can be downloaded here