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!

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

Standalone BLAST with Ruby

 

 

BLAST is one of the most widely used search algorithms in molecular biology. So lets see how you can run and retrieve blast results via a simple Ruby script .I will assume you already have ruby 1.8.5 and above installed in your windows box and a standalone blast.exe which you can download from the NCBI’s ftp site here . The latest windows binaries as of this writing is 2.2.17. Create a new folder in C and call it NCBI_Blast. Paste the downloaded blast program in this folder. Double click the blast program and it will create a bin, doc and data folders inside your your NCBI_Blast folder. If this is your first time to install blast in your machine. You will need to do a little configuration. Follow these instructions for setting up blast .

 

Using your favorite text editor, (I use the Netbeans IDE 6.0 with Ruby support. It is a fantastic Ruby editor and totally free) .

 

#create a query sequence
myseq=”pcaatcacatyyawwqqffgghhhkllkl”

 

#create a temporary file
require ‘tempfile’

temp=Tempfile.new(“seqfile”)
#get the name of the temporary file
name=temp.path
#append the contents your sequence to this temporary file
temp.puts “#{myseq}”
temp.close

#since we have a protein query sequence, we will run a blastp. Please note that you will need to have a valid #database to query against. use the formatdb command to create your database before executing the lines #below.
@program = ‘blastp’
#path to blast

@database = ‘c:/path_to_databasefile’
#name of your query file
@input= name

#your blast output file
@output=’c:/path_output_file’

#assume your blast is in a folder called NCBI_Blast, execute
system( “c:/NCBI_Blast/bin/blastall.exe -p #{@program} -d #{@database} -i #{@input} -o #{@output}”)

#To capture the output in a variable execute this command instead.
#note that we have omitted the blast -o parameter

result=%x(c:/NCBI_Blast/bin/blastall.exe -p #{@program} -d #{@database} -i #{@input} )

#remember to delete the temporary file!

temp.close(true)

And that all folks!