Пример #1
0
    def load_data(self):
        '''
        - Loads all reactions, including locations for enzymes.
        - Separates out the transport reactions as an class dictionary
        - Makes mappings from molecule ids with location tags to external molecules without location tags

        '''

        # use rate_law_utilities to get all_reactions
        all_reactions = load_reactions()

        # make dict of reactions in TRANSPORT_IDS_FILE
        self.all_transport_reactions = {}
        rows = load_tsv(TRANSPORT_IDS_FILE)
        for row in rows:
            reaction_id = row['reaction id']
            stoichiometry = all_reactions[reaction_id]['stoichiometry']
            reversible = all_reactions[reaction_id]['is reversible']
            transporters_loc = all_reactions[reaction_id]['catalyzed by']

            self.all_transport_reactions[reaction_id] = {
                'stoichiometry': stoichiometry,
                'is reversible': reversible,
                'catalyzed by': transporters_loc}

        # Make map of external molecule_ids with a location tag (as used in reaction stoichiometry) to molecule_ids in the environment
        self.molecule_to_external_map = {}
        self.external_to_molecule_map = {}
        rows = load_tsv(EXTERNAL_MOLECULES_FILE)
        for row in rows:
            molecule_id = row['molecule id']
            location = row['exchange molecule location']
            self.molecule_to_external_map[molecule_id + location] = molecule_id
            self.external_to_molecule_map[molecule_id] = molecule_id + location
Пример #2
0
def load_reactions():
    '''
    Load all reactions, including the locations of enzymes into each reaction's 'catalyzed by' key

    Returns:
        all_reactions(dict)
    '''

    # get protein locations
    proteins_locations = {}
    rows = load_tsv(PROTEINS_FILE)
    for row in rows:
        molecule_id = row["id"]
        location = row["location"]
        molecule_loc = ['{}[{}]'.format(molecule_id, loc) for loc in location]
        proteins_locations[molecule_id] = molecule_loc

    # get complex locations
    rows = load_tsv(COMPLEXATION_FILE)
    for row in rows:
        stoichiometry = row["stoichiometry"]
        for stoich in stoichiometry:
            molecule_id = stoich['molecule']
            location = stoich["location"]
            molecule_loc = [
                '{}[{}]'.format(molecule_id, loc) for loc in location
            ]
            proteins_locations[molecule_id] = molecule_loc

    # make dict of all reactions
    all_reactions = {}
    rows = load_tsv(REACTIONS_FILE)
    for row in rows:
        reaction_id = row["reaction id"]
        stoichiometry = row["stoichiometry"]
        reversible = row["is reversible"]
        enzymes = row["catalyzed by"]

        # get location
        enzymes_loc = []
        for enzyme in enzymes:
            if enzyme in proteins_locations.keys():
                enzymes_loc.extend(proteins_locations[enzyme])

        all_reactions[reaction_id] = {
            "stoichiometry": stoichiometry,
            "is reversible": reversible,
            "catalyzed by": enzymes_loc
        }

    return all_reactions
Пример #3
0
    def _load_tsv(self, dir_name, file_name):
        path = self
        steps = file_name.split(os.path.sep)
        for subPath in steps[:-1]:
            if not hasattr(path, subPath):
                setattr(path, subPath, DataStore())
            path = getattr(path, subPath)
        attrName = steps[-1].split(".")[0]
        setattr(path, attrName, [])

        file_path = os.path.join(dir_name, file_name)
        rows = load_tsv(file_path)
        setattr(path, attrName, [row for row in rows])
Пример #4
0
def load_lookup(filename):
    ''' load a file and pass back dicts with lookup_avg and lookup_dist'''
    lookup_avg = {}
    lookup_dist = {}

    rows = load_tsv(filename)
    for row in rows:
        key = row.get('id')
        avg = row.get('average')
        dist = row.get('distribution')

        # check if empty distribution
        if dist:
            dist = [float(value) for value in dist]
        else:
            dist = [0]

        lookup_avg[key] = avg
        lookup_dist[key] = dist

    return lookup_avg, lookup_dist