def do_insert(config="default.conf", logging=False): if config: if isinstance(config, P.Configure): pass elif isinstance(config, str): config = P.Configure.open(config) elif isinstance(config, dict): config = P.Configure().copy(config) else: raise Exception("Invalid configuration object "+ str(config)) P.connect(conf=config, do_logging=logging) try: w = P.Worm() net = P.Network() w.neuron_network(net) w.save() upload_neurons() upload_muscles() upload_lineage_and_descriptions() upload_synapses() upload_receptors_and_innexins() upload_types() serialize_as_n3() #infer() except: traceback.print_exc() finally: P.disconnect()
def read(self): conns = [] cells = [] cell_names = owr.get_cells_in_model() for s in self.all_connections: pre = str(s.pre_cell().name()) post = str(s.post_cell().name()) if isinstance(s.post_cell(), P.Neuron) and pre in cell_names and post in cell_names: syntype = str(s.syntype()) syntype = syntype[0].upper()+syntype[1:] num = int(s.number()) synclass = str(s.synclass()) ci = ConnectionInfo(pre, post, num, syntype, synclass) conns.append(ci) if pre not in cells: cells.append(pre) if post not in cells: cells.append(post) logger.info("Total cells read " + str(len(cells))) logger.info("Total connections read " + str(len(conns))) P.disconnect() return cells, conns
def Evidences(request): P.connect() try: EVIDENCE_DICT = {} count = 0 for evidence in P.Evidence().load(): EVIDENCE_DICT[str(count)] = { 'index': count, 'doi': list(evidence.doi.get()), 'pmid': list(evidence.pmid.get()), 'wormbaseid': list(evidence.wbid.get()), 'author': list(evidence.author.get()), 'title': list(evidence.title.get()), 'year': list(evidence.year.get()), 'uri': list(evidence.uri.get()), 'completeness': '#2B7558' } count += 1 finally: P.disconnect() return render_to_response('pyopenworm/evidences.html', {'evidences': EVIDENCE_DICT})
def test_adapt_reference(data_pool): """Test that we can map a Reference object to a PyOpenWorm Experiment object.""" r = data_pool.get_reference() reference_adapter = Adapter.create(r) experiment = reference_adapter.get_pow() reference = reference_adapter.get_cw() PyOpenWorm.connect() pyow_dict = { 'authors': experiment.author(), 'doi': experiment.doi(), 'pmid': experiment.pmid(), 'title': experiment.title(), 'url': experiment.uri(), 'year': experiment.year(), } cw_dict = { 'authors': set([reference.authors]), 'doi': reference.doi, 'pmid': reference.PMID, 'title': reference.title, 'url': set([reference.url]), 'year': reference.year } PyOpenWorm.disconnect() assert pyow_dict == cw_dict
def __init__(self, cw_obj): # initialize PyOpenWorm connection so we can access its API P.connect() self.channelworm_object = cw_obj cw_dict = model_to_dict(self.channelworm_object) experiment_id = cw_dict.pop('experiment') patch_clamp_id = cw_dict.pop('id') self.pyopenworm_object = P.Experiment() # get the CW model's experiment cw_evidence = C.Experiment.objects.get(id=experiment_id) # make a PyOW evidence object with it pow_evidence = P.Evidence(doi=cw_evidence.doi) # add it to the PyOW experiment model self.pyopenworm_object.reference(pow_evidence) for key, value in cw_dict.iteritems(): self.pyopenworm_object.conditions.set(key, value) # we not longer need PyOW API so we can kill the connection P.disconnect()
def do_insert(config="default.conf", logging=False): if config: if isinstance(config, P.Configure): pass elif isinstance(config, str): config = P.Configure.open(config) elif isinstance(config, dict): config = P.Configure().copy(config) else: raise Exception("Invalid configuration object " + str(config)) P.connect(conf=config, do_logging=logging) try: w = P.Worm() net = P.Network() w.neuron_network(net) w.save() upload_neurons() upload_muscles() upload_lineage_and_descriptions() upload_synapses() upload_receptors_and_innexins() upload_types() serialize_as_n3() #infer() except: traceback.print_exc() finally: P.disconnect()
def __init__(self, cw_obj): self.channelworm_object = cw_obj self.map_properties() P.connect() self.pyopenworm_object.set_data(cw_obj.asarray()) P.disconnect()
def __init__(self, cw_obj): # initialize PyOpenWorm connection so we can access its API P.connect() self.channelworm_object = cw_obj cw_dict = model_to_dict(self.channelworm_object) experiment_id = cw_dict.pop('experiment') patch_clamp_id = cw_dict.pop('id') self.pyopenworm_object = P.Experiment() # get the CW model's experiment cw_evidence = C.Experiment.objects.get(id=experiment_id) # make a PyOW evidence object with it pow_evidence = P.Evidence(doi=cw_evidence.doi) # add it to the PyOW experiment model self.pyopenworm_object.reference(pow_evidence) for key, value in cw_dict.iteritems(): self.pyopenworm_object.conditions.set(key, value) # we not longer need PyOW API so we can kill the connection P.disconnect()
def read(self): conns = [] cells = [] cell_names = owr.get_cells_in_model() for s in self.all_connections: pre = str(s.pre_cell().name()) post = str(s.post_cell().name()) if isinstance( s.post_cell(), P.Neuron) and pre in cell_names and post in cell_names: syntype = str(s.syntype()) syntype = syntype[0].upper() + syntype[1:] num = int(s.number()) synclass = str(s.synclass()) ci = ConnectionInfo(pre, post, num, syntype, synclass) conns.append(ci) if pre not in cells: cells.append(pre) if post not in cells: cells.append(post) logger.info("Total cells read " + str(len(cells))) logger.info("Total connections read " + str(len(conns))) P.disconnect() return cells, conns
def handle(self, *args, **options): P.connect() print 'clearing data' self.Del_Neuron() self.Del_Muscle() self.Del_IonChannel() print 'done' print "calculating scores" self.scoring_ionchannels() self.scoring_neurons() self.scoring_muscles() P.disconnect() print "scores calculated"
def Channels(request): P.connect() try: CHANNEL_DICT = {} for channel in P.Channel().load(): CHANNEL_DICT[str(channel)] = { 'name': str(channel), 'completeness': '#2B7558' } finally: P.disconnect() return render_to_response('pyopenworm/channels.html', {'channels': CHANNEL_DICT})
def Muscles(request): P.connect() try: MUSCLE_DICT = {} for muscle in P.Muscle().load(): MUSCLE_DICT[str(muscle)] = { 'name': str(muscle), 'completeness': '#2B7558' } finally: P.disconnect() return render_to_response('pyopenworm/muscles.html', {'muscles': MUSCLE_DICT})
def Neurons(request): P.connect() try: NEURON_DICT = {} for neuron in P.Neuron().load(): NEURON_DICT[str(neuron)] = { 'name': str(neuron), 'completeness': '#2B7558' } finally: P.disconnect() return render_to_response('pyopenworm/neurons.html', {'neurons': NEURON_DICT})
def Channel(request, channel_id): P.connect() try: channel_dict = {} for channel in P.Channel().load(): channel_dict[str(channel)] = { 'name': str(channel), 'completeness': '#2B7558' } finally: P.disconnect() return render_to_response('pyopenworm/channel.html', {'channel': channel_dict[channel_id]})
def test_adapt_GraphData(data_pool): """ Test that we can map some GraphData to a PyOpenWorm data object. """ graph_data = data_pool.get_graph_data() gda = Adapter.create(graph_data) cw_obj = gda.get_cw() pow_obj = gda.get_pow() PyOpenWorm.connect() assert cw_obj.asarray() == pow_obj.data PyOpenWorm.disconnect()
def setUpClass(cls): import csv PyOpenWorm.connect( conf=Configure( **{'rdf.store_conf': 'tests/test.db', 'rdf.source': 'ZODB'})) PyOpenWorm.loadData(skipIfNewer=False) PyOpenWorm.disconnect() # grab the list of the names of the 302 neurons csvfile = open('OpenWormData/aux_data/neurons.csv', 'r') reader = csv.reader(csvfile, delimiter=';', quotechar='|') # array that holds the names of the 302 neurons at class-level scope cls.neurons = [] for row in reader: if len(row[0]) > 0: # Only saves valid neuron names cls.neurons.append(row[0])
def map_properties(self): """ Map between the properties defined in the subclass. """ # initialize PyOpenWorm connection so we can access its API P.connect() # initialize pyopenworm object self.pyopenworm_object = self.pyopenworm_class() for p, c in self.pyow_to_cw.items(): cw_value = getattr(self.channelworm_object, c) pow_property = getattr(self.pyopenworm_object, p) map(pow_property, [cw_value]) P.disconnect()
def Muscle(request, muscle_id): P.connect() try: muscle_dict = {} for muscle in P.Muscle(muscle_id).load(): ''' 'neurons': list(muscle.neurons.get()), 'receptors': list(muscle.receptors.get()), ''' muscle_dict[str(muscle)] = { 'name': str(muscle), 'completeness': '#2B7558' } finally: P.disconnect() return render_to_response('pyopenworm/muscle.html', {'muscle': muscle_dict[muscle_id]})
def setUpClass(cls): import csv PyOpenWorm.connect(conf=Configure( **{ 'rdf.store_conf': 'tests/test.db', 'rdf.source': 'ZODB' })) PyOpenWorm.loadData(skipIfNewer=False) PyOpenWorm.disconnect() # grab the list of the names of the 302 neurons csvfile = open('OpenWormData/aux_data/neurons.csv', 'r') reader = csv.reader(csvfile, delimiter=';', quotechar='|') # array that holds the names of the 302 neurons at class-level scope cls.neurons = [] for row in reader: if len(row[0]) > 0: # Only saves valid neuron names cls.neurons.append(row[0])
def do_insert(config="default.conf", logging=False): global SQLITE_EVIDENCE global WORM global NETWORK if config: if isinstance(config, P.Configure): pass elif isinstance(config, str): config = P.Configure.open(config) elif isinstance(config, dict): config = P.Configure().copy(config) else: raise Exception("Invalid configuration object " + str(config)) P.connect(conf=config, do_logging=logging) SQLITE_EVIDENCE = P.Evidence(key="C_elegans_SQLite_DB", title="C. elegans sqlite database") try: WORM = P.Worm() NETWORK = P.Network() WORM.neuron_network(NETWORK) NETWORK.worm(WORM) upload_neurons() upload_muscles() upload_lineage_and_descriptions() upload_connections() upload_receptors_types_neurotransmitters_neuropeptides_innexins() upload_additional_receptors_neurotransmitters_neuropeptides_innexins() print("Saving...") WORM.save() #infer() print("Serializing...") serialize_as_n3() except Exception: traceback.print_exc() finally: P.disconnect()
def Neuron(request, neuron_id): P.connect() try: neuron_dict = {} for neuron in P.Neuron(neuron_id).load(): neuron_dict[str(neuron)] = { 'name': str(neuron), 'type': list(neuron.type.get()), 'receptor': list(neuron.receptor.get()), 'innexin': list(neuron.innexin.get()), 'neurotransmitter': list(neuron.neurotransmitter.get()), 'neuropeptide': list(neuron.neuropeptide.get()), 'completeness': '#2B7558' } finally: P.disconnect() return render_to_response('pyopenworm/neuron.html', {'neuron': neuron_dict[neuron_id]})
def read(self): conns = [] cells = [] for s in self.all_connections: pre = str(s.pre_cell()) post = str(s.post_cell()) syntype = str(s.syntype()) num = int(s.number()) synclass = str(s.synclass()) conns.append(ConnectionInfo(pre, post, num, syntype, synclass)) if pre not in cells: cells.append(pre) if post not in cells: cells.append(post) logger.info("Total cells read " + str(len(cells))) logger.info("Total connections read " + str(len(conns))) P.disconnect() return cells, conns
def do_insert(config="default.conf", logging=False): global SQLITE_EVIDENCE global WORM global NETWORK if config: if isinstance(config, P.Configure): pass elif isinstance(config, str): config = P.Configure.open(config) elif isinstance(config, dict): config = P.Configure().copy(config) else: raise Exception("Invalid configuration object " + str(config)) P.connect(conf=config, do_logging=logging) SQLITE_EVIDENCE = P.Evidence(key="C_elegans_SQLite_DB", title="C. elegans sqlite database") try: WORM = P.Worm() NETWORK = P.Network() WORM.neuron_network(NETWORK) NETWORK.worm(WORM) upload_neurons() upload_muscles() upload_lineage_and_descriptions() upload_connections() upload_receptors_types_neurotransmitters_neuropeptides_innexins() print("Saving...") WORM.save() infer() print("Serializing...") serialize_as_n3() except: traceback.print_exc() finally: P.disconnect()
def test_adapt_PatchClamp(data_pool): """ Test that we can map a PatchClamp object to a PyOpenWorm PatchClamp object. """ pc = data_pool.get_patch_clamp() pca = Adapter.create(pc) cw_obj = pca.get_cw() pow_obj = pca.get_pow() PyOpenWorm.connect() pow_dict = { 'delta_t': pow_obj.delta_t(), 'duration': pow_obj.duration(), 'end_time': pow_obj.end_time(), 'ion_channel': pow_obj.ion_channel(), 'protocol_end': pow_obj.protocol_end(), 'protocol_start': pow_obj.protocol_start(), 'protocol_step': pow_obj.protocol_step(), 'start_time': pow_obj.start_time(), } cw_dict = { 'delta_t': cw_obj.deltat, 'duration': cw_obj.duration, 'end_time': cw_obj.end_time, 'ion_channel': cw_obj.ion_channel, 'protocol_end': cw_obj.protocol_end, 'protocol_start': cw_obj.protocol_start, 'protocol_step': cw_obj.protocol_step, 'start_time': cw_obj.start_time, } PyOpenWorm.disconnect() assert cw_dict == pow_dict
def read_data(include_nonconnected_cells=False): print_("Initialising OpenWormReader") P.connect() net = P.Worm().get_neuron_network() all_connections = net.synapses() print_("Finished initialising OpenWormReader") conns = [] cells = [] cell_names = get_cells_in_model(net) for s in all_connections: pre = str(s.pre_cell().name()) post = str(s.post_cell().name()) if isinstance(s.post_cell(), P.Neuron) and pre in cell_names and post in cell_names: syntype = str(s.syntype()) syntype = syntype[0].upper() + syntype[1:] num = int(s.number()) synclass = str(s.synclass()) ci = ConnectionInfo(pre, post, num, syntype, synclass) conns.append(ci) if pre not in cells: cells.append(pre) if post not in cells: cells.append(post) print_("Total cells %i (%i with connections)" % (len(cell_names), len(cells))) print_("Total connections found %i " % len(conns)) P.disconnect() if include_nonconnected_cells: return cell_names, conns else: return cells, conns
def do_insert(): import sys logging = False if len(sys.argv) > 1 and sys.argv[1] == '-l': logging = True P.connect(configFile='default.conf', do_logging=logging) try: upload_muscles() print ("uploaded muscles") upload_lineage_and_descriptions() print ("uploaded lineage and descriptions") upload_synapses() print ("uploaded synapses") upload_receptors_and_innexins() print ("uploaded receptors and innexins") update_neurons_and_muscles_with_lineage_and_descriptions() print ("updated muscles and neurons with cell data") infer() print ("filled in with inferred data") except: traceback.print_exc() finally: P.disconnect()
def do_insert(): import sys logging = False if len(sys.argv) > 1 and sys.argv[1] == '-l': logging = True P.connect(configFile='default.conf', do_logging=logging) try: upload_neurons() print ("uploaded neurons") #upload_muscles() print ("uploaded muscles") upload_lineage_and_descriptions() print ("uploaded lineage and descriptions") #upload_synapses() print ("uploaded synapses") #upload_receptors_and_innexins() print ("uploaded receptors and innexins") #infer() print ("filled in with inferred data") except: traceback.print_exc() finally: P.disconnect()
def tearDownClass(cls): PyOpenWorm.disconnect()
def do_insert(ident, config="default.conf", logging=False, imports_context_ident=None, basedir=aux_data()): sources = init_sources() extras = init_extra_sources(basedir) data_sources_by_key = {x.key: x for x in sources + extras} trans_map = init_translators() + init_extra_neuron_data_translators(extras) P.connect(configFile=config, do_logging=logging) P.config() CTX = Context(ident=ident + '-data', imported=(P.CONTEXT, ), conf=P.config()) EVCTX = Context(ident=ident + '-evidence', imported=(P.CONTEXT, ), conf=P.config()) IWCTX = Context(ident=ident, imported=(CTX, EVCTX), conf=P.config()) imports_context = Context(ident=imports_context_ident, conf=P.config()) try: t0 = time() translators = dict() remaining = list(trans_map) last_remaining = None saved_contexts = set([]) while remaining != last_remaining: next_remaining = [] for t in remaining: if not isinstance(t[0], (list, tuple)): source_keys = (t[0], ) else: source_keys = t[0] sources = tuple( data_sources_by_key.get(s) for s in source_keys) if None in sources: next_remaining.append(t) continue translator_class = t[1] if len(t) > 2: output_key = t[2] else: output_key = None translator = translators.get(translator_class, None) if not translator: translator = translator_class() translators[translator_class] = translator print('\n'.join( 'Input({}/{}): {}'.format(i + 1, len(sources), s) for i, s in enumerate(sources))) print('Translating with {}'.format(translator)) orig_wd = os.getcwd() os.chdir(basedir) try: res = translator(*sources, output_key=output_key) finally: os.chdir(orig_wd) print('Result: {}'.format(res)) if isinstance(res, DataWithEvidenceDataSource): res.data_context.save_context( inline_imports=True, saved_contexts=saved_contexts) res.data_context.save_imports(imports_context) res.evidence_context.save_context( inline_imports=True, saved_contexts=saved_contexts) res.evidence_context.save_imports(imports_context) for ctx in res.contexts: raise Exception() if res: if res.key: data_sources_by_key[res.key] = res else: data_sources_by_key[res.identifier] = res last_remaining = list(remaining) remaining = next_remaining for x in remaining: warn("Failed to process: {}".format(x)) # attach_neuromlfiles_to_channel() t1 = time() print("Saving data...") graph = P.config('rdf.graph') for src in data_sources_by_key.values(): if isinstance(src, DataWithEvidenceDataSource): print('saving', src) CTX.add_import(src.data_context) EVCTX.add_import(src.evidence_context) for ctx in src.contexts: IWCTX.add_import(ctx) IWCTX.save_context(graph, saved_contexts=saved_contexts) IWCTX.save_imports(imports_context) print('imports context size', len(imports_context)) print("Saved %d triples." % IWCTX.triples_saved) t2 = time() print("Serializing...") serialize_as_nquads() t3 = time() print("generating objects took", t1 - t0, "seconds") print("saving objects took", t2 - t1, "seconds") print("serializing objects took", t3 - t2, "seconds") except Exception: traceback.print_exc() finally: P.disconnect()
def my_signal_handler(signal, frame): P.disconnect() sys.exit(0)
def setUpClass(self): PyOpenWorm.connect() PyOpenWorm.loadData(skipIfNewer=False) PyOpenWorm.disconnect() os.chdir('examples')
import PyOpenWorm as P #Create dummy database configuration. d = P.Data({}) #Connect to database with dummy configuration P.connect(conf=d) #Create a new Neuron object to work with n = P.Neuron(name='AVAL') #Create a new Evidence object with `doi` and `pmid` fields populated. #See `PyOpenWorm/evidence.py` for other available fields. e = P.Evidence(doi='125.41.3/ploscompbiol', pmid='57182010') #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. e.asserts(n.receptor('UNC-8')) #Save the Neuron and Evidence objects to the database. n.save() e.save() #What does my evidence object contain? print e #Disconnect from the database. P.disconnect()
ctx = Context(ident='http://example.org/data', conf=conn.conf) 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)
def tearDown(self): PyOpenWorm.disconnect()
def tearDown(self): PyOpenWorm.disconnect() self.delete_dir()
def tearDown(self): PyOpenWorm.disconnect(self.connection) self.delete_dir()
def setUpClass(self): PyOpenWorm.connect() PyOpenWorm.loadData(skipIfNewer=False) PyOpenWorm.disconnect() os.chdir('examples')
def tearDown(self): PyOpenWorm.disconnect()
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)
def __exit__(self, exc_type, exc_val, exc_tb): self.ctx = None self.worm = None self.net = None P.disconnect()
def do_insert(ident, config="default.conf", logging=False, imports_context_ident=None, basedir=aux_data()): sources = init_sources() extras = init_extra_sources(basedir) data_sources_by_key = {x.key: x for x in sources + extras} trans_map = init_translators() + init_extra_neuron_data_translators(extras) P.connect(configFile=config, do_logging=logging) P.config() CTX = Context(ident=ident + '-data', imported=(P.CONTEXT,), conf=P.config()) EVCTX = Context(ident=ident + '-evidence', imported=(P.CONTEXT,), conf=P.config()) IWCTX = Context(ident=ident, imported=(CTX, EVCTX), conf=P.config()) imports_context = Context(ident=imports_context_ident, conf=P.config()) try: t0 = time() translators = dict() remaining = list(trans_map) last_remaining = None saved_contexts = set([]) while remaining != last_remaining: next_remaining = [] for t in remaining: if not isinstance(t[0], (list, tuple)): source_keys = (t[0],) else: source_keys = t[0] sources = tuple(data_sources_by_key.get(s) for s in source_keys) if None in sources: next_remaining.append(t) continue translator_class = t[1] if len(t) > 2: output_key = t[2] else: output_key = None translator = translators.get(translator_class, None) if not translator: translator = translator_class() translators[translator_class] = translator print('\n'.join('Input({}/{}): {}'.format(i + 1, len(sources), s) for i, s in enumerate(sources))) print('Translating with {}'.format(translator)) orig_wd = os.getcwd() os.chdir(basedir) try: res = translator(*sources, output_key=output_key) finally: os.chdir(orig_wd) print('Result: {}'.format(res)) if isinstance(res, DataWithEvidenceDataSource): res.data_context.save_context(inline_imports=True, saved_contexts=saved_contexts) res.data_context.save_imports(imports_context) res.evidence_context.save_context(inline_imports=True, saved_contexts=saved_contexts) res.evidence_context.save_imports(imports_context) for ctx in res.contexts: raise Exception() if res: if res.key: data_sources_by_key[res.key] = res else: data_sources_by_key[res.identifier] = res last_remaining = list(remaining) remaining = next_remaining for x in remaining: warn("Failed to process: {}".format(x)) # attach_neuromlfiles_to_channel() t1 = time() print("Saving data...") graph = P.config('rdf.graph') for src in data_sources_by_key.values(): if isinstance(src, DataWithEvidenceDataSource): print('saving', src) CTX.add_import(src.data_context) EVCTX.add_import(src.evidence_context) for ctx in src.contexts: IWCTX.add_import(ctx) IWCTX.save_context(graph, saved_contexts=saved_contexts) IWCTX.save_imports(imports_context) print('imports context size', len(imports_context)) print("Saved %d triples." % IWCTX.triples_saved) t2 = time() print("Serializing...") serialize_as_nquads() t3 = time() print("generating objects took", t1 - t0, "seconds") print("saving objects took", t2 - t1, "seconds") print("serializing objects took", t3 - t2, "seconds") except Exception: traceback.print_exc() finally: P.disconnect()
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()
def finish(self): P.disconnect()