Category: bioinformatics

Announcing scribl-rails

PfEMP1 domains drawn with scribl

Sometimes back I had mentioned about scribl javascript framework for drawing bioinformatics glyphs on HTML5 canvas. If you are a Rails developer you will be happy to know that I have written  scribl-rails, an asset helper for including scribl in your application asset pipeline.


Add the following to your gemfile:

gem 'scribl-rails' 

ran bundle install from the application directory

Add the following directive to your Javascript manifest file (application.js):

//= require scribl 

Enjoy using scribl-rails and creating cute bio-graphics! Many thanks to Chase Miller for the awesome library!

For more information and development check out the scribl-rails at github

Use Scribl to draw genomic glyphs on HTML5 canvas

The Scribl library by Chase Miller is an awesome and a promising Javascript library for visualizing biological sequence information and rendering it on the web. Scribl  generates biological charts of genomic regions, alignments, and assembly data. The library is under continuous development and I have been able to use it for some internal projects!

A very nice list of examples and introduction is available at the home page and the wiki provides an elaborate user guide!

Happy biology!

Translating a nucleotide sequence in six frames with bioruby

Bioruby offers a very easy and simple way to translate nucleotide sequences.


We know that there are six posible reading frames for any given nucleotide sequence. Generally the longests Open reading frame is taken to be the correct frame, when we do not have information about the possible protein that is encoded by a given gene. By default the translate method performs translation in the first frame but it can take an argument that defines the translation frame

seq.translate(2) #translate using the second reading frame.

Given a long list of sequences how do we quickly determine the correct reading frame. We would want to have method to translate a given  sequence in all frames and pick the longest reading frame. Assuming that the correct reading frame has no stop codons, we can write a quick method to perform  the six frame translation.

 def longest_reading_frame(sequence)
  orfs = [] #a container for orfs(open reading frames)
  #translate a sequence in all 6 frames
   6.times do |frame|
   translated = + 1)
   stop_codons = translated.scan(/\*/).size
    orfs << translated if stop_codons == 0

This method uses an array to collect all translated sequences that contain no stop codons and returns the first sequence in the array. This might not scale very well for very long sequences but that will be a post for another day!

Happy Biology!

My first Bioruby plugin calculates the isoelectric point of a protein

Late last year,  there was a lot of talk about creating a plugin system for Bioruby. The idea is that more people can start to develop bioinformatics libraries using the Ruby language and the libraries can leverage on the bioruby framework. Bioruby maintainers can then concentrate on yet to be defined “core” parts of the library to ensure compatibility and support for the plugins.Together with Pascal Bentz we have created a library to calculate the Isoelectric point of a protein given a Pka set and an  amino acid sequence of a peptide/protein. The project lay domant for a while at github until now! I am happy to release my first bioruby plugin, bio-isoelectric point! Download it at Fork it and check the usage at github


require 'bio'
require 'bio-isoelectric_point'
protein_seq ="KKGFTCGELA")

#what is the protein charge at ph 14?
charge = protein_seq.charge_at(14) #=>-2.999795857467562

#calculate the ph using dtaselect pka set and round off to 3 decimal places
isoelectric_point = protein_seq.isoelectric_point(‘dtaselect’, 3) #=>8.219

