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

How to get ParameterValue objects from an opil.ProtocolInterface #183

Open
tramyn opened this issue Apr 18, 2021 · 1 comment
Open

How to get ParameterValue objects from an opil.ProtocolInterface #183

tramyn opened this issue Apr 18, 2021 · 1 comment
Labels
question Further information is requested

Comments

@tramyn
Copy link

tramyn commented Apr 18, 2021

I want to get opil.ParameterValues from a strateos opil.ProtocolInterface (ex: CellFreeRiboswitches). I tried running the code below but unable to get desired information. What is the correct to do this?

Here is what I have tried so far.

import opil
import sbol

file_path = 'CellFreeRiboswitches.xml'
opil_doc = opil.Document()
opil_doc.read(file_path, sbol3.RDF_XML)
opil_protocol_interfaces = [top_level for top_level in opil_doc.objects if isinstance(top_level, opil.ProtocolInterface)]
parameters = opil_protocol_interfaces[0].has_parameter
parameter_values = []
for parameter in parameters:
     if parameter.default_value:
          parameter_value = opil_doc.find(parameter.default_value)
          if parameter_value:
               parameter_values.append(parameter_value)
if len(parameter_values) == 0:
     raise Exception('Expecting ParameterValues but found none')
@tramyn tramyn added the question Further information is requested label Apr 18, 2021
@bbartley
Copy link
Collaborator

This is easy. Notice that parameter.default_value returns a child ParameterValue object. For example:

for parameter in parameters:
     if parameter.default_value:
          print(parameter.default_value.identity)

http://strateos.com/CellFreeRiboswitches/MeasureParameter3/MeasureValue1
http://strateos.com/CellFreeRiboswitches/IntegerParameter1/IntegerValue1
http://strateos.com/CellFreeRiboswitches/MeasureParameter5/MeasureValue1
...

You may have been expecting a URI reference to a ParameterValue because that's how it was originally specified, but that turned out to be a bug in the specification. See discussion here: #73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants