Skip to content

Commit bfad866

Browse files
authored
Merge pull request #80 from Fxe/dev
Dev
2 parents 8a83e2a + 9de013b commit bfad866

File tree

7 files changed

+45
-32
lines changed

7 files changed

+45
-32
lines changed

modelseedpy/core/msatpcorrection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def expand_model_to_genome_scale(self):
262262
# it is not detrimental to run this twice
263263
self.restore_noncore_reactions(noncore=True, othercompartment=False)
264264
# Extending model with non core reactions while retaining ATP accuracy
265-
self.filtered_noncore = self.modelutl.reaction_expansion_test(self.noncore_reactions,tests)
265+
self.filtered_noncore = self.modelutl.reaction_expansion_test(self.noncore_reactions, tests)
266266
# Removing filtered reactions
267267
for item in self.filtered_noncore:
268268
print("Removing "+item[0].id+" "+item[1])

modelseedpy/core/msbuilder.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -650,4 +650,7 @@ def gapfill_model(original_mdl, target_reaction, template, media):
650650
else:
651651
rxn.upper_bound = 0
652652
rxn.lower_bound = -100
653-
return original_mdl
653+
return original_mdl
654+
655+
def build_metabolic_model(genome, media=None, atp_test_medias=None, core_template=None, genome_scale_template=None):
656+
pass

modelseedpy/core/msgapfill.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def run_gapfilling(self, media=None, target=None, minimum_obj=0.01, binary_check
5757
})
5858
pkgmgr.getpkg("KBaseMediaPkg").build_package(media)
5959

60-
#Filtering breaking reactions out of the database
60+
# Filtering breaking reactions out of the database
6161
if prefilter and self.test_conditions:
6262
pkgmgr.getpkg("GapfillingPkg").filter_database_based_on_tests(self.test_conditions)
6363

