Skip to content

Commit

Permalink
Merge pull request #46 from SD2E/102-strateos_obstacle_course
Browse files Browse the repository at this point in the history
Runs on obstacle_course schema
  • Loading branch information
bbartley authored Oct 26, 2020
2 parents bd18686 + cc8e324 commit a4da33a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions opil/generate_opil_from_strateos.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def main(self):
# Parse the JSON and return a SBOL document
print('Generating OPIL from JSON file ', args_dict['in_file'])
document = self.parse_strateos_json(args_dict['namespace'],
args_dict['protocol_name'], document_dict)
args_dict['protocol_name'], document_dict['inputs'])

# Write out the document to a file
document.bind('opil', opil.Query.OPIL) # Set namespace prefix
Expand All @@ -89,6 +89,8 @@ def parse_strateos_json(self, namespace, protocol_name, document_dict):

# Iterate through the top-level JSON objects and add Parameters to the list
for section_name in document_dict:
if type(document_dict[section_name]) is not dict:
continue
section_dict = document_dict[section_name]

# Parameters are found in 'inputs' JSON objects
Expand All @@ -98,21 +100,23 @@ def parse_strateos_json(self, namespace, protocol_name, document_dict):

# The 'type' value indicates what Parameter subclass should be used.
# Form the Strateos dotname from the section name and parameter name
type = inputs_dict[param_name]['type']
self.handle_type(type, param_name, inputs_dict[param_name],
param_type = inputs_dict[param_name]['type']
self.handle_type(param_type, param_name, inputs_dict[param_name],
section_name + '.' + param_name)

# Add parameters to ProtocolInterface
self.protocol.has_parameter = self.param_list

return self.doc

def handle_type(self, type, id_string, param_dict, dotname):
def handle_type(self, param_type, id_string, param_dict, dotname):
'''
The handle_type method selects the method for parsing the parameter JSON object
based on its type field
'''
method = StrateosOpilGenerator.type_handlers[type]
method = StrateosOpilGenerator.type_handlers[param_type]
if id_string[0].isnumeric(): # Sanitize id
id_string = '_' + id_string
method(self, id_string, param_dict, dotname)

def handle_choice(self, id_string, param_dict, dotname):
Expand Down Expand Up @@ -163,7 +167,15 @@ def handle_measure(self, id_string, param_dict, dotname):
param = opil.MeasureParameter(id_string)
param.name = dotname
if 'default' in param_dict:
default_instance = opil.MeasureValue(id_string + '_default')
SUCCESS = False
i = 0
while not SUCCESS:
try:
default_instance = opil.MeasureValue(id_string + '_default' + str(i))
self.doc.add(default_instance)
SUCCESS = True
except ValueError:
i += 1
default_value = param_dict['default']
if isinstance(default_value, str):

Expand All @@ -181,7 +193,6 @@ def handle_measure(self, id_string, param_dict, dotname):
measure = sbol3.Measure(value, unit_iri, name=measure_name)
default_instance.has_measure = measure
param.default_value = [default_instance]
self.doc.add(default_instance)
if 'required' in param_dict:
param.required = True
self.param_list.append(param)
Expand Down Expand Up @@ -230,7 +241,8 @@ def handle_group_choice(self, id_string, param_dict, dotname):
'bool': handle_bool, 'group': handle_group,
'group+': handle_group, 'group-choice': handle_group_choice,
'integer': handle_integer,
'aliquot': handle_string, 'aliquot+': handle_string}
'aliquot': handle_string, 'aliquot+': handle_string,
'container': handle_string}

if __name__ == "__main__":
opil_generator = StrateosOpilGenerator()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(name='opil',
description='Python package for demonstrating OPIL',
version='1.0a2.post1',
version='1.0a3',
install_requires=[
'sbol3>=1.0a3',
'rdflib>=5.0.0',
Expand Down

0 comments on commit a4da33a

Please sign in to comment.