class NeuronConnectomeCSVTranslation(GenericTranslation): class_context = CONTEXT neurons_source = ObjectProperty(value_type=DataWithEvidenceDataSource) muscles_source = ObjectProperty(value_type=DataWithEvidenceDataSource) key_properties = (GenericTranslation.source, muscles_source, neurons_source)
class Channel(BiologyType): """ A biological ion channel. """ class_context = BiologyType.class_context rdf_type = CHANNEL_RDF_TYPE 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_class = DatatypeProperty() ''' Classification of the encoding gene ''' gene_WB_ID = DatatypeProperty() ''' Wormbase ID of the encoding gene ''' expression_pattern = ObjectProperty(multiple=True, value_type=ExpressionPattern) ''' A pattern of expression of this cell within an organism ''' 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 ''' models = Alias(model) ''' Alias to :py:attr:`model` ''' def __init__(self, name=None, **kwargs): super(Channel, self).__init__(name=name, **kwargs) def defined_augment(self): return self.name.has_defined_value() def identifier_augment(self): return self.make_identifier(self.name.defined_values[0])
class Muscle(Cell): """ A single muscle cell. See what neurons innervate a muscle: Example:: >>> mdr21 = Muscle('MDR21') >>> innervates_mdr21 = mdr21.innervatedBy() >>> len(innervates_mdr21) 4 """ class_context = Cell.class_context innervatedBy = ObjectProperty(value_type=Neuron, multiple=True) ''' Neurons synapsing with this muscle ''' neurons = Alias(innervatedBy) ''' Alias to `innervatedBy` ''' receptors = DatatypeProperty(multiple=True) ''' Receptor types expressed by this type of muscle ''' receptor = Alias(receptors) ''' Alias to `receptors` '''
class HomologyChannelModel(ChannelModel): class_context = CONTEXT homolog = ObjectProperty(value_rdf_type=CHANNEL_RDF_TYPE) def __init__(self, **kwargs): super(HomologyChannelModel, self).__init__(modelType='homology', **kwargs)
class PatchClampChannelModel(ChannelModel): class_context = CONTEXT modeled_from = ObjectProperty(value_type=PatchClampExperiment) def __init__(self, **kwargs): super(PatchClampChannelModel, self).__init__(modelType='patch-clamp', **kwargs)
class NeuronClass(Neuron): class_context = 'http://example.org/rmgr_example' member = ObjectProperty(value_type=Neuron, multiple=True) def __init__(self, name=False, **kwargs): super(NeuronClass, self).__init__(**kwargs) NC_neighbor(owner=self) if name: self.name(name)
class WormAtlasCellListDataTranslation(GenericTranslation): class_context = CONTEXT neurons_source = ObjectProperty() def defined_augment(self): return super(WormAtlasCellListDataTranslation, self).defined_augment() and \ self.neurons_source.has_defined_value() def identifier_augment(self): return self.make_identifier( super(WormAtlasCellListDataTranslation, self).identifier_augment().n3() + self.neurons_source.onedef().identifier.n3())
class Experiment(DataObject): """ Generic class for storing information about experiments Should be overridden by specific types of experiments (example: see PatchClampExperiment in channelworm.py). Overriding classes should have a list called "conditions" that contains the names of experimental conditions for that particular type of experiment. Each of the items in "conditions" should also be either a DatatypeProperty or ObjectProperty for the experiment as well. """ class_context = SCI_CTX reference = ObjectProperty(value_type=Document, multiple=True) ''' Supporting article for this experiment. ''' def __init__(self, **kwargs): super(Experiment, self).__init__(**kwargs) self._condits = {} def get_conditions(self): """Return conditions and their associated values in a dict.""" if not hasattr(self, 'conditions'): raise NotImplementedError('"conditions" attribute must be overridden') for c in self.conditions: value = getattr(self, c) if callable(value): self._condits[c] = value() else: if value: #if property is not empty self._condits[c] = value return self._condits
class A(DataObject): a = ObjectProperty() key_properties = ('a', 'not_an_attr')
class A(DataObject): a = ObjectProperty() b = DatatypeProperty() key_properties = ('a', 'b')
class A(DataObject): a = ObjectProperty()
class Worm(BiologyType): """ A representation of the whole worm """ class_context = BiologyType.class_context rdf_type = WORM_RDF_TYPE scientific_name = DatatypeProperty() ''' Scientific name for the organism ''' name = Alias(scientific_name) ''' Alias to `scientific_name` ''' muscle = ObjectProperty(value_type=Muscle, multiple=True) ''' A type of muscle which is in the worm ''' cell = ObjectProperty(value_type=Cell) ''' A type of cell in the worm ''' neuron_network = ObjectProperty(value_type=Network, inverse_of=(Network, 'worm')) ''' The neuron network of the worm ''' def __init__(self, scientific_name=None, **kwargs): super(Worm, self).__init__(**kwargs) if scientific_name: self.scientific_name(scientific_name) else: self.scientific_name("C. elegans") def get_neuron_network(self): """ Return the neuron network of the worm. Example:: # Grabs the representation of the neuronal network >>> net = P.Worm().get_neuron_network() # Grab a specific neuron >>> aval = net.aneuron('AVAL') >>> aval.type() set([u'interneuron']) #show how many connections go out of AVAL >>> aval.connection.count('pre') 77 :returns: An object to work with the network of the worm :rtype: owmeta.Network """ return self.neuron_network() def muscles(self): """ Get all Muscle objects attached to the Worm. Example:: >>> muscles = P.Worm().muscles() >>> len(muscles) 96 :returns: A set of all muscles :rtype: :py:class:`set` """ return set(x for x in self._muscles_helper()) def _muscles_helper(self): for x in self.muscle.get(): yield x def get_semantic_net(self): """ Get the underlying semantic network as an RDFLib Graph :returns: A semantic network containing information about the worm :rtype: rdflib.ConjunctiveGraph """ return self.rdf def defined_augment(self): ''' True if the name is defined ''' return self.name.has_defined_value() def identifier_augment(self, *args, **kwargs): ''' Result is derived from the name property ''' return self.make_identifier(self.name.defined_values[0])
class Network(BiologyType): """ A network of neurons """ class_context = BiologyType.class_context synapse = ObjectProperty(value_type=Connection, multiple=True) ''' Returns a set of all synapses in the network ''' neuron = ObjectProperty(value_type=Neuron, multiple=True) ''' Returns a set of all Neuron objects in the network ''' worm = ObjectProperty(value_rdf_type=WORM_RDF_TYPE) ''' The worm connected to the network ''' synapses = Alias(synapse) ''' Alias to `synapse` ''' neurons = Alias(neuron) ''' Alias to `neuron` ''' def __init__(self, worm=None, **kwargs): super(Network, self).__init__(**kwargs) if worm is not None: self.worm(worm) def neuron_names(self): """ Gets the complete set of neurons' names in this network. Example:: # Grabs the representation of the neuronal network >>> net = Worm().get_neuron_network() >>> len(set(net.neuron_names())) 302 >>> set(net.neuron_names()) set(['VB4', 'PDEL', 'HSNL', 'SIBDR', ... 'RIAL', 'MCR', 'LUAL']) """ neuron_expr = self.neuron.expr neuron_expr.name() return set(x.toPython() for x in neuron_expr.name) def aneuron(self, name): """ Get a neuron by name. Example:: # Grabs the representation of the neuronal network >>> net = Worm().get_neuron_network() # Grab a specific neuron >>> aval = net.aneuron('AVAL') >>> aval.type() set([u'interneuron']) :param name: Name of a c. elegans neuron :returns: Neuron corresponding to the name given :rtype: owmeta.neuron.Neuron """ return Neuron.contextualize(self.context)(name=name, conf=self.conf) def sensory(self): """ Get all sensory neurons :returns: A iterable of all sensory neurons :rtype: iter(Neuron) """ n = Neuron.contextualize(self.context)() n.type('sensory') self.neuron.set(n) res = list(n.load()) self.neuron.unset(n) return res def interneurons(self): """ Get all interneurons :returns: A iterable of all interneurons :rtype: iter(Neuron) """ n = Neuron.contextualize(self.context)() n.type('interneuron') self.neuron.set(n) res = list(n.load()) self.neuron.unset(n) return res def motor(self): """ Get all motor :returns: A iterable of all motor neurons :rtype: iter(Neuron) """ n = Neuron.contextualize(self.context)() n.type('motor') self.neuron.set(n) res = list(n.load()) self.neuron.unset(n) return res def identifier_augment(self): return self.make_identifier(self.worm.defined_values[0].identifier.n3()) def defined_augment(self): return self.worm.has_defined_value()
class NeuronConnectomeSynapseClassTranslation(GenericTranslation): class_context = CONTEXT neurotransmitter_source = ObjectProperty() key_properties = (GenericTranslation.source, neurotransmitter_source)
class Evidence(DataObject): """ A representation which provides evidence, for a group of statements. Attaching evidence to an set of statements is done like this:: >>> from owmeta.connection import Connection >>> from owmeta.evidence import Evidence >>> from owmeta_core.context import Context Declare contexts:: >>> ACTX = Context(ident="http://example.org/data/some_statements") >>> BCTX = Context(ident="http://example.org/data/some_other_statements") >>> EVCTX = Context(ident="http://example.org/data/some_statements#evidence") Make statements in `ACTX` and `BCTX` contexts:: >>> ACTX(Connection)(pre_cell="VA11", post_cell="VD12", number=3) >>> BCTX(Connection)(pre_cell="VA11", post_cell="VD12", number=2) In `EVCTX`, state that a that a certain document supports the set of statements in `ACTX`, but refutes the set of statements in `BCTX`:: >>> doc = EVCTX(Document)(author='White et al.', date='1986') >>> EVCTX(Evidence)(reference=doc, supports=ACTX.rdf_object) >>> EVCTX(Evidence)(reference=doc, refutes=BCTX.rdf_object) Finally, save the contexts:: >>> ACTX.save_context() >>> BCTX.save_context() >>> EVCTX.save_context() One note about the `reference` predicate: the reference should, ideally, be an unambiguous link to a peer-reviewed piece of scientific literature detailing methods and data analysis that supports the set of statements. However, in gather data from pre-existing sources, going to that level of specificity may be difficult due to deficient query capability at the data source. In such cases, a broader reference, such as a `Website` with information which guides readers to a peer-reviewed article supporting the statement is sufficient. """ class_context = SCI_CTX supports = ObjectProperty(value_type=ContextDataObject, mixins=(ContextToDataObjectMixin, )) '''A context naming a set of statements which are supported by the attached reference''' refutes = ObjectProperty(value_type=ContextDataObject, mixins=(ContextToDataObjectMixin, )) '''A context naming a set of statements which are refuted by the attached reference''' reference = ObjectProperty() '''The resource providing evidence supporting/refuting the attached context''' def defined_augment(self): return ((self.supports.has_defined_value() or self.refutes.has_defined_value()) and self.reference.has_defined_value()) def identifier_augment(self): s = "" if self.supports.has_defined_value: s += self.supports.onedef().identifier.n3() else: s += self.refutes.onedef().identifier.n3() s += self.reference.onedef().identifier.n3() return self.make_identifier(s)
class Connection(BiologyType): class_context = BiologyType.class_context post_cell = ObjectProperty(value_type=Cell) ''' The post-synaptic cell ''' pre_cell = ObjectProperty(value_type=Cell) ''' The pre-synaptic cell ''' number = DatatypeProperty() ''' The weight of the connection ''' synclass = DatatypeProperty() ''' The kind of Neurotransmitter (if any) sent between `pre_cell` and `post_cell` ''' syntype = DatatypeProperty() ''' The kind of synaptic connection. 'gapJunction' indicates a gap junction and 'send' a chemical synapse ''' termination = DatatypeProperty() ''' Where the connection terminates. Inferred from type of post_cell at initialization ''' key_properties = (pre_cell, post_cell, syntype) # Arguments are given explicitly here to support positional arguments def __init__(self, pre_cell=None, post_cell=None, number=None, syntype=None, synclass=None, termination=None, **kwargs): super(Connection, self).__init__(pre_cell=pre_cell, post_cell=post_cell, number=number, syntype=syntype, synclass=synclass, **kwargs) if isinstance(termination, six.string_types): termination = termination.lower() if termination in ('neuron', Termination.Neuron): self.termination(Termination.Neuron) elif termination in ('muscle', Termination.Muscle): self.termination(Termination.Muscle) if isinstance(syntype, six.string_types): syntype = syntype.lower() if syntype in ('send', SynapseType.Chemical): self.syntype(SynapseType.Chemical) elif syntype in ('gapjunction', SynapseType.GapJunction): self.syntype(SynapseType.GapJunction) def __str__(self): nom = [] props = ( 'pre_cell', 'post_cell', 'syntype', 'termination', 'number', 'synclass', ) for p in props: if getattr(self, p).has_defined_value(): nom.append((p, getattr(self, p).defined_values[0])) if len(nom) == 0: return super(Connection, self).__str__() else: return 'Connection(' + \ ', '.join('{}={}'.format(n[0], n[1]) for n in nom) + \ ')'
class Cell(BiologyType): """ A biological cell. All cells with the same `name` are considered to be the same object. Parameters ----------- name : str The name of the cell lineageName : str The lineageName of the cell Examples -------- >>> from owmeta_core.quantity import Quantity >>> c = Cell(lineageName="AB plapaaaap", ... divisionVolume=Quantity("600","(um)^3")) """ class_context = BiologyType.class_context rdf_type = CELL_RDF_TYPE divisionVolume = DatatypeProperty() ''' The volume of the cell at division ''' name = DatatypeProperty() ''' The 'adult' name of the cell typically used by biologists when discussing C. elegans ''' wormbaseID = DatatypeProperty() description = DatatypeProperty() ''' A description of the cell ''' channel = ObjectProperty(value_type=Channel, multiple=True, inverse_of=(Channel, 'appearsIn')) lineageName = DatatypeProperty() ''' The lineageName of the cell ''' synonym = DatatypeProperty(multiple=True) daughterOf = ObjectProperty(value_type=This, inverse_of=(This, 'parentOf')) parentOf = ObjectProperty(value_type=This, multiple=True) key_property = {'property': name, 'type': 'direct'} def __init__(self, name=None, lineageName=None, **kwargs): # NOTE: We name the `name` and `lineageName` as positional parameters for # convenience super(Cell, self).__init__(name=name, lineageName=lineageName, **kwargs) def blast(self): """ Return the blast name. Example:: >>> c = Cell(name="ADAL", lineageName='AB ') >>> c.blast() 'AB' Note that this isn't a `~dataobject_property.Property`. It returns the blast cell part of a `lineageName` value. """ import re try: ln = self.lineageName() x = re.split("[. ]", ln) return x[0] except Exception: return "" def __str__(self): if self.name.has_defined_value(): return str(self.name.defined_values[0].idl) else: return super(Cell, self).__str__()