[BioRuby] Bioruby HTML output

Tomoaki NISHIYAMA tomoakin at kenroku.kanazawa-u.ac.jp
Sun Jan 17 05:12:35 UTC 2010


Hi,

On 2010/01/16, at 17:30, Pjotr Prins wrote:

> On Sat, Jan 16, 2010 at 02:36:02PM +0900, Tomoaki NISHIYAMA wrote:
>>> I am going to add a 'master' switch for escaping of HTML. The  
>>> default
>>> will be with escaping.
>>
>> How do you think to test if the object responds to to_html
>> and then call to_html else pass to escapeHTML.
>
> In this case the object to convert to HTML is a String and part of
> Bio::Alignment. Later implementations of Bio::Alignment could use a
> Bio::Sequence.id (or something Naohisa wrote me).  It would mean we
> would have to create a Bio::Sequence::Descriptor object, which would
> contain several specialistic 'output' generators.


For the meanwhile I don't expect that sophisticated mechanism to
automatically generate proper HTML, but simply add a mean to
distinguish what should be escaped as a normal course and what
is specifically prepared as html by the user.

A user can write:

class HTMLString < String
   def to_html
     self
   end
end

a = Bio::Alignment.new
a.add_seq('ATCCATGG', HTMLString.new('<a href="http://example.com/ 
path/to/original/seqinfo"><em>a</em></a>'))
# this is html under the responsibility of the programmer

a.add_seq('ATGCATGC', '<b>')
# this is not html; don't care on '<', or '>'

simple = Bio::Html::HtmlAlignment.new(a,
   :title => HTMLString.new('A <em>fancy</em> <b>HTML</b> <i>title</ 
i>'))
html = simple.html()

If Bio::Alignment does not force the object given to be String,
such code should be possible without the change in Bio::Alignment,
and only the HtmlAlignment class and the programmer needs to know it.
So, HTML specific code does not need go to regular BioRuby code.

> That would be the proper way to handle it. No testing of methods
> (like to_html), but use the object structure to define what is
> supported (and not).


I'm not sure what do you mean by "use the object structure".
How do you distinguish a plain text and HTML text?
-- 
Tomoaki NISHIYAMA

Advanced Science Research Center,
Kanazawa University,
13-1 Takara-machi,
Kanazawa, 920-0934, Japan


On 2010/01/16, at 17:30, Pjotr Prins wrote:

> On Sat, Jan 16, 2010 at 02:36:02PM +0900, Tomoaki NISHIYAMA wrote:
>>> I am going to add a 'master' switch for escaping of HTML. The  
>>> default
>>> will be with escaping.
>>
>> How do you think to test if the object responds to to_html
>> and then call to_html else pass to escapeHTML.
>
> In this case the object to convert to HTML is a String and part of
> Bio::Alignment. Later implementations of Bio::Alignment could use a
> Bio::Sequence.id (or something Naohisa wrote me).  It would mean we
> would have to create a Bio::Sequence::Descriptor object, which would
> contain several specialistic 'output' generators.
>
> This is a recurrent idea we need to discuss.
>
> I think *all* HTML based stuff should be in its own objects - and its
> own tree (I have created bio/output/html for that purpose).
>
> I think it is a bad idea to clutter regular BioRuby code with HTML
> specific stuff. Likewise for other outputs, as you pointed out, like
> plotting. Output should live in
>
>   bio/lib/output/html
>   bio/lib/output/plot
>   bio/lib/output/gtk
>   bio/lib/output/rails (perhaps)
>   (etc)
>
> that way display code never pollutes the simple Bio::Sequence object,
> for example. You'll get Bio::Html::Sequence for that - or my
> preferred naming Bio::HtmlSequence.
>
> Now if Bio::HtmlSequence could be plugged into Bio::Alignment - the
> latter would not care - and we could adapt the HtmlSequence info to
> show embedded hrefs.
>
> That would be the proper way to handle it. No testing of methods
> (like to_html), but use the object structure to define what is
> supported (and not).
>
> Until we implement that (get Bio::Alignment to support arbitrary
> Sequence objects) I think the master switch is fine. I have updated
> my branch. Default behaviour is escaping. If a user (like me) wants
> it otherwise, it is allowed.
>
> Pj.
>




More information about the BioRuby mailing list