From 40130b273afb35b153f68b21ebd1c5e78745e1e3 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Mon, 9 Dec 2013 16:50:22 +0100
Subject: [PATCH] Use Jinja2 for description extractor

---
 mutalyzer/templates/descriptionExtract.html   | 109 -----------------
 .../templates/description_extractor.html      | 111 ++++++++++++++++++
 mutalyzer/templates/syntax_checker.html       |   2 +-
 mutalyzer/website.py                          |  13 +-
 4 files changed, 118 insertions(+), 117 deletions(-)
 delete mode 100644 mutalyzer/templates/descriptionExtract.html
 create mode 100644 mutalyzer/templates/description_extractor.html

diff --git a/mutalyzer/templates/descriptionExtract.html b/mutalyzer/templates/descriptionExtract.html
deleted file mode 100644
index 27551f31..00000000
--- a/mutalyzer/templates/descriptionExtract.html
+++ /dev/null
@@ -1,109 +0,0 @@
-<html>
-  <head>
-    <link rel="stylesheet"
-      type="text/css"
-      href="static/css/style.css">
-    <title></title>
-  </head>
-  <body>
-    <div metal:define-macro="content">
-      <center>
-        <h3>Variant Description Extractor</h3>
-      </center>
-      <div> <!-- Remove this div later. -->
-        <b style="color: red">Note that this is an experimental service.</b>
-        <br>
-        <br>
-        Extract the HGVS variant description from a reference sequence and an
-        observed sequence. For now, we require the user to fill in two
-        sequences. After the testing phase, we plan to use the underlying
-        algorithm for:
-        <ul>
-          <li>
-            Disambiguation in the name checker. This will enable full support
-            for complex variants.
-          </li>
-          <li>
-            Comparison of two reference sequences. Useful for migrating a
-            variant description to an other reference sequence.
-          </li>
-          <li>
-            Implementation of a Reference Sequence Editor.
-          </li>
-        </ul>
-        <br>
-      </div>
-      <div style="border: 1px solid grey; background-color: aliceblue; padding: 20px;">
-        <form action = "" method = "post">
-          Please supply a reference sequence and an observed sequence.<br>
-          <br>
-          <div style="border: 1px solid grey; padding: 20px">
-            <b>Reference sequence:</b><br>
-            <br>
-            Example: <tt>ATGATGATCAGATACAGTGTGATACAGGTAGTTAGACAA</tt><br>
-            <br>
-            <input
-              type = "text"
-              name = "referenceSeq"
-              tal:attributes = "value lastReferenceSeq"
-              style = "width:100%"
-            ><br>
-            <input type="button" value="Clear field" onclick="clearField(this.form, 'referenceSeq');">
-          </div>
-          <br>
-          <div style="border: 1px solid grey; padding: 20px">
-            <b>Observed sequence:</b><br>
-            <br>
-            Example: <tt>ATGATTTGATCAGATACATGTGATACCGGTAGTTAGGACAA</tt><br>
-            <br>
-            <input
-              type = "text"
-              name = "variantSeq"
-              tal:attributes = "value lastVariantSeq"
-              style = "width:100%"
-            ><br>
-            <input type="button" value="Clear field" onclick="clearField(this.form, 'variantSeq');">
-          </div>
-          <br>
-          <input type="submit" value="Submit">
-          <a href="https://humgenprojects.lumc.nl/trac/mutalyzer/wiki/DescriptionExtractor">Help</a>
-        </form>
-      </div>
-      <div tal:condition = "description">
-        <br>
-        <h3>Variant Description Extractor results:</h3>
-        <div class="messages">
-          <p tal:repeat = "m messages" tal:content = "m/description"
-            tal:attributes = "class m/class; title string:${m/level} (origin: ${m/origin})"></p>
-          <p tal:content = "summary"></p>
-        </div>
-        <div tal:condition = "not:errors">
-          <br>
-          <b>Genomic description:</b><br>
-          <br>
-          <tt>g.<div tal:replace = "description"></div></tt>
-          <br>
-          <br>
-          <br>
-          <b>Overview of the raw variants:</b><br>
-          <br>
-          <table class = "laTable">
-            <tr>
-              <td>Start</td>
-              <td>End</td>
-              <td>Type</td>
-              <td>Deleted</td>
-              <td>Inserted</td>
-              <td>Shift</td>
-              <td>Description</td>
-            </tr>
-            <tr tal:repeat = "i visualisation">
-              <td tal:repeat = "j i" tal:content = "j"></td>
-            </tr>
-          </table>
-        </div>
-      </div> <!-- description -->
-      <br>
-    </div>
-  </body>
-</html>
diff --git a/mutalyzer/templates/description_extractor.html b/mutalyzer/templates/description_extractor.html
new file mode 100644
index 00000000..7d2b5c11
--- /dev/null
+++ b/mutalyzer/templates/description_extractor.html
@@ -0,0 +1,111 @@
+{% extends "base.html" %}
+
+{% set active_page = "description-extractor" %}
+{% set page_title = "Variant Description Extractor" %}
+
+{% block content %}
+
+<p>
+<b style="color: red">Note that this is an experimental service.</b>
+</p>
+
+<p>
+Extract the HGVS variant description from a reference sequence and an
+observed sequence. For now, we require the user to fill in two
+sequences. After the testing phase, we plan to use the underlying
+algorithm for:
+</p>
+
+<ul>
+  <li>
+    Disambiguation in the name checker. This will enable full support
+    for complex variants.
+  </li>
+  <li>
+    Comparison of two reference sequences. Useful for migrating a
+    variant description to an other reference sequence.
+  </li>
+  <li>
+    Implementation of a Reference Sequence Editor.
+  </li>
+</ul>
+
+<div style="border: 1px solid grey; background-color: aliceblue; padding: 20px;">
+  <form action = "" method = "post">
+    Please supply a reference sequence and an observed sequence.<br>
+    <br>
+    <div style="border: 1px solid grey; padding: 20px">
+      <b>Reference sequence:</b><br>
+      <br>
+      Example: <tt>ATGATGATCAGATACAGTGTGATACAGGTAGTTAGACAA</tt><br>
+      <br>
+      <input
+        type = "text"
+        name = "referenceSeq"
+        value = "{{ lastReferenceSeq|e }}"
+        style = "width:100%"
+      ><br>
+      <input type="button" value="Clear field" onclick="clearField(this.form, 'referenceSeq');">
+    </div>
+    <br>
+    <div style="border: 1px solid grey; padding: 20px">
+      <b>Observed sequence:</b><br>
+      <br>
+      Example: <tt>ATGATTTGATCAGATACATGTGATACCGGTAGTTAGGACAA</tt><br>
+      <br>
+      <input
+        type = "text"
+        name = "variantSeq"
+        value = "{{ lastVariantSeq|e }}"
+        style = "width:100%"
+      ><br>
+      <input type="button" value="Clear field" onclick="clearField(this.form, 'variantSeq');">
+    </div>
+    <br>
+    <input type="submit" value="Submit">
+    <a href="https://humgenprojects.lumc.nl/trac/mutalyzer/wiki/DescriptionExtractor">Help</a>
+  </form>
+</div>
+
+{% if description is defined %}
+  <h3>Variant Description Extractor results:</h3>
+
+  <div class="messages">
+    {% for m in messages %}
+      <p class="{{ m.class|e }}" title="{{ m.level|e }} (origin: {{ m.origin|e }})">{{ m.description|e }}</p>
+    {% endfor %}
+    <p>{{ summary|e }}</p>
+  </div>
+
+  {% if not errors %}
+    <p>
+    <b>Genomic description:</b>
+    </p>
+    <p>
+    <tt>g.{{ description|e }}</tt>
+    </p>
+    <p>
+    <b>Overview of the raw variants:</b>
+    </p>
+    <table class = "laTable">
+      <tr>
+        <td>Start</td>
+        <td>End</td>
+        <td>Type</td>
+        <td>Deleted</td>
+        <td>Inserted</td>
+        <td>Shift</td>
+        <td>Description</td>
+      </tr>
+      {% for i in visualisation %}
+        <tr>
+          {% for j in i %}
+            <td>{{ j|e }}</td>
+          {% endfor %}
+        </tr>
+      {% endfor %}
+    </table>
+  {% endif %}
+{% endif %}
+
+{% endblock content %}
diff --git a/mutalyzer/templates/syntax_checker.html b/mutalyzer/templates/syntax_checker.html
index 1052c464..822b532c 100644
--- a/mutalyzer/templates/syntax_checker.html
+++ b/mutalyzer/templates/syntax_checker.html
@@ -33,7 +33,7 @@
   <br>
 </div>
 <br>
