Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2to3 #103

Open
wants to merge 22 commits into
base: ow-0.8
Choose a base branch
from
Open

2to3 #103

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CElegans/pythonScripts/c302/UpdatedSpreadsheetDataReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def readDataFromSpreadsheet(include_nonconnected_cells=False):
conns = []
cells = []

with open(filename, 'rb') as f:
with open(filename, 'r') as f:
reader = csv.DictReader(f)
print "Opened file: " + filename
print("Opened file: " + filename)

known_nonconnected_cells = ['CANL', 'CANR']

Expand Down Expand Up @@ -140,9 +140,9 @@ def readMuscleDataFromSpreadsheet():
muscles = []
conns = []

with open(filename, 'rb') as f:
with open(filename, 'r') as f:
reader = csv.DictReader(f)
print "Opened file: " + filename
print("Opened file: " + filename)

for row in reader:
pre, post, num, syntype, synclass = parse_row(row)
Expand Down
2 changes: 1 addition & 1 deletion CElegans/pythonScripts/c302/bioparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_syn(self, pre_cell, post_cell, type, pol):


def create_n_connection_synapse(self, prototype_syn, n, nml_doc, existing_synapses):
if existing_synapses.has_key(prototype_syn.id):
if prototype_syn.id in existing_synapses:
return existing_synapses[prototype_syn.id]

existing_synapses[prototype_syn.id] = prototype_syn
Expand Down
74 changes: 49 additions & 25 deletions CElegans/pythonScripts/c302/c302.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
try:
from urllib2 import URLError # Python 2
except:
from urllib import URLError # Python 3
from urllib.error import URLError # Python 3

