Test RDFa encoded information for flowcell & libraries.
authorDiane Trout <diane@caltech.edu>
Tue, 28 Aug 2012 23:03:45 +0000 (16:03 -0700)
committerDiane Trout <diane@caltech.edu>
Tue, 28 Aug 2012 23:03:45 +0000 (16:03 -0700)
This shouls make sure that I have the right class type on flowcells
so I can reliably fish it out of a triple store.

htsworkflow/frontend/experiments/tests.py
htsworkflow/frontend/samples/tests.py
htsworkflow/frontend/templates/experiments/flowcell_detail.html
htsworkflow/frontend/templates/experiments/flowcell_header.html

index 537e4b47c2ef871ea084a489ebf68eef6c2d43ef..a72888484d6abb07003ceaa474c2c74b4fbc3457 100644 (file)
@@ -8,6 +8,7 @@ import os
 import shutil
 import sys
 import tempfile
+from urlparse import urljoin
 
 from django.conf import settings
 from django.core import mail
@@ -411,6 +412,53 @@ class ExperimentsTestCases(TestCase):
 
             self.assertEqual(mimetype, response['content-type'])
 
+    def test_flowcell_rdf(self):
+        import RDF
+        from htsworkflow.util.rdfhelp import get_model, \
+             fromTypedNode, \
+             load_string_into_model, \
+             rdfNS, \
+             libraryOntology, \
+             dump_model
+
+        model = get_model()
+
+        expected = {1: ['11034'],
+                    2: ['11036'],
+                    3: ['12044','11045'],
+                    4: ['11047','13044'],
+                    5: ['11055'],
+                    6: ['11067'],
+                    7: ['11069'],
+                    8: ['11070']}
+        url = '/flowcell/42JU1AAXX/'
+        response = self.client.get(url)
+        self.assertEqual(response.status_code, 200)
+        ns = urljoin('http://localhost', url)
+        load_string_into_model(model, 'rdfa', response.content, ns=ns)
+        body = """prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+        prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#>
+
+        select ?flowcell ?flowcell_id ?lane_id ?library_id
+        where {
+          ?flowcell a libns:illumina_flowcell ;
+                    libns:flowcell_id ?flowcell_id ;
+                    libns:has_lane ?lane .
+          ?lane libns:lane_number ?lane_id ;
+                libns:library ?library .
+          ?library libns:library_id ?library_id .
+        }"""
+        query = RDF.SPARQLQuery(body)
+        count = 0
+        for r in query.execute(model):
+            count += 1
+            self.assertEqual(fromTypedNode(r['flowcell_id']), u'42JU1AAXX')
+            lane_id = fromTypedNode(r['lane_id'])
+            library_id = fromTypedNode(r['library_id'])
+            self.assertTrue(library_id in expected[lane_id])
+        self.assertEqual(count, 10)
+
+
 class TestFileType(TestCase):
     def test_file_type_unicode(self):
         file_type_objects = models.FileType.objects
@@ -535,6 +583,9 @@ class TestSequencer(TestCase):
                              "Illumina Genome Analyzer IIx")
         self.assertEqual(fc.sequencer.instrument_name,
                              "ILLUMINA-EC5D15")
+        # well actually we let the browser tack on the host name
+        url = fc.get_absolute_url()
+        self.assertEqual(url, '/flowcell/FC12150/')
 
     def test_rdf(self):
         response = self.client.get('/flowcell/FC12150/', apidata)
index 19f2f6bebd8f98a74ccabc4c581afcf9b5486c49..770d90a8e8925c81c3e77465bfb750fecf2527f3 100644 (file)
@@ -139,6 +139,37 @@ class SampleWebTestCase(TestCase):
         response = self.client.get('/samples/library/10981/json', apidata)
         self.failUnlessEqual(response.status_code, 200)
 
+    def test_library_rdf(self):
+        import RDF
+        from htsworkflow.util.rdfhelp import get_model, \
+             fromTypedNode, \
+             load_string_into_model, \
+             rdfNS, \
+             libraryOntology
+        model = get_model()
+
+        response = self.client.get('/library/10981/')
+        self.assertEqual(response.status_code, 200)
+        load_string_into_model(model, 'rdfa', response.content)
+
+        body = """prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+        prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#>
+
+        select ?library ?name ?library_id ?gel_cut ?made_by
+        where {
+           ?library a libns:library ;
+                    libns:name ?name ;
+                    libns:library_id ?library_id ;
+                    libns:gel_cut ?gel_cut ;
+                    libns:made_by ?made_by
+        }"""
+        query = RDF.SPARQLQuery(body)
+        for r in query.execute(model):
+            self.assertEqual(fromTypedNode(r['library_id']), u'10981')
+            self.assertEqual(fromTypedNode(r['name']),
+                             u'Paired End Multiplexed Sp-BAC')
+            self.assertEqual(fromTypedNode(r['gel_cut']), 400)
+            self.assertEqual(fromTypedNode(r['made_by']), u'Igor')
 
 # The django test runner flushes the database between test suites not cases,
 # so to be more compatible with running via nose we flush the database tables
index a835a6e7d43a7f5f21dbd7bff234972da6e46a61..5ce9fa2a067403650cc0e1ed0f2dc3d05bd98e82 100644 (file)
@@ -28,7 +28,7 @@
       {% for lane in lanes %}
         <tr rel="libns:has_lane" resource="{{lane.get_absolute_url}}" >
           <td><a href="{{lane.get_absolute_url}}">
-              <span property="libns:lane_number">{{lane.lane_number}}</span></a></td>
+              <span property="libns:lane_number" datatype="xsd:decimal">{{lane.lane_number}}</span></a></td>
           <td><a href="{{lane.library.get_absolute_url}}"
                  rel="libns:library"><span property="libns:library_id"
               >{{lane.library.id}}</span></a>
index 55c20d6cbbf8c6ea37a2d83fb83c60d1a251b359..953897c5793702c629f1310dd6c5b787f562d213 100644 (file)
@@ -2,7 +2,7 @@
   <h2>About this Flowcell</h2>
   <b>Flowcell</b>:
     <a href="{{flowcell.get_absolute_url}}" property="libns:flowcell_id">{{flowcell.flowcell_id}}</a>{% if user.is_staff %}<a href="{{flowcell.get_admin_url}}"><img class="icon_button" src="/media/img/admin/icon_changelink.gif" alt="Edit"/></a>{% endif%}
-  <br property="rdf:type" content="libns:illumina_flowcell"/>
+  <br rel="rdf:type" resource="http://jumpgate.caltech.edu/wiki/LibraryOntology#illumina_flowcell"/>
   <div rel="libns:sequenced_by"
        resource="{{flowcell.sequencer.get_absolute_url}}">
   <b>Instrument</b>:
@@ -33,7 +33,7 @@
   <b>Read Length</b>:
     <span property="libns:read_length" datatype="xsd:decimal">{{flowcell.read_length}}</span><br/>
   <b>Control Lane</b>:
-    <span property="libns:control_lane">{{flowcell.control_lane}}</span><br/>
+    <span property="libns:control_lane" datatype="xsd:decimal">{{flowcell.control_lane}}</span><br/>
 
   <b>Notes</b>:
     <pre property="libns:flowcell_notes">{{flowcell.notes}}</pre>