<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="https://chem-bla-ics.linkedchemistry.info/feed/by_tag/html.xml" rel="self" type="application/atom+xml" /><link href="https://chem-bla-ics.linkedchemistry.info/" rel="alternate" type="text/html" /><updated>2026-11-22T12:40:33+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/feed/by_tag/html.xml</id><title type="html">chem-bla-ics</title><subtitle>Chemblaics (pronounced chem-bla-ics) is the science that uses open science and computers to solve problems in chemistry, biochemistry and related fields.</subtitle><author><name>Egon Willighagen</name></author><entry><title type="html">Programming in the Life Sciences #11: HTML</title><link href="https://chem-bla-ics.linkedchemistry.info/2013/10/30/programming-in-life-sciences-11-html.html" rel="alternate" type="text/html" title="Programming in the Life Sciences #11: HTML" /><published>2013-10-30T00:20:00+00:00</published><updated>2013-10-30T00:20:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2013/10/30/programming-in-life-sciences-11-html</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2013/10/30/programming-in-life-sciences-11-html.html"><![CDATA[<p><a href="https://en.wikipedia.org/wiki/HTML">HTML</a> (HyperText Markup Language), the language of the web,
is no longer the only language of the web. But it still is the primary language in which source
code of webpages is shared. Originally, HTML pages were always static: the only HTML source of a
web page was that was downloaded from a website. Nowadays, much HTML the is visualized in your
web browser, is generated on the fly with JavaScript. In fact, that is exactly what you will
learn to do in this course.</p>

<p>HTML has many dialects, and HTML5 is the upcoming next version. The features have become so
extensive that we will not have capture half of them; instead, we will stick to the bare
minimum needed. But even at an minimum, writing a web page with HTML code is basically writing
source code. The compiled version is the view of the webpage your web browser shows you. One
important difference is that HTML is much more like a data model representation than it is like
computational instructions. That is, rather than saying things like <code class="language-plaintext highlighter-rouge">put("String", xCoord, yCoord)</code>,
we define what is to be shown in in what order with general instructions. Well, in pure HTML
that is. <a href="https://en.wikipedia.org/wiki/CSS">Cascading Style Sheets</a> (CSS) is quite outside the
scope of this course.</p>

<p>A minimal HTML page looks like:</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;html&gt;</span>
  <span class="nt">&lt;head&gt;</span>
  <span class="nt">&lt;/head&gt;</span>
  <span class="nt">&lt;body&gt;</span>
  Hello world!
  <span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>

<p>When we think about this structure, we notice that it is not unlike the key-value maps we
covered earlier. For example, compare it to this
<a href="http://chem-bla-ics.blogspot.nl/2013/10/programming-in-life-sciences-10.html">JSON</a>:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span><span class="w">
  </span><span class="nl">"html"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
    </span><span class="nl">"head"</span><span class="p">:{},</span><span class="w">
    </span><span class="nl">"body"</span><span class="p">:{</span><span class="err">value:</span><span class="s2">"Hello world!"</span><span class="p">}</span><span class="w">
  </span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<p>Even if we introduce HTML attributes:</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;html&gt;</span>
  <span class="nt">&lt;head&gt;</span>
  <span class="nt">&lt;/head&gt;</span>
  <span class="nt">&lt;body&gt;</span>
  <span class="nt">&lt;h1&gt;&lt;a</span> <span class="na">name=</span><span class="s">"hello"</span><span class="nt">&gt;</span>Hello world!<span class="nt">&lt;/a&gt;&lt;/h1&gt;</span>
  <span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>

<p>The JSON equivalent would be:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span><span class="w">
  </span><span class="nl">"html"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
    </span><span class="nl">"head"</span><span class="p">:{},</span><span class="w">
    </span><span class="nl">"body"</span><span class="p">:{</span><span class="w">
      </span><span class="nl">"h1"</span><span class="p">:{</span><span class="w">
        </span><span class="nl">"a"</span><span class="p">:{</span><span class="w">
          </span><span class="err">attributes:</span><span class="p">{</span><span class="nl">"name"</span><span class="p">:</span><span class="s2">"hello"</span><span class="p">},</span><span class="w">
          </span><span class="err">value:</span><span class="s2">"Hello world!"</span><span class="w">
        </span><span class="p">}</span><span class="w">
      </span><span class="p">}</span><span class="w">
    </span><span class="p">}</span><span class="w">
  </span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<p>So, while these are quite different languages than programming languages, we can clearly
see they have been made up by the same (computer science) people. But in my opinion, this
is an advantage: because we only need to learn the underlying patterns and can then much
more easily switch between different language.</p>

<p>Now, returning to the HTML example, we introduce a bit of terminology. Let’s start with
the last example:</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;h1&gt;&lt;a</span> <span class="na">name=</span><span class="s">"hello"</span><span class="nt">&gt;</span>Hello world!<span class="nt">&lt;/a&gt;&lt;/h1&gt;</span>
</code></pre></div></div>

<p>This HTML code example shows the <code class="language-plaintext highlighter-rouge">&lt;h1&gt;</code> <strong>element</strong> which has one <strong>child element</strong>
<code class="language-plaintext highlighter-rouge">&lt;a&gt;</code>. This child element has an <strong>attribute</strong> <code class="language-plaintext highlighter-rouge">@name</code>. Elements can contain string content,
such as the <code class="language-plaintext highlighter-rouge">&lt;a&gt;</code> element has, and one or more child elements (and any combination of that).
Attributes can only have string content. The HTML specification defines in detail which
elements can be child elements of other elements. For example, the <code class="language-plaintext highlighter-rouge">&lt;head&gt;</code> element can
only be a child element of <code class="language-plaintext highlighter-rouge">&lt;html&gt;</code>. Similarly, each HTML element can only have specific
attributes, though some attributes can be attached to any element.</p>

<p>There is plenty of documentation on the web, but there are also tools that can help us write
HTML. For example, the <a href="http://validator.w3.org/">http://validator.w3.org/</a>. This website
detects errors in your HTML code, and is quite helpful if you are new to editing HTML, as
well as useful if you have a lot of HTML experience.</p>

<p>HTML elements you may find useful include the following:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">&lt;h1&gt;</code>, <code class="language-plaintext highlighter-rouge">&lt;h2&gt;</code>, …, <code class="language-plaintext highlighter-rouge">&lt;h5&gt;</code>: these are header and can be used to make sections</li>
  <li><code class="language-plaintext highlighter-rouge">&lt;p&gt;</code>: indicates a paragraph</li>
  <li><code class="language-plaintext highlighter-rouge">&lt;div id="someID"&gt;</code>: indicates a section of text. The content of any element with an id attribute can be replaced by any appropriate HTML content with JavaScript</li>
  <li><code class="language-plaintext highlighter-rouge">&lt;a href="http://..."&gt;some link&lt;/a&gt;</code>: this is used to make hyperlinks, href means hyperlink reference</li>
  <li><code class="language-plaintext highlighter-rouge">&lt;a name="mark1"&gt;some text&lt;/a&gt;</code>: this is used to create bookmarks. with <code class="language-plaintext highlighter-rouge">&lt;a href="#mark1"&gt;jump to section Mark 1&lt;/a&gt;</code></li>
  <li><code class="language-plaintext highlighter-rouge">&lt;script&gt;</code>: used to include JavaScript code in your HTML page</li>
  <li><code class="language-plaintext highlighter-rouge">&lt;head&gt;</code>: this HTML blob contains metadata, a list of libraries to be loaded, but also JavaScript which is executed before the HTML <code class="language-plaintext highlighter-rouge">&lt;body&gt;</code> is processed</li>
  <li><code class="language-plaintext highlighter-rouge">&lt;body&gt;</code>: this contains the HTML that is depicted in your browser window</li>
</ul>

<p>Keep the HTML simple; the programming is more important.</p>

