Also make the library index page conform to htsworkflow ontology.
authorDiane Trout <diane@caltech.edu>
Thu, 20 Sep 2012 21:26:46 +0000 (14:26 -0700)
committerDiane Trout <diane@caltech.edu>
Thu, 20 Sep 2012 21:26:46 +0000 (14:26 -0700)
htsworkflow/frontend/samples/fixtures/test_samples.json
htsworkflow/frontend/samples/tests.py
htsworkflow/frontend/templates/samples/library_index.html

index 729f067184863b270ed972b2014b07d2edb515c5..cdaedb10d2dabedc0da8546aa3010ab25994bd63 100644 (file)
@@ -1,5 +1,5 @@
-[ 
-  {"pk": 5, "model": "auth.user", 
+[
+  {"pk": 5, "model": "auth.user",
    "fields": {
        "username": "test",
        "first_name": "",
                  "email": "bob@some.where.else"
                }
     },
- {"pk": 153, "model": "experiments.flowcell", 
+ {"pk": 153, "model": "experiments.flowcell",
   "fields": {
-      "paired_end": true, 
-      "run_date": "2009-09-11 22:12:13", 
-      "read_length": 75, 
+      "paired_end": true,
+      "run_date": "2009-09-11 22:12:13",
+      "read_length": 75,
       "notes": "",
       "advanced_run": false,
       "control_lane": 2,
@@ -41,7 +41,7 @@
       "sequencer": 2,
       "flowcell_id": "303TUAAXX"
       }
-  }, 
+  },
   {"pk": 1193, "model": "experiments.lane",
    "fields": {
        "comment": "No change in cluster numbers, despite slight increase in pM",
@@ -51,7 +51,7 @@
        "lane_number": 1,
        "pM": "8"
        }
-   }, 
+   },
   {"pk": 1197, "model": "experiments.lane",
    "fields": {
        "comment": "stuff",
        "pM": "7",
        "status": 2
        }
-   }, 
-  {"pk": "10981", "model": "samples.library", 
+   },
+  {"pk": "10981", "model": "samples.library",
         "fields": {
-            "ten_nM_dilution": false, 
-            "gel_cut_size": 400, 
-            "library_name": "Paired End Multiplexed Sp-BAC", 
-            "creation_date": "2009-07-21", 
-            "cell_line": 1, 
-            "library_species": 2, 
-            "library_type": null, 
-            "made_by": "Igor", 
+            "ten_nM_dilution": false,
+            "gel_cut_size": 400,
+            "library_name": "Paired End Multiplexed Sp-BAC",
+            "creation_date": "2009-07-21",
+            "cell_line": 1,
+            "library_species": 2,
+            "library_type": null,
+            "made_by": "Igor",
             "affiliations": [
                 2
-            ], 
-            "replicate": 1, 
-            "condition": 1, 
-            "hidden": false, 
-            "stopping_point": "Done", 
-            "tags": [], 
-            "made_for": "Andy Cameron", 
-            "amplified_from_sample": null, 
-            "notes": "Combined 10957-10968", 
-            "undiluted_concentration": "5.1", 
-            "successful_pM": null, 
-            "experiment_type": 10, 
+            ],
+            "replicate": 1,
+            "condition": 1,
+            "hidden": false,
+            "stopping_point": "Done",
+            "tags": [],
+            "made_for": "Andy Cameron",
+            "amplified_from_sample": null,
+            "notes": "Combined 10957-10968",
+            "undiluted_concentration": "5.1",
+            "successful_pM": null,
+            "experiment_type": 10,
             "antibody": null
         }
-    }, 
+    },
     {
-        "pk": "11016", 
-        "model": "samples.library", 
+        "pk": "11016",
+        "model": "samples.library",
         "fields": {
-            "ten_nM_dilution": false, 
-            "gel_cut_size": 325, 
-            "library_name": "Paired End Pfl #3 MP 7/24/9 a", 
-            "creation_date": "2009-08-06", 
-            "cell_line": 1, 
-            "library_species": 9, 
-            "library_type": 2, 
-            "made_by": "Lorian", 
+            "ten_nM_dilution": false,
+            "gel_cut_size": 325,
+            "library_name": "Paired End Pfl #3 MP 7/24/9 a",
+            "creation_date": "2009-08-06",
+            "cell_line": 1,
+            "library_species": 9,
+            "library_type": 2,
+            "made_by": "Lorian",
             "affiliations": [
                 41
-            ], 
-            "replicate": 1, 
-            "condition": 1, 
-            "hidden": false, 
-            "stopping_point": "1Aa", 
-            "tags": [], 
-            "made_for": "", 
-            "amplified_from_sample": 11006, 
-            "notes": "7/31/2009 16:08:22\tColor: Blue", 
-            "undiluted_concentration": "35.5", 
-            "successful_pM": null, 
-            "experiment_type": 8, 
+            ],
+            "replicate": 1,
+            "condition": 1,
+            "hidden": false,
+            "stopping_point": "1Aa",
+            "tags": [],
+            "made_for": "",
+            "amplified_from_sample": "11003",
+            "notes": "7/31/2009 16:08:22\tColor: Blue",
+            "undiluted_concentration": "35.5",
+            "successful_pM": null,
+            "experiment_type": 8,
             "antibody": null
         }