@@ -68,14 +68,16 @@ def run_gapfilling(self, media=None, target=None, minimum_obj=0.01, binary_check
6868
logger.debug('gapfill solution objective value %f (%s) for media %s', sol.objective_value, sol.status, media)
6969

7070
if sol.status != 'optimal':
71-
logger.warning("No solution found for %s", media)
71+
logger.debug("No solution found for %s", media)
7272
return None
7373

7474
self.last_solution = pkgmgr.getpkg("GapfillingPkg").compute_gapfilled_solution()
7575
if self.test_conditions:
76-
self.last_solution = pkgmgr.getpkg("GapfillingPkg").run_test_conditions(self.test_conditions, self.last_solution, self.test_condition_iteration_limit)
76+
self.last_solution = pkgmgr.getpkg("GapfillingPkg").run_test_conditions(
77+
self.test_conditions, self.last_solution, self.test_condition_iteration_limit)
7778
if self.last_solution is None:
78-
logger.warning("no solution could be found that satisfied all specified test conditions in specified iterations!")
79+
logger.debug("No solution could be found that satisfied all \
80+
specified test conditions in specified iterations!")
7981
return None
8082
if binary_check:
8183
return pkgmgr.getpkg("GapfillingPkg").binary_check_gapfilling_solution()

modelseedpy/core/msgenome.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import logging
22
import re
3-
import copy # !!! the import is never used
43
from cobra.core.dictlist import DictList
54

65
logger = logging.getLogger(__name__)
76

7+
DEFAULT_SPLIT = ' '
8+
89

910
def normalize_role(s):
10-
# print(s)
1111
s = s.strip().lower()
12-
s = re.sub('[\W_]+', '', s)
12+
s = re.sub(r'[\W_]+', '', s)
1313
return s
1414

1515

16-
def read_fasta(f, split='|', h_func=None):
16+
def read_fasta(f, split=DEFAULT_SPLIT, h_func=None):
1717
with open(f, 'r') as fh:
1818
return parse_fasta_str(fh.read(), split, h_func)
1919

2020

21-
def parse_fasta_str(faa_str, split='|', h_func=None):
21+
def parse_fasta_str(faa_str, split=DEFAULT_SPLIT, h_func=None):
2222
features = []
2323
seq = None
2424
for line in faa_str.split('\n'):
@@ -32,7 +32,8 @@ def parse_fasta_str(faa_str, split='|', h_func=None):
3232
elif split:
3333
header_data = line[1:].split(split, 1)
3434
seq_id = header_data[0]
35-
desc = header_data[1] # The unit test throws an error when this is commented
35+
if len(header_data) > 1:
36+
desc = header_data[1] # The unit test throws an error when this is commented
3637

3738
seq = MSFeature(seq_id, "", desc)
3839
else:
@@ -108,10 +109,10 @@ def from_protein_sequences_hash(sequences):
108109
genome = MSGenome()
109110
genome.features += features
110111
return genome
111-
112+
112113
def alias_hash(self):
113114
return {alias: gene for gene in self.features for alias in gene.aliases}
114-
115+
115116
def search_for_gene(self, query):
116117
if query in self.features:
117118
return self.features.get_by_id(query)

modelseedpy/core/msmodelutl.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def __init__(self,model):
7474
self.test_objective = None
7575
self.score = None
7676

77-
def printlp(self,lpfilename="debug.lp"):
77+
def printlp(self, lpfilename="debug.lp"):
7878
with open(lpfilename, 'w') as out:
79-
out.write(str(self.model.solver))
79+
out.write(str(self.model.solver))
8080

8181
def build_metabolite_hash(self):
8282
self.metabolite_hash = {}
@@ -345,7 +345,7 @@ def add_gapfilling_solution_to_kbase_model(self,newmodel,gapfilled_reactions,gfi
345345
kbrxn["gapfill_data"][gfid]["0"] = [gapfilled_reactions["reversed"][rxn],1,[]]
346346
return rxn_table
347347

348-
def apply_test_condition(self,condition,model = None):
348+
def apply_test_condition(self, condition, model=None):
349349
"""Applies constraints and objective of specified condition to model
350350
351351
Parameters
@@ -363,7 +363,7 @@ def apply_test_condition(self,condition,model = None):
363363
Raises
364364
------
365365
"""
366-
if model == None:
366+
if model is None:
367367
model = self.model
368368
pkgmgr = self.pkgmgr
369369
else:
@@ -375,7 +375,7 @@ def apply_test_condition(self,condition,model = None):
375375
model.objective.direction = "min"
376376
pkgmgr.getpkg("KBaseMediaPkg").build_package(condition["media"])
377377

378-
def test_single_condition(self,condition,apply_condition=True,model=None):
378+
def test_single_condition(self, condition, apply_condition=True, model=None):
379379
"""Runs a single test condition to determine if objective value on set media exceeds threshold
380380
381381
Parameters
@@ -395,14 +395,14 @@ def test_single_condition(self,condition,apply_condition=True,model=None):
395395
Raises
396396
------
397397
"""
398-
if model == None:
398+
if model is None:
399399
model = self.model
400400
if apply_condition:
401-
self.apply_test_condition(condition,model)
401+
self.apply_test_condition(condition, model)
402402
new_objective = model.slim_optimize()
403403
value = new_objective
404404
if "change" in condition and condition["change"]:
405-
if self.test_objective != None:
405+
if self.test_objective is not None:
406406
value = new_objective - self.test_objective
407407
self.score = value
408408
if model.solver.status != 'optimal':
@@ -418,7 +418,7 @@ def test_single_condition(self,condition,apply_condition=True,model=None):
418418
self.test_objective = new_objective
419419
return True
420420

421-
def test_condition_list(self,condition_list,model=None):
421+
def test_condition_list(self, condition_list: list, model=None):
422422
"""Runs a set of test conditions to determine if objective values on set medias exceed thresholds
423423
424424
Parameters
@@ -443,7 +443,7 @@ def test_condition_list(self,condition_list,model=None):
443443
return False
444444
return True
445445

446-
def reaction_expansion_test(self,reaction_list,condition_list):
446+
def reaction_expansion_test(self, reaction_list: list, condition_list: list):
447447
"""Adds reactions in reaction list one by one and appplies tests, filtering reactions that fail
448448
449449
Parameters
@@ -461,10 +461,15 @@ def reaction_expansion_test(self,reaction_list,condition_list):
461461
Raises
462462
------
463463
"""
464-
print("Expansion started!")
465464
tic = time.perf_counter()
465+
466+
logger.info(f"Expansion started! reaction list: {len(reaction_list)} conditions: {len(condition_list)}")
467+
466468
filtered_list = []
467469
for condition in condition_list:
470+
471+
logger.debug(f'testing condition {condition}')
472+
468473
currmodel = self.model
469474
with currmodel:
470475
self.apply_test_condition(condition)

modelseedpy/fbapkg/gapfillingpkg.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,11 @@ def binary_check_gapfilling_solution(self, solution=None, flux_values=None):
450450
self.model.optimize()
451451
new_solution = self.compute_gapfilled_solution()
452452
return new_solution
453-
454-
#This function is designed to KO all gapfilled reactions not included in the solution
453+
455454
def knockout_gf_reactions_outside_solution(self,solution = None,flux_values = None):
455+
"""
456+
This function is designed to KO all gap filled reactions not included in the solution
457+
"""
456458
if solution == None:
457459
solution = self.compute_gapfilled_solution()
458460
if flux_values == None:
@@ -500,18 +502,18 @@ def run_test_conditions(self,condition_list,solution = None,max_iterations = 10)
500502
return None
501503
return solution
502504

503-
def filter_database_based_on_tests(self,test_conditions):
505+
def filter_database_based_on_tests(self, test_conditions):
504506
filetered_list = []
505507
with self.model:
506508
rxnlist = []
507509
for reaction in self.model.reactions:
508510
if reaction.id in self.gapfilling_penalties:
509511
if "reverse" in self.gapfilling_penalties[reaction.id]:
510-
rxnlist.append([reaction,"<"])
512+
rxnlist.append([reaction, "<"])
511513
if "forward" in self.gapfilling_penalties[reaction.id]:
512-
rxnlist.append([reaction,">"])
514+
rxnlist.append([reaction, ">"])
513515
self.pkgmgr.getpkg("ObjConstPkg").constraints["objc"]["1"].lb = 0
514-
filtered_list = self.modelutl.reaction_expansion_test(rxnlist,test_conditions)
516+
filtered_list = self.modelutl.reaction_expansion_test(rxnlist, test_conditions)
515517
#Now constraining filtered reactions to zero
516518
for item in filtered_list:
517519
logger.debug("Filtering:",item[0].id,item[1])

modelseedpy/fbapkg/kbasemediapkg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ def build_package(self, media_or_parameters, default_uptake=None, default_excret
6060
self.variables["logconc"][met.id].lb = ln(mediacpd.concentration)
6161
self.variables["logconc"][met.id].ub = ln(mediacpd.concentration)
6262
else:
63-
logger.warn('Media compound: ', mediacpd.id,' not found in model.')
63+
logger.info(f'Media compound: {mediacpd.id} not found in model.')

0 commit comments

Comments
 (0)