<p><strong>Exercise</strong>: below is part of the HTML/JavaScript <a href="https://github.com/egonw/mscpils/blob/master/example1.html">source code</a>
behind <a href="http://chem-bla-ics.blogspot.nl/2013/10/programming-in-life-sciences-5.html">this app</a>.
Please indicate which lines are HTML source code, and what is JavaScript.</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">&lt;!DOCTYPE HTML PUBLIC
  "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd"&gt;</span>
<span class="nt">&lt;html&gt;</span>
<span class="c">&lt;!--

Copyright (c) 2013  Egon Willighagen &lt;egon.willighagen@maastrichtuniversity.nl&gt;

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the "Software"), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.

--&gt;</span>
<span class="nt">&lt;head&gt;</span>
  <span class="nt">&lt;title&gt;</span>OpenPHACTS Jasmine Spec Runner<span class="nt">&lt;/title&gt;</span>
  <span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"lib/jquery-1.9.1.min.js"</span><span class="nt">&gt;&lt;/script&gt;</span>
  <span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span> <span class="na">src=</span><span class="s">"lib/purl.js"</span><span class="nt">&gt;&lt;/script&gt;</span>

  <span class="c">&lt;!-- include source files here... --&gt;</span>
  <span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span> <span class="na">src=</span><span class="s">"src/OPS.js"</span><span class="nt">&gt;&lt;/script&gt;</span>
  <span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span> <span class="na">src=</span><span class="s">"src/ConceptWikiSearch.js"</span><span class="nt">&gt;&lt;/script&gt;</span>

  <span class="c">&lt;!-- setup --&gt;</span>
  <span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span><span class="nt">&gt;</span>
  <span class="c1">// get the app_key and app_id from the webpage call --&gt;</span>
<span class="kd">var</span> <span class="nx">prmstr</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">search</span><span class="p">.</span><span class="nf">substr</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">prmarr</span> <span class="o">=</span> <span class="nx">prmstr</span><span class="p">.</span><span class="nf">split </span><span class="p">(</span><span class="dl">"</span><span class="s2">&amp;</span><span class="dl">"</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">params</span> <span class="o">=</span> <span class="p">{};</span>
<span class="k">for</span> <span class="p">(</span> <span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">prmarr</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">tmparr</span> <span class="o">=</span> <span class="nx">prmarr</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nf">split</span><span class="p">(</span><span class="dl">"</span><span class="s2">=</span><span class="dl">"</span><span class="p">);</span>
    <span class="nx">params</span><span class="p">[</span><span class="nx">tmparr</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="nx">tmparr</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
<span class="p">}</span>
  <span class="nt">&lt;/script&gt;</span>
<span class="nt">&lt;/head&gt;</span>

<span class="nt">&lt;body&gt;</span>
  <span class="nt">&lt;h3&gt;</span>Output<span class="nt">&lt;/h3&gt;</span>
  <span class="nt">&lt;h3&gt;</span>Search Results<span class="nt">&lt;/h3&gt;</span>
  <span class="nt">&lt;p&gt;&lt;div</span> <span class="na">id=</span><span class="s">"table"</span><span class="nt">&gt;&lt;/div&gt;&lt;/p&gt;</span>
  <span class="nt">&lt;h3&gt;</span>Compound Details<span class="nt">&lt;/h3&gt;</span>
  <span class="nt">&lt;p&gt;&lt;div</span> <span class="na">id=</span><span class="s">"details"</span><span class="nt">&gt;&lt;/div&gt;&lt;/p&gt;</span>
  <span class="nt">&lt;h3&gt;</span>JSON reply<span class="nt">&lt;/h3&gt;</span>
  <span class="nt">&lt;p&gt;&lt;div</span> <span class="na">id=</span><span class="s">"json"</span><span class="nt">&gt;</span>Nothing yet<span class="nt">&lt;/div&gt;&lt;/p&gt;</span>
  <span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span><span class="nt">&gt;</span>
<span class="kd">var</span> <span class="nx">searcher</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Openphacts</span><span class="p">.</span><span class="nc">ConceptWikiSearch</span><span class="p">(</span>
  <span class="dl">"</span><span class="s2">https://beta.openphacts.org</span><span class="dl">"</span><span class="p">,</span>
  <span class="nx">params</span><span class="p">[</span><span class="dl">"</span><span class="s2">app_id</span><span class="dl">"</span><span class="p">],</span> <span class="nx">params</span><span class="p">[</span><span class="dl">"</span><span class="s2">app_key</span><span class="dl">"</span><span class="p">]</span>
<span class="p">);</span>
<span class="kd">var</span> <span class="nx">callback</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">success</span><span class="p">,</span> <span class="nx">status</span><span class="p">,</span> <span class="nx">response</span><span class="p">){</span>
  <span class="nb">document</span><span class="p">.</span><span class="nf">getElementById</span><span class="p">(</span><span class="dl">"</span><span class="s2">json</span><span class="dl">"</span><span class="p">).</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nf">stringify</span><span class="p">(</span><span class="nx">response</span><span class="p">);</span>
  <span class="nx">html</span> <span class="o">=</span> <span class="dl">"</span><span class="s2">&lt;table&gt;</span><span class="dl">"</span><span class="p">;</span>
  <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">response</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">&lt;tr&gt;</span><span class="dl">"</span><span class="p">;</span>
    <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">&lt;td&gt;</span><span class="dl">"</span><span class="p">;</span>
    <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">Name: &lt;span&gt;</span><span class="dl">"</span> <span class="o">+</span>
      <span class="nx">response</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">prefLabel</span> <span class="o">+</span>
      <span class="dl">"</span><span class="s2">&lt;/span&gt;</span><span class="dl">"</span><span class="p">;</span>
    <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">&lt;/td&gt;</span><span class="dl">"</span><span class="p">;</span>
    <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">&lt;/tr&gt;</span><span class="dl">"</span><span class="p">;</span>
  <span class="p">}</span>
  <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">&lt;/table&gt;</span><span class="dl">"</span><span class="p">;</span>
  <span class="nb">document</span><span class="p">.</span><span class="nf">getElementById</span><span class="p">(</span><span class="dl">"</span><span class="s2">table</span><span class="dl">"</span><span class="p">).</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">html</span><span class="p">;</span>
<span class="p">};</span>
<span class="nx">searcher</span><span class="p">.</span><span class="nf">byTag</span><span class="p">(</span>
  <span class="dl">'</span><span class="s1">Aspirin</span><span class="dl">'</span><span class="p">,</span> <span class="dl">'</span><span class="s1">5</span><span class="dl">'</span><span class="p">,</span> <span class="dl">'</span><span class="s1">4</span><span class="dl">'</span><span class="p">,</span>
  <span class="dl">'</span><span class="s1">07a84994-e464-4bbf-812a-a4b96fa3d197</span><span class="dl">'</span><span class="p">,</span>
  <span class="nx">callback</span>
<span class="p">);</span>
  <span class="nt">&lt;/script&gt;</span>
<span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>]]></content><author><name>Egon Willighagen</name></author><category term="pra3006" /><category term="html" /><summary type="html"><![CDATA[HTML (HyperText Markup Language), the language of the web, is no longer the only language of the web. But it still is the primary language in which source code of webpages is shared. Originally, HTML pages were always static: the only HTML source of a web page was that was downloaded from a website. Nowadays, much HTML the is visualized in your web browser, is generated on the fly with JavaScript. In fact, that is exactly what you will learn to do in this course.]]></summary></entry><entry><title type="html">Programming in the Life Sciences #6: functions</title><link href="https://chem-bla-ics.linkedchemistry.info/2013/10/12/programming-in-life-sciences-6-functions.html" rel="alternate" type="text/html" title="Programming in the Life Sciences #6: functions" /><published>2013-10-12T00:00:00+00:00</published><updated>2013-10-12T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2013/10/12/programming-in-life-sciences-6-functions</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2013/10/12/programming-in-life-sciences-6-functions.html"><![CDATA[<p>One key feature of programming languages is the following: first, there is linearity. This is an important point
that is not always clear to students who just start to program. In fact, ask yourself what the algorithm is for
counting the chairs in the room where you are now sitting. Could a computer do that in the same way? How should
your algorithm change? A key point is, is that the program is run step by step, in a linear way.</p>

