Example #1
0
    def extend_S_from_gams_inputfile(self, filename=None):
        """Extend S matrix using the gams S matrix format.
        Args:
            filename (None, optional): The name of the inputfile.
        """
        self.S = gams_parser.convert_parameter_table_to_dict(os.path.join(
            self.data_filepath, filename),
                                                             Sdict=self.S)

        self.refresh_database(previous_operations_on='S')
Example #2
0
    def load(self):
        # Method 1: JSON approach
        if self.dbdict_json is not None:
            self.logger.debug('Reading S matrix from JSON...')
            self.Sji = json.load(
                open(
                    os.path.join(
                        self.data_filepath,
                        self.dbdict_json['Sji']),
                    'r+'))
            self.S = self.transpose_S(self.Sji)
            self.reactions = sorted(self.Sji.keys())
            self.internal_rxns = copy.deepcopy(self.reactions)
            self.metabolites = sorted(self.S.keys())
            self.logger.debug('Reading reaction type file...')
            self.rxntype = json.load(
                open(
                    os.path.join(
                        self.data_filepath,
                        self.dbdict_json['reactiontype']),
                    'r+'))

        # Method 2: Standard GAMS input file
        else:
            self.logger.debug('Reading S matrix from txt...')
            self.S = gams_parser.convert_parameter_table_to_dict(
                os.path.join(self.data_filepath,
                             self.dbdict_gams['Sji'])
            )
            self.Sji = self.transpose_S(self.S)

            # Load reactions
            self.logger.debug('Reading reaction file...')
            self.reactions = gams_parser.convert_set_to_list(
                os.path.join(self.data_filepath, self.dbdict_gams['reaction'])
            )
            # Create internal reactions list
            self.internal_rxns = copy.deepcopy(self.reactions)

            self.logger.debug('Reading metabolite file...')
            self.metabolites = gams_parser.convert_set_to_list(
                os.path.join(self.data_filepath, self.dbdict_gams['metabolite'])
            )

            self.logger.debug('Reading reaction type file...')
            self.rxntype = gams_parser.convert_parameter_list_to_dict(
                os.path.join(self.data_filepath, self.dbdict_gams['reactiontype']),
                datadict=None
            )
        self.validate()
Example #3
0
    def load_toy_model(self):

        # Method 1: JSON approach
        if self.dbdict_json is not None:
            self.logger.debug('Reading S matrix from JSON...')
            self.Sji = json.load(
                open(os.path.join(self.data_filepath, self.dbdict_json['Sji']),
                     'r+'))
            self.S = self.transpose_S(self.Sji)
            self.reactions = sorted(self.Sji.keys())
            self.internal_rxns = copy.deepcopy(self.reactions)
            self.metabolites = sorted(self.S.keys())
            self.logger.debug('Reading reaction type file...')
            self.rxntype = json.load(
                open(
                    os.path.join(self.data_filepath,
                                 self.dbdict_json['reactiontype']), 'r+'))

            self.logger.debug('Reading Nint(loop, j) from JSON...')
            #no hay loops en el toy_model
            #self.Ninternal = json.load(
            #    open(
            #        os.path.join(
            #            self.data_filepath,
            #            self.dbdict_json['Nint']),
            #        'r+'))

            #self.loops = sorted(self.Ninternal.keys())
        # Method 2: Standard GAMS input file
        else:
            self.logger.debug('Reading S matrix from txt...')
            self.S = gams_parser.convert_parameter_table_to_dict(
                os.path.join(self.data_filepath, self.dbdict_gams['Sji']))
            self.Sji = self.transpose_S(self.S)

            self.logger.debug('Reading metabolite file...')
            self.metabolites = gams_parser.convert_set_to_list(
                os.path.join(self.data_filepath,
                             self.dbdict_gams['metabolite']))
            # Load reactions
            self.logger.debug('Reading reaction file...')
            self.reactions = gams_parser.convert_set_to_list(
                os.path.join(self.data_filepath, self.dbdict_gams['reaction']))
            self.internal_rxns = copy.deepcopy(self.reactions)

            self.logger.debug('Reading reaction type file...')
            self.rxntype = gams_parser.convert_parameter_list_to_dict(
                os.path.join(self.data_filepath,
                             self.dbdict_gams['reactiontype']),
                datadict=None)
            self.logger.debug('Reading Nint(loop, j) from txt...')
            self.Ninternal = gams_parser.convert_parameter_table_to_dict(
                os.path.join(self.data_filepath, self.dbdict_gams['Nint']))

            self.logger.debug('Reading loop file...')
            self.loops = gams_parser.convert_set_to_list(
                os.path.join(self.data_filepath, self.dbdict_gams['loops']))

        if self.excluded_reactions is not None:
            self.all_excluded_reactions = list(
                set(self.excluded_reactions + self.blocked_rxns))
        else:
            self.all_excluded_reactions = self.blocked_rxns

        #self.validate()

        if self.reduce_model_size:
            self.remove_blocked_reactions()
            self.validate()