Skip to content

Commit

Permalink
Starting on #319
Browse files Browse the repository at this point in the history
  • Loading branch information
mwatts15 committed Sep 20, 2017
1 parent e94462a commit cb5720e
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 54 deletions.
112 changes: 60 additions & 52 deletions OpenWormData/scripts/insert_worm.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ def upload_ionchannels():
c.gene_name(gene_name)
c.gene_WB_ID(gene_WB_ID)
c.description(description)
c.expression_pattern(expression_pattern)
patterns = expression_pattern.split(r' | ')
regex = re.compile(r' *\[([^\]]+)\] *(.*) *')

matches = [regex.match(pat) for pat in patterns]
patterns = [P.ExpressionPattern(wormbaseID=m.group(1), description=m.group(2)) for m in matches if m is not None]
for pat in patterns:
c.expression_pattern(pat)

c.save()
print ("uploaded ion_channel")
except Exception:
Expand All @@ -77,33 +84,15 @@ def upload_ionchannels():
def upload_channelneuron_association():
print ("uploading the channel neuron association")
try:
net = NETWORK
with open(CHANNEL_NEURON_SOURCE, 'rb') as f:
reader = csv.reader(f, delimiter='\t')
rows = 0
heading = skip_to_header(reader)
for row in reader:
neuronlist = []
if rows < 3:
rows += 1
continue
elif rows == 3:
heading = row
rows += 1
continue
rows += 1

cols = 0
for col in row:
if cols >= 0 and cols <= 101:
cols += 1
else:
if col == '1' or col == '2':
neuronlist.append(heading[cols])
cols += 1
neuronlist = extract_neuron_names(heading, row)
ch = P.Channel(name=str(row[0]))
for neuron in neuronlist:
n = P.Neuron(name=str(neuron))
net.neuron(n)
NETWORK.neuron(n)
ch.appearsIn(n)
print ("uploaded channel neuron association")
except Exception:
Expand All @@ -113,39 +102,58 @@ def upload_channelneuron_association():
def upload_channelmuscle_association():
print ("uploading the channel muscle association")
try:
w = WORM
with open(CHANNEL_MUSCLE_SOURCE, 'rb') as f:
reader = csv.reader(f, delimiter='\t')
rows = 0
heading = skip_to_header(reader)
for row in reader:
musclelist = []
if rows < 3:
rows += 1
continue
elif rows == 3:
heading = row
rows += 1
continue
rows += 1

cols = 0
for col in row:
if cols >= 0 and cols <= 6:
cols += 1
else:
if col == '1' or col == '2':
musclelist.append(heading[cols])
cols += 1
musclelist = extract_muscle_names(heading, row)
ch = P.Channel(name=str(row[0]))
for muscle in musclelist:
m = P.Muscle(name=str(muscle))
w.muscle(m)
WORM.muscle(m)
ch.appearsIn(m)
print ("uploaded channel muscle association")
except Exception:
traceback.print_exc()


def extract_neuron_names(heading, row):
neuronlist = []
cols = 0
for col in row:
if cols >= 0 and cols <= 101:
cols += 1
else:
if col == '1' or col == '2':
neuronlist.append(heading[cols])
cols += 1
return neuronlist


def extract_muscle_names(heading, row):
musclelist = []
cols = 0
for col in row:
if cols >= 0 and cols <= 6:
cols += 1
else:
if col == '1' or col == '2':
musclelist.append(heading[cols])
cols += 1
return musclelist


def skip_to_header(reader):
heading = None
rows = 0
for row in reader:
if rows == 3:
heading = row
break
rows += 1
return heading


def upload_muscles():
""" Upload muscles and the neurons that connect to them
"""
Expand Down Expand Up @@ -646,16 +654,16 @@ def do_insert(config="default.conf", logging=False):
WORM.neuron_network(NETWORK)
NETWORK.worm(WORM)

upload_neurons()
upload_muscles()
# upload_neurons()
# upload_muscles()
upload_ionchannels()
upload_channelneuron_association()
upload_channelmuscle_association()
attach_neuromlfiles_to_channel()
upload_lineage_and_descriptions()
upload_connections()
upload_receptors_types_neurotransmitters_neuropeptides_innexins()
upload_additional_receptors_neurotransmitters_neuropeptides_innexins()
# upload_channelneuron_association()
# upload_channelmuscle_association()
# attach_neuromlfiles_to_channel()
# upload_lineage_and_descriptions()
# upload_connections()
# upload_receptors_types_neurotransmitters_neuropeptides_innexins()
# upload_additional_receptors_neurotransmitters_neuropeptides_innexins()

print("Saving...")
WORM.save()
Expand Down
4 changes: 3 additions & 1 deletion PyOpenWorm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
from .my_neuroml import NeuroML
from .connection import Connection
from .experiment import Experiment
from .channel import Channel
from .channel import Channel, ExpressionPattern
from .channelworm import ChannelModel, PatchClampExperiment
from .plot import Plot

Expand Down Expand Up @@ -114,6 +114,7 @@
"Connection",
"Experiment",
"Channel",
"ExpressionPattern",
"ChannelModel",
"PatchClampExperiment",
"Plot"]
Expand Down Expand Up @@ -270,6 +271,7 @@ def connect(configFile=False,
SimpleProperty.register()
Relationship.register()
Channel.register()
ExpressionPattern.register()
ChannelModel.register()
Experiment.register()
PatchClampExperiment.register()
Expand Down
32 changes: 31 additions & 1 deletion PyOpenWorm/channel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import rdflib as R
from .pProperty import Property
from .channelworm import ChannelModel
from .dataObject import DataObject
Expand Down Expand Up @@ -100,7 +101,10 @@ def __init__(self, name=False, **kwargs):
Channel.DatatypeProperty('description', self)
Channel.DatatypeProperty('gene_name', self)
Channel.DatatypeProperty('gene_WB_ID', self)
Channel.DatatypeProperty('expression_pattern', self)
Channel.ObjectProperty('expression_pattern',
owner=self,
multiple=True,
value_type=ExpressionPattern)
Channel.DatatypeProperty('neuroML_file', owner=self)
Channel.DatatypeProperty('proteins', self, multiple=True)
Channel.ObjectProperty('appearsIn', self, multiple=True,
Expand All @@ -123,3 +127,29 @@ def identifier(self):
else:
# name is already set, so we can make an identifier from it
return self.make_identifier(self.name.defined_values[0])


class ExpressionPattern(DataObject):
def __init__(self, wormbaseID=None, description=None, **kwargs):
super(ExpressionPattern, self).__init__(**kwargs)
ExpressionPattern.DatatypeProperty('wormbaseID', owner=self)
ExpressionPattern.DatatypeProperty('wormbaseURL', owner=self)
ExpressionPattern.DatatypeProperty('description', owner=self)

if wormbaseID:
self.wormbaseID(wormbaseID)
self.wormbaseURL(R.URIRef("http://www.wormbase.org/species/all/expr_pattern/"+wormbaseID))

if description:
self.description(description)

@property
def defined(self):
return super(ExpressionPattern, self).defined \
or self.wormbaseID.has_defined_value()

def identifier(self):
if super(ExpressionPattern, self).defined:
return super(ExpressionPattern, self).identifier()
else:
return self.make_identifier(self.wormbaseID.defined_values[0])

0 comments on commit cb5720e

Please sign in to comment.