<p>However, we very easily jump to functions. In fact, we use so many libraries nowadays, this linearity is not so
clear anymore. Things just happen with magic library calls. But at the same time, the library calls make our life
a lot easier: by using functions, we group functionality in easy to read and easier to understand blobs.</p>

<p>OK, the previous example showed that we could use the HTML <code class="language-plaintext highlighter-rouge">@onClick</code> attribute to provide further detail.
But I did not show how. This is how:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">Name: &lt;span onClick=</span><span class="se">\"</span><span class="s2">showDetails('</span><span class="dl">"</span> <span class="o">+</span>
  <span class="nf">escape</span><span class="p">(</span><span class="nx">dataJSON</span><span class="p">)</span> <span class="o">+</span> <span class="dl">"</span><span class="se">\</span><span class="s2">')</span><span class="se">\"</span><span class="s2">&gt;</span><span class="dl">"</span> <span class="o">+</span> 
  <span class="nx">response</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">prefLabel</span> <span class="o">+</span> <span class="dl">"</span><span class="s2">&lt;/span&gt;</span><span class="dl">"</span><span class="p">;</span>
</code></pre></div></div>

<p>This code adds the <code class="language-plaintext highlighter-rouge">@onClick</code> attribute and a function call to the <code class="language-plaintext highlighter-rouge">showDetails()</code> method which takes one parameter,
where we pass escaped JSON. That is non-trivial, I understand, and may be due to my limited knowledge of JavaScript.
The escaping of the JSON is needed to make quotes match in the generated HTML. In the function later, we can unescape
it and get the original JSON again. Importantly, the dataJSON data contains all the details I like to show.</p>

<p>Now, this functions needs to be defined. Yes, plural, because two functions are used in this code snippet: <code class="language-plaintext highlighter-rouge">showDetails()</code>
and <code class="language-plaintext highlighter-rouge">escape()</code>. The last is defined by one of the used libraries. The <code class="language-plaintext highlighter-rouge">showDetails()</code> function, however, I made up.
So, I had to define it elsewhere in the HTML document, and it looks like:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">showDetails</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">dataJSON</span><span class="p">){</span>
  <span class="nx">data</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nf">parse</span><span class="p">(</span><span class="nf">unescape</span><span class="p">(</span><span class="nx">dataJSON</span><span class="p">));</span>
  <span class="nb">document</span><span class="p">.</span><span class="nf">getElementById</span><span class="p">(</span><span class="dl">"</span><span class="s2">details</span><span class="dl">"</span><span class="p">).</span><span class="nx">innerHTML</span> <span class="o">=</span>
    <span class="nx">data</span><span class="p">.</span><span class="nx">_about</span><span class="p">;</span>
<span class="p">};</span>
</code></pre></div></div>

<p>This example actually gives the exact same output as the code in the previous post, but with one major difference.
We now can extend the function as much as we like, but the code to output the list of found compounds does not have
to get more complex than it already is.</p>]]></content><author><name>Egon Willighagen</name></author><category term="pra3006" /><category term="javascript" /><category term="html" /><summary type="html"><![CDATA[One key feature of programming languages is the following: first, there is linearity. This is an important point that is not always clear to students who just start to program. In fact, ask yourself what the algorithm is for counting the chairs in the room where you are now sitting. Could a computer do that in the same way? How should your algorithm change? A key point is, is that the program is run step by step, in a linear way.]]></summary></entry><entry><title type="html">Programming in the Life Sciences #4: communication from within HTML</title><link href="https://chem-bla-ics.linkedchemistry.info/2013/10/09/programming-in-life-sciences-4.html" rel="alternate" type="text/html" title="Programming in the Life Sciences #4: communication from within HTML" /><published>2013-10-09T00:00:00+00:00</published><updated>2013-10-09T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2013/10/09/programming-in-life-sciences-4</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2013/10/09/programming-in-life-sciences-4.html"><![CDATA[<p>The purpose of a web service is that you give it a question or task, and that it returns an answer. For example, we can ask the
<a href="http://www.openphacts.org/">Open PHACTS</a> platform what compounds it knows with aspirin in the name. We pass the question (with the
<a href="http://chem-bla-ics.blogspot.nl/2013/10/programming-in-life-sciences-2-accounts.html">API key</a>) and get a list of matching compounds.
Now, this communication is complex: it happens at many levels, which are spelled out in the
<a href="https://en.wikipedia.org/wiki/Internet_model">Internet Model</a>. There are various variants of the stack of communication layers,
but we are interested mostly in the top layers, at the <em>application layer</em>. In fact, for this course this model only serves as
supporting information for those who want to learn more.</p>

<p>Practically, what matters here is how to ask the question and how to understand the answer.</p>

<p>We are supported in these practicalities with JavaScript libraries, in particular the <a href="https://github.com/openphacts/ops.js">ops.js</a>
library and general <a href="https://en.wikipedia.org/wiki/JSON">JSON</a> functionality provided by most browsers (unless the student decided to use
a <em>different</em> programming language, in which there are different libraries). Personally, I have only very limited JavaScript experience,
and this mostly goes back to the good old <a href="http://www.biomedcentral.com/1471-2105/8/487">Userscript and Greasemonkey days</a> (wow! the
paper is actually the <a href="http://www.altmetric.com/details.php?citation_id=103983">4th highest scoring BMC Bioinformatics article!</a>).
But because my JavaScript knowledge is limited and rusty, I spent a good part of today, to get a basic example running. Very basic,
and barely exceeding the communication details. That is, this is the output in the browser:</p>

<p><img src="/assets/images/mcspils_jsonOutput.png" alt="" /></p>

<p>So, what does the question look like? The question is actually hardcoded in the HTML source, but the page does take two parameters:
the <code class="language-plaintext highlighter-rouge">app_key</code> and <code class="language-plaintext highlighter-rouge">app_id</code> that come <a href="http://chem-bla-ics.blogspot.nl/2013/10/programming-in-life-sciences-2-accounts.html">with your Open PHACTS account</a>.</p>

<p>The ops.js library helps us, and wraps the Open PHACTS LDA methods in JavaScript methods. Thus, rather can crafting special HTTP calls,
we use two JavaScript calls:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">searcher</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Openphacts</span><span class="p">.</span><span class="nc">ConceptWikiSearch</span><span class="p">(</span>
  <span class="dl">"</span><span class="s2">https://beta.openphacts.org</span><span class="dl">"</span><span class="p">,</span>
  <span class="nx">params</span><span class="p">[</span><span class="dl">"</span><span class="s2">app_id</span><span class="dl">"</span><span class="p">],</span> <span class="nx">params</span><span class="p">[</span><span class="dl">"</span><span class="s2">app_key</span><span class="dl">"</span><span class="p">]</span>
<span class="p">);</span>
<span class="nx">searcher</span><span class="p">.</span><span class="nf">byTag</span><span class="p">(</span>
  <span class="dl">'</span><span class="s1">Aspirin</span><span class="dl">'</span><span class="p">,</span> <span class="dl">'</span><span class="s1">20</span><span class="dl">'</span><span class="p">,</span> <span class="dl">'</span><span class="s1">4</span><span class="dl">'</span><span class="p">,</span> <span class="dl">'</span><span class="s1">07a84994-e464-4bbf-812a-a4b96fa3d197</span><span class="dl">'</span><span class="p">,</span>
  <span class="nx">callback</span>
<span class="p">);</span>
</code></pre></div></div>

