Yield model reaction limits as YAML dicts.
11925
def model_reaction_limits(model):
    """"""
    for reaction in sorted(model.reactions, key=lambda r: r.id):
        equation = reaction.properties.get('equation')
        if equation is None:
            continue

        # Determine the default flux limits. If the value is already at the
        # default it does not need to be included in the output.
        lower_default, upper_default = None, None
        if model.default_flux_limit is not None:
            if equation.direction.reverse:
                lower_default = -model.default_flux_limit
            else:
                lower_default = 0.0

            if equation.direction.forward:
                upper_default = model.default_flux_limit
            else:
                upper_default = 0.0

        lower_flux, upper_flux = None, None
        if reaction.id in model.limits:
            _, lower, upper = model.limits[reaction.id]
            lower_flux = _get_output_limit(lower, lower_default)
            upper_flux = _get_output_limit(upper, upper_default)

        if lower_flux is not None or upper_flux is not None:
            d = OrderedDict([('reaction', reaction.id)])
            d.update(_generate_limit_items(lower_flux, upper_flux))

            yield d
1102399
def parse_yaml(self, y):
        ''''''
        self.sequence = int(y['sequence'])
        self.target_component = \
                TargetExecutionContext().parse_yaml(y['targetComponent'])
        if RTS_EXT_NS_YAML + 'properties' in y:
            for p in y.get(RTS_EXT_NS_YAML + 'properties'):
                if 'value' in p:
                    value = p['value']
                else:
                    value = None
                self._properties[p['name']] = value
        return self
650719
def parse_yaml(self, y):
        '''

        '''
        super(WaitTime, self).parse_yaml(y)
        self.wait_time = int(y['condition']['waitTime']['waitTime'])
        return self
147469
def modules(self):
        """"""

        resource = self.RMODULES

        params = {
            self.PLIMIT: self.max_items,
            self.PSORT_BY: self.VLATEST_RELEASE
        }

        for page in self._fetch(resource, params):
            yield page
159455
def load_all(self, target_uris, **kwargs):
        '''
        
        '''
        yaml_series = self._load_first(
            target_uris, yamlsettings.yamldict.load_all, **kwargs
        )
        yaml_dicts = []
        for yaml_dict in yaml_series:
            yaml_dicts.append(yaml_dict)
        # return YAMLDict objects
        return yaml_dicts
830079
def load_yaml(filename):
    
    try:
        with open(filename, 'rb') as f:
            return yaml.load(f, Loader=Loader)
    except (IOError, yaml.error.YAMLError) as exc:
        raise ConfigReadError(filename, exc)
796725
def _get_work_spec(self, args):
        ''''''
        with open(args.work_spec_path) as f:
            return yaml.load(f)
943758
def _yield_estimators(model):
    
    yield from _yield_preproc_steps(model)

    net_prefixes = []
    module_prefixes = []

    if isinstance(model, Pipeline):
        name = model.steps[-1][0]
        net_prefixes.append(name)
        module_prefixes.append(name)
        net = model.steps[-1][1]
    else:
        net = model

    yield '__'.join(net_prefixes), net

    module = net.module
    module_prefixes.append('module')
    yield '__'.join(module_prefixes), module
1266324
def list_all(self):
        '''
        
        '''
        if isinstance(self.minion.opts['reactor'], six.string_types):
            log.debug('Reading reactors from yaml %s', self.opts['reactor'])
            try:
                with salt.utils.files.fopen(self.opts['reactor']) as fp_:
                    react_map = salt.utils.yaml.safe_load(fp_)
            except (OSError, IOError):
                log.error('Failed to read reactor map: "%s"', self.opts['reactor'])
            except Exception:
                log.error(
                    'Failed to parse YAML in reactor map: "%s"',
                    self.opts['reactor']
                )
        else:
            log.debug('Not reading reactors from yaml')
            react_map = self.minion.opts['reactor']
        return react_map
835493
def gen_from_yaml_config(self, config_path: str) -> Iterator:
        
        if not config_path:
            return {}

        with open(config_path, 'r') as f:
            yaml_config = yaml.load(f)

        gen = map(lambda x: (x[0].upper(), x[1]), yaml_config.items())

        return gen
575713
def parse_limits_file(path):
    

    context = FilePathContext(path)

    format = resolve_format(None, context.filepath)
    if format == 'tsv':
        logger.debug('Parsing limits file {} as TSV'.format(
            context.filepath))
        with context.open('r') as f:
            for limit in parse_limits_table_file(f):
                yield limit
    elif format == 'yaml':
        logger.debug('Parsing limits file {} as YAML'.format(
            context.filepath))
        with context.open('r') as f:
            for limit in parse_limits_yaml_file(context, f):
                yield limit
    else:
        raise ParseError('Unable to detect format of limits file {}'.format(
            context.filepath))
