Add a /config/<fcid>/json url that returns information about a flowcell
authorDiane Trout <diane@caltech.edu>
Sat, 19 Sep 2009 01:15:42 +0000 (01:15 +0000)
committerDiane Trout <diane@caltech.edu>
Sat, 19 Sep 2009 01:15:42 +0000 (01:15 +0000)
this includes test code that verifies the underlying dictionary
representing the flowcell is correct, as well as testing that we
can retrieve data from the url only if we're logged in.

Now I need to implement something similar for sharing information
about libraries.

htsworkflow/frontend/experiments/experiments.py
htsworkflow/frontend/experiments/fixtures/test_flowcells.json [new file with mode: 0644]
htsworkflow/frontend/experiments/tests.py [new file with mode: 0644]
htsworkflow/frontend/experiments/urls.py

index 5b7019343b698f28d68cb874627bc856bb8bae7b..d0dd7641383d0c2e3bba8d7a69104e4903fa7692 100755 (executable)
@@ -1,15 +1,74 @@
 # some core functions of the exp tracker module
 from datetime import datetime, timedelta
+try:
+    import json
+except ImportError, e:
+    import simplejson as json
+    
 import os
 import re
 
-from django.http import HttpResponse
+from django.contrib.auth.decorators import login_required
+from django.core.exceptions import ObjectDoesNotExist
+from django.core.mail import send_mail, mail_admins
+from django.http import HttpResponse, Http404
+
 from htsworkflow.frontend import settings
 from htsworkflow.frontend.experiments.models import FlowCell, DataRun
 from htsworkflow.frontend.samples.models import Library
-from django.core.exceptions import ObjectDoesNotExist
-from django.core.mail import send_mail, mail_admins
 
+def flowcell_information(flowcell_id):
+    """
+    Return a dictionary describing a flowcell
+    """
+    try:
+        fc = FlowCell.objects.get(flowcell_id=flowcell_id)
+    except FlowCell.DoesNotExist, e:
+        return None
+
+    lane_set = {}
+    for lane in fc.lane_set.all():
+        lane_set[lane.lane_number] = {
+            'cluster_estimate': lane.cluster_estimate,
+            'comment': lane.comment,
+            'flowcell': lane.flowcell.flowcell_id,
+            'lane_number': int(lane.lane_number),
+            'library_name': lane.library.library_name,
+            'library_id': lane.library_id,
+            'pM': float(lane.pM),
+        }
+    info = {
+        'advanced_run': fc.advanced_run,
+        'cluster_station_id': fc.cluster_station_id,
+        'cluster_station': fc.cluster_station.name,
+        'control_lane': int(fc.control_lane),
+        # 'datarun_set': how should this be represented?,
+        'flowcell_id': fc.flowcell_id,
+        'id': fc.id,
+        'lane_set': lane_set,
+        'notes': fc.notes,
+        'paired_end': fc.paired_end,
+        'read_length': fc.read_length,
+        'run_date': fc.run_date.isoformat(),
+        'sequencer_id': fc.sequencer_id,
+        'sequencer': fc.sequencer.name,
+    }
+    
+    return info
+
+@login_required    
+def flowcell_json(request, fc_id):
+    """
+    Return a JSON blob containing enough information to generate a config file.
+    """
+    fc_dict = flowcell_information(fc_id)
+
+    if fc_dict is None:
+        raise Http404
+    
+    fc_json = json.dumps(fc_dict)
+    return HttpResponse(fc_json, mimetype = 'application/json')
+    
 def updStatus(request):
     output=''
     user = 'none'