<p>The first statement creates an LDA method object, while the second makes an actual question. I have not defined the callback variable,
which actually is a JavaScript function that looks like:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">callback</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">success</span><span class="p">,</span> <span class="nx">status</span><span class="p">,</span> <span class="nx">response</span><span class="p">){</span>
  <span class="kd">var</span> <span class="nx">result</span> <span class="o">=</span> <span class="nx">searcher</span><span class="p">.</span><span class="nf">parseResponse</span><span class="p">(</span><span class="nx">response</span><span class="p">);</span>
  <span class="nb">document</span><span class="p">.</span><span class="nf">getElementById</span><span class="p">(</span><span class="dl">"</span><span class="s2">output</span><span class="dl">"</span><span class="p">).</span><span class="nx">innerHTML</span> <span class="o">=</span>
    <span class="dl">"</span><span class="s2">Results: </span><span class="dl">"</span> <span class="o">+</span> <span class="nx">JSON</span><span class="p">.</span><span class="nf">stringify</span><span class="p">(</span><span class="nx">result</span><span class="p">);</span>
<span class="p">};</span>
</code></pre></div></div>

<p>When the LDA web service returns data, this method gets called, providing asynchronous functionality to keep the web page responsive.
But when called, it first parses the returned data, and then puts the JSON output as text in the HTML. The output that is given in
the earlier screenshot.</p>

<p>So, hurdle taken. From here on it’s easier. Regular looping over the results, creating some HTML output, etc. The
<a href="https://gist.github.com/egonw/6902776">full source code</a> if this example is available as Gist.</p>]]></content><author><name>Egon Willighagen</name></author><category term="pra3006" /><category term="javascript" /><category term="html" /><category term="openphacts" /><category term="doi:10.1186/1471-2105-8-487" /><summary type="html"><![CDATA[The purpose of a web service is that you give it a question or task, and that it returns an answer. For example, we can ask the Open PHACTS platform what compounds it knows with aspirin in the name. We pass the question (with the API key) and get a list of matching compounds. Now, this communication is complex: it happens at many levels, which are spelled out in the Internet Model. There are various variants of the stack of communication layers, but we are interested mostly in the top layers, at the application layer. In fact, for this course this model only serves as supporting information for those who want to learn more.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://chem-bla-ics.linkedchemistry.info/assets/images/mcspils_jsonOutput.png" /><media:content medium="image" url="https://chem-bla-ics.linkedchemistry.info/assets/images/mcspils_jsonOutput.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Programming in the Life Sciences #5: converting the results into HTML</title><link href="https://chem-bla-ics.linkedchemistry.info/2013/10/09/programming-in-life-sciences-5.html" rel="alternate" type="text/html" title="Programming in the Life Sciences #5: converting the results into HTML" /><published>2013-10-09T00:00:00+00:00</published><updated>2013-10-09T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2013/10/09/programming-in-life-sciences-5</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2013/10/09/programming-in-life-sciences-5.html"><![CDATA[<p>Now that we have <a href="http://chem-bla-ics.blogspot.nl/2013/10/programming-in-life-sciences-4.html">the communication working</a>
with the Open PHACTS LDA, it is time to make a nice GUI. I will not go into details, but we can use basic JavaScript to
iterate over the JSON results, and, for example, create a HTML table:</p>

<p><img src="/assets/images/mscpils1_output.png" alt="" /></p>

<p>In fact, I hooked in some HTML <code class="language-plaintext highlighter-rouge">onClick()</code> functionality so that when you click one of the compound names, you get further
details (under <em>Compound Details</em>), though that only outputs the ConceptWiki URI at this moment. A simple for-loop does
the heavy work:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">html</span> <span class="o">=</span> <span class="dl">"</span><span class="s2">&lt;table&gt;</span><span class="dl">"</span><span class="p">;</span>
<span class="k">for </span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">response</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">&lt;tr&gt;</span><span class="dl">"</span><span class="p">;</span>
  <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">&lt;td&gt;</span><span class="dl">"</span><span class="p">;</span>
  <span class="nx">dataJSON</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nf">stringify</span><span class="p">(</span><span class="nx">response</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
  <span class="c1">//   dataJSON.replace(/"/g, "'");</span>
  <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">Name: &lt;span&gt;</span><span class="dl">"</span> <span class="o">+</span> <span class="nx">response</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">prefLabel</span> <span class="o">+</span> <span class="dl">"</span><span class="s2">&lt;/span&gt;</span><span class="dl">"</span><span class="p">;</span>
  <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">&lt;/td&gt;</span><span class="dl">"</span><span class="p">;</span>
  <span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">&lt;/tr&gt;</span><span class="dl">"</span><span class="p">;</span>
<span class="p">}</span>
<span class="nx">html</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">&lt;/table&gt;</span><span class="dl">"</span><span class="p">;</span>
<span class="nb">document</span><span class="p">.</span><span class="nf">getElementById</span><span class="p">(</span><span class="dl">"</span><span class="s2">table</span><span class="dl">"</span><span class="p">).</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">html</span><span class="p">;</span>
</code></pre></div></div>

<p>So, we’re set to teach the students all the basics of programming: loops, variables, functions, etc.</p>]]></content><author><name>Egon Willighagen</name></author><category term="pra3006" /><category term="html" /><category term="javascript" /><summary type="html"><![CDATA[Now that we have the communication working with the Open PHACTS LDA, it is time to make a nice GUI. I will not go into details, but we can use basic JavaScript to iterate over the JSON results, and, for example, create a HTML table:]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://chem-bla-ics.linkedchemistry.info/assets/images/mscpils1_output.png" /><media:content medium="image" url="https://chem-bla-ics.linkedchemistry.info/assets/images/mscpils1_output.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Pulling out data as JSON from XHTML+RDFa</title><link href="https://chem-bla-ics.linkedchemistry.info/2010/09/10/pulling-out-data-as-json-from-xhtmlrdfa.html" rel="alternate" type="text/html" title="Pulling out data as JSON from XHTML+RDFa" /><published>2010-09-10T00:00:00+00:00</published><updated>2010-09-10T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2010/09/10/pulling-out-data-as-json-from-xhtmlrdfa</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2010/09/10/pulling-out-data-as-json-from-xhtmlrdfa.html"><![CDATA[<p>I am keen on <a href="/blog/tag/rdfa">RDFa</a> and <a href="http://sv.wikipedia.org/wiki/Resource_Description_Framework">RDF <i class="fa-solid fa-recycle fa-xs"></i></a> in general; that should not be a surprise.
RDFa is a serialization of RDF triples embedded in (X)HTML. I recently posted about <a href="https://chem-bla-ics.linkedchemistry.info/2010/08/10/xhtmlrdfa-chemical-examples.html">chemical examples of XHTML+RDFa <i class="fa-solid fa-recycle fa-xs"></i></a>.
Now, the reason for putting data in HTML as RDFa is that we can easily pull it out again, e.g. with <a href="http://www.w3.org/2007/08/pyRdfa/">this distiller</a>.
But the fun goes on, and we can actually also run SPARQL directly on it, for example with RDFaDev which I
<a href="https://chem-bla-ics.linkedchemistry.info/2010/07/19/scripts-logs-as-htmlrdfa-mix-free-text.html">recently blogged about <i class="fa-solid fa-recycle fa-xs"></i></a>.</p>

<p>Now, consider we have all these nice visualization tools written in JavaScript which can visualize data from <a href="http://www.json.org/">JSON</a> sources,
the mashup requires a JSON serialization of that data embedded in HTML pages. Now, I have no experience with the cool JavaScript tools, and hope
someone can help me out here, but the JSON bit I already <a href="http://www.semanticoverflow.com/questions/587/is-there-a-web-service-that-allow-me-to-run-sparql-against-a-xhtmlrdfa-website">got help with before on SemanticOverflow</a>
(thanx to <a href="http://www.semanticoverflow.com/users/148/comment-bot">Comment Bot</a>!). The service mentioned no longer works, but there are plenty of alternatives.</p>

<p>Now, Peter is creating this nice data set about <a href="http://wwmm.ch.cam.ac.uk/blogs/murrayrust/?p=2596">green solvents from patents</a>, and it would be great of that data ends up online as RDFa, so that we can easily visualize the trends in solvent use over the years. But as I do not have this data as XHTML+RDFa yet, you will have to do with another example: boiling points.</p>

<p>So, let’s consider the data on <a href="https://egonw.github.io/cheminformatics.classics/classic1.html">this page <i class="fa-solid fa-recycle fa-xs"></i></a>, relating paraffin molecules to boiling points, and we’ll take a complexity descriptor (<em>w0</em>, Wiener descriptor) and the boilingpoint (<em>t0</em>). so we get this SPARQL query:</p>

<pre>PREFIX cc: &lt;http://github.com/egonw/cheminformatics.classics/1/#&gt;

SELECT * {
    ?mol cc:w0 ?w ;
         cc:p0 ?p .
}
</pre>

<p>Now, we want to run this query on the aforementioned page, so we add a FROM clause:</p>

<pre>PREFIX cc: &lt;http://github.com/egonw/cheminformatics.classics/1/#&gt;

SELECT *
FROM &lt;http://www.w3.org/2007/08/pyRdfa/extract?uri=http%3A%2F%2Fegonw.github.com%2Fcheminformatics.classics%2Fclassic1.html&amp;format=pretty-xml&amp;warnings=false&amp;parser=lax&amp;space-preserve=true&gt;
{
    ?mol cc:w0 ?w ;
         cc:p0 ?p .
}
</pre>

<p>Notice the use of the distiller here. This way, with a service like <a href="http://sparql.org/sparql.html">that on sparql.org</a>, we can get JSON returned. The result is a bit verbose, but that can perhaps be tuned:</p>

<pre>{
  "head": {
    "vars": [ "w" , "p" ]
  } ,
  "results": {
    "bindings": [
      {
        "w": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "56" } ,
        "p": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "4" }
      } ,
      {
        "w": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "35" } ,
        "p": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "3" }
      }
    ]
  }
}
</pre>