import sys
sys.path.append("..")
Expand Down Expand Up @@ -249,7 +249,7 @@ def add_new_sinusoidal_input(nml_doc, cell, delay, duration, amplitude, period,
phase = DB_soma_pos[cell]
#phase = get_cell_position(cell).x
phase = phase * -0.886
print "### CELL %s PHASE: %s" % (cell, phase)
print("### CELL %s PHASE: %s" % (cell, phase))

if cell.startswith("VB"):
if amplitude.startswith("-"):
Expand Down Expand Up @@ -356,7 +356,7 @@ def get_random_colour_hex():

def get_file_name_relative_to_c302(file_name):

if os.environ.has_key('C302_HOME'):
if 'C302_HOME' in os.environ:
return os.path.relpath(os.environ['C302_HOME'],file_name)


Expand Down Expand Up @@ -477,13 +477,14 @@ def generate(net_id,

regex_param_overrides = {'mirrored_elec_conn_params':{}}
if param_overrides:
for k, v in param_overrides.iteritems():
for k, v in param_overrides.items():
if k == 'mirrored_elec_conn_params':
for mk, mv in v.iteritems():
for mk, mv in v.items():
if is_regex_string(mk):
regex_param_overrides['mirrored_elec_conn_params'][mk] = mv
continue
mirror_param(params, mk, mv)
else:
mirror_param(params, mk, mv)


elif k == 'custom_component_type_gate_overrides':
Expand Down Expand Up @@ -559,7 +560,10 @@ def generate(net_id,
nml_doc.pulse_generators.append(params.offset_current)

if is_cond_based_cell(params):
nml_doc.fixed_factor_concentration_models.append(params.concentration_model)
if isinstance(params.concentration_model, list):
nml_doc.fixed_factor_concentration_models.extend(params.concentration_model)
else:
nml_doc.fixed_factor_concentration_models.append(params.concentration_model)

cell_names, conns = get_cell_names_and_connection(data_reader)

Expand Down Expand Up @@ -596,11 +600,11 @@ def generate(net_id,
# def_file = './%s' % ctd
def_file = "%s/%s" % (os.path.dirname(os.path.abspath(__file__)), ctd)

if param_overrides.has_key('custom_component_type_gate_overrides') and param_overrides[
if param_overrides and 'custom_component_type_gate_overrides' in param_overrides and param_overrides[
'custom_component_type_gate_overrides']:
root = etree.parse(def_file).getroot()

for k, v in param_overrides['custom_component_type_gate_overrides'].iteritems():
for k, v in param_overrides['custom_component_type_gate_overrides'].items():
channel_id = k.split('__')[0]
gate_id = k.split('__')[1]
gate_attr = k.split('__')[2]
Expand Down Expand Up @@ -653,7 +657,7 @@ def generate(net_id,
# put that Population into the Network data structure from above
net.populations.append(pop0)

if cells_vs_name.has_key(cell):
if cell in cells_vs_name:
p = Property(tag="OpenWormBackerAssignedName", value=cells_vs_name[cell])
pop0.properties.append(p)

Expand Down Expand Up @@ -784,7 +788,7 @@ def generate(net_id,
# put that Population into the Network data structure from above
net.populations.append(pop0)

if cells_vs_name.has_key(muscle):
if muscle in cells_vs_name:
# No muscles adopted yet, but just in case they are in future...
p = Property(tag="OpenWormBackerAssignedName", value=cells_vs_name[muscle])
pop0.properties.append(p)
Expand Down Expand Up @@ -897,19 +901,27 @@ def generate(net_id,
new_param = new_param.replace('_GJ', '')
new_param_v = regex_param_overrides[key]


if new_param in param_overrides:
continue
# add regex param unless there is a specific param
set_param(params, new_param, new_param_v)

if regex_param_overrides.has_key('mirrored_elec_conn_params'):
for k, v in regex_param_overrides['mirrored_elec_conn_params'].iteritems():
if 'mirrored_elec_conn_params' in regex_param_overrides:
for k, v in regex_param_overrides['mirrored_elec_conn_params'].items():

pattern = k.split('$')[0] + '$'
pattern = pattern.replace('_to_', '-')

if re.match(pattern, conn_shorthand):
new_param = conn_shorthand.replace('-', '_to_') + k.split('$')[1]
new_param = new_param.replace('_GJ', '')
new_param_mirrored = conn.post_cell + '_' + new_param.split('_')[1] + '_' + conn.pre_cell + '_' + '_'.join(new_param.split('_')[3:])
new_param_v = v

if new_param in param_overrides['mirrored_elec_conn_params'] or new_param_mirrored in param_overrides['mirrored_elec_conn_params']:
continue
# add regex param unless there is a specific param
mirror_param(params, new_param, new_param_v)

if conns_to_include and conn_shorthand not in conns_to_include:
Expand All @@ -926,7 +938,7 @@ def generate(net_id,
syn0 = params.get_syn(conn.pre_cell, conn.post_cell, conn_type, conn_pol)

if print_connections:
print conn_shorthand + " " + str(conn.number) + " " + orig_pol + " " + conn.synclass + " " + syn0.id
print(conn_shorthand + " " + str(conn.number) + " " + orig_pol + " " + conn.synclass + " " + syn0.id)


polarity = None
Expand Down Expand Up @@ -980,9 +992,9 @@ def generate(net_id,
break
'''
else:
print conn_shorthand
print conn_number_override
print conn_number_scaling'''
print(conn_shorthand)
print(conn_number_override)
print(conn_number_scaling)'''
"""if polarity:
print "%s %s num:%s" % (conn_shorthand, polarity, number_syns)
elif elect_conn:
Expand Down Expand Up @@ -1076,11 +1088,13 @@ def generate(net_id,

if len(muscles_to_include)>0:
for conn in muscle_conns:
if not conn.post_cell in muscles_to_include:
continue
if not conn.post_cell in muscles_to_include:#
continue#
if not conn.pre_cell in lems_info["cells"] and not conn.pre_cell in muscles_to_include:
continue



# take information about each connection and package it into a
# NeuroML Projection data structure
proj_id = get_projection_id(conn.pre_cell, conn.post_cell, conn.synclass, conn.syntype)
Expand All @@ -1092,6 +1106,8 @@ def generate(net_id,
conn_type = "neuron_to_muscle"
if conn.pre_cell in muscles_to_include:
conn_type = "muscle_to_muscle"
#if conn.post_cell in lems_info['cells']:
# conn_type = "muscle_to_neuron"
conn_pol = "exc"
orig_pol = "exc"

Expand All @@ -1118,19 +1134,27 @@ def generate(net_id,
new_param = new_param.replace('_GJ', '')
new_param_v = regex_param_overrides[key]


if new_param in param_overrides:
continue
# add regex param unless there is a specific param
set_param(params, new_param, new_param_v)

if regex_param_overrides.has_key('mirrored_elec_conn_params'):
for k, v in regex_param_overrides['mirrored_elec_conn_params'].iteritems():
if 'mirrored_elec_conn_params' in regex_param_overrides:
for k, v in regex_param_overrides['mirrored_elec_conn_params'].items():

pattern = k.split('$')[0] + '$'
pattern = pattern.replace('_to_', '-')

if re.match(pattern, conn_shorthand):
new_param = conn_shorthand.replace('-', '_to_') + k.split('$')[1]
new_param = new_param.replace('_GJ', '')
new_param_mirrored = conn.post_cell + '_' + new_param.split('_')[1] + '_' + conn.pre_cell + '_' + '_'.join(new_param.split('_')[3:])
new_param_v = v

if new_param in param_overrides['mirrored_elec_conn_params'] or new_param_mirrored in param_overrides['mirrored_elec_conn_params']:
continue
# add regex param unless there is a specific param
mirror_param(params, new_param, new_param_v)

if conns_to_include and conn_shorthand not in conns_to_include:
Expand All @@ -1147,7 +1171,7 @@ def generate(net_id,
syn0 = params.get_syn(conn.pre_cell, conn.post_cell, conn_type, conn_pol)

if print_connections:
print conn_shorthand + " " + str(conn.number) + " " + orig_pol + " " + conn.synclass
print(conn_shorthand + " " + str(conn.number) + " " + orig_pol + " " + conn.synclass)


polarity = None
Expand Down Expand Up @@ -1195,9 +1219,9 @@ def generate(net_id,
break
'''
else:
print conn_shorthand
print conn_number_override
print conn_number_scaling'''
print(conn_shorthand)
print(conn_number_override)
print(conn_number_scaling)'''
"""if polarity:
print "%s %s num:%s" % (conn_shorthand, polarity, number_syns)
elif elect_conn:
Expand Down
Loading