def parse_content_item(self,
                           text: str,
                           text_with_uri: Dict,
                           fluid_units: Tuple = {},
                           timepoint_units: Tuple = {}):
        contents = []
        tokens = self._cell_tokenizer.tokenize(text, keep_skip=False)
        if len(tokens) < 1:
            raise TableException('Invalid value: %s does not contain a name' %
                                 text)

        cell_type = self._get_token_type(self._cell_parser.parse(tokens))
        if cell_type == 'NAME_VALUE_UNIT':
            label, value, unit = self._get_name_values_unit(tokens)
            named_link = self.create_name_with_uri(label, text_with_uri)
            unit = self.process_content_item_unit(unit, fluid_units,
                                                  timepoint_units)
            measured_unit = MeasuredUnit(float(value), unit)
            content = ReagentIntent(named_link)
            content.add_reagent_value(measured_unit)
            contents.append(content)
        elif cell_type == 'NAME':
            for label in self.extract_name_value(text):
                named_link = self.create_name_with_uri(label, text_with_uri)
                name = NamedStringValue(named_link)
                contents.append(name)
        else:
            # default to a name string value
            for label in self.extract_name_value(text):
                named_link = self.create_name_with_uri(label, text_with_uri)
                name = NamedStringValue(named_link)
                contents.append(name)
        return contents
    def test_reagent_to_opil_without_timepoint(self):
        reagent_name = NamedLink('M9',
                                 'https://hub.sd2e.org/user/sd2e/design/M9/1')
        reagent = ReagentIntent(reagent_name)
        reagent_value = MeasuredUnit(10.0, 'uM')
        reagent.add_reagent_value(reagent_value)

        #TODO:
        reagent_component = reagent.reagent_values_to_opil_measures()
    def process_values_unit(self, text, units={}, unit_type=None):
        """
        Parses the content of a cell to identify its value and unit. 
    
        Args: 
            text: the content of a cell
            units: a list of units that the cell can be assigned to as its unit type.
            unit_type: an optional variable to specify what type of unit this function is parsing. Default to None.
        
        Return:
            a list of MeasuredUnit for representing values and units.
        Raises:
            A TableException is thrown for a cell that has no unit. 
        """
        result = []
        tokens = self._cell_tokenizer.tokenize(text,
                                               keep_separator=False,
                                               keep_skip=False)
        if not self.is_valued_cell(text):
            raise TableException('%s does not contain a unit' % text)
        if len(tokens) < 1:
            raise TableException(
                'Invalid value: %s does not contain a numerical value' % text)
        cell_type = self._get_token_type(self._cell_parser.parse(tokens))

        abbrev_units = self._abbreviated_unit_dict[
            unit_type] if unit_type is not None else {}
        if cell_type == 'VALUES_UNIT':
            values, unit = self._get_values_unit(tokens)
            validated_unit = self._determine_unit(unit, units, abbrev_units)
            if units and validated_unit in units:
                for value in values:
                    measured_unit = MeasuredUnit(float(value), validated_unit)
                    result.append(measured_unit)

        elif cell_type == 'VALUE_UNIT_PAIRS':
            for value, unit in self._get_values_unit_pairs(
                    tokens, units, unit_type):
                validated_unit = self._determine_unit(unit, units,
                                                      abbrev_units)
                if units and validated_unit in units:
                    measured_unit = MeasuredUnit(float(value), validated_unit)
                    result.append(measured_unit)
        return result
    def test_control_with_content_size_1(self):
        control_intent = ControlIntent()
        control_intent.set_control_type('EMPTY_VECTOR')
        content = ReagentIntent(NamedLink('beta_estradiol'))
        reagent_value = MeasuredUnit(0.05, 'micromole')
        content.add_reagent_value(reagent_value)
        control_intent.add_content(content)

        content_structure_request = [{
            dc_constants.NAME: {
                dc_constants.LABEL: 'beta_estradiol',
                dc_constants.SBH_URI: dc_constants.NO_PROGRAM_DICTIONARY
            },
            dc_constants.VALUE: '0.05',
            dc_constants.UNIT: 'micromole'
        }]
        self.assertEqual(
            {
                dc_constants.TYPE: 'EMPTY_VECTOR',
                dc_constants.CONTENTS: [content_structure_request]
            }, control_intent.to_structured_request())
 def _add_temperature_values_from_variant_measures(self, variant_measures, measurement_intent):
     for variant_measure in variant_measures:
         unit_name = sbol3_utils.get_unit_name_from_uri(variant_measure.unit)
         measured_unit = MeasuredUnit(variant_measure.value, unit_name)
         timepoint_intent = TemperatureIntent(measured_unit)
         measurement_intent.add_timepoint(timepoint_intent)
 def _add_reagent_values_from_variant_measures(self, variant_measures, reagent_intent):
     for variant_measure in variant_measures:
         unit_name = sbol3_utils.get_unit_name_from_uri(variant_measure.unit)
         measured_unit = MeasuredUnit(variant_measure.value, unit_name)
         reagent_intent.add_reagent_value(measured_unit)
示例#7
0
def create_opil_measurement_parameter_value(value: float, unit=''):
    parameter_value = opil.MeasureValue()
    measure = MeasuredUnit(value, unit)
    parameter_value.has_measure = measure.to_opil_measure()
    return parameter_value