Skip to content

Commit

Permalink
Updating PatchClampExperiment and other types
Browse files Browse the repository at this point in the history
  • Loading branch information
mwatts15 committed Jan 26, 2019
1 parent f043332 commit 711357d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 80 deletions.
119 changes: 46 additions & 73 deletions PyOpenWorm/channelworm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from yarom.utils import slice_dict

import six
from .experiment import Experiment
from .dataObject import DataObject, DatatypeProperty, ObjectProperty
from .channel_common import CHANNEL_RDF_TYPE
Expand All @@ -9,90 +10,62 @@
class PatchClampExperiment(Experiment):
"""
Store experimental conditions for a patch clamp experiment.
"""

Attributes
----------
Ca_concentration : DatatypeProperty
Calcium concentration
Cl_concentration : DatatypeProperty
Chlorine concentration
blockers : DatatypeProperty
Channel blockers used for this experiment
cell : DatatypeProperty
The cell this experiment was performed on
cell_age : DatatypeProperty
Age of the cell
delta_t : DatatypeProperty
class_context = SCI_BIO_CTX.identifier

duration : DatatypeProperty
Ca_concentration = DatatypeProperty()
'''Calcium concentration'''

end_time : DatatypeProperty
Cl_concentration = DatatypeProperty()
'''Chlorine concentration'''

extra_solution : DatatypeProperty
blockers = DatatypeProperty()
'''Channel blockers used for this experiment'''

initial_voltage : DatatypeProperty
Starting voltage of the patch clamp
ion_channel : DatatypeProperty
The ion channel being clamped
membrane_capacitance : DatatypeProperty
Initial membrane capacitance
mutants : DatatypeProperty
Type(s) of mutants being used in this experiment
patch_type : DatatypeProperty
Type of patch clamp being used ('voltage' or 'current')
pipette_solution : DatatypeProperty
Type of solution in the pipette
protocol_end : DatatypeProperty
cell = DatatypeProperty()
'''The cell this experiment was performed on'''

protocol_start : DatatypeProperty
cell_age = DatatypeProperty()
'''Age of the cell'''

protocol_step : DatatypeProperty
delta_t = DatatypeProperty()

start_time : DatatypeProperty
duration = DatatypeProperty()

temperature : DatatypeProperty
end_time = DatatypeProperty()

type : DatatypeProperty
extra_solution = DatatypeProperty()

"""
class_context = SCI_BIO_CTX.identifier
initial_voltage = DatatypeProperty()
'''Starting voltage of the patch clamp'''

ion_channel = DatatypeProperty()
'''The ion channel being clamped'''

membrane_capacitance = DatatypeProperty()
'''Initial membrane capacitance'''

mutants = DatatypeProperty()
'''Type(s) of mutants being used in this experiment'''

patch_type = DatatypeProperty()
'''Type of patch clamp being used ('voltage' or 'current')'''

pipette_solution = DatatypeProperty()
'''Type of solution in the pipette'''

protocol_end = DatatypeProperty()

protocol_start = DatatypeProperty()

protocol_step = DatatypeProperty()

start_time = DatatypeProperty()

temperature = DatatypeProperty()

conditions = [
'Ca_concentration',
'Cl_concentration',
'blockers',
'cell',
'cell_age',
'delta_t',
'duration',
'end_time',
'extra_solution',
'initial_voltage',
'ion_channel',
'membrane_capacitance',
'mutants',
'patch_type',
'pipette_solution',
'protocol_end',
'protocol_start',
'protocol_step',
'start_time',
'temperature',
'type',
]

def __init__(self, reference=False, **kwargs):
conditions = slice_dict(kwargs, self.conditions)
kwargs = {k: kwargs[k] for k in kwargs if k not in conditions}
super(PatchClampExperiment, self).__init__(reference, **kwargs)

# enumerate conditions patch-clamp experiments should have

for c in self.conditions:
PatchClampExperiment.DatatypeProperty(c, self)

for c, v in conditions.items():
getattr(self, c).set(v)
type = DatatypeProperty()


class ChannelModelType:
Expand Down Expand Up @@ -134,7 +107,7 @@ def __init__(self, modelType=None, *args, **kwargs):
super(ChannelModel, self).__init__(*args, **kwargs)

#Change modelType value to something from ChannelModelType class on init
if isinstance(modelType, str):
if isinstance(modelType, six.string_types):
modelType = modelType.lower()
if modelType in ('homology', ChannelModelType.homologyEstimate):
self.modelType(ChannelModelType.homologyEstimate)
Expand Down
8 changes: 5 additions & 3 deletions PyOpenWorm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

def additional_args(parser):
'Add some additional options specific to CLI'
parser.add_argument('--output-mode', default='text')
parser.add_argument('--output-mode', default='text',
help='How to print the results of a command'
' (if any). Either "json" or "text" (the default)')
parser.add_argument('--text-field-separator', default='\t',
description='Separator to use between fields in text-mode output')
help='Separator to use between fields in text-mode output')
parser.add_argument('--text-record-separator', default='\n',
description='Separator to use between records in text-mode output')
help='Separator to use between records in text-mode output')


class NSHandler(object):
Expand Down
6 changes: 2 additions & 4 deletions PyOpenWorm/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class Experiment(DataObject):

def __init__(self, reference=None, **kwargs):
super(Experiment, self).__init__(**kwargs)
Experiment.ObjectProperty('reference',
owner=self,
value_type=Evidence,
multiple=True)
self.reference = Experiment.ObjectProperty(value_type=Evidence,
multiple=True)

if isinstance(reference, Evidence):
#TODO: make this so the reference asserts this Experiment when it is added
Expand Down
27 changes: 27 additions & 0 deletions tests/ChannelWormTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
from PyOpenWorm.channelworm import PatchClampExperiment, ChannelModel, ChannelModelType


class PatchClampExperimentTest(unittest.TestCase):

def test_cw_init(self):
PatchClampExperiment(cell='blah', delta_t=.002)


class ChannelModelTest(unittest.TestCase):

def test_cm_init_pc_model_type(self):
cm = ChannelModel(modelType='patch-clamp')
self.assertEqual(ChannelModelType.patchClamp, cm.modelType.onedef())

def test_cm_init_homology_model_type(self):
cm = ChannelModel(modelType='homology')
self.assertEqual(ChannelModelType.homologyEstimate, cm.modelType.onedef())

def test_cm_init_unknown_model_type(self):
cm = ChannelModel(modelType='homolog')
self.assertIsNone(cm.modelType.onedef())

def test_cm_init_homoly_model_type(self):
cm = ChannelModel(modelType=23)
self.assertIsNone(cm.modelType.onedef())

0 comments on commit 711357d

Please sign in to comment.