<p>The point is, I am sure at least one of my readers knows how to visualize the data in <a href="http://sparql.org/sparql?query=PREFIX+cc%3A+%3Chttp%3A%2F%2Fgithub.com%2Fegonw%2Fcheminformatics.classics%2F1%2F%23%3E%0D%0A%0D%0ASELECT+%3Fw+%3Fp%0D%0AFROM+%3Chttp%3A%2F%2Fwww.w3.org%2F2007%2F08%2FpyRdfa%2Fextract%3Furi%3Dhttp%253A%252F%252Fegonw.github.com%252Fcheminformatics.classics%252Fclassic1.html%26format%3Dpretty-xml%26warnings%3Dfalse%26parser%3Dlax%26space-preserve%3Dtrue%3E%0D%0A%7B%0D%0A++++%3Fmol+cc%3Aw0+%3Fw+%3B%0D%0A+++++++++cc%3Ap0+%3Fp+.%0D%0A%7D&amp;default-graph-uri=&amp;stylesheet=%2Fxml-to-html.xsl&amp;output=json&amp;force-accept=text%2Fplain">this JSON</a> with, for example, <a href="http://code.google.com/apis/chart/">Google Chart</a>, particularly, because all the mashing up is embedded in the just linked-to, though obscure, URL. And, if it helps, you can otherwise use the <a href="http://sparql.org/sparql?query=PREFIX+cc%3A+%3Chttp%3A%2F%2Fgithub.com%2Fegonw%2Fcheminformatics.classics%2F1%2F%23%3E%0D%0A%0D%0ASELECT+%3Fw+%3Fp%0D%0AFROM+%3Chttp%3A%2F%2Fwww.w3.org%2F2007%2F08%2FpyRdfa%2Fextract%3Furi%3Dhttp%253A%252F%252Fegonw.github.com%252Fcheminformatics.classics%252Fclassic1.html%26format%3Dpretty-xml%26warnings%3Dfalse%26parser%3Dlax%26space-preserve%3Dtrue%3E%0D%0A%7B%0D%0A++++%3Fmol+cc%3Aw0+%3Fw+%3B%0D%0A+++++++++cc%3Ap0+%3Fp+.%0D%0A%7D&amp;default-graph-uri=&amp;stylesheet=%2Fxml-to-html.xsl&amp;output=csv&amp;force-accept=text%2Fplain">CSV</a> or <a href="http://sparql.org/sparql?query=PREFIX+cc%3A+%3Chttp%3A%2F%2Fgithub.com%2Fegonw%2Fcheminformatics.classics%2F1%2F%23%3E%0D%0A%0D%0ASELECT+%3Fw+%3Fp%0D%0AFROM+%3Chttp%3A%2F%2Fwww.w3.org%2F2007%2F08%2FpyRdfa%2Fextract%3Furi%3Dhttp%253A%252F%252Fegonw.github.com%252Fcheminformatics.classics%252Fclassic1.html%26format%3Dpretty-xml%26warnings%3Dfalse%26parser%3Dlax%26space-preserve%3Dtrue%3E%0D%0A%7B%0D%0A++++%3Fmol+cc%3Aw0+%3Fw+%3B%0D%0A+++++++++cc%3Ap0+%3Fp+.%0D%0A%7D&amp;default-graph-uri=&amp;stylesheet=%2Fxml-to-html.xsl&amp;output=tsv&amp;force-accept=text%2Fplain">TSV</a> output. The output of that is even more simple (CSV):</p>

<pre>w,p
56,4
286,9
35,3
220,8
20,2
84,5
10,1
165,7
120,6
</pre>

<p>The first one who can use one of the above URLs to extract the data from that XHTML+RDFa page to create a scatter plot in a HTML page with some JavaScript library, wins a free mention in my blog! ;)</p>]]></content><author><name>Egon Willighagen</name></author><category term="chemistry" /><category term="html" /><category term="rdfa" /><category term="sparql" /><category term="json" /><summary type="html"><![CDATA[I am keen on RDFa and RDF in general; that should not be a surprise. RDFa is a serialization of RDF triples embedded in (X)HTML. I recently posted about chemical examples of XHTML+RDFa . Now, the reason for putting data in HTML as RDFa is that we can easily pull it out again, e.g. with this distiller. But the fun goes on, and we can actually also run SPARQL directly on it, for example with RDFaDev which I recently blogged about .]]></summary></entry><entry><title type="html">Added a Simile Timeline to my homepage</title><link href="https://chem-bla-ics.linkedchemistry.info/2010/08/30/added-simile-timeline-to-my-homepage.html" rel="alternate" type="text/html" title="Added a Simile Timeline to my homepage" /><published>2010-08-30T00:00:00+00:00</published><updated>2010-08-30T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2010/08/30/added-simile-timeline-to-my-homepage</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2010/08/30/added-simile-timeline-to-my-homepage.html"><![CDATA[<p>I finally got around to updating my <a href="http://egonw.github.com/">homepage</a>. Not entirely done yet, but it was overdue. The changelog
includes a removal of the sidebar, which did not look nice when the page was embedded in my blog (the <em>Home</em> tab),
<a href="http://xmlns.com/foaf/spec/">foaf:interest</a> <a href="http://www.w3.org/TR/xhtml-rdfa-primer/">RDFa</a> annotation, a ToC line just below
the header, and a <a href="http://draft.blogger.com/www.simile-widgets.org/timeline/">Simile Timeline</a> widget with my research positions
and a selection of peer-reviewed papers:</p>

