Skip to content

Commit

Permalink
Added BOF to cmpb pipeline #8
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-Hades committed May 24, 2024
1 parent 73666da commit 37b400c
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 20 deletions.
83 changes: 83 additions & 0 deletions dev/CB_test_modules.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2760,6 +2760,89 @@
"source": [
"specimen.hqtb."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<bound method SBase.getNotesString of <Model Kp_std \"Genome-scale metabolic model of K. pneumoniae HS11286\">>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from refinegems.utility.io import load_model\n",
"\n",
"p = '/Users/brune/Documents/11_Test_Data/test_SPECIMEN/thesis/Kp_std/02_generate_draft_model/Kp_std_draft.xml'\n",
"model = load_model(p,'libsbml')\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"model.getModelHistory()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'<notes>\\n <html xmlns=\"http://www.w3.org/1999/xhtml\">\\n <p>Description: This model was built with CarveMe version 1.5.1</p>\\n </html>\\n</notes>'"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = model.getNotesString()\n",
"x\n",
"# 'CarveMe' in x"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Description': 'This model was built with CarveMe version 1.5.1'}"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mod2 = load_model(p, 'cobra')\n",
"mod2.notes"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
48 changes: 33 additions & 15 deletions src/specimen/cmpb/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
# requirements
################################################################################

import os
import cobra
import logging
import pandas as pd
from datetime import date
Expand All @@ -16,11 +14,12 @@
import warnings
import yaml

from cobra import Reaction
from libsbml import readSBML

from refinegems.curation.pathways import kegg_pathway_analysis
from refinegems.classes.reports import ModelInfoReport
from refinegems.curation.biomass import test_biomass_presence
from refinegems.curation.biomass import test_biomass_presence, check_normalise_biomass
from refinegems.analysis import growth
from refinegems.utility.connections import run_memote, perform_mcc, adjust_BOF
from refinegems.curation.curate import resolve_duplicates
Expand Down Expand Up @@ -263,20 +262,39 @@ def between_analysis(model, cfg, step):

# BOF
# ---
# @TODO
# BOFdat - optional
current_model = load_model(current_modelpath,'cobra')
if config['BOF']['run_bofdat']:
new_bof = adjust_BOF(config['BOF']['bofdat_params']['full_genome_sequence'],
current_modelpath,
current_model,
dna_weight_fraction = config['BOF']['bofdat_params']['dna_weight_fraction'],
weight_frac = config['BOF']['bofdat_params']['weight_fraction'])
# @TODO
# save ?
# check and normalise
elif config['BOF']['normalise']:
pass
#@TODO
check_bof = test_biomass_presence(current_model)
if check_bof:
current_model.reactions.get_by_id(check_bof[0]).reaction = adjust_BOF(config['BOF']['bofdat_params']['full_genome_sequence'],
current_modelpath,
current_model,
dna_weight_fraction = config['BOF']['bofdat_params']['dna_weight_fraction'],
weight_frac = config['BOF']['bofdat_params']['weight_fraction'])
current_model = check_normalise_biomass(current_model)
else:
bof_reac = Reaction('Biomass_BOFdat')
bof_reac.name = 'Biomass objective function created by BOFdat'
current_model.add_reactions([bof_reac])
current_model.reactions.get_by_id(bof_reac).reaction = adjust_BOF(config['BOF']['bofdat_params']['full_genome_sequence'],
current_modelpath,
current_model,
dna_weight_fraction = config['BOF']['bofdat_params']['dna_weight_fraction'],
weight_frac = config['BOF']['bofdat_params']['weight_fraction'])
current_model = check_normalise_biomass(current_model)

# check and normalise
else:
current_model = check_normalise_biomass(current_model)

# save
# save model
if config['general']['save_all_models']:
write_model_to_file(Path(dir,'cmpb_out','models','after_BOF.xml'))
current_modelpath = Path(dir,'cmpb_out','models','after_BOF.xml')
else:
write_model_to_file(current_modelpath)

# MCC
# ---
Expand Down
6 changes: 2 additions & 4 deletions src/specimen/data/config/cmpb_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,5 @@ BOF:
full_genome_sequence: USER # whole genome sequence
dna_weight_fraction: USER # DNA weight fraction for the organism
weight_fraction: USER # Ezyme/ion weight fractions for the organism
# if BOFdat is not run, the biomass objective function
# can still - optionally - normalised
normalise: True
# @TODO


2 changes: 1 addition & 1 deletion src/specimen/hqtb/core/refinement/smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def run(genome:str,model:str,dir:str,mcc='skip',
bof_reac = Reaction('Biomass_BOFdat')
bof_reac.name = 'Biomass objective function created by BOFdat'
model.add_reactions([bof_reac])
model.reactions.get_by_id(pos_bofs[0]).reaction = adjust_BOF(genome, temp_model.name, model, dna_weight_frac, ion_weight_frac)
model.reactions.get_by_id(bof_reac).reaction = adjust_BOF(genome, temp_model.name, model, dna_weight_frac, ion_weight_frac)

# optimise BOF(s)
model = check_normalise_biomass(model)
Expand Down

0 comments on commit 37b400c

Please sign in to comment.