Skip to content

Commit be807f7

Browse files
committed
Adding a command for showing cells
- Fixing WormBaseIDSetter -- was skipping too many lines and not normalizing cell names - Small update to uses of OWM._conf
1 parent b5a0e8a commit be807f7

File tree

8 files changed

+77
-9
lines changed

8 files changed

+77
-9
lines changed

Diff for: examples/default.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"rdf.source" : "lazy_pickle",
2+
"rdf.source" : "zodb",
33
"rdf.store_conf" : "../.owm/worm.db",
44
"imports_context_id": "http://openworm.org/data/imports",
55
"rdf.upload_block_statement_count" : 50

Diff for: owmeta/bundle.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def __init__(self, ident, bundles_directory=None, version=None, conf=None, remot
242242
bundles_directory = expanduser(p('~', '.owmeta', 'bundles'))
243243
self.bundles_directory = bundles_directory
244244
if not conf:
245-
conf = {'rdf.source': 'lazy_pickle'}
245+
conf = {'rdf.source': 'zodb'}
246246
self.version = version
247247
self.remotes = remotes
248248
self._given_conf = conf

Diff for: owmeta/cli_hints.py

+7
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,11 @@
185185
},
186186
},
187187
},
188+
'owmeta.commands.biology.CellCmd': {
189+
'show': {
190+
(METHOD_NAMED_ARG, 'cell_name_or_id'): {
191+
'names': ['cell_name_or_id'],
192+
},
193+
},
194+
},
188195
}

Diff for: owmeta/command.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from .command_util import (IVar, SubCommand, GeneratorWithData, GenericUserError,
2828
DEFAULT_OWM_DIR)
2929
from .commands.bundle import OWMBundle
30+
from .commands.biology import CellCmd
3031
from .context import Context, DEFAULT_CONTEXT_KEY, IMPORTS_CONTEXT_KEY
3132
from .capability import provide
3233
from .capabilities import FilePathProvider
@@ -588,7 +589,7 @@ def edit(self, context=None, format=None, editor=None, list_formats=False):
588589
from subprocess import call
589590
if context is None:
590591
ctx = self._parent._default_ctx
591-
ctxid = self._parent._conf()[DEFAULT_CONTEXT_KEY]
592+
ctxid = self._parent._conf(DEFAULT_CONTEXT_KEY)
592593
else:
593594
ctx = Context(ident=context, conf=self._parent._conf())
594595
ctxid = context
@@ -722,6 +723,8 @@ class OWM(object):
722723

723724
registry = SubCommand(OWMRegistry)
724725

726+
cell = SubCommand(CellCmd)
727+
725728
def __init__(self, owmdir=None):
726729
self.progress_reporter = default_progress_reporter
727730
self.message = lambda *args, **kwargs: print(*args, **kwargs)
@@ -1390,7 +1393,7 @@ def list_contexts(self):
13901393

13911394
@property
13921395
def rdf(self):
1393-
return self._conf()['rdf.graph']
1396+
return self._conf('rdf.graph')
13941397

13951398
def commit(self, message):
13961399
'''

Diff for: owmeta/commands/biology.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import six
2+
3+
from ..command_util import GeneratorWithData
4+
from ..cell import Cell
5+
6+
7+
class CellCmd(object):
8+
'''
9+
Commands for dealing with biological cells
10+
'''
11+
12+
def __init__(self, parent, *args, **kwargs):
13+
self._parent = parent
14+
15+
def show(self, cell_name_or_id, context=None):
16+
'''
17+
Show information about the cell
18+
19+
Parameters
20+
----------
21+
cell_name_or_id : str
22+
Cell name or Cell URI
23+
context : str
24+
Context to search in. Optional, defaults to the default context.
25+
'''
26+
27+
if not context:
28+
ctx = self._parent._default_ctx
29+
else:
30+
ctx = Context(context)
31+
32+
def helper():
33+
for cell in ctx.stored(Cell).query(name=cell_name_or_id).load():
34+
yield cell
35+
break
36+
else: # no break
37+
uri = self._parent._den3(cell_name_or_id)
38+
for x in ctx.stored(Cell)(ident=uri).load():
39+
yield cell
40+
41+
def fmt_text(cell):
42+
try:
43+
sio = six.StringIO()
44+
45+
nm = self._parent._conf('rdf.namespace_manager')
46+
print('%s(%s)' % (cell.__class__.__name__, nm.normalizeUri(cell.identifier)), file=sio)
47+
print(' Lineage name: %s' % cell.lineageName(), file=sio)
48+
print(' Name: %s' % cell.name(), file=sio)
49+
print(' WormBase ID: %s' % cell.wormbaseID(), end='', file=sio)
50+
return sio.getvalue()
51+
except AttributeError:
52+
res = str(cell)
53+
L.error('Failed while creating formatting string representation for %s', res)
54+
return res
55+
56+
return GeneratorWithData(helper(), text_format=fmt_text)

Diff for: owmeta/data_trans/wormbase.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ class WormbaseIDSetter(CSVDataTranslator):
243243
def translate(self, data_source, cells_source):
244244
""" Upload muscles and the neurons that connect to them """
245245
res = self.make_new_output((data_source,))
246-
with self.make_reader(data_source, skipinitialspace=True, skipheader=True, skiplines=1, dict_reader=True) as csvreader:
246+
with self.make_reader(data_source, skipinitialspace=True, skipheader=True,
247+
skiplines=1, dict_reader=True) as csvreader:
247248
# TODO: Improve this evidence by going back to the actual research
248249
# by using the wormbase REST API in addition to or instead of the CSV file
249250
with res.evidence_context(Evidence=Evidence, Website=Website) as ctx:
@@ -252,10 +253,11 @@ def translate(self, data_source, cells_source):
252253
ctx.Evidence(reference=doc, supports=doc_ctx.rdf_object)
253254

254255
for num, line in enumerate(csvreader):
255-
if num < 2: # skip rows with no data
256+
if num < 1: # skip rows with no data
256257
continue
257258

258-
cell = cells_source.data_context.stored(Cell).query(name=line['Cell'])
259+
cell_name = normalize_cell_name(line['Cell'])
260+
cell = cells_source.data_context.stored(Cell).query(name=cell_name)
259261
for loaded_cell in cell.load():
260262
doc_ctx(loaded_cell).wormbaseID(line['WormBase ID'])
261263

Diff for: readme.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"rdf.source" : "lazy_pickle",
2+
"rdf.source" : "zodb",
33
"rdf.store_conf" : "$HERE/.owm/worm.db"
44
}
55

Diff for: tests/data_integrity_test.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"connectomecsv" : "OpenWormData/aux_data/connectome.csv",
33
"neuronscsv" : "OpenWormData/aux_data/neurons.csv",
4-
"rdf.source" : "lazy_pickle",
4+
"rdf.source" : "zodb",
55
"rdf.store_conf" : ".owm/worm.db",
66
"rdf.upload_block_statement_count" : 50
77
}

0 commit comments

Comments
 (0)