<p><img src="/assets/images/egonw1.png" alt="" /></p>]]></content><author><name>Egon Willighagen</name></author><category term="rdfa" /><category term="html" /><summary type="html"><![CDATA[I finally got around to updating my homepage. Not entirely done yet, but it was overdue. The changelog includes a removal of the sidebar, which did not look nice when the page was embedded in my blog (the Home tab), foaf:interest RDFa annotation, a ToC line just below the header, and a Simile Timeline widget with my research positions and a selection of peer-reviewed papers:]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://chem-bla-ics.linkedchemistry.info/assets/images/egonw1.png" /><media:content medium="image" url="https://chem-bla-ics.linkedchemistry.info/assets/images/egonw1.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">XHTML+RDFa: chemical examples</title><link href="https://chem-bla-ics.linkedchemistry.info/2010/08/10/xhtmlrdfa-chemical-examples.html" rel="alternate" type="text/html" title="XHTML+RDFa: chemical examples" /><published>2010-08-10T00:00:00+00:00</published><updated>2010-08-10T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2010/08/10/xhtmlrdfa-chemical-examples</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2010/08/10/xhtmlrdfa-chemical-examples.html"><![CDATA[<p>Steffen <a href="https://chem-bla-ics.linkedchemistry.info/2010/08/09/xhtmlrdfa-template.html?showComment=1281418346085#c5562162287116420044">asked <i class="fa-solid fa-recycle fa-xs"></i></a>
me if I could also provide a few examples on how to actually put RDF triples in the HTML, as the
<a href="https://chem-bla-ics.linkedchemistry.info/2010/08/09/xhtmlrdfa-template.html">template <i class="fa-solid fa-recycle fa-xs"></i></a> I gave yesterday is a mere empty canvas to draw the
triples on. There are actually <a href="https://chem-bla-ics.linkedchemistry.info/tag/rdfa">various examples <i class="fa-solid fa-recycle fa-xs"></i></a>
in my blog, which I will summarize here.</p>

<p>Before I start, I like to put some emphasize on the following <a href="http://www.w3.org/TR/xhtml-rdfa-primer/">RDFa</a> pattern. An RDF
resource that serves as subject is always mapped to a HTML element. This can be a div element, but also other elements, as we
will see in the example.</p>

<h3 id="a-molecule-smiles">A molecule SMILES</h3>

<p>The <a href="https://chem-bla-ics.linkedchemistry.info/2006/12/10/including-smiles-cml-and-inchi-in.html">oldest RDFa example <i class="fa-solid fa-recycle fa-xs"></i></a> in my blog is from</p>
<ol>
  <li>That was almost two years before the final <a href="http://www.w3.org/TR/2008/REC-rdfa-syntax-20081014">Recommendation</a>, and
is not quite accurate anymore. But here’s the correct version:</li>
</ol>

<script src="https://gist.github.com/517826.js?file=gistfile1.html">
</script>

<p>This example shows how to embed the SMILES string CCO semantically. This example shows that the outer most span element is
used to define the subject of the <a href="http://www.w3.org/TR/rdf-concepts/#section-triples">RDF triple</a>, using the @about
attribute to define the <a href="http://www.w3.org/TR/rdf-concepts/#section-URI-Vocabulary">URI of the resource</a>: <em>#ethanol</em>.
Note that this URI is relative to the URI of the HTML page in which it is embedded. Later we will see an example with a full URI.</p>

<h3 id="but-i-dont-want-to-hack-html">But I don’t want to hack HTML!</h3>

<p>Yeah, fair point. Just make a point with your publisher when you submit a new paper. It is the duty of the publisher and
your software vendor to do this right. In 2008 I wrote a small <a href="https://wiki.mozilla.org/Labs/Ubiquity">Ubiquity</a> script
to automagically
<a href="https://chem-bla-ics.linkedchemistry.info/2008/09/01/ubiquity-fun-entering-semantic-markup.html">convert an InChI into semantified HTML content <i class="fa-solid fa-recycle fa-xs"></i></a>.
But I am not sure this script still works. If interesting, let me know, and I will revive the Firefox thingy.</p>

<h3 id="and-why-would-i-want-to-do-it-anyway">And why would I want to do it anyway??</h3>

<p>Because software can more easily understand what you mean. This is why Google is now pushing
<a href="http://googlewebmastercentral.blogspot.com/2009/05/introducing-rich-snippets.html">rich snippets</a>.
<a href="http://cb.openmolecules.net/">Chemical blogspace</a> understands them too, allowing you to see
<a href="https://chem-bla-ics.linkedchemistry.info/2007/05/05/cb-comments-for-inchis.html">blog posts about molecules on other webpages <i class="fa-solid fa-recycle fa-xs"></i></a>.
With a simple bit of JavaScript you can link from your webpages, you can
<a href="https://chem-bla-ics.linkedchemistry.info/2007/01/02/chemistry-in-html-javascript-from.html">enrich your HTML sites with semantic chemistry <i class="fa-solid fa-recycle fa-xs"></i></a> yourself.
<a href="http://www.bioclipse.net/">Bioclipse</a> also has no problem with extracting
<a href="https://chem-bla-ics.linkedchemistry.info/2010/01/28/semantic-web-features-in-bioclipse-22.html">the RDF from HTML <i class="fa-solid fa-recycle fa-xs"></i></a>.
Even <a href="https://chem-bla-ics.linkedchemistry.info/2010/07/19/scripts-logs-as-htmlrdfa-mix-free-text.html">Firefox can understand it <i class="fa-solid fa-recycle fa-xs"></i></a>.
Really, there is no end to it.</p>

<p>Of course, why you should do this comes basically down to Molecular Chemometrics Principle #2, but I have not written that
on up yet (see also <a href="https://chem-bla-ics.linkedchemistry.info/2010/08/09/molecular-chemometrics-principles-1.html">McPrinciple #1 <i class="fa-solid fa-recycle fa-xs"></i></a>).</p>

<h3 id="reporting-problems-with-molecular-representations">Reporting problems with molecular representations</h3>

<p>More recently, I reported about using RDFa in human readable log file for computations I am doing (see
<a href="https://chem-bla-ics.linkedchemistry.info/2010/07/19/scripts-logs-as-htmlrdfa-mix-free-text.html">Scripts logs as HTML+RDFa: mix free text reporting with CSV <i class="fa-solid fa-recycle fa-xs"></i></a>). 
That code looks like:</p>

<script src="https://gist.github.com/517889.js?file=gistfile1.html"></script>

<p>This example uses a <em>div</em> element to host the subject resource. Again, the resource URI is relative to the URI of
the document, e.g. <a href="http://rdf.farmbio.uu.se/uppmax-cdk/results.html">this one</a>. We can also note a new attribute,
<em>@typeof</em>, which is here used to define the <a href="http://www.w3.org/TR/rdf-schema/#ch_type">rdf:type</a> of the <em>#200234</em> resource.</p>

<p>This code snippet does not define the <em>um</em> namespace, which was done elsewhere in the HTML. Moreover, this
code snippet does not actually reuse existing ontologies, which is highly recommended. The
<a href="https://chem-bla-ics.linkedchemistry.info/2010/06/26/it-is-my-great-pleasure-to-present-full.html">upcoming RDF symposium in Boston <i class="fa-solid fa-recycle fa-xs"></i></a>
will tell you all about chemical ontologies in the RDF world (see <a href="http://egonw.github.com/acsrdf2010/">this detailed program</a>,
which itself is HTML+RDFa!). But, if you would just overlook the ad hoc namespaces used, you might appreciate the
nesting: besides the compound (<em>#200234</em>), a second resource is defined (#error0). In total, this example contains six triples.</p>

<p>Meanwhile, the output simply looks like:</p>

<div about="#200234" typeof="um:Compound">CID <span property="um:cid" datatype="xsd:integer">200234</span>: <span rel="um:hasProblem"><span about="#error0" typeof="um:Problem"><span property="um:hasElement">Ti</span><span property="um:hasIndex" datatype="xsd:integer">1</span></span></span></div>

<h3 id="a-molecule-table">A molecule table</h3>

<p>This third, and for now last, example shows several other features. This HTML snippet show a one entry
molecule table, very much like those molecular spreadsheets in Excel, but than right here in your webbrowser.
(Can you imagine what happens if we mash this up with
<a href="https://doi.org/10.59350/3basz-t0n97 :">JavaScript molecular viewers <i class="fa-solid fa-recycle fa-xs"></i></a></p>

<script src="https://gist.github.com/517927.js?file=gistfile1.html"></script>

<p>First of all, the <a href="http://chem-bla-ics.blogspot.com/search?q=rdf.openmolecules.net">rdf.openmolecules.net</a> project
is used to construct an absolute URI for the molecule. The table then gives some properties of the molecule:
its name (using <a href="http://dublincore.org/">Dublin Core</a>, though perhaps <a href="http://www.w3.org/TR/rdf-schema/#ch_label">rdfs:label</a>
is better), the boiling point (nicely encoded as <em>t0</em> in <a href="https://doi.org/10.1021/ja01193a005">this 1947 paper</a>),
two cheminformatics descriptors, and the SMILES, using the same approach as the first example in this post.</p>

<p>The output of this table looks like:</p>

<table xmlns="http://www.w3.org/1999/xhtml" xmlns:cc="http://github.com/egonw/cheminformatics.classics/1/#" xmlns:dc="http://purl.org/dc/terms/" xmlns:chem="http://www.blueobelisk.org/chemistryblogs/">
  <tbody><tr typeof="cc:molecule" about="http://rdf.openmolecules.net/?InChI=1/C4H10/c1-3-4-2/h3-4H2,1-2H3">
    <td><span property="dc:title">n-Butane</span></td>
    <td><span property="cc:t0">-0.5</span></td>
    <td><span property="cc:w0">10</span></td>
    <td><span property="cc:p0">1</span></td>
    <td><span property="chem:smiles">CCCC</span></td>
  </tr>
  </tbody>
</table>

<p>I will shortly blog about the source of the above code snippet, but you are invited to go ahead and checkout
<a href="http://github.com/egonw">my GitHub activity</a> (<a href="http://github.com/egonw.atom">RSS</a>).</p>

<p>Steffen, I think these examples should get you pretty far, but please let me know if you have further questions!</p>]]></content><author><name>Egon Willighagen</name></author><category term="html" /><category term="rdf" /><category term="justdoi:10.59350/3basz-t0n97" /><category term="justdoi:10.1021/ja01193a005" /><category term="rdfa" /><summary type="html"><![CDATA[Steffen asked me if I could also provide a few examples on how to actually put RDF triples in the HTML, as the template I gave yesterday is a mere empty canvas to draw the triples on. There are actually various examples in my blog, which I will summarize here.]]></summary></entry><entry><title type="html">XHTML+RDFa Template</title><link href="https://chem-bla-ics.linkedchemistry.info/2010/08/09/xhtmlrdfa-template.html" rel="alternate" type="text/html" title="XHTML+RDFa Template" /><published>2010-08-09T00:00:00+00:00</published><updated>2010-08-09T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2010/08/09/xhtmlrdfa-template</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2010/08/09/xhtmlrdfa-template.html"><![CDATA[<p>There was some <a href="http://jessykate.posterous.com/activity-streams-for-open-science">more</a> <a href="http://jessykate.posterous.com/open-science-microformats-initial-thoughts">discussion</a>
on machine readability of notebooks again, something I have <a href="http://chem-bla-ics.blogspot.com/search?q=RDFa&amp;max-results=20">blogged</a>
<a href="http://chem-bla-ics.blogspot.com/search?q=microformats&amp;max-results=20">about</a> for a long time now.</p>

<p>One technical approach to implement the idea of adding semantic to text in HTML pages is <a href="http://www.w3.org/TR/xhtml-rdfa-primer/">RDFa</a>.
But with any technology, scientists seems to have an in-built deficiency of thinking clearly, and anything beyond being able to format
your bibliography with the correct <strong>bold</strong> and <em>italic</em> seems to be a bit much asked.</p>

<p>Anyway, for future reference, this is a basic HTML framework for embedding RDFa:</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
<span class="cp">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
    "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"&gt;</span>
<span class="nt">&lt;html</span> <span class="na">xmlns=</span><span class="s">"http://www.w3.org/1999/xhtml"</span>
    <span class="na">version=</span><span class="s">"XHTML+RDFa 1.0"</span> <span class="na">xml:lang=</span><span class="s">"en"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;head&gt;</span>
    <span class="nt">&lt;title&gt;</span>ACS RDF Symposium, Boston, August 2010<span class="nt">&lt;/title&gt;</span>
  <span class="nt">&lt;/head&gt;</span>
  <span class="nt">&lt;body&gt;</span>
  <span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>

<p>Perhaps you prefer the <a href="http://github.com/egonw/cheminformatics.classics/raw/master/xhtml+rdfa.template.html">raw source</a>.</p>]]></content><author><name>Egon Willighagen</name></author><category term="html" /><category term="rdf" /><category term="rdfa" /><summary type="html"><![CDATA[There was some more discussion on machine readability of notebooks again, something I have blogged about for a long time now.]]></summary></entry><entry><title type="html">Script logs as HTML+RDFa: mix free text reporting with CSV</title><link href="https://chem-bla-ics.linkedchemistry.info/2010/07/19/scripts-logs-as-htmlrdfa-mix-free-text.html" rel="alternate" type="text/html" title="Script logs as HTML+RDFa: mix free text reporting with CSV" /><published>2010-07-19T00:00:00+00:00</published><updated>2010-07-19T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2010/07/19/scripts-logs-as-htmlrdfa-mix-free-text</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2010/07/19/scripts-logs-as-htmlrdfa-mix-free-text.html"><![CDATA[<p><a href="http://blogs.talis.com/nodalities/author/richard-wallis/">Richard</a> (<a href="http://www.talis.com/">Talis</a>) wrote up a
<a href="http://blogs.talis.com/nodalities/2010/07/the-data-publishing-three-step.php">three-step tutorial</a> on how to publish
your data. I think I would be more than happy if scientists reached step 1. Related, Ola asked me a while ago if I
was interested in using the computing facilities of <a href="http://www.uppmax.uu.se/">UPPMAX</a>, and I was. But until this
weekend I did not have the time or energy to give it a spin. If you are puzzled how the heck I see those two items
related, read on :)</p>

