Skip to content

Commit

Permalink
Adjusted code in curate #52
Browse files Browse the repository at this point in the history
  • Loading branch information
GwennyGit committed Feb 2, 2023
1 parent 0326be3 commit 0c58e02
Showing 1 changed file with 2 additions and 75 deletions.
77 changes: 2 additions & 75 deletions refinegems/curate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,12 @@
While working on GEMs the user might come across ill-annotated or missing metabolites, reactions and genes. This module aims to enable faster manual curation by allowing to edit an excel table directly which is used to update the given model. This module makes use of the cvterms module aswell.
"""
from Bio import Entrez, SeqIO
from tqdm.auto import tqdm
from refinegems.cvterms import add_cv_term_reactions, add_cv_term_genes, add_cv_term_metabolites, metabol_db_dict, parse_id_from_cv_term
from refinegems.cvterms import add_cv_term_reactions, add_cv_term_metabolites, metabol_db_dict, parse_id_from_cv_term
from refinegems.entities import create_gpr, create_reaction

__author__ = "Famke Baeuerle"


def get_name_from_locus(locus):
"""fetches protein name from NCBI
Args:
locus (string): NCBI compatible locus_tag
Returns:
str: protein name / description
"""
handle = Entrez.efetch(
db="protein",
id=locus,
rettype="gbwithparts",
retmode='text')
records = SeqIO.parse(handle, "gb")

for i, record in enumerate(records):
return record.description

def create_reaction(model, reaction_id, name, reactants, products, fluxes, reversible, fast, sbo):
"""creates new reaction in the given model
Args:
model (libsbml-model): model loaded with libSBML
reaction_id (str): BiGG id of the reaction to create
name (string): human readable name of the reaction
reactants (dict): metabolites as keys and their stoichiometry as values
products (dict): metabolites as keys and their stoichiometry as values
fluxes (dict): lower_bound and upper_bound as keys
reversible (bool): true/false for the reaction
fast (bool): true/false for the reaction
sbo (string): SBO term of the reaction
Returns:
tuple: (reaction, modified model)
"""
reaction = model.createReaction()
reaction.setId('R_' + reaction_id)
reaction.setName(name)
reaction.setMetaId('meta_R_' + reaction_id)
reaction.setSBOTerm(sbo)
reaction.setFast(fast)
reaction.setReversible(reversible)
for metab, stoich in reactants.items(): #reactants as dict with metab:stoich
reaction.addReactant(model.getSpecies('M_' + metab), stoich)
for metab, stoich in products.items(): #reactants as dict with metab:stoich
reaction.addProduct(model.getSpecies('M_' + metab), stoich)
reaction.getPlugin(0).setLowerFluxBound(fluxes['lower_bound'])
reaction.getPlugin(0).setUpperFluxBound(fluxes['upper_bound'])
return reaction, model

def create_gpr(model, locus_tag, email):
"""creates GeneProduct in the given model
Args:
model (libsbml-model): model loaded with libSBML
locus_tag (string): NCBI compatible locus_tag
email (string): User Email to access the NCBI Entrez database
Returns:
tuple: (gpr, modified model)
"""
Entrez.email = email
gpr = model.getPlugin(0).createGeneProduct()
name = get_name_from_locus(locus_tag)
gpr.setName(name)
gpr.setId(locus_tag)
gpr.setMetaId('meta_' + locus_tag)
gpr.setLabel(locus_tag)
gpr.setSBOTerm("SBO:0000243")
add_cv_term_genes(locus_tag, 'NCBI', gpr)
return gpr, model

def add_reactions_from_table(model, table, email):
"""adds all reactions with their info given in the table to the given model
Expand Down

0 comments on commit 0c58e02

Please sign in to comment.