コード例 #1
0
class POW:
    def __init__(self):
        self.ctx: Context = None
        self.worm: Worm = None
        self.net: Network = None

    def __enter__(self):
        # if P.connected:
        #     raise RuntimeError("Already connected")
        P.connect(POW_CONF_PATH)
        self.ctx = Context(ident=WORM_IDENT)
        self.worm = self.ctx.stored(Worm)()
        self.net = self.worm.neuron_network()

        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.ctx = None
        self.worm = None
        self.net = None
        P.disconnect()
コード例 #2
0
ファイル: add_reference.py プロジェクト: gsarma/PyOpenWorm
ctx = Context(ident='http://example.org/data')
evctx = Context(ident='http://example.org/meta')

# Create a new Neuron object to work with
n = ctx(Neuron)(name='AVAL')

# Create a new Evidence object with `doi` and `pmid` fields populated.
# See `PyOpenWorm/evidence.py` for other available fields.
d = evctx(Document)(key='Anonymous2011', doi='125.41.3/ploscompbiol', pmid='12345678')
e = evctx(Evidence)(key='Anonymous2011', reference=d)

# Evidence object asserts something about the enclosed dataObject.
# Here we add a receptor to the Neuron we made earlier, and "assert it".
# As the discussion (see top) reads, this might be asserting the existence of
# receptor UNC-8 on neuron AVAL.
n.receptor('UNC-8')

e.supports(ctx.rdf_object)

# Save the Neuron and Evidence objects to the database.
ctx.save_context()
evctx.save_context()

# What does my evidence object contain?
for e_i in evctx.stored(Evidence)().load():
    print(e_i.reference())
    print(e_i.supports())

# Disconnect from the database.
P.disconnect()
コード例 #3
0
evctx = Context(ident='http://example.org/meta', conf=conn.conf)

# Create a new Neuron object to work with
n = ctx(Neuron)(name='AVAL')

# Create a new Evidence object with `doi` and `pmid` fields populated.
# See `PyOpenWorm/evidence.py` for other available fields.
d = evctx(Document)(key='Anonymous2011',
                    doi='125.41.3/ploscompbiol',
                    pmid='12345678')
e = evctx(Evidence)(key='Anonymous2011', reference=d)

# Evidence object asserts something about the enclosed dataObject.
# Here we add a receptor to the Neuron we made earlier, and "assert it".
# As the discussion (see top) reads, this might be asserting the existence of
# receptor UNC-8 on neuron AVAL.
n.receptor('UNC-8')

e.supports(ctx.rdf_object)

# Save the Neuron and Evidence objects to the database.
ctx.save_context()
evctx.save_context()

# What does my evidence object contain?
for e_i in evctx.stored(Evidence)().load():
    print(e_i.reference(), e_i.supports())

# Disconnect from the database.
P.disconnect(conn)
コード例 #4
0
        if len(lctx) == 0:
            return frozenset()
        else:
            lctx = frozenset(ctxs) & lctx
            if len(lctx) == 0:
                return lctx
    return frozenset() if lctx is None else lctx


qctx = Context()
qctx(Neuron)('AVAL').innexin('UNC-7')
ctxs = query_context(conn.conf['rdf.graph'], qctx)
for c in ctxs:
    mqctx = Context(conf=conn.conf)
    print('CONTEXT', c.identifier)
    ev = mqctx.stored(Evidence)()
    ev.supports(Context(ident=c.identifier, conf=conn.conf).rdf_object)
    for x in ev.load():
        ref = x.reference()
        if isinstance(ref, Document):
            print(ref)
            print('AUTHOR:', ref.author())
            print('URI:', ref.uri())
            print('DOI:', ref.doi())
            print('PMID:', ref.pmid())
            print('WBID:', ref.wbid())
            print()
        elif isinstance(ref, Website):
            print(ref)
            print('TITLE:', ref.title())
            print('URL:', ref.url())
コード例 #5
0
ファイル: query_context.py プロジェクト: openworm/PyOpenWorm
        if len(lctx) == 0:
            return frozenset()
        else:
            lctx = frozenset(ctxs) & lctx
            if len(lctx) == 0:
                return lctx
    return frozenset() if lctx is None else lctx


qctx = Context()
qctx(Neuron)('AVAL').innexin('UNC-7')
ctxs = query_context(conn.conf['rdf.graph'], qctx)
for c in ctxs:
    mqctx = Context(conf=conn.conf)
    print('CONTEXT', c.identifier)
    ev = mqctx.stored(Evidence)()
    ev.supports(Context(ident=c.identifier, conf=conn.conf).rdf_object)
    for x in ev.load():
        ref = x.reference()
        if isinstance(ref, Document):
            print(ref)
            print('AUTHOR:', ref.author())
            print('URI:', ref.uri())
            print('DOI:', ref.doi())
            print('PMID:', ref.pmid())
            print('WBID:', ref.wbid())
            print()
        elif isinstance(ref, Website):
            print(ref)
            print('TITLE:', ref.title())
            print('URL:', ref.url())
コード例 #6
0
from PyOpenWorm.evidence import Evidence
from PyOpenWorm.experiment import Experiment

#Connect to existing database.
P.connect('default.conf')

ctx = Context(ident="http://example.org/bio/ion_channel")

chan = ctx(Channel)(name='Ch0')
chan.subfamily("chanfam")

cm = ctx(PatchClampChannelModel)(key='patch-clamp-01')
cm.ion('K+')
cm.gating('voltage')
chan.model(cm)
pc = ctx(PatchClampExperiment)(
    key='patch-clamp-01',
    initial_voltage=Quantity(30, 'mV'),
    pipette_solution='Ringer\'s solution',
    start_time=datetime.datetime(2018, 5, 26, 15, 56, 41, 244489),
    end_time=datetime.datetime(2018, 5, 26, 15, 57, 41, 244489),
    type='current clamp')

cm.modeled_from(pc)

ctx.save_context()

print(cm.rdf.serialize(format='n3').decode('utf-8'))
chan1 = ctx.stored(Channel)()
print((set(chan1.load())))