229438
def models(self):
        '''
        
        '''
        model_dict = self._build_all_dependencies()
        while True:
            model = self._get_model_without_dependencies(model_dict)
            if not model:
                break
            yield (model, self._models().get(model))
773567
def create_model(self):
        
        properties = {
            'name': self.name,
            'default_flux_limit': 1000
        }

        # Load objective as biomass reaction
        objective = self.get_active_objective()
        if objective is not None:
            reactions = dict(objective.reactions)
            if len(reactions) == 1:
                reaction, value = next(iteritems(reactions))
                if ((value < 0 and objective.type == 'minimize') or
                        (value > 0 and objective.type == 'maximize')):
                    properties['biomass'] = reaction

        model = NativeModel(properties)

        # Load compartments into model
        for compartment in self.compartments:
            model.compartments.add_entry(compartment)

        # Load compounds into model
        for compound in self.species:
            model.compounds.add_entry(compound)

        # Load reactions into model
        for reaction in self.reactions:
            model.reactions.add_entry(reaction)

        # Create model reaction set
        for reaction in model.reactions:
            model.model[reaction.id] = None

        # Convert reaction limits properties to proper limits
        for reaction in model.reactions:
            props = reaction.properties
            if 'lower_flux' in props or 'upper_flux' in props:
                lower = props.get('lower_flux')
                upper = props.get('upper_flux')
                model.limits[reaction.id] = reaction.id, lower, upper

        # Load model limits from FBC V1 bounds if present, i.e. if FBC V1 is
        # used instead of V2.
        limits_lower = {}
        limits_upper = {}
        for bounds in self.flux_bounds:
            reaction = bounds.reaction
            if reaction in model.limits:
                continue

            if bounds.operation == SBMLFluxBoundEntry.LESS_EQUAL:
                if reaction not in limits_upper:
                    limits_upper[reaction] = bounds.value
                else:
                    raise ParseError(
                        'Conflicting bounds for {}'.format(reaction))
            elif bounds.operation == SBMLFluxBoundEntry.GREATER_EQUAL:
                if reaction not in limits_lower:
                    limits_lower[reaction] = bounds.value
                else:
                    raise ParseError(
                        'Conflicting bounds for {}'.format(reaction))
            elif bounds.operation == SBMLFluxBoundEntry.EQUAL:
                if (reaction not in limits_lower and
                        reaction not in limits_upper):
                    limits_lower[reaction] = bounds.value
                    limits_upper[reaction] = bounds.value
                else:
                    raise ParseError(
                        'Conflicting bounds for {}'.format(reaction))

        for reaction in model.reactions:
            if reaction.id in limits_lower or reaction.id in limits_upper:
                lower = limits_lower.get(reaction.id, None)
                upper = limits_upper.get(reaction.id, None)
                model.limits[reaction.id] = reaction.id, lower, upper

        return model
1293307
def mols_from_file(path, no_halt=True, assign_descriptors=True):
    """"""
    with open(path, 'rb') as f:
        fd = (tx.decode(line) for line in f)
        for c in mol_supplier(fd, no_halt, assign_descriptors):
            yield c
1235722
def _iter_key_ranges(self):
    """"""
    while True:
      if self._current_key_range is None:
        if self._key_ranges:
          self._current_key_range = self._key_ranges.pop()
          # The most recently popped key_range may be None, so continue here
          # to find the next keyrange that's valid.
          continue
        else:
          break

      for key, o in self._iter_key_range(
          copy.deepcopy(self._current_key_range)):
        # The caller must consume yielded values so advancing the KeyRange
        # before yielding is safe.
        self._current_key_range.advance(key)
        yield o
      self._current_key_range = None
769071
def _load_yaml_config(path=None):
    """"""
    furious_yaml_path = path or find_furious_yaml()
    if furious_yaml_path is None:
        logging.debug("furious.yaml not found.")
        return None

    with open(furious_yaml_path) as yaml_file:
        return yaml_file.read()
1322971
def create_from_yamlfile(cls, yamlfile):
        """"""
        data = load_yaml(yamlfile)
        nebins = len(data)
        emin = np.array([data[i]['emin'] for i in range(nebins)])
        emax = np.array([data[i]['emax'] for i in range(nebins)])
        ref_flux = np.array([data[i]['flux'][1] for i in range(nebins)])
        ref_eflux = np.array([data[i]['eflux'][1] for i in range(nebins)])
        conv = np.array([data[i]['eflux2npred'] for i in range(nebins)])
        ref_npred = conv*ref_eflux
        ones = np.ones(ref_flux.shape)
        ref_spec = ReferenceSpec(emin, emax, ones, ref_flux, ref_eflux, ref_npred)
        norm_data = np.array([data[i]['eflux'] for i in range(nebins)])
        ll_data =  np.array([data[i]['logLike'] for i in range(nebins)])
        max_ll = ll_data.max(1)
        nll_data = (max_ll - ll_data.T).T
        return cls(norm_data, nll_data, ref_spec, 'eflux')