diff --git a/htsworkflow/frontend/experiments/fixtures/test_flowcells.json b/htsworkflow/frontend/experiments/fixtures/test_flowcells.json
new file mode 100644 (file)
index 0000000..74f438d
--- /dev/null
@@ -0,0 +1,1058 @@
+[
+  {"pk": 5, "model": "auth.user", 
+   "fields": {
+       "username": "test",
+       "first_name": "",
+       "last_name": "",
+       "is_active": true,
+       "is_superuser": false,
+       "is_staff": false,
+       "last_login": "2009-01-01 00:00:01",
+       "groups": [],
+       "user_permissions": [],
+       "password": "sha1$foo$5e4eefec1144a04becfb7da79244f07c487fc345",
+       "email": "",
+       "date_joined": "2009-01-01 00:01:01"
+       }
+   },
+ {"pk": 1, "model": "experiments.clusterstation", "fields": {"name": "old"}}, 
+ {"pk": 2, "model": "experiments.clusterstation", "fields": {"name": "loaner"}}, 
+ {"pk": 3, "model": "experiments.clusterstation", "fields": {"name": "new"}}, 
+ {"pk": 1, "model": "experiments.sequencer", "fields": {"name": "Rotifer (HWI-EAS229)"}}, 
+ {"pk": 2, "model": "experiments.sequencer", "fields": {"name": "Tardigrade"}}, 
+ {"pk": 3, "model": "experiments.sequencer", "fields": {"name": "Sequenced somewhere else."}}, 
+ {"pk": 153, "model": "experiments.flowcell", 
+  "fields": {
+      "paired_end": true, 
+      "run_date": "2009-09-11 22:12:13", 
+      "read_length": 75, 
+      "notes": "",
+      "advanced_run": false,
+      "control_lane": 2,
+      "cluster_station": 3,
+      "sequencer": 2,
+      "flowcell_id": "303TUAAXX"
+      }
+  }, 
+  {"pk": 1193, "model": "experiments.lane",
+   "fields": {
+       "comment": "No change in cluster numbers, despite slight increase in pM",
+       "library": 10984,
+       "cluster_estimate": 129000,
+       "flowcell": 153,
+       "lane_number": 1,
+       "pM": "8"
+       }
+   }, 
+  {"pk": 10984, "model": "samples.library", 
+        "fields": {
+            "library_id": "10981", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 400, 
+            "library_name": "Paired End Multiplexed Sp-BAC", 
+            "creation_date": "2009-07-21", 
+            "cell_line": 1, 
+            "library_species": 10, 
+            "library_type": null, 
+            "made_by": "Igor", 
+            "affiliations": [
+                40
+            ], 
+            "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": 1194, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11019,
+       "cluster_estimate": 152000,
+       "flowcell": 153,
+       "lane_number": 2,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11019, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11016", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 325, 
+            "library_name": "Paired End Pfl #3 MP 7/24/9 a", 
+            "creation_date": "2009-08-06", 
+            "cell_line": 1, 
+            "library_species": 22, 
+            "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, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1195, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11042,
+       "cluster_estimate": 162000,
+       "flowcell": 153,
+       "lane_number": 3,
+       "pM": "7"
+       }
+   },  
+    {
+        "pk": 11042, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11039", 
+            "ten_nM_dilution": false, 
+            "avg_lib_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, 
+                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, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1196, "model": "experiments.lane",
+   "fields": {
+       "comment": "This lane's library had the second lowest concentration of all the libraries built at the same time (2.05ng/ul)",
+       "library": 11063,
+       "cluster_estimate": 24000,
+       "flowcell": 153,
+       "lane_number": 4,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11063, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11060", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired ends 100 VC_CN_4_M_MBB1185_s1", 
+            "creation_date": "2009-09-01", 
+            "cell_line": 1, 
+            "library_species": 8, 
+            "library_type": 2, 
+            "made_by": "Brian Williams", 
+            "affiliations": [
+                37, 
+                8
+            ], 
+            "replicate": 1, 
+            "condition": 1, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "Brian Williams", 
+            "amplified_from_sample": null, 
+            "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 24.2", 
+            "undiluted_concentration": "2.05", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1197, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11064,
+       "cluster_estimate": 140000,
+       "flowcell": 153,
+       "lane_number": 5,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11064, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11061", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired ends 101 VC_CN_4_M_MBB1185_s2", 
+            "creation_date": "2009-09-01", 
+            "cell_line": 1, 
+            "library_species": 8, 
+            "library_type": 2, 
+            "made_by": "Brian Williams", 
+            "affiliations": [
+                37, 
+                8
+            ], 
+            "replicate": 1, 
+            "condition": 1, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "Brian Williams", 
+            "amplified_from_sample": null, 
+            "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 33.1", 
+            "undiluted_concentration": "12.9", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1198, "model": "experiments.lane",
+   "fields": {
+       "comment": "This lane's library had the lowest concentration of all the libraries built at the same time (1.2ng/ul)",
+       "library": 11065,
+       "cluster_estimate": 2000,
+       "flowcell": 153,
+       "lane_number": 6,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11065, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11062", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired ends 102 VC_AU_8_M_MBB4721_s1", 
+            "creation_date": "2009-09-01", 
+            "cell_line": 1, 
+            "library_species": 8, 
+            "library_type": 2, 
+            "made_by": "Brian Williams", 
+            "affiliations": [
+                37, 
+                8
+            ], 
+            "replicate": 1, 
+            "condition": 1, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "Brian Williams", 
+            "amplified_from_sample": null, 
+            "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 13.9", 
+            "undiluted_concentration": "1.2", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1199, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11066,
+       "cluster_estimate": 120000,
+       "flowcell": 153,
+       "lane_number": 7,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11066, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11063", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired ends 103 VC_AU_8_M_MBB4721_s2", 
+            "creation_date": "2009-09-01", 
+            "cell_line": 1, 
+            "library_species": 8, 
+            "library_type": 2, 
+            "made_by": "Brian Williams", 
+            "affiliations": [
+                37, 
+                8
+            ], 
+            "replicate": 1, 
+            "condition": 1, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "Brian Williams", 
+            "amplified_from_sample": null, 
+            "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 46.9", 
+            "undiluted_concentration": "24.5", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1200, "model": "experiments.lane",
+   "fields": {
+       "comment": "This lane's library had the third lowest concentration of all the libraries built at the same time (5.21ng/ul), but gave perfectly normal cluster numbers",
+       "library": 11067,
+       "cluster_estimate": 157000,
+       "flowcell": 153,
+       "lane_number": 8,
+       "pM": "7"
+       }
+   },
+    {
+        "pk": 11067, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11064", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired ends 104 VC_CN_7_M_MBB4898_s1", 
+            "creation_date": "2009-09-01", 
+            "cell_line": 1, 
+            "library_species": 8, 
+            "library_type": 2, 
+            "made_by": "Brian Williams", 
+            "affiliations": [
+                37, 
+                8
+            ], 
+            "replicate": 1, 
+            "condition": 1, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "Brian Williams", 
+            "amplified_from_sample": null, 
+            "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 20.4", 
+            "undiluted_concentration": "5.21", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    },
+   {"pk": 152, "model": "experiments.flowcell", 
+   "fields": {
+       "paired_end": false,
+       "run_date": "2009-09-10 18:30:15",
+       "read_length": 38,
+       "notes": "328461 4897273 RGT-0248815\r\n328479 4897265 RGT-0249274\r\n330421 4822845 SR-0005496",
+       "advanced_run": false,
+       "control_lane": 4,
+       "cluster_station": 3,
+       "sequencer": 1,
+       "flowcell_id": "42JTNAAXX"
+       }
+   }, 
+  {"pk": 1185, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11038,
+       "cluster_estimate": 174000,
+       "flowcell": 152,
+       "lane_number": 1,
+       "pM": "7"
+       }
+   },
+    {
+        "pk": 11038, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11035", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired ends 95 Gilberto_d3_control_LTA", 
+            "creation_date": "2009-08-25", 
+            "cell_line": 1, 
+            "library_species": 9, 
+            "library_type": 2, 
+            "made_by": "Brian Williams", 
+            "affiliations": [
+                14
+            ], 
+            "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: 67.1", 
+            "undiluted_concentration": "28.5", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1186, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11040,
+       "cluster_estimate": 173000,
+       "flowcell": 152,
+       "lane_number": 2,
+       "pM": "7"
+       }
+   },
+    {
+        "pk": 11040, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11037", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired ends 97 Kuntz_PDHT", 
+            "creation_date": "2009-08-25", 
+            "cell_line": 1, 
+            "library_species": 3, 
+            "library_type": 2, 
+            "made_by": "Brian Williams", 
+            "affiliations": [
+                26
+            ], 
+            "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: 52.7", 
+            "undiluted_concentration": "25.5", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1187, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11048,
+       "cluster_estimate": 198000,
+       "flowcell": 152,
+       "lane_number": 3,
+       "pM": "7"
+       }
+   },
+    {
+        "pk": 11048, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11045", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 250, 
+            "library_name": "FLDN1 8/3/9 anti-AcH3 chip B6 a", 
+            "creation_date": "2009-08-26", 
+            "cell_line": null, 
+            "library_species": 9, 
+            "library_type": 1, 
+            "made_by": "Lorian", 
+            "affiliations": [
+                18
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "2A", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": 11044, 
+            "notes": "8/21/2009 11:57:54\tColor: Yellow", 
+            "undiluted_concentration": "20.5", 
+            "successful_pM": null, 
+            "experiment_type": 2, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1188, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11049,
+       "cluster_estimate": 212000,
+       "flowcell": 152,
+       "lane_number": 4,
+       "pM": "7"}
+   },
+    {
+        "pk": 11049, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11046", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 250, 
+            "library_name": "FLDN1 7/8/9 anti-DiMeH3K4 chip B6 a", 
+            "creation_date": "2009-08-26", 
+            "cell_line": null, 
+            "library_species": 9, 
+            "library_type": 1, 
+            "made_by": "Lorian", 
+            "affiliations": [
+                18
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "2A", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": 11045, 
+            "notes": "8/21/2009 11:57:54\tColor: Blue", 
+            "undiluted_concentration": "23.9", 
+            "successful_pM": null, 
+            "experiment_type": 2, 
+            "antibody": null
+        }
+    },   
+  {"pk": 1189, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11057,
+       "cluster_estimate": 49000,
+       "flowcell": 152,
+       "lane_number": 5,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11057, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11054", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 225, 
+            "library_name": "HNDHT HLH hnd-1 strain HT115 fed anti-hlh-1 2% fix plate a", 
+            "creation_date": "2009-08-31", 
+            "cell_line": null, 
+            "library_species": 3, 
+            "library_type": 1, 
+            "made_by": "Lorian", 
+            "affiliations": [
+                26
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": 11051, 
+            "notes": "8/26/2009 14:46:56\tColor: Purple", 
+            "undiluted_concentration": "1.47", 
+            "successful_pM": null, 
+            "experiment_type": 2, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1190, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11059,
+       "cluster_estimate": 48000,
+       "flowcell": 152,
+       "lane_number": 6,
+       "pM": "7"
+       }
+   },
+    {
+        "pk": 11059, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11056", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 225, 
+            "library_name": "HNDM3 HLH hnd-1 strain mex-3 fed anti-hlh-1 2% fix plate a", 
+            "creation_date": "2009-08-31", 
+            "cell_line": null, 
+            "library_species": 3, 
+            "library_type": 1, 
+            "made_by": "Lorian", 
+            "affiliations": [
+                26
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": 11053, 
+            "notes": "8/26/2009 14:46:56\tColor: Black", 
+            "undiluted_concentration": "1.42", 
+            "successful_pM": null, 
+            "experiment_type": 2, 
+            "antibody": null
+        }
+    },     
+  {"pk": 1191, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11060,
+       "cluster_estimate": 4000,
+       "flowcell": 152,
+       "lane_number": 7,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11060, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11057", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 225, 
+            "library_name": "HNDM3 4H8 hnd-1 strain mex-3 fed 4H8 2% fix plate a", 
+            "creation_date": "2009-08-31", 
+            "cell_line": null, 
+            "library_species": 3, 
+            "library_type": 1, 
+            "made_by": "Lorian", 
+            "affiliations": [
+                26
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": 11054, 
+            "notes": "8/26/2009 14:46:56\tColor: Orange.", 
+            "undiluted_concentration": "1.3", 
+            "successful_pM": null, 
+            "experiment_type": 2, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1192, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11068,
+       "cluster_estimate": 5000,
+       "flowcell": 152,
+       "lane_number": 8,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11068, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11065", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired ends 105 Kuntz PDM3", 
+            "creation_date": "2009-09-01", 
+            "cell_line": 1, 
+            "library_species": 3, 
+            "library_type": 2, 
+            "made_by": "Brian Williams", 
+            "affiliations": [
+                26
+            ], 
+            "replicate": 1, 
+            "condition": 1, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "Brian Williams", 
+            "amplified_from_sample": null, 
+            "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 30.5", 
+            "undiluted_concentration": "2.47", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 151, "model": "experiments.flowcell",
+   "fields": {
+       "paired_end": false,
+       "run_date": "2009-09-08 15:39:28",
+       "read_length": 38,
+       "notes": "Rebuild of broken flowcell\r\n\r\n328461 4820241 RGT-0215719\r\n328479 4897265 RGT-0249510\r\n330421 4822845 SR-0005402\r\n",
+       "advanced_run": false,
+       "control_lane": 5,
+       "cluster_station": 3,
+       "sequencer": 2,
+       "flowcell_id": "42JU1AAXX"
+       }
+   },
+  {"pk": 1177, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11037,
+       "cluster_estimate": 177000,
+       "flowcell": 151,
+       "lane_number": 1,
+       "pM": "7"
+       }
+   }, 
+  {"pk": 1178, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11039,
+       "cluster_estimate": 169000,
+       "flowcell": 151,
+       "lane_number": 2,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11039, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11036", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired ends 96 Kuntz_PDE1", 
+            "creation_date": "2009-08-25", 
+            "cell_line": 1, 
+            "library_species": 3, 
+            "library_type": 2, 
+            "made_by": "Brian Williams", 
+            "affiliations": [
+                26
+            ], 
+            "replicate": 1, 
+            "condition": 1, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "Brian Williams", 
+            "amplified_from_sample": null, 
+            "notes": "fragment size = 300 bp", 
+            "undiluted_concentration": "30.6", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    }, 
+    {
+        "pk": 11037, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11034", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired ends 94 Gilberto_d3_denerv_LTA", 
+            "creation_date": "2009-08-25", 
+            "cell_line": 1, 
+            "library_species": 9, 
+            "library_type": 2, 
+            "made_by": "Brian Williams", 
+            "affiliations": [
+                14
+            ], 
+            "replicate": 1, 
+            "condition": 1, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "Brian Williams", 
+            "amplified_from_sample": null, 
+            "notes": "fragment size = 300 bp", 
+            "undiluted_concentration": "27", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    }, 
+    {
+        "pk": 11047, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11044", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 225, 
+            "library_name": "p300 60h C2 FA KF 12/22/8 a", 
+            "creation_date": "2009-08-26", 
+            "cell_line": null, 
+            "library_species": 9, 
+            "library_type": 1, 
+            "made_by": "Lorian", 
+            "affiliations": [
+                21
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "2A", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": 11043, 
+            "notes": "8/21/2009 11:57:54\tColor: Orange", 
+            "undiluted_concentration": "22.4", 
+            "successful_pM": null, 
+            "experiment_type": 2, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1179,
+   "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11047,
+       "cluster_estimate": 196000,
+       "flowcell": 151,
+       "lane_number": 3,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11047, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11044", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 225, 
+            "library_name": "p300 60h C2 FA KF 12/22/8 a", 
+            "creation_date": "2009-08-26", 
+            "cell_line": null, 
+            "library_species": 9, 
+            "library_type": 1, 
+            "made_by": "Lorian", 
+            "affiliations": [
+                21
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "2A", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": 11043, 
+            "notes": "8/21/2009 11:57:54\tColor: Orange.", 
+            "undiluted_concentration": "22.4", 
+            "successful_pM": null, 
+            "experiment_type": 2, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1180, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11050,
+       "cluster_estimate": 200000,
+       "flowcell": 151,
+       "lane_number": 4,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11050, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11047", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 250, 
+            "library_name": "FLDN1 7/8/9 anti-TriMeH3K27 chip B6 a", 
+            "creation_date": "2009-08-26", 
+            "cell_line": null, 
+            "library_species": 9, 
+            "library_type": 1, 
+            "made_by": "Lorian", 
+            "affiliations": [
+                18
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "2A", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": 11046, 
+            "notes": "8/21/2009 11:57:54\tColor: Green", 
+            "undiluted_concentration": "24.9", 
+            "successful_pM": null, 
+            "experiment_type": 2, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1181, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11058,
+       "cluster_estimate": 104000,
+       "flowcell": 151,
+       "lane_number": 5,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11058, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11055", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 225, 
+            "library_name": "HNDHT 4H8 hnd-1 strain HT115 fed 4H8 2% fix plate a", 
+            "creation_date": "2009-08-31", 
+            "cell_line": null, 
+            "library_species": 3, 
+            "library_type": 1, 
+            "made_by": "Lorian", 
+            "affiliations": [
+                26
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "1Aa", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": 11052, 
+            "notes": "8/26/2009 14:46:56\tColor: White.", 
+            "undiluted_concentration": "2.17", 
+            "successful_pM": null, 
+            "experiment_type": 2, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1182, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11070,
+       "cluster_estimate": 168000,
+       "flowcell": 151,
+       "lane_number": 6,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11070, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11067", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 325, 
+            "library_name": "Paired End SP-BAC Barcoding test 250-300 bp", 
+            "creation_date": "2009-09-03", 
+            "cell_line": 1, 
+            "library_species": 10, 
+            "library_type": 2, 
+            "made_by": "Igor", 
+            "affiliations": [
+                40
+            ], 
+            "replicate": 1, 
+            "condition": 1, 
+            "hidden": false, 
+            "stopping_point": "Done", 
+            "tags": [], 
+            "made_for": "Andy Cameron", 
+            "amplified_from_sample": null, 
+            "notes": "12 SP BACs", 
+            "undiluted_concentration": "1.45", 
+            "successful_pM": null, 
+            "experiment_type": 8, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1183, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11072,
+       "cluster_estimate": 184000,
+       "flowcell": 151,
+       "lane_number": 7,
+       "pM": "7"
+       }
+   }, 
+    {
+        "pk": 11072, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11069", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired End AG-3d-1 AG domain of floral meristem day 3, rep 1", 
+            "creation_date": "2009-09-02", 
+            "cell_line": null, 
+            "library_species": 6, 
+            "library_type": 2, 
+            "made_by": "Yuling Jiao", 
+            "affiliations": [
+                29
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "Done", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": null, 
+            "notes": "nanodrop: Xng/ul.", 
+            "undiluted_concentration": "18.3", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+    }, 
+  {"pk": 1184, "model": "experiments.lane",
+   "fields": {
+       "comment": "",
+       "library": 11073,
+       "cluster_estimate": 182000,
+       "flowcell": 151,
+       "lane_number": 8,
+       "pM": "7"
+       }
+   },
+    {
+        "pk": 11073, 
+        "model": "samples.library", 
+        "fields": {
+            "library_id": "11070", 
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 300, 
+            "library_name": "Paired End AG-5d-1 AG domain of floral meristem day 5, rep 1", 
+            "creation_date": "2009-09-02", 
+            "cell_line": null, 
+            "library_species": 6, 
+            "library_type": 2, 
+            "made_by": "Yuling Jiao", 
+            "affiliations": [
+                29
+            ], 
+            "replicate": 1, 
+            "condition": null, 
+            "hidden": false, 
+            "stopping_point": "Done", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": null, 
+            "notes": "nanodrop: 40ng/ul\r\nCalibrated qbit with standards.\r\nMeasured 2ul library with qbit using HS kit.\r\n", 
+            "undiluted_concentration": "20.3", 
+            "successful_pM": null, 
+            "experiment_type": 4, 
+            "antibody": null
+        }
+     }
+]
diff --git a/htsworkflow/frontend/experiments/tests.py b/htsworkflow/frontend/experiments/tests.py
new file mode 100644 (file)
index 0000000..6ac669e
--- /dev/null
@@ -0,0 +1,74 @@
+try:
+    import json
+except ImportError, e:
+    import simplejson as json
+    
+from django.test import TestCase
+from htsworkflow.frontend.experiments import models
+from htsworkflow.frontend.experiments import experiments
+
+class ExperimentsTestCases(TestCase):
+    fixtures = ['test_flowcells.json']
+
+    def setUp(self):
+        pass
+
+    def test_flowcell_information(self):
+        """
+        Check the code that packs the django objects into simple types.
+        """
+        for fc_id in [u'303TUAAXX', u"42JTNAAXX", "42JU1AAXX"]:
+            fc_dict = experiments.flowcell_information(fc_id)
+            fc_django = models.FlowCell.objects.get(flowcell_id=fc_id)
+            self.failUnlessEqual(fc_dict['flowcell_id'], fc_id)
+            self.failUnlessEqual(fc_django.flowcell_id, fc_id)
+            self.failUnlessEqual(fc_dict['sequencer'], fc_django.sequencer.name)
+            self.failUnlessEqual(fc_dict['read_length'], fc_django.read_length)
+            self.failUnlessEqual(fc_dict['notes'], fc_django.notes)
+            self.failUnlessEqual(fc_dict['cluster_station'], fc_django.cluster_station.name)
+
+            for lane in fc_django.lane_set.all():
+                lane_dict = fc_dict['lane_set'][lane.lane_number]
+                self.failUnlessEqual(lane_dict['cluster_estimate'], lane.cluster_estimate)
+                self.failUnlessEqual(lane_dict['comment'], lane.comment)
+                self.failUnlessEqual(lane_dict['flowcell'], lane.flowcell.flowcell_id)
+                self.failUnlessEqual(lane_dict['lane_number'], lane.lane_number)
+                self.failUnlessEqual(lane_dict['library_name'], lane.library.library_name)
+                self.failUnlessEqual(lane_dict['library_id'], lane.library_id)
+                self.failUnlessAlmostEqual(lane_dict['pM'], float(lane.pM))
+                    
+            self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
+            response = self.client.get('/experiments/config/%s/json' % (fc_id,))
+            # strptime isoformat string = '%Y-%m-%dT%H:%M:%S'
+            fc_json = json.loads(response.content)
+            self.failUnlessEqual(fc_json['flowcell_id'], fc_id)
+            self.failUnlessEqual(fc_json['sequencer'], fc_django.sequencer.name)
+            self.failUnlessEqual(fc_json['read_length'], fc_django.read_length)
+            self.failUnlessEqual(fc_json['notes'], fc_django.notes)
+            self.failUnlessEqual(fc_json['cluster_station'], fc_django.cluster_station.name)
+
+
+            for lane in fc_django.lane_set.all():
+                lane_dict = fc_json['lane_set'][unicode(lane.lane_number)]
+                self.failUnlessEqual(lane_dict['cluster_estimate'], lane.cluster_estimate)
+                self.failUnlessEqual(lane_dict['comment'], lane.comment)
+                self.failUnlessEqual(lane_dict['flowcell'], lane.flowcell.flowcell_id)
+                self.failUnlessEqual(lane_dict['lane_number'], lane.lane_number)
+                self.failUnlessEqual(lane_dict['library_name'], lane.library.library_name)
+                self.failUnlessEqual(lane_dict['library_id'], lane.library_id)
+                self.failUnlessAlmostEqual(lane_dict['pM'], float(lane.pM))
+
+    def test_invalid_flowcell(self):
+        """
+        Make sure we get a 404 if we request an invalid flowcell ID
+        """
+        self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
+        response = self.client.get('/experiments/config/nottheone/json')
+        self.failUnlessEqual(response.status_code, 404)
+
+    def test_not_logged_in(self):
+        """
+        Require logging in to retrieve meta data
+        """
+        response = self.client.get(u'/experiments/config/303TUAAXX/json')
+        self.failUnlessEqual(response.status_code, 302)
index aaefba3b4cc2ca7cbf5987e0b6f961ed746a808a..67eabab1a026d6cae02d860e9bd420fb768e4801 100755 (executable)
@@ -4,6 +4,7 @@ urlpatterns = patterns('',
     (r'^$', 'htsworkflow.frontend.experiments.views.index'),
     #(r'^liblist$', 'htsworkflow.frontend.experiments.views.test_Libs'),
     #(r'^(?P<run_folder>.+)/$', 'gaworkflow.frontend.experiments.views.detail'),
+    (r'^config/(?P<fc_id>.+)/json', 'htsworkflow.frontend.experiments.experiments.flowcell_json'),
     (r'^fcsheet/(?P<fcid>.+)/$', 'htsworkflow.frontend.experiments.views.makeFCSheet'),
     (r'^updStatus$', 'htsworkflow.frontend.experiments.experiments.updStatus'),
     (r'^getConfile$', 'htsworkflow.frontend.experiments.experiments.getConfile'),