[BioRuby] Bioruby HTML output
Toshiaki Katayama
ktym at hgc.jp
Tue Jan 19 12:41:31 UTC 2010
Dear Pj and all,
I'm sorry that I could not spare enough time to follow this thread
but I'd like to add some comments.
Firstly, I don't like to use the method name 'to_html' as we already
deprecated to use 'to_fasta' because 'to_' is reserved for conversion
of the class in Ruby's convention (above two methods just convert
String to String).
We (Nakao-san and me) are now working to improve our TogoWS service
(http://togows.dbcls.jp) by supporting RDF output. I hope to propose
a generalized way to achieve this (hopefully, before the BioHackathon
2010 http://hackathon3.dbcls.jp/).
Our current attempt is to have an 'output' method in the Bio::DB class
and each sub-class implements actual 'output_*' methods relevant
to appropriate formats.
# This kind of requirements may also be true for classes other than
# the Bio::DB (for example, Bio::Sequence, Alignment, Newick classes),
# so we may put this interface in the top level class (Bio::Root?),
# which does not exist for now, though.
In TogoWS, we internally use the BioRuby library, and the URI
http://togows.dbcls.jp/entry/exampledb/1/definition
is sent to the 'definition' method defined in the Bio::ExampleDB class.
Similarly, we can map '.' notation in the following URLs to call output
method using their suffix as a format specifier.
http://togows.dbcls.jp/entry/exampledb/1.rdf
http://togows.dbcls.jp/entry/exampledb/1.fasta
Therefore, these can be mapped to output(:rdf) and output(:fasta) method
calls to the Bio::ExampleDB class, respectively.
All we need to do is to add these methods in every database class
comprehensively.
I think this is simple enough and beautiful.
I'll attach a primitive pseudo code in below.
Comments are welcome.
Regards,
Toshiaki Katayama
module Bio
class DB
def output(format)
send("output_#{format.to_s.downcase}")
end
end
end
module Bio
class ExampleDB < DB
# output sequence of the entry in FASTA format
def output_fasta
">#{@entry_id} #{@definition}\n#{@sequence}\n"
end
# output contents of the entry in RDF (N3) format
def output_rdf
prefix_subject = "http://togows.dbcls.jp/entry/exampledb"
prefix_predicate = "http://togows.dbcls.jp/ontology/exampledb"
"<#{prefix_subject}/#{@entry_id}>\t<#{prefix_predicate}#definition>\t#{@definition} .\n" +
"<#{prefix_subject}/#{@entry_id}>\t<#{prefix_predicate}#sequence>\t#{@sequence} .\n"
end
# output contents of the entry in HTML format
def output_html
"<h1>#{@entry_id}</h1> ... blah, blah, blah ..."
end
end
end
entry = Bio::ExampleDB.new(str)
entry.output(:fasta)
# =>
# >ENTRY_ID
# atgcatgcatgcatgcatgc
entry.output(:rdf)
# =>
# <http://togows.dbcls.jp/entry/exampledb/ENTRY_ID> <http://togows.dbcls.jp/ontology/exampledb#definition> "DEFINITION" .
# <http://togows.dbcls.jp/entry/exampledb/ENTRY_ID> <http://togows.dbcls.jp/ontology/exampledb#seqence> "atgcatgcatgcatgc" .
On 2010/01/19, at 19:50, Pjotr Prins wrote:
> Based on Tomoaki's comments I propose the following:
>
> The requirements are:
>
> A- input objects that know about HTML should generate that
> B- other input files get escapeHTML(object.to_s)
>
> For a container/displayer to recognize object A, object A should have
> a method to_html:
>
> class ObjectA
> def to_html
> end
> end
>
> If to_html does not exist to_s is called - and escaped. The principle
> will go into a mixin for the container class.
>
> Everyone OK with this?
>
> Pj.
> _______________________________________________
> BioRuby Project - http://www.bioruby.org/
> BioRuby mailing list
> BioRuby at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioruby
More information about the BioRuby
mailing list