-{% if variant %}
+{% if variant is defined %}
   <h3>Variant syntax checker results:</h3>
   {% if parseError %}
     <div class="messages">
diff --git a/mutalyzer/website.py b/mutalyzer/website.py
index 53e65cfd..ecbdf93b 100644
--- a/mutalyzer/website.py
+++ b/mutalyzer/website.py
@@ -459,7 +459,7 @@ class SyntaxCheck:
         counter = Db.Counter()
         counter.increment('syntaxcheck', 'website')
 
-        variant = i.variant
+        variant = i.variant or ''
         if variant.find(',') >= 0:
             output.addMessage(__file__, 2, "WCOMMASYNTAX",
                 "Comma's are not allowed in the syntax, autofixed.")
@@ -962,14 +962,14 @@ class DescriptionExtractor:
         output = Output(__file__)
         IP = web.ctx["ip"]
 
+        if not (referenceSeq and variantSeq):
+            return render.description_extractor()
+
         args = {
             'lastReferenceSeq' : referenceSeq,
             'lastVariantSeq'   : variantSeq
         }
 
-        if not (referenceSeq and variantSeq):
-            return render_.descriptionExtract(args)
-
         output.addMessage(__file__, -1, 'INFO',
             "Received Description Extract request from %s" % IP)
 
@@ -998,14 +998,13 @@ class DescriptionExtractor:
             'visualisation'    : visualisation,
             'errors'           : errors,
             'summary'          : summary,
-            'messages'         : map(util.message_info,
-                output.getMessages())
+            'messages'         : map(util.message_info, output.getMessages())
         }
 
         output.addMessage(__file__, -1, 'INFO',
             "Finished Description Extract request")
 
-        return render_.descriptionExtract(args)
+        return render.description_extractor(args)
     #descriptionExtract
 #DescriptionExtract
 
-- 
GitLab