15
15
from ..document import Document
16
16
from ..evidence import Evidence
17
17
from ..neuron import Neuron
18
- from ..muscle import Muscle
18
+ from ..muscle import Muscle , BodyWallMuscle
19
19
from ..worm import Worm
20
20
from ..network import Network
21
21
@@ -110,7 +110,7 @@ def translate(self, data_source, neurons_source, muscles_source):
110
110
res .evidence_context (Evidence )(key = "emmons2015" ,
111
111
reference = doc ,
112
112
supports = docctx .rdf_object )
113
- with docctx (Neuron , Muscle , Cell , Connection ) as ctx :
113
+ with docctx (Neuron , Muscle , BodyWallMuscle , Cell , Connection ) as ctx :
114
114
res .data_context .add_import (ctx .context )
115
115
with open (data_source .full_path ()) as csvfile :
116
116
edge_reader = csv .reader (csvfile )
@@ -125,25 +125,22 @@ def translate(self, data_source, neurons_source, muscles_source):
125
125
elif syn_type == 'chemical' :
126
126
syn_type = 'send'
127
127
128
+ source_is_bwm = 'BWM' in source .upper ()
129
+ target_is_bwm = 'BWM' in target .upper ()
130
+
128
131
source = normalize_cell_name (source ).upper ()
129
132
target = normalize_cell_name (target ).upper ()
130
133
131
134
weight = int (weight )
132
135
133
- # remove BMW from Body Wall Muscle cells
134
- if 'BWM' in source :
135
- source = normalize_muscle (source )
136
- if 'BWM' in target :
137
- target = normalize_muscle (target )
138
-
139
136
# change certain muscle names to names in wormbase
140
137
if source in changed_muscles :
141
138
source = changed_muscle (source )
142
139
if target in changed_muscles :
143
140
target = changed_muscle (target )
144
141
145
- sources = convert_to_cell (ctx , source , muscles , neurons )
146
- targets = convert_to_cell (ctx , target , muscles , neurons )
142
+ sources = convert_to_cell (ctx , source , muscles , neurons , source_is_bwm )
143
+ targets = convert_to_cell (ctx , target , muscles , neurons , target_is_bwm )
147
144
148
145
for s in sources :
149
146
for t in targets :
@@ -241,16 +238,21 @@ def translate(self, data_source, neurotransmitter_source):
241
238
return res
242
239
243
240
244
- def convert_to_cell (ctx , name , muscles , neurons ):
241
+ def convert_to_cell (ctx , name , muscles , neurons , is_bwm ):
245
242
ret = []
246
243
res = None
247
244
res2 = None
248
245
if name in neurons :
249
246
res = ctx .Neuron (name )
250
- elif name in muscles :
251
- res = ctx .Muscle (name )
252
247
elif name in TO_EXPAND_MUSCLES :
248
+ # All of the muscle cell types we need to expand are pharyngeal, so no need to
249
+ # pass through is_bwm
253
250
res , res2 = expand_muscle (ctx , name )
251
+ elif name in muscles :
252
+ if is_bwm :
253
+ res = ctx .BodyWallMuscle (name )
254
+ else :
255
+ res = ctx .Muscle (name )
254
256
elif name in OTHER_CELLS :
255
257
res = ctx .Cell (name )
256
258
@@ -266,28 +268,15 @@ def add_synapse(ctx, source, target, weight, syn_type):
266
268
c = ctx .Connection (pre_cell = source , post_cell = target ,
267
269
number = weight , syntype = syn_type )
268
270
269
- if isinstance (source , ctx . Neuron ) and isinstance (target , ctx . Neuron ):
271
+ if isinstance (source , Neuron ) and isinstance (target , Neuron ):
270
272
c .termination ('neuron' )
271
- elif isinstance (source , ctx . Neuron ) and isinstance (target , ctx . Muscle ) or \
272
- isinstance (source , ctx . Muscle ) and isinstance (target , ctx . Neuron ):
273
+ elif isinstance (source , Neuron ) and isinstance (target , Muscle ) or \
274
+ isinstance (source , Muscle ) and isinstance (target , Neuron ):
273
275
c .termination ('muscle' )
274
276
275
277
return c
276
278
277
279
278
- # to normalize certian body wall muscle cell names
279
- SEARCH_STRING_MUSCLE = re .compile (r'\w+[BWM]+\w+' )
280
- REPLACE_STRING_MUSCLE = re .compile (r'[BWM]+' )
281
-
282
-
283
- def normalize_muscle (name ):
284
- # normalize names of Body Wall Muscles
285
- # if there is 'BWM' in the name, remove it
286
- if re .match (SEARCH_STRING_MUSCLE , name ):
287
- name = REPLACE_STRING_MUSCLE .sub ('' , name )
288
- return name
289
-
290
-
291
280
MUSCLES = {
292
281
'ANAL' : 'MU_ANAL' ,
293
282
'INTR' : 'MU_INT_R' ,
0 commit comments