Ejemplo n.º 1
0
        internal_ids = []
        for metab in network.metabolites:
            if not metab.is_external:
                id_ind = [ind for ind, id in enumerate(ids) if id == metab.id]
                if len(id_ind):
                    internal_ids.append(id_ind[0])

        ids = list(np.delete(ids, internal_ids))
        cone = np.delete(cone, internal_ids, axis=1)

    if mpi_wrapper.is_first_process():
        try:
            np.savetxt(args.out_path,
                       cone,
                       delimiter=',',
                       header=','.join(ids),
                       comments='')
        except OverflowError:
            normalised = np.transpose(normalize_columns(np.transpose(cone)))
            np.savetxt(args.out_path,
                       normalised,
                       delimiter=',',
                       header=','.join(ids),
                       comments='')

    if args.print_conversions:
        print_ecms_direct(np.transpose(cone), ids)

    end = time()
    mp_print('Ran in %f seconds' % (end - start))
Ejemplo n.º 2
0
def calc_ECMs(file_path, print_results=False, input_file_path=''):
    """
    Calculates ECMs using ECMtool
    :return ecms: np.array
            This array contains the ECMs as columns and the metabolites as rows
    :param file_path: string
            String with path to the SBML-file.
    :param reactions_to_tag: list with strings
            List with reaction-IDs of reactions that need to be tagged
    :param print_results: Boolean
    :param hide_metabs: indices of metabolites that should be ignored
    """
    # Stap 1: netwerk bouwen
    network = extract_sbml_stoichiometry(file_path, determine_inputs_outputs=True)

    external_inds = [ind for ind, metab in enumerate(network.metabolites) if metab.is_external]

    """The following are just for checking the inputs to this program."""
    metab_info_ext = [(ind, metab.id, metab.name, metab.direction) for ind, metab in
                      enumerate(network.metabolites) if metab.is_external]

    """I extract some information about the external metabolites for checking"""
    metab_info_ext_df = pd.DataFrame(metab_info_ext, columns=['metab_ind', 'metab_id', 'metab_name', 'Direction'])

    """You can choose to save this information, by uncommenting this line"""
    #    metab_info_ext_df.to_csv(path_or_buf='external_info_iJR904.csv', index=False)

    """If an input file is supplied, we set in input, output, and hide metabolites from this"""
    if input_file_path:  # If no input file is supplied, standard detection of ecmtool is used
        info_metabs_df = pd.read_csv(input_file_path)
        info_metabs_input = info_metabs_df[info_metabs_df.Input == 1]
        info_metabs_output = info_metabs_df[info_metabs_df.Output == 1]
        info_metabs_hidden = info_metabs_df[info_metabs_df.Hidden == 1]

        # Get the indices that correspond to the metabolites that are inputs, outputs, or hidden.
        input_inds = list(info_metabs_input.Index.values)
        output_inds = list(info_metabs_output.Index.values) + [ind for ind, metab in enumerate(network.metabolites) if
                                                               metab.id == 'objective']
        hide_inds = list(info_metabs_hidden.Index.values)
        prohibit_inds = [ind for ind, metab in enumerate(network.metabolites) if
                         (metab.is_external) & (not ind in input_inds + output_inds + hide_inds) & (
                             not metab.id == 'objective')]
        both_inds = [ind for ind in range(len(network.metabolites)) if (ind in input_inds) and (ind in output_inds)]

        # Use input information to set input, output, hidden, and prohibited metabolites
        network.set_inputs(input_inds)
        network.set_outputs(output_inds)
        network.set_both(both_inds)
        network.prohibit(prohibit_inds)
        network.hide(hide_inds)

        # Print comma-separated lists of input information. These lists can be used for running the same computation
        # via command line, for example to use other arguments
        print(','.join(map(str, input_inds)))
        print(','.join(map(str, output_inds)))
        print(','.join(map(str, hide_inds)))
        print(','.join(map(str, prohibit_inds)))

    """Keep a copy of the full network before compression. This can be nice for later."""
    full_network = copy.deepcopy(network)
    orig_N = network.N

    """"Split in and out metabolites, to facilitate ECM computation"""
    network.split_in_out(only_rays=False)

    """Stap 2: compress network"""
    network.compress(verbose=True)

    """Stap 3: Ecms enumereren"""
    #  In this script, indirect intersection is used. Use command line options to use direct intersection
    cone = get_conversion_cone(network.N, network.external_metabolite_indices(), network.reversible_reaction_indices(),
                            network.input_metabolite_indices(), network.output_metabolite_indices(), only_rays=False,
                            verbose=True)
    cone_transpose, ids = unsplit_metabolites(np.transpose(cone), network)
    cone = np.transpose(cone_transpose)

    if print_results:
        print_ecms_direct(np.transpose(cone), ids)

    cone = cone.transpose()  # columns will be the different ECMs, rows are metabolites

    return cone, ids, full_network