Skip to content

Commit

Permalink
Merge pull request #322 from SD2E/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tramyn authored Feb 18, 2021
2 parents 42a7f4b + 78b9a3e commit e03944d
Show file tree
Hide file tree
Showing 15 changed files with 503 additions and 141 deletions.
38 changes: 38 additions & 0 deletions intent_parser/accessor/aquarium_opil_accessor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import intent_parser.utils.intent_parser_utils as ip_utils
import intent_parser.protocols.opil_parameter_utils as opil_utils
import logging

from intent_parser.intent_parser_exceptions import IntentParserException


class AquariumOpilAccessor(object):
"""
Retrieve experimental request from Aquarium-opil.
Refer to link for getting aquarium-opil file:
https://github.com/aquariumbio/aquarium-opil
"""

logger = logging.getLogger('aqurium_opil_accessor')
_SUPPORTED_PROTOCOLS = {'jellyfish': 'jellyfish_htc.xml'
}

def __init__(self):
pass

def get_experimental_request_as_opil_doc(self, experimental_request_name):
if experimental_request_name in self._SUPPORTED_PROTOCOLS:
opil_doc = ip_utils.load_sbol_xml_file(self._SUPPORTED_PROTOCOLS[experimental_request_name])
return opil_doc

raise IntentParserException('Aquarium does not support %s as an experimental request' % experimental_request_name)

def get_protocol_interface(self, protocol_name):
opil_doc = self.get_experimental_request_as_opil_doc(protocol_name)
protocol_interfaces = opil_utils.get_protocol_interfaces_from_sbol_doc(opil_doc)
if len(protocol_interfaces) == 0:
raise IntentParserException('No opil protocol interface found from aquarium protocol %s' % protocol_name)

if len(protocol_interfaces) > 1:
raise IntentParserException('Expected to find one opil protocol interface for %s but more than one was found' % protocol_name)

return protocol_interfaces[0]
20 changes: 10 additions & 10 deletions intent_parser/accessor/strateos_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from intent_parser.intent_parser_exceptions import IntentParserException
from transcriptic import Connection
import intent_parser.constants.intent_parser_constants as ip_constants
import intent_parser.protocols.opil_parameter_utils as opil_utils
import logging
import opil
import time
import threading

import sbol3

