Example #1
0
def metacom_analysis(sbml_dir, out_dir, seeds, host_mn):
    """Run the metabolism community analysis part of m2m.

    Args:
        sbml_dir (str): sbml input directory
        out_dir (str): results directory
        seeds (str): seeds file
        host_mn (str): metabolic network file for host
    """
    # INDIVIDUAL SCOPES
    union_targets_iscope = iscope(sbml_dir, seeds, out_dir)
    # COMMUNITY SCOPE
    instance_com, targets_cscope = cscope(sbml_dir, seeds, out_dir, host_mn)
    # ADDED VALUE
    newtargets = addedvalue(union_targets_iscope, targets_cscope, out_dir)
    if len(newtargets) > 0:
        sbml_management.create_species_sbml(
            newtargets, out_dir + "/community_analysis/targets.sbml")
        logger.info("Target file created with the addedvalue targets in: " +
                    out_dir + "/community_analysis/targets.sbml")
        # Add these targets to the instance
        logger.info("Setting these " + str(len(newtargets)) + " as targets")
        instance_w_targets = add_targets_to_instance(instance_com, out_dir,
                                                     newtargets)
        # MINCOM
        mincom(instance_w_targets, out_dir)
        # remove intermediate files
        os.unlink(instance_com)
        os.unlink(instance_w_targets)
    else:
        logger.info(
            "No newly producible compounds, hence no community selection will be computed"
        )
        os.unlink(instance_com)
Example #2
0
def main_added_value(sbmldir, seeds, outdir, host):
    """Run addedvalue command.
    
    Args:
        sbmldir (str): SBML file directory
        seeds (str): SBML file for seeds
        outdir (str): results directory
        host (str): SBML file for host
    """
    iscope_metabolites = main_iscope(sbmldir, seeds, outdir)
    #logger.info(", ".join(iscope_metabolites))
    cscope_metabolites = main_cscope(sbmldir, seeds, outdir, host)
    newtargets = addedvalue(iscope_metabolites, cscope_metabolites, outdir)
    if len(newtargets) > 0:
        sbml_management.create_species_sbml(newtargets, outdir + "/community_analysis/targets.sbml")
        logger.info("Target file created with the addedvalue targets in: " +
                    outdir + "/community_analysis/targets.sbml")
Example #3
0
def main_seeds(metabolites_file, outdir):
    """Run seeds command.
    
    Args:
        metabolites_file (str): text file with metabolites IDs, one per line
        outdir (str): Results directory
    """
    outfile = outdir + "/seeds.sbml"
    with open(metabolites_file, "r") as f:
        rawdata = f.readlines()
    metabolites_set = set()
    for elem in rawdata:
        metabolites_set.add(elem.strip("\n"))
    for metabolite in metabolites_set:
        assert re.match(
            "^[A-Za-z0-9_-]*$", metabolite
        ) and not metabolite[0].isdigit(
        ), "Seed file is not in the correct format. Error with %s. Example of a correct ID is M_OXYGEN__45__MOLECULE_c. Rules = only numbers, letters or underscore in IDs, not starting with a number. One ID per line." %(metabolite)
    sbml_management.create_species_sbml(metabolites_set, outfile)
    logger.info("Seeds SBML file created in " + outfile)
Example #4
0
def metacom_analysis(sbml_dir, out_dir, seeds, host_mn, targets_file):
    """Run the metabolism community analysis part of m2m.

    Args:
        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
    """
    # INDIVIDUAL SCOPES
    union_targets_iscope = iscope(sbml_dir, seeds, out_dir)
    # COMMUNITY SCOPE
    instance_com, targets_cscope = cscope(sbml_dir, seeds, out_dir,
                                          targets_file, host_mn)
    # ADDED VALUE
    addedvalue_targets = addedvalue(union_targets_iscope, targets_cscope,
                                    out_dir)

    # If user gives a target file, check if the targets are in the addevalue
    if targets_file is not None:
        user_targets = set(sbml_management.get_compounds(targets_file))
        newtargets = user_targets
        individually_producible_targets = user_targets.intersection(
            union_targets_iscope)
        if len(individually_producible_targets) > 0:
            logger.info(
                '\n The following ' +
                str(len(individually_producible_targets)) +
                " targets are individually reachable by at least one organism: \n"
            )
            logger.info("\n".join(individually_producible_targets))
        commonly_producible_targets = user_targets.intersection(
            addedvalue_targets)
        if len(commonly_producible_targets) > 0:
            logger.info(
                '\n The following ' + str(len(commonly_producible_targets)) +
                " targets are additionally reachable through putative cooperation events: \n"
            )
            logger.info("\n".join(commonly_producible_targets))
        else:
            logger.info(
                "Cooperation events do not enable the producibility of additional targets"
            )
    else:
        user_targets = None
        newtargets = addedvalue_targets

    if len(newtargets) > 0:
        target_file_path = os.path.join(
            *[out_dir, 'community_analysis', 'targets.sbml'])
        if targets_file is not None:
            logger.info(
                "\nTarget file created with the targets provided by the user in: "
                + target_file_path)

        else:
            sbml_management.create_species_sbml(newtargets, target_file_path)
            logger.info(
                "\nTarget file created with the addedvalue targets in: " +
                target_file_path)

        sbml_management.create_species_sbml(newtargets, target_file_path)

        # Add these targets to the instance
        logger.info("Setting " + str(len(newtargets)) +
                    " compounds as targets \n")
        # if len(newtargets) != len(addedvalue_targets):
        #     logger.info("\n".join(newtargets))

        instance_w_targets = add_targets_to_instance(instance_com, out_dir,
                                                     newtargets)
        # MINCOM
        mincom(instance_w_targets, out_dir)
        # remove intermediate files
        os.unlink(instance_com)
        os.unlink(instance_w_targets)
    else:
        logger.info(
            "No newly producible compounds, hence no community selection will be computed"
        )
        os.unlink(instance_com)

    # Create targets result file
    targets_producibility(out_dir, union_targets_iscope, targets_cscope,
                          addedvalue_targets, user_targets)