<p>Two days later, today, I ran my first analysis. Still a test run, but using the <a href="http://cdk.sf.net/">CDK</a> to perceive
atom types on the first 2.5 GB of <a href="http://pubchem.ncbi.nlm.nih.gov/">PubChem</a> data. The full data set is now 80 GB,
and I will start doing this analysis today. You might remember this already two years ago (see
<a href="https://chem-bla-ics.linkedchemistry.info/2008/05/03/wicked-chemistry-and-unit-testing.html">Wicked chemistry and unit testing <i class="fa-solid fa-recycle fa-xs"></i></a>)
for a small subset, but only now have the power to analyze all compounds. The UPPMAX system I work on has 348, each
with 8 cores. Each core has 3 GB of memory, but I am using the
<a href="http://pele.farmbio.uu.se/nightly-1.2.3/cdk-javadoc-1.2.4/org/openscience/cdk/io/iterator/IteratingPCCompoundXMLReader.html">IteratingPCCompoundXMLReader</a>
class anyway. Analyzing the 2.5 GB of data was done using 50 nodes, and finished in about a minute. Nice :)</p>

<p>Now, this first run dumped the results as a plain text file, looking like:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>CID 200234: Ti  1
CID 200235: Ti 1
CID 200237: Sb 1 Sb 2
CID 200365: S 1
CID 200761: Hg 1
CID 201374: Ce 1 Ce 2
CID 201395: As 1 
</code></pre></div></div>

<p>Simple and effective.</p>

<p>Or? And this is where the two items outlined in the first paragraph meet. No, this is not useful. Since the output
is from an analysis of PubChem, I’m sure you already figured out that the first two columns indicate the compound
being analyzed. You might also work out that then the elements are given for which the atom type perception failed.
You may even figure out that the number is likely to be the index in the connection table representation of the
molecule. Right?</p>

