m2m’s API
Workflow
m2m workflow
- metage2metabo.m2m.m2m_workflow.add_targets_to_instance(instancefile, output_dir, target_set)[source]
Add targets to the ASP community instance file.
- Parameters:
instancefile (str) – instance filepath
output_dir (str) – directory for results
target_set (set) – targets to be added
- Returns:
new instance filepath
- Return type:
str
- metage2metabo.m2m.m2m_workflow.metacom_analysis(sbml_dir, out_dir, seeds, host_mn, targets_file, cpu_number=1, target_com_scope=None)[source]
Run the metabolism community analysis part of m2m.
- Parameters:
sbml_dir (str) – sbml input directory
out_dir (str) – results directory
seeds (str) – seeds file
host_mn (str) – metabolic network file for host
targets_file (str) – targets file
cpu_number (int) – number of CPU to use for multiprocessing
target_com_scope (bool) – if True, will use all metabolties in com_scope as targets for minimal community predictions.
- metage2metabo.m2m.m2m_workflow.run_workflow(inp_dir, out_dir, nb_cpu, clean, seeds, noorphan_bool, padmet_bool, host_mn, targets_file, use_pwt_xml, target_com_scope=None)[source]
Run the whole m2m workflow.
- Parameters:
inp_dir (str) – genomes directory
out_dir (str) – results directory
nb_cpu (int) – cpu number for multi-processing
clean (bool) – clean PGDB and re-run them
seeds (str) – seeds file
noorphan_bool (bool) – ignores orphan reactions if True
padmet_bool (bool) – creates padmet files if True
host_mn (str) – metabolic network file for host
targets_file (str) – targets file
use_pwt_xml (bool) – use Pathway Tools XML instead of creating them with padmet
target_com_scope (bool) – if True, will use all metabolties in com_scope as targets for minimal community predictions.
- metage2metabo.m2m.m2m_workflow.targets_producibility(m2m_out_dir, union_targets_iscope, targets_cscope, addedvalue_targets, user_targets=None, target_com_scope=None)[source]
Create a json summarizing the producibility of the targets (either the addedvalue or the user provided targets)
- Parameters:
m2m_out_dir (str) – M2M results directory
union_targets_iscope (list) – targets producible by indiviual
targets_cscope (list) – targets producible by community
addedvalue_targets (list) – targets produbed by the community and not by individual
user_targets (list) – targets provided by the user
target_com_scope (bool) – if True, will use all metabolties in com_scope as targets for minimal community predictions.
Reconstruction
- metage2metabo.m2m.reconstruction.analyze_recon(sbml_folder, output_stat_file, padmet_folder=None, padmet_bool=None, nb_cpu=1)[source]
Analyze the sbml and/or the padmet files after metabolic network reconstruction. And write the result in a file.
- Parameters:
sbml_folder (str) – directory of SBML files
output_stat_file (str) – path to output stat file
padmet_folder (str) – directory of PADMET files
padmet_bool (bool) – use or not the padmet files
nb_cpu (int) – number of CPU to use
- metage2metabo.m2m.reconstruction.create_padmet_stat(species_name, padmet_file)[source]
Extract reactions/pathways/compounds/genes from a padmet file.
- Parameters:
species_name (str) – species names
padmet_file (str) – path to a padmet file
- Returns
list: [species name, list of genes, list of reactions, list of reactions associated with genes, list of compounds, list of pathways]
- metage2metabo.m2m.reconstruction.create_sbml_stat(species_name, sbml_file)[source]
Extract reactions/pathways/compounds/genes from a sbml file.
- Parameters:
species_name (str) – species names
sbml_file (str) – path to a sbml file
- Returns
list: [species name, list of genes, list of reactions, list of reactions associated with genes, list of compounds]
- metage2metabo.m2m.reconstruction.genomes_to_pgdb(genomes_dir, output_dir, cpu, clean, use_pwt_xml)[source]
Run Pathway Tools on each genome of the repository
- Parameters:
genomes_dir (str) – genome repository
output_dir (str) – output repository
cpu (int) – number of CPUs to use
clean (bool) – delete PGDBs in ptools-local coresponding to the input data
use_pwt_xml (bool) – use Pathway Tools XML instead of creating them with padmet
- Returns:
pgdb repository
- Return type:
pgdb_dir (str)
- metage2metabo.m2m.reconstruction.mean_sd_data(datas)[source]
Compute the mean and standard deviation from a list.
- Parameters:
datas (list) – list of integer/float
- Returns
mean_data (float): mean of the list sd_data (flaot): standard deviation of the lsit
- metage2metabo.m2m.reconstruction.recon(inp_dir, out_dir, noorphan_bool, padmet_bool, sbml_level, nb_cpu, clean, use_pwt_xml)[source]
Run metabolic network reconstruction with Pathway Tools and get SBMLs.
- Parameters:
inp_dir (str) – genomes directory
out_dir (str) – results directory
noorphan_bool (bool) – ignores orphan reactions if True
padmet_bool (bool) – creates padmet files if True
sbml_level (str) – SBML level (2 or 3)
nb_cpu (int) – number of CPU for multiprocessing
clean (bool) – re-run metabolic reconstructions that are already available if found
use_pwt_xml (bool) – use Pathway Tools XML instead of creating them with padmet
- Returns:
PGDB directory (str), SBML directory (str)
- Return type:
tuple
Individual scope
- metage2metabo.m2m.individual_scope.analyze_indiv_scope(scope_dict, seeds_status_dict, seeds)[source]
Analyze the output of Menescope, stored in two dictionaries
- Parameters:
scope_dict (dict) – output of all menescope runs
seeds_status_dict (dict) – production status of seeds in all menescope runs
seeds (str) – SBML seeds file
- Returns:
union of all the individual scopes
- Return type:
set
- metage2metabo.m2m.individual_scope.indiv_scope_on_species(sbml_path, bname, seeds_path)[source]
Run Menetools and analyse individual metabolic capabilities on a sbml.
- Parameters:
sbml_path (str) – path to SBML file
bname (str) – name linked to SBML file
seeds_path (str) – path to SBML seeds file
- Returns:
[boolean error, bname, dictionary containing menescope results]
- Return type:
list
- metage2metabo.m2m.individual_scope.indiv_scope_run(sbml_dir, seeds, output_dir, cpu_number=1)[source]
Run Menetools and analyse individual metabolic capabilities.
- Parameters:
sbml_dir (str) – directory of SBML files
seeds (str) – SBML seeds file
output_dir (str) – directory for results
cpu_number (int) – number of CPU to use for multiprocessing
- Returns:
path to output file for scope from Menetools analysis
- Return type:
str
- metage2metabo.m2m.individual_scope.iscope(sbmldir, seeds, out_dir, cpu_number=1)[source]
Compute individual scopes (reachable metabolites) for SBML files in a directory.
- Parameters:
sbmldir (str) – SBML files directory
seeds (str) – SBML seeds file
out_dir (str) – output directory
cpu_number (int) – number of CPU to use for multiprocessing
- Returns:
union of reachable metabolites for all metabolic networks
- Return type:
set
- metage2metabo.m2m.individual_scope.reverse_scope(scope_dict, output_dir)[source]
Reverse a scope dictionary by focusing on metabolite producers.
- Parameters:
scope_dict (dict) – dict of scope
output_dir (str) – path to output directory
- Returns:
paths to the JSON and TSV outputs
- Return type:
(str, str)
Community scope
- metage2metabo.m2m.community_scope.comm_scope_run(instance, output_dir, host_mn=None)[source]
Run Miscoto_scope and analyse community metabolic capabilities
- Parameters:
instance (str) – instance filepath
output_dir (str) – directory for results
host_mn (str) – metabolic network file for host
- Returns:
microbiota scope dict: contribution of microbes to the scope
- Return type:
set
- metage2metabo.m2m.community_scope.cscope(sbmldir, seeds, out_dir, targets_file=None, host=None)[source]
Run community scope.
- Parameters:
sbmldir (str) – SBML files directory
seeds (str) – SBML file for seeds
out_dir (str) – output directory
targets_file (str) – targets file
host (str, optional) – Defaults to None. Host metabolic network (SBML)
- Returns:
instance file (str) and community scope (set)
- Return type:
tuple
- metage2metabo.m2m.community_scope.instance_community(sbml_dir, seeds, output_dir, targets_file=None, host_mn=None)[source]
Create ASP instance for community analysis.
- Parameters:
sbml_dir (str) – directory of symbionts SBML files
seeds (str) – seeds SBML file
output_dir (str) – directory for results
targets_file (str) – targets file
host_mn (str) – metabolic network file for host
- Returns:
instance filepath
- Return type:
str
- metage2metabo.m2m.community_scope.reverse_cscope(bact_contrib, reverse_dict, output_dir)[source]
Reverse a scope dictionary by focusing on metabolite producers.
- Parameters:
bact_contrib (dict) – dict of bacteria contributions to community scope
reverse_dict (dict) – dict of metabolite producers in community
output_dir (str) – path to output directory
- Returns:
paths to the JSON and TSV outputs
- Return type:
(str, str)
Cooperation potential (added-value)
- metage2metabo.m2m.community_addedvalue.addedvalue(iscope_rm, cscope_rm, out_dir)[source]
Compute the added value of considering interaction with microbiota metabolism rather than individual metabolisms.
- Parameters:
iscope_rm (set) – union of metabolites in all individual scopes
cscope_rm (set) – metabolites reachable by community/microbiota
out_dir (str) – output directory
- Returns:
set of metabolites that can only be reached by a community
- Return type:
set
Minimal community
- metage2metabo.m2m.minimal_community.compute_mincom(instancefile, miscoto_dir)[source]
Run minimal community selection and analysis.
- Parameters:
instancefile (str) – filepath to instance file
miscoto_dir (str) – directory with results
- Returns:
results of miscoto_mincom analysis
- Return type:
dict
- metage2metabo.m2m.minimal_community.mincom(instance_w_targets, seeds, targets, out_dir)[source]
Compute minimal community selection and show analyses.
- Parameters:
instance_w_targets (str) – ASP instance filepath
seeds (str) – seeds filepath
targets (str) – targets set
out_dir (str) – results directory
SBML Management
- metage2metabo.sbml_management.compare_seeds_and_targets(seedfile, targetfile)[source]
Returns the intersection of the seeds and the targets
- Parameters:
seedfile (str) – path to seeds SBML file
targetfile (str) – path to targets SBML file
- Returns:
intersection of seeds and targets
- Return type:
set
- metage2metabo.sbml_management.create_species_sbml(metabolites, outputfile)[source]
Create a SBML files with a list of species containing metabolites of the input set. Check if there are forbidden SBML characters in the metabolite IDs/ If yes, exit.
- Parameters:
metabolites (set) – set of metabolites
outputfile (str) – SBML file to be written
- metage2metabo.sbml_management.get_compounds(sbml_file)[source]
Get compound from sbml
- Parameters:
sbml_file (str) – SBML file
- Returns:
compound
- Return type:
list
- metage2metabo.sbml_management.pgdb_to_sbml(pgdb_dir, output_dir, noorphan_bool, padmet_bool, sbml_level, cpu)[source]
Turn Pathway Tools PGDBs into SBML2 files using Padmet
- Parameters:
pgdb_dir (str) – PGDB directory
output_dir (str) – results directory
noorphan_bool (bool) – ignores orphan reactions if True
padmet_bool (bool) – creates padmet files if True
sbml_level (int) – SBML level
cpu (int) – number of CPU for multi-process
- Returns:
SBML directory if successful
- Return type:
sbml_dir (str)
- metage2metabo.sbml_management.run_pgdb_to_sbml(species_multiprocess_data)[source]
Turn PGDBs into SBML2 using multi-processing.
- Parameters:
species_multiprocess_data (list) – pathname to species pgdb dir, pathname to species sbml file
- Returns:
Check if sbml file exists
- Return type:
sbml_check (bool)
Utils
- metage2metabo.utils.check_absolute_path(directory, target)[source]
Check if the extracted element is inside the output directory. If not, it is a potential path traversal attempt.
- Parameters:
directory (str) – path to output directory for extraction.
target (str) – path of file contained in tar file.
- metage2metabo.utils.check_program(program)[source]
Check whether Pathway Tools is in the PATH
- Returns:
True if Pathway Tools is in the PATH, False otherwise
- Return type:
bool
- metage2metabo.utils.file_or_folder(variable_folder_file)[source]
Check if the variable is file or a folder
- Parameters:
variable_folder_file (str) – path to a file or a folder
- Returns:
{name of input file: path to input file}
- Return type:
dict
- metage2metabo.utils.get_basename(filepath)[source]
Return the basename of given filepath.
- Parameters:
filepath (str) – path to a file
- Returns:
basename
- Return type:
str
>>> basename('~/an/interesting/file.txt') 'file
- metage2metabo.utils.get_extension(filepath)[source]
Get the extension of a filepath
- Parameters:
filepath (str) – path to a file
- Returns:
extention of the file
- Return type:
str
>>> extension('~/an/interesting/file.lp') 'lp' >>> extension('nothing') '' >>> extension('nothing.important') 'important'
- metage2metabo.utils.is_valid_dir(dirpath)[source]
Return True if directory exists or can be created (then create it)
- Parameters:
dirpath (str) – path of directory
- Returns:
True if dir exists, False otherwise
- Return type:
bool
- metage2metabo.utils.is_valid_file(filepath)[source]
Return True if filepath exists
- Parameters:
filepath (str) – path to file
- Returns:
True if path exists, False otherwise
- Return type:
bool
m2m_analysis
m2m_analysis workflow
- metage2metabo.m2m_analysis.m2m_analysis_workflow.run_analysis_workflow(sbml_folder, target_folder_file, seed_file, output_dir, taxon_file, oog_jar, host_file=None, taxonomy_level='phylum')[source]
Run the whole m2m_analysis workflow
- Parameters:
sbml_folder (str) – sbml directory
target_folder_file (str) – targets file or folder containing multiple sbmls
seed_file (str) – seeds file
output_dir (str) – results directory
taxon_file (str) – mpwt taxon file for species in sbml folder
oog_jar (str) – path to OOG jar file
host_file (str) – metabolic network file for host
taxonomy_level (str) – taxonomy level, must be: phylum, class, order, family, genus or species.
Enumeration of Minimal communities
- metage2metabo.m2m_analysis.enumeration.convert_groups_to_equation(bacterial_groups)[source]
Convert bacterial groups (from extract_groups_from_enumeration) to boolean equation.
- Parameters:
bacterial_groups (list) – list of frozenset containing each different group of the community
- Returns:
string representing the boolean equation of minimal communities
- Return type:
boolean_equation (str)
- metage2metabo.m2m_analysis.enumeration.enumeration(sbml_folder, target_file, seed_file, output_json, host_file)[source]
Run miscoto enumeration on one target file
- Parameters:
sbml_folder (str) – sbml directory
target_file (str) – targets file
seed_file (str) – seeds file
output_json (str) – path to json output
host_file (str) – metabolic network file for host
- Returns:
path to output json
- Return type:
str
- metage2metabo.m2m_analysis.enumeration.enumeration_analysis(sbml_folder, target_folder_file, seed_file, output_dir, host_file=None)[source]
Run miscoto enumeration on input data
- Parameters:
sbml_folder (str) – sbml directory
target_folder_file (str) – targets file or folder containing multiple sbmls
seed_file (str) – seeds file
output_dir (str) – results directory
host_file (str) – metabolic network file for host
- Returns:
{target_filename_without_extension: json_output_path}
- Return type:
dict
- metage2metabo.m2m_analysis.enumeration.extract_groups_from_enumeration(results)[source]
From the results of the enumeration computes the boolean eaqution of the minimal communities. It is a very simple method that will fail for enumeration with numerous and complex combinations.
- Parameters:
results (dict) – results dictionary of miscoto for the enumeration.
- Returns:
list of frozenset containing each different group of the community
- Return type:
bacterial_groups (list)
Creation of graph solution
- metage2metabo.m2m_analysis.solution_graph.create_gml(json_paths, target_paths, output_dir, taxon_file=None)[source]
Create solution graph from miscoto output and compute stats
- Parameters:
json_paths (str) – {target: path_to_corresponding_json}
target_paths (str) – {target: path_to_corresponding_sbml}
output_dir (str) – results directory
taxon_file (str) – mpwt taxon file for species in sbml folder
- metage2metabo.m2m_analysis.solution_graph.graph_analysis(json_file_folder, target_folder_file, output_dir, taxon_file=None, taxonomy_level='phylum')[source]
Run the graph creation on miscoto output
- Parameters:
json_file_folder (str) – json file or folder containing multiple jsons
target_folder_file (str) – targets file or folder containing multiple sbmls
output_dir (str) – results directory
taxon_file (str) – mpwt taxon file for species in sbml folder
taxonomy_level (str) – taxonomy level, must be: phylum, class, order, family, genus or species.
- Returns:
path to folder containing gml results
- Return type:
str
Compression of graph
- metage2metabo.m2m_analysis.graph_compression.bbl_to_html(bbl_input, html_output)[source]
Powergraph website creation. This create a folder with html/CSS/JS files. By using the index.html file in a browser, user can see the powergraph.
- Parameters:
bbl_input (str) – bbl input file
html_output (str) – html output file
- metage2metabo.m2m_analysis.graph_compression.bbl_to_svg(oog_jar, bbl_input, svg_output)[source]
Powergraph picture creation
- Parameters:
oog_jar (str) – path to oog jar file
bbl_input (str) – bbl input file
svg_output (str) – svg output file
- metage2metabo.m2m_analysis.graph_compression.check_oog_jar_file(oog_jar)[source]
Check Oog jar file
- Parameters:
oog_jar (str) – path to oog jar file
- metage2metabo.m2m_analysis.graph_compression.compression(gml_input, bbl_output)[source]
Solution graph compression
- Parameters:
gml_input (str) – gml file
bbl_output (str) – bbl output file
- metage2metabo.m2m_analysis.graph_compression.convert_taxon_id(taxon_id)[source]
Some taxon IDs are converted by powergrasp. Especially some strings are replaced by their Unicode ints. This function replaces these codes by the corresponding string.
- Parameters:
taxon_id (str) – taxon ID with potential Unicode int.
- Returns:
converted taxon ID
- Return type:
taxon_id (str)
- metage2metabo.m2m_analysis.graph_compression.merge_html_css_js(html_output, merged_html_path)[source]
Merge HTML/CSS/JS files into one HTML file
- Parameters:
html_output (str) – path to html folder (containing css, html and css files)
merged_html_path (str) – path to the output merged html file
- metage2metabo.m2m_analysis.graph_compression.powergraph_analysis(enumeration_json_folder, gml_input_file_folder, output_folder, oog_jar=None, taxon_file=None, taxonomy_level='phylum', test_powergraph=True)[source]
Run the graph compression and picture creation
- Parameters:
enumeration_json_folder (str) – path to the enumeration json folder or file
gml_input_file_folder (str) – path to the gml folder or the gml file
output_folder (str) – path to the output folder
oog_jar (str) – path to OOG jar file
taxon_file (str) – mpwt taxon file for species
taxonomy_level (str) – taxonomy level, must be: phylum, class, order, family, genus or species
test_powergraph (bool) – boolean to decide if the powergraph combinations must be tested to check for use of heuristics
- metage2metabo.m2m_analysis.graph_compression.test_powergraph_heuristics(enumeration_json_file, powergraph_bubble_file, output_minimal_equations_folder, taxon_species)[source]
PowerGrASP can use heuristics to compress the graph and creates powergraph representation. So some powergraphs visualisation are not correct according to the combination of the enumeration of minimal solution. This function tests the powergraph to see if the viusalized combinations corresponds to the one of the enumeration. If no heuristics have been used, then the function tries to create a boolean equation summarizing the powergraph.
- Parameters:
enumeration_json_file (str) – path to enumeration json file
powergraph_bubble_file (str) – path to the bbl file containing powergraph
output_minimal_equations_folder (str) – output fodler for minimal boolean equation of powernodes
taxon_species (dict) – associate organism ID as key with taxon name as value
- metage2metabo.m2m_analysis.graph_compression.update_js(html_output, essentials, alternatives)[source]
Update graph.js to add colors for essential and alternative symbionts.
- Parameters:
html_output (str) – path to html folder (containing js subfolder with gaph.js)
essentials (list) – list of essential symbionts
alternatives (list) – list of alternative symbionts
- metage2metabo.m2m_analysis.graph_compression.update_js_taxonomy(html_output, taxon_colors, essentials, alternatives)[source]
Update graph.js to add colors according to taxon.
- Parameters:
html_output (str) – path to html folder (containing js subfolder with gaph.js)
taxon_colors (dict) – dictionary {taxon_name: associated_color}
essentials (list) – list of essential symbionts
alternatives (list) – list of alternative symbionts
- metage2metabo.m2m_analysis.graph_compression.update_svg(svg_file, essentials, alternatives)[source]
Update svg file to add colors for essential and alternative symbionts.
- Parameters:
svg_file (str) – path to svg file
essentials (list) – list of essential symbionts
alternatives (list) – list of alternative symbionts
taxonomy
- metage2metabo.m2m_analysis.taxonomy.extract_taxa(mpwt_taxon_file, taxon_output_file, tree_output_file, taxonomy_level='phylum')[source]
From NCBI taxon ID, extract taxonomy rank and create a tree file
- Parameters:
mpwt_taxon_file (str) – mpwt taxon file for species in sbml folder
taxon_output_file (str) – path to taxonomy output file
tree_output_file (str) – path to tree output file
taxonomy_level (str) – taxonomy level, must be: phylum, class, order, family, genus or species.
- metage2metabo.m2m_analysis.taxonomy.get_taxon(taxonomy_file_path)[source]
From the taxonomy file (created by extract_taxa) create a dictionary and a list linking taxon and species
- Parameters:
taxonomy_file_path (str) – path to the taxonomy_file
- Returns:
associate organism ID as key with taxon name as value all_taxa (list): list all taxa in file
- Return type:
taxon_named_species (dict)
Main
- metage2metabo.__main__.create_metadata(dict_args, duration, metadata_json_file)[source]
Create metadata from args and package versions.
- Parameters:
dict_args (dict) – dict of args given to argparse
duration (int) – time of the run
metadata_json_file (str) – pat hto metadata output file
- metage2metabo.__main__.main_added_value(sbmldir, seeds, outdir, host)[source]
Run addedvalue command.
- Parameters:
sbmldir (str) – SBML file directory
seeds (str) – SBML file for seeds
outdir (str) – results directory
host (str) – SBML file for host
- metage2metabo.__main__.main_mincom(sbmldir, seedsfiles, outdir, targets, host)[source]
Run mincom command.
- Parameters:
sbmldir (str) – SBML files directory
seedsfiles (str) – SBML file for seeds
outdir (str) – results directory
targets (str) – targets SBML file
host (str) – SBML file for host
- metage2metabo.__main__.main_seeds(metabolites_file, outdir)[source]
Run seeds command.
- Parameters:
metabolites_file (str) – text file with metabolites IDs, one per line
outdir (str) – Results directory