# calculate the isoelectric point pH with a custom set
custom_pka_set = { “N_TERMINUS” => 8.1,
“K” => 10.1,
“R” => 12.1,
“H” => 6.4,
“C_TERMINUS” => 3.15,
“D” => 4.34,
“E” => 4.33,
“C” => 8.33,
“Y” => 9.5
iep_ph = protein_seq.isoelectric_point(custom_pka_set, 3) #=> 8.193

This gem supports the following Pka sets, as well as allowing a user to provide a custom Pka set.

    * dta_select
    * emboss
    * rodwell
    * wikipedia
    * sillero

Happy biology!

Standalone BLAST with Ruby revisited

Earlier  I showed a very simple way to perform a BLAST  using Ruby. Today I would like to revisit that topic for two reasons.

  1. The “using ruby with blast” search term seems to be very common and actually one of the ways that people reach my blog.
  2. The original post was not very through.

BLAST aka Basic Local Alignment Tool is used to search a sequence (either DNA or protein) against a database of other sequences (either all nucleotide or all protein) in order to identify similar sequences. BLAST has many different flavors and can  search DNA against DNA or protein against protein and also can translate a nucleotide query and search it against a protein database  and vice versa. It can also compute a “profile” for the query sequence and use that for further searches as well as search the query against a database of profiles.

The BLAST tool is fundamental to molecular biologists and bioinformaticians. There are excellent books and tutorials on how to and when to use BLAST, so i will assume all you need is to automated your work and parse the results. The actual algorithm is implemented in C and freely  available from the NCBI website.The first thing  to do is to download the appropriate binaries for your platform. Instructions for setting up and installing BLAST

Once installed on your system  the primary method of interaction is using the command line. Use formatdb to create blast databases and blastall to search for sequence homology for a given sequence against a given blast database.

In Ruby, there are two ways you can call the BLAST program. First using the Bioruby library and second by writing your own ruby wrapper for the BLAST command line parameters and execution. Most often, one executes BLAST from the command line and then process the results file which is in either one of the many BLAST output formats. Bioruby is excellent  at parsing the results file. Using Bioruby with BLAST is  very straightforward:

#blasting the bioruby way #query_file: a list of query sequences in fasta format #database_path: a path to the actual BLAST formatted database #program: The BLAST program to call, either of blastp,blastn,tblastn e.t.c.
def bio_blast(program, database_path,query_file)

factory = Bio::Blast.local(program,database_path)
ff =, query_file)
ff.each do |entry|
report = factory.query(entry) # report will be a Blast::Report object
# iterate trough the hits
report.each do|hit|
puts hit.bit_score        # bit score (*)
puts hit.query_seq        # query sequence
puts hit.midline          # middle line string of alignment of homologous region (*)
puts hit.target_seq       # hit sequence
puts hit.evalue           # E-value
puts hit.identity         # % identity
puts hit.overlap          # length of overlapping region
puts hit.query_id         # identifier of query sequence
puts hit.query_def        # definition(comment line) of query sequence
puts hit.query_len        # length of query sequence
puts hit.target_id        # identifier of hit sequence
puts hit.target_def       # definition(comment line) of hit sequence
puts hit.target_len       # length of hit sequence
puts hit.query_start      # start position of homologous region in query sequence
puts hit.query_end        # end position of homologous region in query sequence
puts hit.target_start     # start position of homologous region in hit(target) sequence
puts hit.target_end       # end position of homologous region in hit(target) sequence
puts hit.lap_at           # array of above four numbers
hit.each do |hsp|
puts hsp.query_from

A ruby class for screen-scraping plasmodb database

Plasmodb is the primary resource for retrieving Plasmodium falciparum genomic data and information. Unfortunately this database has no API or XML service to request or query its  information from a programmer’s point of view or for easy automation of sequence information retrieval.  Recently I needed to download a long list of Plasmodium falciparum genomic, Protein and other information for a set of genes. Been lazy to click and open the webpage for each gene in my list. I wrote this in ruby.

It would be great if Plasmodb  would provide an easy way  of automated sequence retrieval. A webservice or an XML output format would do. Screen scraping is not a very efficient approach.  Here we use Scrapi which  is an HTML scraping toolkit for Ruby. It uses CSS selectors to write easy, maintainable scraping rules to select, extract and store data from HTML content.

#A class to fetch information from plasmodb using the scrapi API
##TODO handle  Scraper::Reader::HTTPUnspecifiedError
class Plasmodb
   #retrives a information  using the gene_id
   #returns a structure obj
  def fetch_by_gene_id(var_name)
      scraper = Scraper.define do
        process "div#genomicSequence pre",    :genomic_sequence  => :text
        process "div#transcriptSequence pre", :mrna_sequence =>:text
        process "div#proteinSequence pre",    :protein_sequence  =>:text
        process "div#Aliases td>table",       :aliases =>:text
        result :protein_sequence,:aliases,:mrna_sequence,:genomic_sequence

     uri = URI.parse(search_link)
     @query = scraper.scrape(uri)

    rescue Scraper::Reader::HTTPUnspecifiedError
  #returns the predicted protein sequence
  def protein_sequence
