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, standalone=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.

  • standalone (bool) – use standalone mode of Pathway Tools

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, standalone=None)[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

  • standalone (bool) – use standalone mode of Pathway Tools

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, standalone=None)[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

  • standalone (bool) – use standalone mode of Pathway Tools

Returns:

PGDB directory (str), SBML directory (str)

Return type:

tuple

metage2metabo.m2m.reconstruction.update_pathway_tools_xml(input_sbml, output_sbml)[source]

Update XML from Pathway Tools by adding a ‘M_’ prefix to avoid issue, when using metaboltie IDs.

Parameters:
  • input_sbml (str) – path to xml input file

  • output_sbml (str) – path to xml output file

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

metage2metabo.utils.is_valid_path(filepath)[source]

Return True if filepath is valid

Parameters:

filepath (str) – path to file

Returns:

True if path exists, False otherwise

Return type:

bool

metage2metabo.utils.safe_tar_extract_all(tar_file, outdir)[source]

Perform a sanitized check to ensure no file outside the output folder will be modified.

Parameters:
  • tar_file (str) – path to tar file.

  • outdir (str) – path to output directory for extraction.

m2m_analysis

m2m_analysis workflow

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

Compression of graph

taxonomy

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()[source]

Run programm.

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_cscope(*allargs)[source]

Run cscope command.

metage2metabo.__main__.main_iscope(*allargs)[source]

Run iscope command.

metage2metabo.__main__.main_metacom(*allargs)[source]

Run main workflow.

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_recon(*allargs)[source]

Run recon command.

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

metage2metabo.__main__.main_test(outdir, cpu)[source]

Run test command.

Parameters:
  • outdir (str) – directory containing the test data and the test output

  • cpu (int) – number of cpu to use (recommended: 2)

metage2metabo.__main__.main_workflow(*allargs)[source]

Run main workflow.