bioruby e gli engines di rails -ita-
TRANSCRIPT
Scrip&ng e RailsEngines possono coesistere ?
Ruby Social Club Raoul J.P. Bonnal [email protected]
h=ps://github.com/helios/bioruby-‐gem h=p://bioruby.open-‐bio.org/
Milano, 24 Febbraio 2011
Ruby, dove?
Ambien& di
U&lizzo
Web
Admin Scienza
Ruby, dove?
Ambien& di
U&lizzo
Web
Admin Scienza
Web Rails
Sinatra
Cool.io
Ruby, dove?
Ambien& di
U&lizzo
Web
Admin Scienza Admin
Capistrano
Ruby, dove?
Ambien& di
U&lizzo
Web
Admin Scienza Scienza
SciRuby
BioRuby
Graphics/PloPng
BioRuby conceP
• La bioinforma&ca è una disciplina scien&fica dedicata alla risoluzione di problemi biologici a livello molecolare con metodo informa&ci
• BioRuby è una libreria, scri=a completamente in Ruby, il cui scopo è quello di ges&re alcuni aspeP della bioinforma&ca
h=p://it.wikipedia.org/wiki/Bioinforma&ca h=p://bioruby.open-‐bio.org/
BioRuby contribuire
BioRuby contribuire
Sviluppatori molto conserva&vi in realtà acce=ano ma ci vuole tempo
Il proge=o BioGem
Maggiore necessità di apertura verso il fresh code, che non sarà bug free ma almeno c’è
Script e Engine
In BioInforma&ca spesso chi produce da& non si preoccupa di come ques& verranno visualizza&
Script e Engine
In BioInforma&ca spesso chi produce da& non si preoccupa di come ques& verranno visualizza&,
almeno non subito… geek.take_rest if boss.watch? results!
class Boss! def watch?(result)! result.fancy?! end!end!class Result! def fancy?! (kind_of? GorgeousImage) || has_cool_interface? ! end!end!
Script e Engine
Oppure li analizza con strumen& differen&, che però spesso non offrono molta flessibilità
Script e Engine
Quindi che fare ? 30 + 1 = 31
Solo che quell’ UNO crea mol& più problemi di quanto si pensi – Web Applica&on, che richiede tempo – Riusabilità: possibile proliferazione di applicazioni – Mantenibilità – E’ slegato dalla libreria che produce/ges&sce i da&?
Perché mischiare Script e Engine?
• U&lizzare database sia da parte di script che da parte di uten& “web”. – script: solitamente macinano da& – web:
• vuole esplorare i da& sia quelli in input che il risultato • Services
• Credo che mantenere tu=o in un unico posto sia meno dispersivo e di solito chi sviluppa il livello di analisi/database POI si preoccupa anche di sviluppare l’interfaccia
Il Generatore1
Il Generatore1
Il Generatore1
Bundler, Jeweler +
Hacking
Il Generatore2
$ biogem --with-engine=joke fake!!create !.gitignore!!create !Rakefile!!create !Gemfile!!create !LICENSE.txt!!create !README.rdoc!!create !.document!!create !lib!!create !lib/bio-fake.rb!!create !test!!create !test/helper.rb!!create !test/test_bio-fake.rb!!create !db!!create !app!!create !app/controllers!!create !app/views!!create !app/helpers!!create !config!!create !lib/bio-fake-engine.rb!!create !lib/bio-fake.rb!
********************************************************************************!* *!* Remember to require this library in the Gemfile of your Rails applicat *!* ion. *!* Please take a look at bioruby-fake/lib/bio-fake-engine.rb file for an *!* example of how integrate your engine into a rails application. *!* Thanks! *!* *!********************************************************************************!
!create !config/routes.rb!Jeweler has prepared your gem in bioruby-fake!Fetching source index for http://rubygems.org/!Could not reach rubygems repository http://
rubygems.org/!Using rake (0.8.7) !Using bio (1.4.1) !Using bundler (1.0.10) !Using git (1.2.5) !Using jeweler (1.5.2) !Using rcov (0.9.9) !Using shoulda (2.11.3) !Your bundle is complete! Use `bundle show
[gemname]` to see where a bundled gem is installed.!
rake version:write!(in /Users/bonnalraoul/Documents/Develop/
prototypes/bioruby-fake)!Updated version: 0.0.0!rake gemspec!(in /Users/bonnalraoul/Documents/Develop/
prototypes/bioruby-fake)!Generated: bio-fake.gemspec!bio-fake.gemspec is valid.!
Engine require 'bio-fake'!require 'rails'!
module BioFake! class Engine < Rails::Engine! # Config defaults!
config.widget_factory_name = "default factory name"! config.mount_at = '/'!
# # Load rake tasks!
# rake_tasks do! # load File.join(File.dirname(__FILE__), 'rails/railties/tasks.rake')!
# end ! # Check the gem config!
initializer "check config" do |app|! # make sure mount_at ends with trailing slash!
config.mount_at += '/' unless config.mount_at.last == '/'!
end!
initializer "static assets" do |app|!
app.middleware.use ::ActionDispatch::Static, "#{root}/public"! end! paths.app.models << "lib"! end!
end! h=p://keithschacht.com/crea&ng-‐a-‐rails-‐3-‐engine-‐plugin-‐gem/
Engine Rou&ng Rails.application.routes.draw do |map|!
mount_at = BioFake::Engine.config.mount_at!
#ROUTES from code below:!
# YourPathToTheControllerFiles = “bio/kb/gex”!# OtherControllerName = slice!
# !# gex /gex(.:format) {:controller=>"bio/kb/gex/populations", :action=>"index"}!
# filter_population GET /gex/populations/:id/filter(.:format) {:action=>"filter", :controller=>"bio/kb/gex/populations"}!# populations GET /gex/populations(.:format) {:action=>"index", :controller=>"bio/kb/gex/populations"}!
# population GET /gex/populations/:id(.:format) {:action=>"show", :controller=>"bio/kb/gex/populations"}!
# samples GET /gex/samples(.:format) {:action=>"index", :controller=>"bio/kb/gex/samples"}!# sample GET /gex/samples/:id(.:format) {:action=>"show", :controller=>"bio/kb/gex/samples"}!
# slices GET /gex/slices(.:format) {:action=>"index", :controller=>"bio/kb/gex/slices"}!# slice GET /gex/slices/:id(.:format) {:action=>"show", :controller=>"bio/kb/gex/slices”}!
scope mount_at, :module=>'SUBSITITUTE YourPathToTheControllerFiles'do ! resources :ControllerName, :only => [ :index, :show] do ! member do ! get :example!
end #member ! end #resource! resources :SUBSTITUTEOtherControllerName, :only => [ :index, :show]!
end #scope!end!
Rails Ini&alizer
Codice che deve essere aggiunto all’applicazione
# config/initializers/bio-fake.rb! # create a file called bio-fake.rb! # you can change the mount point of you engine, using option! # --with_engine=namespace like http://YourDomain:port/YourMountPoint! # Otherwise, if you want your RailsEngine to be called at root level, leave everything as it now,
without that file.!
module BioFake! class Engine < Rails::Engine! config.mount_at = '/joke’! end! end!
Scrip&ng e RailsEngines possono coesistere ?
SI
Da risolvere
• Come posso ges&re le interdipendenze tra database in gemme differen&?
• I/O di da& in formato tabellare: tab, csv – Conviene me=ere in db classici ? – NOSQL ? – Tenere I file?
• I database spesso sono legacy e devono interagire tramite le gemme – SQLite3 per la distribuzione
Ringraziamen&
Bioruby • Toshiaki Katayama • Pjotr Prins
Fondazione INGM • Massimiliano Pagani • Riccardo L. Rossi • Valeria Ranzani
P.T.P. • Francesco Strozzi
Domande ?