Skip to content

Commit

Permalink
Moving some properties into class definition (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwatts15 committed Jun 9, 2018
1 parent 5ec03c7 commit 178996c
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 128 deletions.
7 changes: 5 additions & 2 deletions PyOpenWorm/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from string import Template
import neuroml

from PyOpenWorm.channel import Channel
from PyOpenWorm.biology import BiologyType
from .channel import Channel
from .biology import BiologyType
from .dataObject import DatatypeProperty, ObjectProperty, This
from .cell_common import CELL_RDF_TYPE

__all__ = ["Cell"]

Expand Down Expand Up @@ -74,6 +75,8 @@ class Cell(BiologyType):

class_context = BiologyType.class_context

rdf_type = CELL_RDF_TYPE

divisionVolume = DatatypeProperty()
''' The volume of the cell at division
Expand Down
135 changes: 64 additions & 71 deletions PyOpenWorm/channel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
import rdflib as R

from PyOpenWorm.channelworm import ChannelModel
from PyOpenWorm.biology import BiologyType
from .dataObject import DatatypeProperty, ObjectProperty
from .channelworm import ChannelModel
from .biology import BiologyType
from .channel_common import CHANNEL_RDF_TYPE
from .cell_common import CELL_RDF_TYPE


class ExpressionPattern(BiologyType):

class_context = BiologyType.class_context

wormbaseid = DatatypeProperty()
wormbaseURL = DatatypeProperty()
description = DatatypeProperty()

def __init__(self, wormbaseid=None, description=None, **kwargs):
super(ExpressionPattern, self).__init__(**kwargs)

if wormbaseid:
self.wormbaseid(wormbaseid)
self.wormbaseURL(R.URIRef("http://www.wormbase.org/species/all/expr_pattern/" + wormbaseid))

@property
def defined(self):
return super(ExpressionPattern, self).defined \
or self.wormbaseid.has_defined_value()

@property
def identifier(self):
if super(ExpressionPattern, self).defined:
return super(ExpressionPattern, self).identifier
else:
return self.make_identifier(self.wormbaseid.defined_values[0])


class Channel(BiologyType):
Expand All @@ -11,94 +42,56 @@ class Channel(BiologyType):
Attributes
----------
Models : Property
Get experimental models of this ion channel
subfamily : DatatypeProperty
Ion channel's subfamily
name : DatatypeProperty
Ion channel's name
description : DatatypeProperty
A description of the ion channel
gene_name : DatatypeProperty
Name of the gene that codes for this ion channel
gene_WB_ID : DatatypeProperty
Wormbase ID of the encoding gene
gene_class : DatatypeProperty
Classification of the encoding gene
proteins : DatatypeProperty
Proteins associated with this channel
expression_pattern : ObjectProperty
"""

class_context = BiologyType.class_context
rdf_type = CHANNEL_RDF_TYPE

def __init__(self, name=False, **kwargs):
super(Channel, self).__init__(**kwargs)
from PyOpenWorm.cell import Cell
Channel.DatatypeProperty('subfamily', owner=self)
Channel.DatatypeProperty('description', owner=self)
Channel.DatatypeProperty('name', self)
Channel.DatatypeProperty('description', self)
Channel.DatatypeProperty('gene_name', self)
Channel.DatatypeProperty('gene_WB_ID', self)
Channel.ObjectProperty('expression_pattern',
owner=self,
multiple=True,
value_type=ExpressionPattern)
Channel.DatatypeProperty('neuroML_file', owner=self)
Channel.DatatypeProperty('proteins', self, multiple=True)
Channel.ObjectProperty('appearsIn', self, multiple=True,
value_type=Cell)
self.model = Channel.ObjectProperty(value_type=ChannelModel)
# TODO: assert this in the adapter instead
# Channel.DatatypeProperty('description_evidences', self)
# TODO: assert this in the adapter instead
# Channel.DatatypeProperty('expression_evidences', self)

if name:
self.name(name)
subfamily = DatatypeProperty()
''' Ion channel's subfamily '''

@property
def defined(self):
return super(Channel, self).defined or self.name.has_defined_value()
name = DatatypeProperty()
''' Ion channel's name '''

@property
def identifier(self):
if super(Channel, self).defined:
return super(Channel, self).identifier
else:
# name is already set, so we can make an identifier from it
return self.make_identifier(self.name.defined_values[0])
description = DatatypeProperty()
''' A description of the ion channel '''

gene_name = DatatypeProperty()
''' Name of the gene that codes for this ion channel '''

class ExpressionPattern(BiologyType):
gene_class = DatatypeProperty()
''' Classification of the encoding gene '''

class_context = BiologyType.class_context
gene_WB_ID = DatatypeProperty()
''' Wormbase ID of the encoding gene '''

def __init__(self, wormbaseID=None, description=None, **kwargs):
super(ExpressionPattern, self).__init__(**kwargs)
ExpressionPattern.DatatypeProperty('wormbaseID', owner=self)
ExpressionPattern.DatatypeProperty('wormbaseURL', owner=self)
ExpressionPattern.DatatypeProperty('description', owner=self)
expression_pattern = ObjectProperty(multiple=True,
value_type=ExpressionPattern)
''' A pattern of expression of this cell within an organism '''

if wormbaseID:
self.wormbaseID(wormbaseID)
self.wormbaseURL(R.URIRef("http://www.wormbase.org/species/all/expr_pattern/"+wormbaseID))
neuroml_file = DatatypeProperty()
''' A NeuroML describing a model of this ion channel '''

if description:
self.description(description)
proteins = DatatypeProperty(multiple=True)
''' Proteins associated with this channel '''

appearsIn = ObjectProperty(multiple=True, value_rdf_type=CELL_RDF_TYPE)
''' Cell types in which the ion channel has been expressed '''

model = ObjectProperty(value_type=ChannelModel)
''' Get experimental models of this ion channel '''

@property
def defined(self):
return super(ExpressionPattern, self).defined \
or self.wormbaseID.has_defined_value()
return super(Channel, self).defined or self.name.has_defined_value()

@property
def identifier(self):
if super(ExpressionPattern, self).defined:
return super(ExpressionPattern, self).identifier
if super(Channel, self).defined:
return super(Channel, self).identifier
else:
return self.make_identifier(self.wormbaseID.defined_values[0])
# name is already set, so we can make an identifier from it
return self.make_identifier(self.name.defined_values[0])


__yarom_mapped_classes__ = (Channel, ExpressionPattern)
53 changes: 24 additions & 29 deletions PyOpenWorm/channelworm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from yarom.utils import slice_dict

from .experiment import Experiment
from .dataObject import DataObject
from .dataObject import DataObject, DatatypeProperty, ObjectProperty
from .channel_common import CHANNEL_RDF_TYPE


class PatchClampExperiment(Experiment):
Expand Down Expand Up @@ -104,25 +105,6 @@ class ChannelModel(DataObject):
There may be multiple models for a single channel.
Parameters
----------
modelType : DatatypeProperty
What this model is based on (either "homology" or "patch-clamp")
Attributes
----------
modelType : DatatypeProperty
Passed in on construction
ion : DatatypeProperty
The type of ion this channel selects for
gating : DatatypeProperty
The gating mechanism for this channel ("voltage" or name of ligand(s) )
references : Property
Evidence for this model. May be either Experiment or Evidence object(s).
conductance : DatatypeProperty
The conductance of this ion channel. This is the initial value, and
should be entered as a Quantity object.
Example usage::
# Create a ChannelModel
Expand All @@ -135,12 +117,22 @@ class ChannelModel(DataObject):
"""
class_context = 'http://openworm.org/schema/sci/bio'

def __init__(self, modelType=False, *args, **kwargs):
modelType = DatatypeProperty()
''' The type of model employed to describe a channel '''

ion = DatatypeProperty(multiple=True)
''' The type of ion this channel selects for '''
gating = DatatypeProperty(multiple=True)
''' The gating mechanism for this channel ("voltage" or name of ligand(s) ) '''

conductance = DatatypeProperty()
'''
The conductance of this ion channel. This is the initial value, and should
be entered as a Quantity object.
'''

def __init__(self, modelType=None, *args, **kwargs):
super(ChannelModel, self).__init__(*args, **kwargs)
ChannelModel.DatatypeProperty('modelType', self)
ChannelModel.DatatypeProperty('ion', self, multiple=True)
ChannelModel.DatatypeProperty('gating', self, multiple=True)
ChannelModel.DatatypeProperty('conductance', self)

#Change modelType value to something from ChannelModelType class on init
if (isinstance(modelType, str)):
Expand All @@ -152,18 +144,21 @@ def __init__(self, modelType=False, *args, **kwargs):


class PatchClampChannelModel(ChannelModel):
modeled_from = ObjectProperty(value_type=PatchClampExperiment)

def __init__(self, **kwargs):
super(PatchClampChannelModel, self).__init__(modelType='patch-clamp',
**kwargs)
self.modeled_from = PatchClampChannelModel.ObjectProperty(value_type=PatchClampExperiment)


class HomologyChannelModel(ChannelModel):
#
# from PyOpenWorm.channel import Channel
homolog = ObjectProperty(value_rdf_type=CHANNEL_RDF_TYPE)

def __init__(self, **kwargs):
super(HomologyChannelModel, self).__init__(modelType='homology',
**kwargs)
from PyOpenWorm.channel import Channel
self.homolog = HomologyChannelModel.ObjectProperty(value_type=Channel)


__yarom_mapped_classes__ = (ChannelModel, PatchClampExperiment)
__yarom_mapped_classes__ = (ChannelModel, HomologyChannelModel, PatchClampChannelModel, PatchClampExperiment)
13 changes: 9 additions & 4 deletions PyOpenWorm/dataObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def _create_property_class(
linkName,
property_type,
value_type=None,
value_rdf_type=None,
multiple=False,
link=None,
lazy=True,
Expand All @@ -515,6 +516,9 @@ def _create_property_class(
if value_type is This:
value_type = owner_class

if isinstance(value_type, six.text_type):
value_type = owner_class.mapper.load_class(value_type)

if value_type is None:
value_type = BaseDataObject

Expand All @@ -524,16 +528,17 @@ def _create_property_class(
else:
klass = None
if property_type == 'ObjectProperty':
value_rdf_type = value_type.rdf_type
if value_type is not None and value_rdf_type is None:
value_rdf_type = value_type.rdf_type
klass = SP.ObjectProperty
elif property_type == 'DatatypeProperty':
value_rdf_type = False
value_rdf_type = None
klass = SP.DatatypeProperty
elif property_type == 'UnionProperty':
value_rdf_type = False
value_rdf_type = None
klass = SP.UnionProperty
else:
value_rdf_type = False
value_rdf_type = None

if link is None:
if owner_class.rdf_namespace is None:
Expand Down
44 changes: 22 additions & 22 deletions PyOpenWorm/neuron.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from __future__ import print_function

from wrapt import ObjectProxy
from PyOpenWorm.pProperty import Property
from PyOpenWorm.cell import Cell
from PyOpenWorm.connection import Connection
from .pProperty import Property
from .dataObject import DatatypeProperty
from .cell import Cell
from .connection import Connection


# XXX: Should we specify somewhere whether we have NetworkX or something else?

class NeuronProxy(ObjectProxy):

def __init__(self, neighbor, connection, *args):
Expand Down Expand Up @@ -64,16 +63,6 @@ class Neuron(Cell):
Attributes
----------
type : DatatypeProperty
The neuron type (i.e., sensory, interneuron, motor)
receptor : DatatypeProperty
The receptor types associated with this neuron
innexin : DatatypeProperty
Innexin types associated with this neuron
neurotransmitter : DatatypeProperty
Neurotransmitters associated with this neuron
neuropeptide : DatatypeProperty
Name of the gene corresponding to the neuropeptide produced by this neuron
neighbor : Property
Get neurons connected to this neuron if called with no arguments, or
with arguments, state that neuronName is a neighbor of this Neuron
Expand All @@ -85,21 +74,32 @@ class Neuron(Cell):

class_context = Cell.class_context

type = DatatypeProperty(multiple=True)
''' The neuron type (i.e., sensory, interneuron, motor) '''

receptor = DatatypeProperty(multiple=True)
''' The receptor types associated with this neuron '''

innexin = DatatypeProperty(multiple=True)
''' Innexin types associated with this neuron '''

neurotransmitter = DatatypeProperty(multiple=True)
''' Neurotransmitters associated with this neuron '''

neuropeptide = DatatypeProperty(multiple=True)
''' Name of the gene corresponding to the neuropeptide produced by this neuron '''

receptors = receptor
''' Alias to receptor '''

def __init__(self, name=False, **kwargs):
super(Neuron, self).__init__(name=name, **kwargs)
# Get neurons connected to this neuron
Neighbor(owner=self)
# Get connections from this neuron
ConnectionProperty(owner=self)

Neuron.DatatypeProperty("type", self, multiple=True)
Neuron.DatatypeProperty("receptor", self, multiple=True)
Neuron.DatatypeProperty("innexin", self, multiple=True)
Neuron.DatatypeProperty("neurotransmitter", self, multiple=True)
Neuron.DatatypeProperty("neuropeptide", self, multiple=True)
### Aliases ###
self.get_neighbors = self.neighbor
self.receptors = self.receptor

def contextualize(self, context):
res = super(Neuron, self).contextualize(context)
Expand Down

0 comments on commit 178996c

Please sign in to comment.