コード例 #1
0
def load_custom_reactions_to_be_excluded():
    """A list of undesirable reactions that are specific
    to the glycolysis study

    Returns:
        TYPE: Description
    """
    NTP_involving_rxns = gams_parser.convert_set_to_list(
        os.path.join(DATA_DIR, 'NTP_and_AMP_reactions.txt')
    )
    cofactor_only_rxns = gams_parser.convert_set_to_list(
        os.path.join(DATA_DIR, 'cofactor_only_reactions.txt')
    )
    cofactor_only_rxns.append('R10092')

    methylglyoxal_rxns = [
        'R00203',
        'R00205',
        'R01016',
        'R02260',
        'R02527',
        'R02528',
        'R02529',
        'R02530',
        'R02531',
        'R07183',
        'R09796',
        'R10049',
        'R10050'
    ]

    other_undesirable_rxns = [
        # Bicarbonate and pyrrole cycle
        'R09794',
        'R09795',
        # Undesirable glucose uptake loop
        'R00305',
        'R00874',
        'R07359',
        'R00837',
        'R09749',
        'R03075',
        'R02985',
        'R02558',
        'R01555',
        'R02727',
        'R00010',
        'R02778',
        'R08946',
        'R00306'
    ]

    excluded_reactions = (NTP_involving_rxns +
                          methylglyoxal_rxns +
                          cofactor_only_rxns +
                          other_undesirable_rxns)

    all_excluded_reactions = list(set(excluded_reactions))
    return all_excluded_reactions
コード例 #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()
コード例 #3
0
def load_db_v3_toy_model(user_defined_export_rxns_Sji,
                         reduce_model_size=True,
                         logger=None):
    """Load OptStoic database v3

    Returns:
        TYPE: Description

    Args:
        reduce_model_size (bool, optional): True if you want to reduce the size of the
            model by removing blocked reactions from the S matrix.
        user_defined_export_rxns_Sji (dict, optional): The list of export reactions that
            need to be added to the model for metabolite exchange (i.e., any metabolite
            that participate in the design equation)
    """
    if logger is None:
        logger = create_logger(name="optstoicpy.core.database.load_db_v3")

    # get reactions that are manually curated to be excluded for glycolysis
    # study
    excluded_reactions = load_custom_reactions_to_be_excluded()

    dbdict_json = {
        'Sji': 'toy_model_Sji.json',
        #'Nint': 'Nint_ecolicore.json',
        'reactiontype': 'toy_model_reactiontype.json'
    }

    dbdict_gams = {
        'Sji': 'optstoic_v3_Sij.txt',
        'reaction': 'optstoic_v3_reactions.txt',
        'metabolite': 'optstoic_v3_metabolites.txt',
        'reactiontype': 'optstoic_v3_reactiontype.txt',
        'loops': 'optstoic_v3_loops_nocofactor.txt',
        'Nint': 'optstoic_v3_null_sij_nocofactor.txt',
        'blocked_rxns': 'optstoic_v3_blocked_reactions_0to5ATP.txt',
    }

    logger.debug('Reading blocked reactions file...')
    if 'blocked_rxns' in dbdict_gams:
        blocked_rxns = gams_parser.convert_set_to_list(
            os.path.join(DATA_DIR, dbdict_gams['blocked_rxns']))
    else:
        blocked_rxns = None

    DB = Database(description='toy_model_v3',
                  data_filepath=DATA_DIR,
                  dbdict_json=dbdict_json,
                  dbdict_gams=dbdict_gams,
                  blocked_rxns=[],
                  excluded_reactions=excluded_reactions,
                  reduce_model_size=reduce_model_size)

    DB.load_toy_model()

    # Update reaction type
    # Update reaction type  = 0
    irreversible_fwd_rxns = gams_parser.convert_set_to_list(
        os.path.join(DATA_DIR,
                     'optstoic_v3_ATP_irreversible_forward_rxns.txt'))

    new_reaction_type_dict = dict(
        list(zip(irreversible_fwd_rxns, [0] * len(irreversible_fwd_rxns))))
    # Update reaction type  =  2
    irreversible_bwd_rxns = gams_parser.convert_set_to_list(
        os.path.join(DATA_DIR,
                     'optstoic_v3_ATP_irreversible_backward_rxns.txt'))

    new_reaction_type_dict.update(
        dict(list(zip(irreversible_bwd_rxns,
                      [2] * len(irreversible_bwd_rxns)))))

    DB.update_rxntype(new_reaction_type_dict)

    # user_defined_export_rxns = ['EX_glc', 'EX_nad', 'EX_adp',
    #                             'EX_phosphate', 'EX_pyruvate', 'EX_nadh',
    #                             'EX_atp', 'EX_h2o', 'EX_hplus', 'EX_nadp',
    #                             'EX_nadph']

    # Add a list of export reactions and the metabolites
    #if user_defined_export_rxns_Sji is not None:
    user_defined_export_rxns_Sij = Database.transpose_S(
        user_defined_export_rxns_Sji)

    DB.set_database_export_reaction(user_defined_export_rxns_Sij)

    return DB
コード例 #4
0
def load_base_reaction_db_ecolicore(user_defined_export_rxns_Sji=None,
                                    logger=None):
    """Load the base reaction database with all reactions
    (i.e., no blocked reactions and no loops)

    Args:
        user_defined_export_rxns_Sji (None, optional): Description

    Returns:
        :obj:`BaseReactionDatabase`:
    """
    if logger is None:
        logger = create_logger(
            name="optstoicpy.core.database.load_base_reaction_db")

    # get reactions that are manually curated to be excluded for glycolysis
    # study
    excluded_reactions = load_custom_reactions_to_be_excluded()

    dbdict_json = {
        'Sji': 'Sji_dict_ecolicore.json',
        'reactiontype': 'ecolicore_reactiontype.json'
    }
    dbdict_gams = {
        'Sji': 'optstoic_v3_Sij.txt',
        'reaction': 'optstoic_v3_reactions.txt',
        'metabolite': 'optstoic_v3_metabolites.txt',
        'reactiontype': 'optstoic_v3_reactiontype.txt'
    }

    DB = BaseReactionDatabase(data_filepath=DATA_DIR,
                              dbdict_json=dbdict_json,
                              dbdict_gams=dbdict_gams)

    DB.load_ecolicore()

    # Update reaction type
    # Update reaction type  = 0
    irreversible_fwd_rxns = gams_parser.convert_set_to_list(
        os.path.join(DATA_DIR,
                     'optstoic_v3_ATP_irreversible_forward_rxns.txt'))

    new_reaction_type_dict = dict(
        list(zip(irreversible_fwd_rxns, [0] * len(irreversible_fwd_rxns))))
    # Update reaction type  =  2
    irreversible_bwd_rxns = gams_parser.convert_set_to_list(
        os.path.join(DATA_DIR,
                     'optstoic_v3_ATP_irreversible_backward_rxns.txt'))

    new_reaction_type_dict.update(
        dict(list(zip(irreversible_bwd_rxns,
                      [2] * len(irreversible_bwd_rxns)))))

    DB.update_rxntype(new_reaction_type_dict)

    # Add a list of export reactions and the metabolites
    if user_defined_export_rxns_Sji is not None:
        user_defined_export_rxns_Sij = Database.transpose_S(
            user_defined_export_rxns_Sji)

        DB.set_database_export_reaction(user_defined_export_rxns_Sij)
    return DB
コード例 #5
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()