class StrateosAccessor(object):
"""
Expand Down Expand Up @@ -123,19 +124,18 @@ def _fetch_protocols(self):

def convert_protocol_to_opil(self, protocol):
strateos_namespace = 'http://strateos.com/'
protocol_name = protocol['name']
sg = opil.StrateosOpilGenerator()
sbol_doc = sg.parse_strateos_json(strateos_namespace,
protocol['name'],
protocol_name,
protocol['id'],
protocol['inputs'])
protocol_interface = None
for obj in sbol_doc.objects:
if type(obj) is opil.opil_factory.ProtocolInterface:
protocol_interface = obj

if not protocol_interface:
protocol_interfaces = opil_utils.get_protocol_interfaces_from_sbol_doc(sbol_doc)
if len(protocol_interfaces) == 0:
raise IntentParserException('Unable to locate OPIL protocol interface when converting transcriptic protocol for %s ' % protocol_name)
if len(protocol_interfaces) > 1:
raise IntentParserException(
'Unable to locate OPIL protocol interface when converting transcriptic protocols to OPIL')
'Expected to find one opil protocol interface for %s but more than one was found' % protocol_name)

return protocol_interface, sbol_doc
return protocol_interfaces[0], sbol_doc

14 changes: 14 additions & 0 deletions intent_parser/constants/intent_parser_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,25 @@
UO_MILLI_MOLAR = 'https://identifiers.org/UO:0000063'
UO_GRAM_PER_LITER = 'https://identifiers.org/UO:0000175'
UO_NANO_GRAM_PER_LITER = 'https://identifiers.org/UO:0010050'

# measurement-typeis specific to SD2 project
SD2_AUTOMATED_TEST_URI = 'http://sd2e.org#automatedTest'
SD2_CONDITION_SPACE_URI = 'http://sd2e.org#conditionSpace'
SD2_EXPERIMENTAL_DESIGN_URI = 'http://sd2e.org#experimentalDesign'

MEASUREMENT_TYPE_MAPPINGS = {
MEASUREMENT_TYPE_FLOW: NCIT_FLOW_URI,
MEASUREMENT_TYPE_RNA_SEQ: NCIT_RNA_SEQ_URI,
MEASUREMENT_TYPE_DNA_SEQ: NCIT_DNA_SEQ_URI,
MEASUREMENT_TYPE_PROTEOMICS: NCIT_PROTEOMICS_URI,
MEASUREMENT_TYPE_SEQUENCING_CHROMATOGRAM: NCIT_SEQUENCING_CHROMATOGRAM_URI,
MEASUREMENT_TYPE_AUTOMATED_TEST: SD2_AUTOMATED_TEST_URI,
MEASUREMENT_TYPE_CFU: NCIT_CFU_URI,
MEASUREMENT_TYPE_PLATE_READER: NCIT_PLATE_READER_URI,
MEASUREMENT_TYPE_CONDITION_SPACE: SD2_CONDITION_SPACE_URI,
MEASUREMENT_TYPE_EXPERIMENTAL_DESIGN: SD2_EXPERIMENTAL_DESIGN_URI
}

# Strateos Protocols Supported in IP
GROWTH_CURVE_PROTOCOL = 'GrowthCurve'
OBSTACLE_COURSE_PROTOCOL = 'ObstacleCourse'
Expand Down
12 changes: 12 additions & 0 deletions intent_parser/document/analyze_document_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def _write_ignored_terms(self):
self.LOGGER.info('Writing ignored terms to file.')
ip_utils.write_json_to_file(self._ignore_terms, self.ANALYZE_IGNORE_TERMS_FILE)

def get_all_analyzed_results(self, document_id):
if document_id not in self.analyzed_documents:
return None

analyze_document = self.analyzed_documents[document_id]
return analyze_document.get_result()

def get_first_analyze_result(self, document_id):
if document_id not in self.analyzed_documents:
return None
Expand Down Expand Up @@ -76,6 +83,11 @@ def remove_analyze_result_with_term(self, document_id, matching_term):
analyze_document = self.analyzed_documents[document_id]
return analyze_document.remove_all(matching_term)

def remove_document(self, document_id):
if document_id not in self.analyzed_documents:
return
self.analyzed_documents.pop(document_id)

def remove_analyze_result(self, document_id, paragraph_index, matching_term, sbh_uri, start_offset, end_offset):
if document_id not in self.analyzed_documents:
return
Expand Down
23 changes: 15 additions & 8 deletions intent_parser/intent/control_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import intent_parser.constants.sd2_datacatalog_constants as dc_constants
import intent_parser.constants.intent_parser_constants as ip_constants
import sbol3.constants as sbol_constants
import opil

"""
Intent Parser's representation for a control.
"""
Expand Down Expand Up @@ -106,23 +106,29 @@ def _encode_content_using_sbol(self, sbol_document):
content_template = LocalSubComponent(identity=self._id_provider.get_unique_sd2_id(),
types=[sbol_constants.SBO_FUNCTIONAL_ENTITY])
content_template.name = 'content template'
content_variable = VariableFeature(cardinality=sbol_constants.SBOL_ONE)
content_variable = VariableFeature(identity=self._id_provider.get_unique_sd2_id(),
cardinality=sbol_constants.SBOL_ONE)

content_variants = []
content_variant_measures = []
for content in self._contents:
if isinstance(content, ReagentIntent):
content_component = content.to_sbol(sbol_document)
content_variants.append(content_component)
content_variant_measure = content.to_opil()
content_variant_measures.append(content_variant_measure)

if content.get_timepoint() is not None:
content_variant_measure = content.get_timepoint().to_sbol()
content_variant_measures.append(content_variant_measure)
content_timepoint_measure = content.get_timepoint().to_opil()
content_variant_measures.append(content_timepoint_measure)

elif isinstance(content, NamedStringValue):
content_component = Component(identity=self._id_provider.get_unique_sd2_id(),
component_type=sbol_constants.SBO_FUNCTIONAL_ENTITY)
content_component.name = content.get_named_link().get_name()
content_sub_component = SubComponent(content.get_named_link().get_link())
content_component.features = [content_sub_component]
if content.get_named_link().get_link() is not None:
content_sub_component = SubComponent(content.get_named_link().get_link())
content_component.features = [content_sub_component]
content_variants.append(content_component)
sbol_document.add(content_component)

Expand All @@ -141,14 +147,15 @@ def _encode_control_type_using_opil(self, opil_measurement):
def _encode_timepoints_using_opil(self, opil_measurement):
encoded_timepoints = []
for timepoint in self._timepoints:
encoded_timepoints.append(timepoint.to_sbol())
encoded_timepoints.append(timepoint.to_opil())
opil_measurement.time = encoded_timepoints

def _encode_strains_using_sbol(self, sbol_document):
strain_template = LocalSubComponent(identity=self._id_provider.get_unique_sd2_id(),
types=[sbol_constants.SBO_FUNCTIONAL_ENTITY])
strain_template.name = 'strains template'
strain_variable = VariableFeature(cardinality=sbol_constants.SBOL_ONE)
strain_variable = VariableFeature(identity=self._id_provider.get_unique_sd2_id(),
cardinality=sbol_constants.SBOL_ONE)
strain_variable.name = 'strain VariableFeature'
strain_variable.variable = strain_template
strain_variable.variant = [strain.to_sbol(sbol_document) for strain in self._strains]
Expand Down
22 changes: 22 additions & 0 deletions intent_parser/intent/experimental_request_intent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from intent_parser.intent.control_intent import ControlIntent
from intent_parser.intent.lab_intent import LabIntent
from intent_parser.intent.measurement_intent import MeasurementIntent
from intent_parser.intent.parameter_intent import ParameterIntent
import logging

class ExperimentalRequestIntent(object):
"""
Intent Parser's representation of an experimental request
"""

logger = logging.getLogger('experimental_request_intent')

def __init__(self, experimental_request_name=''):
self._experimental_request_name = experimental_request_name
self._lab_intent = LabIntent()
self._measurement_intents = []
self._control_intent = ControlIntent()
self._parameter_intent = ParameterIntent()

def add_measurement_intent(self, measurement_intent):
self._measurement_intents.add(measurement_intent)
Loading

0 comments on commit e03944d

Please sign in to comment.