-    }, 
+    },
     {
-        "pk": "11039", 
-        "model": "samples.library", 
+        "pk": "11039",
+        "model": "samples.library",
         "fields": {
-            "ten_nM_dilution": false, 
-            "gel_cut_size": 300, 
-            "library_name": "Paired ends 99 GM12892", 
-            "creation_date": "2009-08-25", 
-            "cell_line": 1, 
-            "library_species": 8, 
-            "library_type": 2, 
-            "made_by": "Brian Williams", 
+            "ten_nM_dilution": false,
+            "gel_cut_size": 300,
+            "library_name": "Paired ends 99 GM12892",
+            "creation_date": "2009-08-25",
+            "cell_line": 1,
+            "library_species": 8,
+            "library_type": 2,
+            "made_by": "Brian Williams",
             "affiliations": [
-                4, 
-                8, 
+                4,
+                8,
                 12
-            ], 
-            "replicate": 1, 
-            "condition": 1, 
-            "hidden": false, 
-            "stopping_point": "1Aa", 
-            "tags": [], 
-            "made_for": "Brian Williams", 
-            "amplified_from_sample": null, 
-            "notes": "fragment size = 300 bp, Amicon filtered\r\nnanodrop: 56.3", 
-            "undiluted_concentration": "28.7", 
-            "successful_pM": null, 
-            "experiment_type": 4, 
+            ],
+            "replicate": 1,
+            "condition": 1,
+            "hidden": false,
+            "stopping_point": "1Aa",
+            "tags": [],
+            "made_for": "Brian Williams",
+            "amplified_from_sample": null,
+            "notes": "fragment size = 300 bp, Amicon filtered\r\nnanodrop: 56.3",
+            "undiluted_concentration": "28.7",
+            "successful_pM": null,
+            "experiment_type": 4,
             "antibody": null
         }
     },
     {
-        "pk": "11003", 
-        "model": "samples.library", 
+        "pk": "11003",
+        "model": "samples.library",
         "fields": {
-            "ten_nM_dilution": false, 
-            "gel_cut_size": 325, 
-            "library_name": "Paired End Pfl #3 MP 7/24/9", 
-            "creation_date": "2009-08-05", 
-            "cell_line": 1, 
-            "library_species": 8, 
-            "library_type": 2, 
-            "made_by": "Lorian", 
+            "ten_nM_dilution": false,
+            "gel_cut_size": 325,
+            "library_name": "Paired End Pfl #3 MP 7/24/9",
+            "creation_date": "2009-08-05",
+            "cell_line": 1,
+            "library_species": 8,
+            "library_type": 2,
+            "made_by": "Lorian",
             "affiliations": [
                 41
-            ], 
-            "replicate": 1, 
-            "condition": 1, 
-            "hidden": true, 
-            "stopping_point": "1A", 
-            "tags": [], 
-            "made_for": "", 
-            "amplified_from_sample": null, 
-            "notes": "7/31/2009 16:08:22\tColor: Blue", 
-            "undiluted_concentration": null, 
-            "successful_pM": null, 
-            "experiment_type": 8, 
+            ],
+            "replicate": 1,
+            "condition": 1,
+            "hidden": true,
+            "stopping_point": "1A",
+            "tags": [],
+            "made_for": "",
+            "amplified_from_sample": null,
+            "notes": "7/31/2009 16:08:22\tColor: Blue",
+            "undiluted_concentration": null,
+            "successful_pM": null,
+            "experiment_type": 8,
             "antibody": null
         }
     },
     {
-        "pk": "11005", 
-        "model": "samples.library", 
+        "pk": "11005",
+        "model": "samples.library",
         "fields": {
-            "ten_nM_dilution": false, 
-            "gel_cut_size": 325, 
-            "library_name": "null cell line", 
-            "creation_date": "2009-08-05", 
-            "cell_line": null, 
-            "library_species": 8, 
-            "library_type": 2, 
-            "made_by": "Lorian", 
+            "ten_nM_dilution": false,
+            "gel_cut_size": 325,
+            "library_name": "null cell line",
+            "creation_date": "2009-08-05",
+            "cell_line": null,
+            "library_species": 8,
+            "library_type": 2,
+            "made_by": "Lorian",
             "affiliations": [
                 41
-            ], 
-            "replicate": 1, 
-            "condition": 1, 
-            "hidden": true, 
-            "stopping_point": "1A", 
-            "tags": [], 
-            "made_for": "", 
-            "amplified_from_sample": null, 
-            "notes": "7/31/2009 16:08:22\tColor: Blue", 
-            "undiluted_concentration": null, 
-            "successful_pM": null, 
-            "experiment_type": 8, 
+            ],
+            "replicate": 1,
+            "condition": 1,
+            "hidden": true,
+            "stopping_point": "1A",
+            "tags": [],
+            "made_for": "",
+            "amplified_from_sample": null,
+            "notes": "7/31/2009 16:08:22\tColor: Blue",
+            "undiluted_concentration": null,
+            "successful_pM": null,
+            "experiment_type": 8,
             "antibody": null
         }
     }
index 770d90a8e8925c81c3e77465bfb750fecf2527f3..daabc11fe9f9289b4055cb13395565d61bae3dae 100644 (file)
@@ -52,7 +52,6 @@ class SampleWebTestCase(TestCase):
     fixtures = ['test_samples.json']
 
     def test_library_info(self):
-
         for lib in Library.objects.all():
             lib_dict = library_dict(lib.id)
             url = '/samples/library/%s/json' % (lib.id,)
@@ -171,6 +170,48 @@ class SampleWebTestCase(TestCase):
             self.assertEqual(fromTypedNode(r['gel_cut']), 400)
             self.assertEqual(fromTypedNode(r['made_by']), u'Igor')
 
+    def test_library_index_rdfa(self):
+        from htsworkflow.util.rdfhelp import \
+             add_default_schemas, get_model, load_string_into_model
+
+        from htsworkflow.util.rdfinfer import Infer
+
+        model = get_model()
+        add_default_schemas(model)
+        inference = Infer(model)
+
+        response = self.client.get('/library/')
+        self.assertEqual(response.status_code, 200)
+        load_string_into_model(model, 'rdfa', response.content)
+
+        errmsgs = list(inference.run_validation())
+        self.assertEqual(len(errmsgs), 2)
+        # didn't feel like giving the index page a type since all
+        # its doing is showing a list of things.
+        for err in errmsgs:
+            self.assertEqual(err, 'Missing type for: http://localhost/')
+
+        body =  """prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+        prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#>
+
+        select ?library ?library_id ?name ?species
+        where {
+           ?library a libns:Library .
+           OPTIONAL { ?library libns:library_id ?library_id . }
+           OPTIONAL { ?library libns:species ?species . }
+           OPTIONAL { ?library libns:name ?name . }
+        }"""
+        bindings = set(['library', 'library_id', 'name', 'species'])
+        query = RDF.SPARQLQuery(body)
+        count = 0
+        for r in query.execute(model):
+            count += 1
+            for name, value in r.items():
+                self.assertTrue(name in bindings)
+                self.assertTrue(value is not None)
+
+        self.assertEqual(count, len(Library.objects.filter(hidden=False)))
+
 # 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
 # of interest before creating our sample data.
index 8f351fedafef7d1405d6a3ba034c568ca1fad0e5..ccba5614f9c7003b4f70822df06c30daeea4beb7 100644 (file)
     </thead>
     <tbody >
       {% for lib in library_list %}
-      <tr about="{{lib.library.get_absolute_url}}">
+      <tr typeof="libns:Library" about="{{lib.library.get_absolute_url}}">
         <td ><a href="{{lib.library.get_absolute_url}}">{{ lib.amplified_from }}</a></td>
         <td ><a href="{{lib.library.get_absolute_url}}"><span property="libns:library_id">{{ lib.library_id }}</span></a></td>
-        <td ><a href="{{lib.library.library_species.get_absolute_url}}" rel="libns:species"><span property="libns:species_name">{{ lib.species_name }}</span></a></td>
-        <td ><a href="{{ lib.library.get_absolute_url }}"><span property="libns:name">{{ lib.library_name }}</span></a></td>
+        <td rel="libns:species">
+          <a typeof="libns:Species"
+             href="{{lib.library.library_species.get_absolute_url}}">
+            <span property="libns:species_name">{{ lib.species_name }}</span>
+          </a>
+        </td>
+        <td >
+          <a href="{{ lib.library.get_absolute_url }}">
+            <span property="libns:name">{{ lib.library_name }}</span>
+          </a>
+        </td>
         <td  bgcolor="#00BFFF">{{ lib.lanes_run.0.0 }}</td>
         <td  bgcolor="#00BFFF">{{ lib.lanes_run.0.1 }}</td>
         <td  bgcolor="#00BFFF">{{ lib.lanes_run.0.2 }}</td>