[BioRuby] Bio::Blat

Naohisa GOTO ngoto at gen-info.osaka-u.ac.jp
Wed Sep 3 14:31:43 UTC 2008


On Tue, 2 Sep 2008 12:28:59 +0200
Davide Rambaldi <davide.rambaldi at ifom-ieo-campus.it> wrote:

> Hi all, I am trying to use Ruby and BioRuby to translate a Perl  
> script that I am using in my lab to parse psl files.
> 
> The blatanalyzer script should:
> 
> sort entries according to identity, coverage, score, cut psl files in  
> order to keep only alignments with a given identity,
> generate report tables (similar to a web blat result table in the  
> UCSC server), convert psl to gff and gtf, etc...
> 
> USAGE:
> 
> Usage ./blatanalyzer.rb [options] action file.psl
> 
> and can be used also in a pipe (cat file.psl | ./blatanalyzer.rb action)
> 
> 
> I am a newbye of Ruby scripting (and also I am currently trying to  
> understand the conventions used in BioRuby) so I am not sure if my  
> design is decent or completely stupid/crazy.
> 
> First of all, I need some extra methods not present in  
> Bio::Blat::Report (like coverage, sorting_by,  grouping, etc...) so  
> my idea is to made a subclass of Bio::Blat::Report:
> 
> module Bio
>    class Blat
>      class Analyzer < Report
> 	def coverage
> 	  implementation here ...
> 	end
>      end
>    end
> end
> 
> Is this a good idea?

In Ruby, a class that inherits existing class can be affected
by internal changes of the existing class, including conflicts
of private method names and instance variable names.

If you can follow changes of the ancestral class and can change
your code following the ancestral changes, to create subclass
may be the most efficient way, from the viewpoint of running
speed, memory efficiency, and code size.

If you don't want to do so, and/or the internal structure of
the ancestral class isn't clear, it is safe to store as an object,
without inheritance.

Note that this is only from practical point of view,
as I don't know so much about the philosophy of OOP. 

> On the other side I am working on a Bio::Blat::Application that  
> should initialize options (parsed by a OptParser class), load a  
> stream, pass the stream to the Bio::Blat::Analyzer object, choose  
> which method (action) apply to the stream.
> 
> Is OK to put this code in the Bio::Blat namespace? or I should put it  
> in an external Application class?

In your application, you can do whatever you like.
However, I think using your original namespace would be better
to avoid confusion, especially when errors occur.

In addition, be careful when using the mod_ruby apache module.
Because mod_ruby shares Ruby interpreters among different scripts,
modifying existing class/module in mod_ruby is not recommended
unless you understand what you are doing.

> 
> Actually the structure of my blatanalyzer.rb application is this one
> 
> class Color
>    # to handle colorized output (use term-ansicolor)
> end
> 
> class OptParser
>    # parse command line options
> end
> 
> module Bio
>    class Blat
> 
>      class Analyzer < Report
>        # extend the functionality of the Report with sorting,  
> grouping and other methods
>      end
> 
>      class Application
>        # load a stream, check options, select action and execute it  
> printing result on STDOUT
>      end
> 
>    end
> end
> 
> # MAIN.APP
> # slurp command line options and start application
> options = OptParser.parse(ARGV)
> Bio::Blat::Application.new(options,ARGF)
> 
> 
> Something I need to change? make sense?

In your application, you can do whatever you want to do.
What I write here is only an empirical suggestion.

-- 
Naohisa Goto
ngoto at gen-info.osaka-u.ac.jp / ng at bioruby.org



More information about the BioRuby mailing list