From: Diane Trout Date: Thu, 21 Jan 2010 22:25:09 +0000 (+0000) Subject: Don't throw an error if library.cell_line is None. X-Git-Tag: 0.4.0~21 X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=3d72e1d85b0153a3ed9bc454826fb2fe7b817efa Don't throw an error if library.cell_line is None. The API was having problems where if the cell_line wasn't set it was trying to do None.cellline_name, which didn't work so well. In addition there were a few other type conversion issues, such as unicode(None) != None. So I added unicode_or_none --- diff --git a/htsworkflow/frontend/experiments/tests.py b/htsworkflow/frontend/experiments/tests.py index a27023c..6a3278a 100644 --- a/htsworkflow/frontend/experiments/tests.py +++ b/htsworkflow/frontend/experiments/tests.py @@ -42,7 +42,7 @@ class ExperimentsTestCases(TestCase): 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.failUnlessAlmostEqual(float(lane_dict['pM']), float(lane.pM)) self.failUnlessEqual(lane_dict['library_species'], lane.library.library_species.scientific_name) @@ -64,7 +64,7 @@ class ExperimentsTestCases(TestCase): 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.failUnlessAlmostEqual(float(lane_dict['pM']), float(lane.pM)) self.failUnlessEqual(lane_dict['library_species'], lane.library.library_species.scientific_name) diff --git a/htsworkflow/frontend/samples/fixtures/test_samples.json b/htsworkflow/frontend/samples/fixtures/test_samples.json index edb76e1..9a549c5 100644 --- a/htsworkflow/frontend/samples/fixtures/test_samples.json +++ b/htsworkflow/frontend/samples/fixtures/test_samples.json @@ -130,5 +130,34 @@ "experiment_type": 8, "antibody": null } + }, + { + "pk": "11005", + "model": "samples.library", + "fields": { + "ten_nM_dilution": false, + "avg_lib_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, + "antibody": null + } } ] diff --git a/htsworkflow/frontend/samples/tests.py b/htsworkflow/frontend/samples/tests.py index f8eaf0f..5f6b7a4 100644 --- a/htsworkflow/frontend/samples/tests.py +++ b/htsworkflow/frontend/samples/tests.py @@ -19,6 +19,7 @@ from htsworkflow.frontend.samples.views import \ library_json from htsworkflow.frontend.auth import apidata +from htsworkflow.util.conversion import unicode_or_none # 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 @@ -139,8 +140,8 @@ class SampleWebTestCase(TestCase): #self.failUnlessEqual(d['amplified_from_sample'], lib.amplified_from_sample) self.failUnlessEqual(d['antibody_id'], lib.antibody_id) self.failUnlessEqual(d['avg_lib_size'], lib.avg_lib_size) - self.failUnlessEqual(d['cell_line'], lib.cell_line.cellline_name) self.failUnlessEqual(d['cell_line_id'], lib.cell_line_id) + self.failUnlessEqual(d['cell_line'], unicode_or_none(lib.cell_line)) self.failUnlessEqual(d['experiment_type'], lib.experiment_type.name) self.failUnlessEqual(d['experiment_type_id'], lib.experiment_type_id) self.failUnlessEqual(d['id'], lib.id) diff --git a/htsworkflow/frontend/samples/views.py b/htsworkflow/frontend/samples/views.py index 9456712..dd474a6 100644 --- a/htsworkflow/frontend/samples/views.py +++ b/htsworkflow/frontend/samples/views.py @@ -19,9 +19,11 @@ from htsworkflow.pipelines.runfolder import load_pipeline_run_xml from htsworkflow.pipelines import runfolder from htsworkflow.pipelines.eland import ResultLane from htsworkflow.frontend import settings +from htsworkflow.util.conversion import unicode_or_none from htsworkflow.util import makebed from htsworkflow.util import opener + from django.core.exceptions import ObjectDoesNotExist from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import render_to_response @@ -472,8 +474,8 @@ def library_dict(library_id): #'antibody_name': lib.antibody_name(), # we have no antibodies. 'antibody_id': lib.antibody_id, 'avg_lib_size': lib.avg_lib_size, - 'cell_line': lib.cell_line.cellline_name, 'cell_line_id': lib.cell_line_id, + 'cell_line': unicode_or_none(lib.cell_line), 'experiment_type': lib.experiment_type.name, 'experiment_type_id': lib.experiment_type_id, 'id': lib.id, @@ -489,8 +491,8 @@ def library_dict(library_id): 'notes': lib.notes, 'replicate': lib.replicate, 'stopping_point': lib.stopping_point, - 'successful_pM': unicode(lib.successful_pM), - 'undiluted_concentration': unicode(lib.undiluted_concentration) + 'successful_pM': unicode_or_none(lib.successful_pM), + 'undiluted_concentration': unicode_or_none(lib.undiluted_concentration) } if lib.library_type_id is None: info['library_type'] = None diff --git a/htsworkflow/util/conversion.py b/htsworkflow/util/conversion.py new file mode 100644 index 0000000..9246468 --- /dev/null +++ b/htsworkflow/util/conversion.py @@ -0,0 +1,12 @@ +""" +Miscellaneous, more refined type casting functions +""" + +def unicode_or_none(value): + """ + Convert value to unicode if its not none. + """ + if value is None: + return None + else: + return unicode(value)