#  Returns the genomic sequence
  def genomic_sequence
  #returns Aliases
  def aliases
  #returns the mrna sequence
  def mrna_sequence

#Use the class to fetch information.
require 'rubygems'
require 'bio'
require 'scrapi'

file = "/home/george/genes_list.txt" #a file containing a list of accession numbers.
#one accession number per line

plasmo = #initialize a plasmodb class instance

#Read the file and process each accession number.
File.readlines(file).each do |line|
  plasmo.fetch_by_gene_id(line)  #fetches the information from Plasmodb.
  #print a fasta entry for the protein sequence

#another example
#p =
#puts p.genomic_sequence

PC vs Apple Mac (Not the war!)

My good old PC running Linux OS is coming of age and recently started failing. The Optical drive is not functional and occasionally it will freeze. The Top cover does not hold anymore and the graphical TFT screen needs to be supported carefully.

While this particular computer has served me well, I am at that point where i need a new machine but am torn between an Apple Mac and a PC running Linux. First my work involves the following aspects;

  1. Compiling and running bioinformatics software developed using open source standards and technologies
  2. Programming
  3. Word processing and document editing
  4. Occasional mathematical modeling
  5. Administering  Unix based servers

I have tried to come up with a computer-model agnostic specifications for my needs.


* High Processor speed (2.60GHZ or above)

* High Memory (4GB or above)

* Medium Hard-disk space (160GB and above)

* Long Battery life ( 5hours and above)

* Durable external cover

* Ergonomic keys and mouse

* Support for multiple external devices(printers,Cameras,Microphones,Storage devices,monitors)

* Excellent support for wireless technologies

* Support for running multiple operating systems on the same machine

Size and weight

* Lightweight

* convenience while travelling while traveling

Operating System

* A Unix or Linux derived operating system

* Easy to upgrade at zero or minimal cost

* Free patches against known security holes and problems.


* Support for Open software standards

* Support for Microsoft, Adobe and other proprietary software vendor’s products


* Excellent inbuilt support against Malware, Trojans and viruses at minimal or no cost

* Support for locking the machine while away or against unauthorized login

* Ability to easily ‘tag’ the machine in case of theft

Price : Affordable and reasonable

Based on the above specifications I have evaluated two computers models that can satisfy the above needs.

1. A PC laptop computer running a Linux based operating system

2. An Apple Macintosh laptop computer

I have ruled out a Windows/DOS based Operating software because  Microsoft Windows based operating system cannot offer  support for open source standards and technologies. OS upgrade for windows is very expensive and the OS is highly prone to malware, Trojans and viruses. Most bioinformatics software and tools are developed on Unix or  Linux environment.

PC can support Linux installations even though one looses on hardware optimization. Linux has a relatively poor graphical user interface and functionality when compared to Mac OS or Windows. There is limited support for document processing, graphics and rich multimedia applications support. Linux does not support any of the Microsoft software applications natively. There are open source equivalents but most lack good support.

Apple Macintosh computers are based on Unix and open source technologies, they support both closed source and open source standards. The hardware is optimized and accelerated for the Apple mac OS. They offer excellent graphical user interface system, a powerful terminal for interaction with the OS, they are not prone to virus attacks, and they support long battery life as well as portability, ergonomics and a relatively within a  price range equivalent to a PC of the same specifications.

Given my budget constrains, I am thinking that a 2.53GHz Apple Macintosh 13 inch model with 4GB of memory is best for my needs. There is little price differences between the PC and Macintosh models based on my specifications. PC models do not favor Linux installations and Linux hardware support is not guaranteed. They however seem to have a more flexible price ranges depending on the manufacturers, vendors, quality and specifications.

I will keep Linux to run my server applications.