<p>But what about machine readability? I could, of course, write the output as CSV, but then I would loose my ability
to write the report in human readable format. And moreover, the list of failing atom types does not have a fixed
length, as you can see in the example lines given earlier.</p>

<p>Now, this is where RDF comes in. If I create my output as HTML+RDFa, I can do fancy stuff. My results page could
link directly to PubChem, so that I can inspect the actual compound. Though I could do that even with merely HTML.
But with <a href="http://www.w3.org/TR/xhtml-rdfa-primer/">RDFa</a>, I can actually make my free text log output machine
readable. I can accurately annotate what bits are informative:</p>

<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">about=</span><span class="s">"#200234"</span> <span class="na">typeof=</span><span class="s">"um:Compound"</span><span class="nt">&gt;</span>CID
  <span class="nt">&lt;span</span> <span class="na">property=</span><span class="s">"um:cid"</span> <span class="na">datatype=</span><span class="s">"xsd:integer"</span><span class="nt">&gt;</span>200234<span class="nt">&lt;/span&gt;</span>:
  <span class="nt">&lt;span</span> <span class="na">rel=</span><span class="s">'um:hasProblem'</span><span class="nt">&gt;</span>
    <span class="nt">&lt;span</span> <span class="na">about=</span><span class="s">'#error0'</span> <span class="na">typeof=</span><span class="s">'um:Problem'</span><span class="nt">&gt;</span>
      <span class="nt">&lt;span</span> <span class="na">property=</span><span class="s">'um:hasElement'</span><span class="nt">&gt;</span>Ti<span class="nt">&lt;/span&gt;</span>
      <span class="nt">&lt;span</span> <span class="na">property=</span><span class="s">'um:hasIndex'</span> <span class="na">datatype=</span><span class="s">'xsd:integer'</span><span class="nt">&gt;</span>1<span class="nt">&lt;/span&gt;</span>
    <span class="nt">&lt;/span&gt;</span>
  <span class="nt">&lt;/span&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</code></pre></div></div>

<p>The file is not backed up by an OWL ontology, but where possible one would do that. Reuse of ontologies is a good
thing (e.g. use a service like <a href="http://schemapedia.com/">Schemapedia</a>).</p>

<p>Now, I can easily open up this file in a web browser (follow <a href="http://rdf.farmbio.uu.se/uppmax-cdk/results.html">this link</a>)
and get the same view as above. But I can also import the file directly into Bioclipse (see
<a href="https://chem-bla-ics.linkedchemistry.info/2010/01/28/semantic-web-features-in-bioclipse-22.html">Semantic Web features in Bioclipse 2.2 <i class="fa-solid fa-recycle fa-xs"></i></a>),
or in any other tool that supports RDFa. I can then use SPARQL to do some first analysis, for example, with:</p>

<div class="language-sparql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">PREFIX</span><span class="w"> </span><span class="nn">um</span><span class="o">:</span><span class="w"> </span><span class="nn">&lt;http://egonw.github.com/uppmax&gt;</span><span class="w">

</span><span class="k">SELECT</span><span class="w"> </span><span class="nv">?elem</span><span class="w"> </span><span class="p">(</span><span class="nb">count</span><span class="p">(</span><span class="o">*</span><span class="p">)</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="nv">?count</span><span class="p">)</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="nv">?compound</span><span class="w"> </span><span class="nn">um</span><span class="o">:</span><span class="ss">cid</span><span class="w"> </span><span class="nv">?cid</span><span class="p">;</span><span class="w">
     </span><span class="nn">um</span><span class="o">:</span><span class="ss">hasProblem</span><span class="w"> </span><span class="nv">?problem</span><span class="w"> </span><span class="p">.</span><span class="w">
  </span><span class="nv">?problem</span><span class="w"> </span><span class="nn">um</span><span class="o">:</span><span class="ss">hasElement</span><span class="w"> </span><span class="nv">?elem</span><span class="w"> </span><span class="p">.</span><span class="w">
</span><span class="p">}</span><span class="w"> </span><span class="k">GROUP</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="nv">?elem</span><span class="w"> </span><span class="k">ORDER</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="nv">?elem</span><span class="w">
</span></code></pre></div></div>

<p>Combine that with the <a href="http://rdfadev.sourceforge.net/">RDFaDev</a> tool I wrote about last week (see
<a href="https://chem-bla-ics.linkedchemistry.info/2010/07/16/rdfadev-htmlrdfa-development-with.html">RDFaDev: HTML+RDFa development with FireFox <i class="fa-solid fa-recycle fa-xs"></i></a>).
Now you should get some feeling of the advantages of using Open Standards: I can do some initial analysis of the results,
just right there in the web browser you have open anyway:</p>

<p><img src="/assets/images/rdfaLogfiles.png" alt="" /></p>

<p>Therefore, next time you ask your data analyst to perform some calculation, insist that he sends you HTML+RDFa log files with
results. Better, ask him to put it online, and you immediately reach
<a href="http://blogs.talis.com/nodalities/2010/07/the-data-publishing-three-step.php">Step 3</a>
in the analysis by David.</p>]]></content><author><name>Egon Willighagen</name></author><category term="html" /><category term="rdf" /><category term="sparql" /><category term="rdfa" /><summary type="html"><![CDATA[Richard (Talis) wrote up a three-step tutorial on how to publish your data. I think I would be more than happy if scientists reached step 1. Related, Ola asked me a while ago if I was interested in using the computing facilities of UPPMAX, and I was. But until this weekend I did not have the time or energy to give it a spin. If you are puzzled how the heck I see those two items related, read on :)]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://chem-bla-ics.linkedchemistry.info/assets/images/rdfaLogfiles.png" /><media:content medium="image" url="https://chem-bla-ics.linkedchemistry.info/assets/images/rdfaLogfiles.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">RDFaDev: HTML+RDFa development with FireFox</title><link href="https://chem-bla-ics.linkedchemistry.info/2010/07/16/rdfadev-htmlrdfa-development-with.html" rel="alternate" type="text/html" title="RDFaDev: HTML+RDFa development with FireFox" /><published>2010-07-16T00:10:00+00:00</published><updated>2010-07-16T00:10:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2010/07/16/rdfadev-htmlrdfa-development-with</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2010/07/16/rdfadev-htmlrdfa-development-with.html"><![CDATA[<p><a href="http://www.blogger.com/profile/14759936105694870796">Celso</a> informed me in <a href="https://chem-bla-ics.linkedchemistry.info/2007/06/27/chemical-rdfa-with-operator-in-firefox.html">this old post <i class="fa-solid fa-recycle fa-xs"></i></a>
about an alternative to <a href="https://chem-bla-ics.linkedchemistry.info/2007/08/22/operator-08-released-new-sechemtic-user.html">Operator <i class="fa-solid fa-recycle fa-xs"></i></a> for RDFa handling in browsers, or
<a href="http://firefox.com/">Firefox</a> in this case: the <a href="http://rdfadev.sourceforge.net/">RDFaDev add-on</a>. It works quite well, extracts the RDFa, reports common problems, and
even allows running SPARQL directly on the web page, all from within a browser pop up window:</p>

<p><img src="/assets/images/ffRDFa1.png" alt="" /></p>]]></content><author><name>Egon Willighagen</name></author><category term="rdf" /><category term="html" /><category term="rdfa" /><summary type="html"><![CDATA[Celso informed me in this old post about an alternative to Operator for RDFa handling in browsers, or Firefox in this case: the RDFaDev add-on. It works quite well, extracts the RDFa, reports common problems, and even allows running SPARQL directly on the web page, all from within a browser pop up window:]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://chem-bla-ics.linkedchemistry.info/assets/images/ffRDFa1.png" /><media:content medium="image" url="https://chem-bla-ics.linkedchemistry.info/assets/images/ffRDFa1.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>