modelseed / modelseedpy Goto Github PK
View Code? Open in Web Editor NEWPython package for building and analyzing models using ModelSEED
License: MIT License
Python package for building and analyzing models using ModelSEED
License: MIT License
Hello!
I merged the upstream MSpy into my fork and was reacquainted with some bugs that I corrected in my fork. A few of them here:
Self
is already passed as an argument (here and here) by calling the function from the Class object, so explicitly listing the argument (when the function does not accept any other argument) will cause an error.model.
is missing from these calls, where the Class object does not directly store the metabolites
.rxn.id
is a string here, and not a function, so this would throw an error.group
variable in this line is never defined. I think that the author intended to extract the matched regex content in m
, so group
should be replaced with m
.I will share more bugs through this medium, since it seems to be more amenable than a PR with my whole fork.
Thank you :)
Andrew
Is it possible to use genomes annotated in PATRIC to build models using ModelSEEDpy instead of the web server?
Currently, when I try :
import modelseedpy
from modelseedpy import MSBuilder, MSGenome
from modelseedpy.helpers import get_template
from modelseedpy.core.mstemplate import MSTemplateBuilder
from cobra.io import write_sbml_model
import pandas as pd
#load dataframe with info on genomes
df_genomes = pd.read_csv('best_per_genus.tsv', sep='\t')
gram_pos_phyla = ['Firmicutes', 'Actinobacteria']
for patric_id, genome_path, phylum in zip(df_genomes['genome_id'], df_genomes['path_2_faa'], df_genomes['phylum']):
#Select template based on phylum
if(phylum in gram_pos_phyla):
template_name = 'template_gram_pos'
else:
template_name = 'template_gram_neg'
print(patric_id)
#Load the genome as a fasta file (.faa)
genome = MSGenome.from_fasta(genome_path, split=' ')
print(len(genome.features))
# Build template
template = MSTemplateBuilder.from_dict(get_template(template_name)).build()
# Build model
model = MSBuilder.build_metabolic_model(str(patric_id), genome, template=template, allow_all_non_grp_reactions=False, annotate_with_rast=True, gapfill_model=False)
print(len(model.reactions))
# Save model
write_sbml_model(model, folder+'/'+str(patric_id)+'.sbml')
I get models with significantly different reactions then the ones I get in the webserver.
Hello!
The Gapfilling function in MSBuilder
returns the original, ungapfilled, model instead of the gapfilled model. This seems counter-intuitive and to be a bug instead of a feature. How is the user expected to acquire the gapfilled model from a static method unless it is returned??
The link of functionalities can not be found. Python Notebooks
Hi there.
Could you please add in the requirements
file the versions of the dependencies?
I am running on some issues that come up from example a conflict with scikit-learn
.
Here is how it behaves:
genome_class = genome_classifier.classify(genome)
returned the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In [4], line 2
1 from modelseedpy.helpers import get_classifier
----> 2 genome_classifier = get_classifier('knn_filter')
3 genome_class = genome_classifier.classify(genome)
4 print(genome_class)
File ~/.local/lib/python3.10/site-packages/modelseedpy/helpers.py:46, in get_classifier(classifier_id)
44 print(cls_features)
45 with open(cls_pickle, "rb") as fh:
---> 46 model_filter = pickle.load(fh)
47 with open(cls_features, "r") as fh:
48 features = json.load(fh)
ModuleNotFoundError: No module named 'sklearn.neighbors._dist_metrics'
When I downgraded my scikit-learn
to the 0.24.0
version it worked fine.
However, I then tried to run
genome_class = genome_classifier.classify(genome)
and I got this:
genome_class = genome_classifier.classify(genome)
Traceback (most recent call last):
File "/home/luna.kuleuven.be/u0156635/.conda/envs/modelseed/lib/python3.9/site-packages/modelseedpy/ml/predict_phenotype.py", line 94, in create_indicator_matrix
indicators[np.array(matching_index)] = 1
IndexError: arrays used as indices must be of integer (or boolean) type
I am not sure if the last error is due to a version conflict but i guess something is not installed as it should .
Thanks !
AttributeError Traceback (most recent call last)
Input In [6], in
----> 1 model = MSBuilder.build_metabolic_model('ecoli.core', genome, template, None, allow_all_non_grp_reactions=True, annotate_with_rast=True)
2 model
File ~/anaconda3/envs/genre/lib/python3.10/site-packages/ModelSEEDpy-0.2.2-py3.10.egg/modelseedpy/core/msbuilder.py:616, in MSBuilder.build_metabolic_model(model_id, genome, gapfill_media, template, index, allow_all_non_grp_reactions, annotate_with_rast, gapfill_model)
614 # Gapfilling model
615 if gapfill_model:
--> 616 model = MSBuilder.gapfill_model(model, 'bio1', builder.template, gapfill_media)
617 return model
File ~/anaconda3/envs/genre/lib/python3.10/site-packages/ModelSEEDpy-0.2.2-py3.10.egg/modelseedpy/core/msbuilder.py:630, in MSBuilder.gapfill_model(original_mdl, target_reaction, template, media)
623 pkgmgr = MSPackageManager.get_pkg_mgr(model)
624 pkgmgr.getpkg("GapfillingPkg").build_package({
625 "default_gapfill_templates": [template],
626 "gapfill_all_indecies_with_default_templates": 1,
627 "minimum_obj": 0.01,
628 "set_objective": 1
629 })
--> 630 pkgmgr.getpkg("KBaseMediaPkg").build_package(media)
631 #with open('Gapfilling.lp', 'w') as out:
632 # out.write(str(model.solver))
633 sol = model.optimize()
File ~/anaconda3/envs/genre/lib/python3.10/site-packages/ModelSEEDpy-0.2.2-py3.10.egg/modelseedpy/fbapkg/kbasemediapkg.py:49, in KBaseMediaPkg.build_package(self, media_or_parameters, default_uptake, default_excretion)
45 reaction.update_variable_bounds() # FIXME: this seems unnecessary
47 if self.parameters["media"]:
48 # Searching for media compounds in model
---> 49 for compound in self.parameters["media"].mediacompounds:
50 mdlcpds = self.find_model_compounds(compound.id)
51 for mdlcpd in mdlcpds:
AttributeError: 'NewModelTemplate' object has no attribute 'mediacompounds'
only allow spontaneous reaction if all substrates are present in the metabolism
Hi!
Using the attached .faa
file and through the ModelSEED platform I built the also attached .sbml
growing model.
I am now trying to reproduce that through the CLI and here is what I have done so far:
# modelseedpy
from modelseedpy import KBaseMediaPkg
from modelseedpy import MSBuilder, MSGenome
# cobrakbase
import cobrakbase
genome = MSGenome.from_fasta('data/genomes/s_infantis/s_inf_all_contigs_default.faa')
kbase_api = cobrakbase.KBaseAPI()
kb_template = kbase_api.get_from_ws("GramNegModelTemplateV4","NewKBaseModelTemplates")
model = MSBuilder.build_metabolic_model('salmonella infantis', genome, template = kb_template, allow_all_non_grp_reactions = True)
#Pulling a KBase media to specify an environment for gapfilling
media = kbase_api.get_from_ws("Complete","KBaseMedia")
#Gapfilling the model in the specified media
model = MSBuilder.gapfill_model(model, "bio1", kb_template, media)
#Applying the same media to the resulting model
kmp = KBaseMediaPkg(model)
kmp.build_package(media)
However, my media
is just empty and therefore, my new model is not growing.
print(media.data)
{'source_id': 'Complete',
'isMinimal': 0,
'name': 'Complete',
'type': 'unknown',
'id': 'kb|media.626',
'mediacompounds': [],
'isDefined': 1,
'__VERSION__': 1,
'exclude_dict': set(),
'data_keys': {'source_id': str,
'isMinimal': int,
'name': str,
'type': str,
'id': str,
'mediacompounds': list,
'isDefined': int,
'__VERSION__': int},
'info': <cobrakbase.kbase_object_info.KBaseObjectInfo at 0x7f210d4ab220>,
'data': {...},
'provenance': [{'time': '2013-06-20T17:04:46+0000',
'epoch': 1371747886000,
'service': 'KBaseFBAModeling',
'service_ver': '0',
'method': 'load_media_from_bio',
'method_params': [],
'input_ws_objects': [],
'resolved_ws_objects': [],
'intermediate_incoming': [],
'intermediate_outgoing': [],
'external_data': [],
'subactions': [],
'custom': {}}],
'path': ['262/34/1'],
'creator': 'chenry',
'orig_wsid': None,
'created': '2014-01-18T09:09:51+0000',
'epoch': 1390036191265,
'refs': [],
'copied': None,
'copy_source_inaccessible': 0}
I would like to ask you:
Thank you very much for your time and help!
p.s. I have a .txt
suffix on the files so GitHub allows them as attached
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.