Exemplo n.º 1
0
def main():

    # 1. Parse command line

    usage = "Usage: %prog <filename> [options]"
    version = "%prog\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-c",
                      "--compartment-suffixes",
                      dest="compartmentSuffixes",
                      help="STRING of compartment "
                      "suffixes (separated by whitespace)",
                      metavar="STRING")

    options, args = parser.parse_args()

    if len(args) < 1:
        print "Error: No filename given."
        print("Usage is\n    " + os.path.basename(sys.argv[0]) + " <filename> "
              "[options]")
        exit()

    filename = args[0]

    # 2. Parse reaction file

    model = MetabolicModel()
    try:
        model.addReactionsFromFile(filename)
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(filename))
        print strerror
        exit()
Exemplo n.º 2
0
def main():
    # Parse command line

    usage = "Usage: %prog [options]"
    version = "%prog\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-r",
                      "--reactions",
                      dest="reactionFile",
                      help="use the "
                      "given reaction FILE as input",
                      metavar="FILE")
    parser.add_option(
        "-o",
        "--output",
        dest="outputFile",
        help="write the "
        "stoichiometric matrix to FILE (should have .m extension)",
        metavar="FILE")

    options, _ = parser.parse_args()
    parser.check_required("-r")
    parser.check_required("-o")

    # Parse reaction file

    model = MetabolicModel()
    try:
        model.addReactionsFromFile(options.reactionFile)
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(options.reactionFile))
        print strerror
        exit()
Exemplo n.º 3
0
def main():
    # 1. Parse command line

    usage = "Usage: %prog <file1> <file2> [options]"
    version = "%prog\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-o",
                      "--output",
                      dest="outputFile",
                      help="output FILE "
                      "(output is written to console if this is missing)",
                      metavar="FILE")
    parser.add_option("-c",
                      "--cutoff",
                      dest="cutoff",
                      help="Cutoff below which"
                      " difference is considered zero; default is 1E-10")
    parser.set_defaults(cutoff="1E-10")

    options, args = parser.parse_args()

    if len(args) < 2:
        print "Error: Need two solution files."
        print("Usage is\n    " + os.path.basename(sys.argv[0]) + " <file1> "
              "<file2> [options]")
        exit()

    try:
        cutoff = float(options.cutoff)
    except ValueError:
        print "Error: Invalid floating point value for cutoff."
        exit()
    if cutoff < 0.:
        print(
            "Warning: Cutoff is less than zero. Setting cutoff to zero, "
            "i.e. no cutoff.")
        cutoff = 0.

    basename = map(os.path.basename, args)
    # Use full path for identifying files if basenames are identical
    if basename[0] == basename[1]:
        basename = args

    # 2. Parse solution files and compute absolute differences

    solution = MetabolicFlux(), MetabolicFlux()
    for i in range(2):
        # Get pair of MetabolicFlux objects
        try:
            solution[i].readFromFile(args[i])
        except IOError, strerror:
            print("An error occurred while trying to read file %s:" %
                  os.path.basename(basename[i]))
            print strerror
            exit()
        except SyntaxError, strerror:
            print "An error occurred parsing file %s:" % basename[i]
            print strerror
            exit()
Exemplo n.º 4
0
def main():
    # 1. Parse command line

    usage = "Usage: %prog <solution-file> [options]"
    version = "%prog\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-r",
                      "--reactions",
                      dest="reactionFile",
                      help="use "
                      "reversibilities from reaction FILE",
                      metavar="FILE")
    parser.add_option("-p",
                      "--parameters",
                      dest="paramFile",
                      help="use constraints from the given scenario FILE",
                      metavar="FILE")

    options, args = parser.parse_args()

    # 2. Read solution file

    solution = MetabolicFlux()
    try:
        solution.readFromFile(args[0])
    except IndexError:
        print("Error: No solution file given.\nUsage is\n    " +
              os.path.basename(sys.argv[0]) + " <solution-file> [options]")
        exit()
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(args[0]))
        print strerror
        exit()
Exemplo n.º 5
0
def main():
    # Parse command line

    usage = "Usage: %prog [options]"
    version = "%prog\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-i",
                      "--input",
                      dest="inputFile",
                      help="use the "
                      "given reaction FILE as input",
                      metavar="FILE")
    parser.add_option("-o",
                      "--output",
                      dest="outputFile",
                      help="write output "
                      "(reaction file) to FILE (must not be the same as input "
                      "file)",
                      metavar="FILE")

    options, _ = parser.parse_args()
    parser.check_required("-i")
    parser.check_required("-o")

    if os.path.exists(options.outputFile):
        if os.path.samefile(options.outputFile, options.inputFile):
            print "Error: Output file must not be the same as input file!"
            exit()

    # Call reaction parser for fixing the reaction file

    rparser = ReactionParser()
    try:
        rparser.fixfile(options.inputFile, options.outputFile)
    except IOError, strerror:
        print(
            "An error occurred while trying to read file %s or write file "
            "%s:" % (os.path.normpath(
                options.inputFile), os.path.normpath(options.outputFile)))
        print strerror
        exit()
Exemplo n.º 6
0
def main():
    if _mpi_avail:
        comm = MPI.COMM_WORLD
        numprocs = comm.Get_size()
        rank = comm.Get_rank()
        if numprocs == 1:
            comm = None
    else:
        comm = None

    if not _mpi_avail or rank == 0:  # Start of root process code

        # 1. Parse command line

        usage = "Usage: %prog [options]"
        version = "Knockout analysis\n" + COPYRIGHT_VERSION_STRING
        parser = OptionParser(usage=usage, version=version)
        momaOptions = parser.add_option_group("General MOMA options")
        momaOptions.add_option("-r",
                               "--reactions",
                               dest="reactionFile",
                               help="perform knockout analysis on the network "
                               "given by the reaction FILE",
                               metavar="FILE")
        momaOptions.add_option("-p",
                               "--parameters",
                               dest="paramFile",
                               help="use the given scenario FILE for the "
                               "wildtype",
                               metavar="FILE")
        momaOptions.add_option("-o",
                               "--output",
                               dest="outputFile",
                               help="write"
                               " output of knockout analysis to FILE",
                               metavar="FILE")
        momaOptions.add_option("-w",
                               "--wt-solution",
                               dest="wtSolution",
                               help="use the given solution FILE for the "
                               "wildtype (optional)",
                               metavar="FILE")
        momaOptions.add_option(
            "-v",
            "--reduce-by-fva",
            dest="redFvaFile",
            help="use FVA result from FILE to reduce matrix "
            "(experimental; only works if perturbed solution"
            " space is a subset of the wildtype solution "
            "space)",
            metavar="FILE")
        koOptions = parser.add_option_group("Options for knockout analysis")
        koOptions.add_option("-f",
                             "--solution-files",
                             dest="fluxFilePrefix",
                             help="write MOMA/FBA solutions to files marked "
                             "with FILE-PREFIX (may contain path)",
                             metavar="FILE-PREFIX")
        koOptions.add_option(
            "-g",
            "--ko-groups",
            dest="koGroupDictFile",
            help="read reaction groups to be knocked out "
            "together from CSV FILE (if not given, individual "
            "reactions are knocked out)",
            metavar="FILE")
        koOptions.add_option("-n",
                             "--ko-ungrouped",
                             action="store_true",
                             dest="koUngrouped",
                             help="knock out individual "
                             "reactions that do not belong to any group (only "
                             "with -g)")
        koOptions.add_option("-m",
                             "--moma",
                             dest="useMoma",
                             help="perform MOMA"
                             ", options: 'always', 'never' (FBA only), 'auto' "
                             "(default: FBA first, then MOMA if not lethal)",
                             metavar="WHEN")
        wmOptions = parser.add_option_group("Extra options for weighted MOMA")
        wmOptions.add_option(
            "-x",
            "--wmoma",
            dest="wMomaFvaFile",
            help="perform weighted MOMA with weights computed "
            "from the given FVA solution FILE",
            metavar="FILE")
        wmOptions.add_option(
            "-a",
            "--alpha",
            dest="alpha",
            type="float",
            help="parameter ALPHA for computation of weights:"
            " w = alpha + exp(-beta*(fvaMax-fvaMin)) (default:"
            " %g)" % _DEFAULT_ALPHA)
        wmOptions.add_option(
            "-b",
            "--beta",
            dest="beta",
            type="float",
            help="parameter BETA for computation of weights: "
            "w = alpha + exp(-beta*(fvaMax-fvaMin)) (default: "
            "%g)" % _DEFAULT_BETA)
        optOptions = parser.add_option_group("Options for optimization")
        optOptions.add_option("-s",
                              "--solver",
                              dest="solver",
                              help="QP solver "
                              "to be used for MOMA (default cvxopt)",
                              metavar="SOLVER")
        optOptions.add_option("-i",
                              "--iterations",
                              dest="numIter",
                              type="int",
                              help="number of NLP runs to perform (from "
                              "different random start points) - per knockout")
        optOptions.add_option(
            "-l",
            "--use-full-matrix",
            action="store_true",
            dest="useFullMatrix",
            help="use full matrix "
            "(disable removal of dead ends and nonfunctional "
            "reactions)")
        parser.set_defaults(solver="default",
                            numIter=1,
                            koUngrouped=False,
                            useMoma="auto",
                            useFullMatrix=False,
                            alpha=_DEFAULT_ALPHA,
                            beta=_DEFAULT_BETA)

        try:
            options, _ = parser.parse_args()
            parser.check_required("-r")
            parser.check_required("-p")
            parser.check_required("-o")
        except SystemExit, e:
            _mpi_exit(comm, e.args[0])

        weighted = bool(options.wMomaFvaFile)
        if weighted:
            if options.alpha < 0.:
                print "Error: alpha must be non-negative."
                _mpi_exit(comm, 1)
            if options.beta <= 0.:
                print "Error: beta must be positive."
                _mpi_exit(comm, 1)

        if options.numIter < 1:
            print "Error: Number of NLP runs must be positive."
            _mpi_exit(comm, 1)

        try:
            useMoma = decodeWhen(options.useMoma,
                                 set((When.NEVER, When.AUTO, When.ALWAYS)))
        except KeyError:
            print(
                "Error: Illegal value for -m option (allowed values are "
                "'auto', 'never', or 'always').")
            _mpi_exit(comm, 1)

        # 2. Parse reaction file

        rparser = ReactionParser()
        model = MetabolicModel()
        try:
            model.addReactionsFromFile(options.reactionFile, rparser)
        except IOError, strerror:
            print("An error occurred while trying to read file %s:" %
                  os.path.basename(options.reactionFile))
            print strerror
            _mpi_exit(comm, 1)
Exemplo n.º 7
0
def main():
    # 1. Parse command line

    usage = "Usage: %prog [options]"
    version = "Model assertion watcher\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-r",
                      "--reactions",
                      dest="reactionFile",
                      help="read "
                      "metabolic model from the given reaction FILE",
                      metavar="FILE")
    parser.add_option("-p",
                      "--parameters",
                      dest="paramFile",
                      help="use the "
                      "given scenario FILE for model analysis ",
                      metavar="FILE")
    parser.add_option("-a",
                      "--assertions",
                      dest="assertionFile",
                      help="read "
                      "assertions from FILE",
                      metavar="FILE")
    parser.add_option(
        "-t",
        "--tolerance",
        dest="tolerance",
        type="float",
        help="FVA: tolerance for objective function (0 < VALUE < "
        "1; default: .95)",
        metavar="VALUE")
    parser.set_defaults(tolerance=.95)

    options, _ = parser.parse_args()
    parser.check_required("-r")
    parser.check_required("-p")
    parser.check_required("-a")

    if options.tolerance <= 0. or options.tolerance > 1.:
        print "Error: Tolerance must be in interval (0, 1]"
        exit()

    # 2. Create MetabolicModel from reaction file

    rparser = ReactionParser()
    model = MetabolicModel()
    try:
        model.addReactionsFromFile(options.reactionFile, rparser)
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(options.reactionFile))
        print strerror
        exit()
Exemplo n.º 8
0
def main():
    # 1. Parse command line

    usage = "Usage: %prog <solution-file> [options]"
    version = "Split-ratio analysis\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-r",
                      "--reactions",
                      dest="reactionFile",
                      help="use "
                      "metabolic model given by reaction FILE",
                      metavar="FILE")
    parser.add_option("-m",
                      "--metabolite",
                      dest="metabolite",
                      help="NAME of "
                      "the single metabolite to be analyzed (optional)",
                      metavar="NAME")
    parser.add_option("-o",
                      "--output",
                      dest="outputFile",
                      help="perform "
                      "analysis for all metabolites and write output to FILE",
                      metavar="FILE")
    parser.add_option("-t",
                      "--omit-fluxes-below",
                      dest="threshold",
                      type="float",
                      help="omit metabolites in output whose flux"
                      " is below the given THRESHOLD (only with -o)",
                      metavar="THRESHOLD")
    parser.add_option("-u",
                      "--omit-unbranched",
                      dest="omitUnbranched",
                      action="store_true",
                      help="if set, metabolites with "
                      "unbranched flux are omitted (only with -o)")
    parser.add_option("-c",
                      "--cutoff",
                      dest="cutoff",
                      type="float",
                      help="use "
                      "the given cutoff VALUE (default 0)",
                      metavar="VALUE")
    parser.add_option("-f",
                      "--cutoff-is-absolute",
                      dest="cutoffIsAbsolute",
                      action="store_true",
                      help="if set, cutoff is in absolute "
                      "flux units rather than a value between 0 and 1")
    parser.add_option(
        "-a",
        "--list-all",
        dest="listAll",
        action="store_true",
        help="if set, cutoff is ignored, and even zero fluxes are"
        " shown (per definition as outgoing)")
    parser.set_defaults(threshold=-1.,
                        omitUnBranched=False,
                        cutoff=0.,
                        cutoffIsAbsolute=False,
                        listAll=False)

    options, args = parser.parse_args()
    parser.check_required('-r')

    if not options.metabolite and not options.outputFile:
        print "Neither metabolite nor output file given. Nothing to do."
        exit()

    # 2. Read solution file

    solution = MetabolicFlux()
    try:
        solution.readFromFile(args[0])
    except IndexError:
        print("Error: No solution file given.\nUsage is\n    " +
              os.path.basename(sys.argv[0]) + " <solution-file> [options]")
        exit()
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(args[0]))
        print strerror
        exit()
Exemplo n.º 9
0
def main():
    # 1. Parse command line

    usage = "Usage: %prog [options]"
    version = "Transporter check\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option(
        "-r",
        "--reactions",
        dest="reactionFile",
        help="perform Flux Balance Analysis on the network given "
        "by the reaction FILE",
        metavar="FILE")
    parser.add_option("-p",
                      "--parameters",
                      dest="paramFile",
                      help="use the given scenario FILE for Flux Balance "
                      "Analysis",
                      metavar="FILE")
    parser.add_option("-t",
                      "--transporters",
                      dest="transFile",
                      help="use list of transporters from FILE",
                      metavar="FILE")
    parser.add_option("-o",
                      "--output",
                      dest="outputFile",
                      help="write output of Flux Balance Analysis to FILE",
                      metavar="FILE")

    options, _ = parser.parse_args()
    parser.check_required("-r")
    parser.check_required("-p")
    parser.check_required("-t")
    parser.check_required("-o")

    # 2. Parse reaction file

    rparser = ReactionParser()
    model = MetabolicModel()
    try:
        model.addReactionsFromFile(options.reactionFile, rparser)
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(options.reactionFile))
        print strerror
        exit()
Exemplo n.º 10
0
def main():
    # 1. Parse command line

    usage = "Usage: %prog [options]"
    version = "%prog\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-r",
                      "--reactions",
                      dest="reactionFile",
                      help="use the given reaction FILE",
                      metavar="FILE")
    parser.add_option("-s",
                      "--solution",
                      dest="solutionFile",
                      help="parse the given FBA solution FILE",
                      metavar="FILE")
    parser.add_option("-c",
                      "--cutoff",
                      dest="cutoff",
                      type="float",
                      help="threshold below which a flux is to be considered "
                      "zero; default: 1E-10)",
                      metavar="VALUE")
    parser.set_defaults(cutoff=1E-10)

    options, _ = parser.parse_args()
    parser.check_required("-r")
    parser.check_required("-s")

    # 2. Parse reaction file

    rparser = ReactionParser()
    model = MetabolicModel()
    try:
        model.addReactionsFromFile(options.reactionFile, rparser)
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(options.reactionFile))
        print strerror
        exit()
Exemplo n.º 11
0
def main():
    # 1. Parse command line

    usage = "Usage: %prog [options]"
    version = "Metabolite flux minimization\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-r",
                      "--reactions",
                      dest="reactionFile",
                      help="perform Metabolite Flux Minimization on the"
                      " network given by the reaction FILE",
                      metavar="FILE")
    parser.add_option("-p",
                      "--parameters",
                      dest="paramFile",
                      help="use the given scenario FILE",
                      metavar="FILE")
    parser.add_option("-o",
                      "--output",
                      dest="outputFile",
                      help="write MFM output to FILE",
                      metavar="FILE")
    parser.add_option("-t",
                      "--tolerance",
                      dest="tolerance",
                      type="float",
                      help="tolerance for objective function (0 < VALUE "
                      "< 1; default: .95)",
                      metavar="VALUE")
    parser.add_option("-l",
                      "--use-full-matrix",
                      action="store_true",
                      dest="useFullMatrix",
                      help="use full matrix (disable "
                      "removal of dead ends and nonfunctional reactions)")
    parser.set_defaults(tolerance=.95, useFullMatrix=False)

    options, _ = parser.parse_args()
    parser.check_required("-r")
    parser.check_required("-p")
    parser.check_required("-o")

    if options.tolerance <= 0. or options.tolerance > 1.:
        print "Error: Tolerance must be in interval (0, 1]"
        exit()

    # 2. Parse reaction file

    rparser = ReactionParser()
    model = MetabolicModel()
    try:
        model.addReactionsFromFile(options.reactionFile, rparser)
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(options.reactionFile))
        print strerror
        exit()
Exemplo n.º 12
0
def main():
    # 1. Parse command line

    usage = "Usage: %prog [options]"
    version = ("Minimization of metabolic adjustment\n" +
               COPYRIGHT_VERSION_STRING)
    parser = OptionParser(usage=usage, version=version)
    momaOptions = parser.add_option_group("General MOMA options")
    momaOptions.add_option("-r",
                           "--reactions",
                           dest="reactionFile",
                           help="perform MOMA on the mutant network given by "
                           "the reaction FILE",
                           metavar="FILE")
    momaOptions.add_option("-p",
                           "--parameters",
                           dest="paramFile",
                           help="use the given scenario FILE for the mutant",
                           metavar="FILE")
    momaOptions.add_option("-w",
                           "--wt-solution",
                           dest="wtSolution",
                           help="use the given solution FILE for the wildtype",
                           metavar="FILE")
    momaOptions.add_option("-o",
                           "--output",
                           dest="outputFile",
                           help="write flux distribution computed by MOMA to "
                           "FILE",
                           metavar="FILE")
    momaOptions.add_option("-v",
                           "--reduce-by-fva",
                           dest="redFvaFile",
                           help="use FVA result from FILE to reduce matrix "
                           "(experimental; only works if perturbed solution "
                           "space is a subset of the wildtype solution space)",
                           metavar="FILE")
    wmOptions = parser.add_option_group("Extra options for weighted MOMA")
    wmOptions.add_option("-x",
                         "--wmoma",
                         dest="wMomaFvaFile",
                         help="perform "
                         "weighted MOMA with weights computed from the given "
                         "FVA solution FILE",
                         metavar="FILE")
    wmOptions.add_option(
        "-a",
        "--alpha",
        dest="alpha",
        type="float",
        help="parameter ALPHA for computation of weights: "
        "w = alpha + exp(-beta*(fvaMax-fvaMin)) (default: %g)" %
        _DEFAULT_ALPHA)
    wmOptions.add_option(
        "-b",
        "--beta",
        dest="beta",
        type="float",
        help="parameter BETA for computation of weights: "
        "w = alpha + exp(-beta*(fvaMax-fvaMin)) (default: %g)" % _DEFAULT_BETA)
    optOptions = parser.add_option_group("Options for optimization")
    optOptions.add_option("-s",
                          "--solver",
                          dest="solver",
                          help="QP/NLP solver "
                          "to be used for MOMA (default: cvxopt)")
    optOptions.add_option("-i",
                          "--iterations",
                          dest="numIter",
                          type="int",
                          help="number of NLP runs to perform (from different "
                          "random start points; default: %u)" %
                          FbaParam.DEFAULT_NUMITER,
                          metavar="N")
    optOptions.add_option("-l",
                          "--use-full-matrix",
                          action="store_true",
                          dest="useFullMatrix",
                          help="use full matrix (disable "
                          "removal of dead ends, nonfunctional reactions, and "
                          "reactions with flux restricted to zero) - slow")
    parser.set_defaults(solver="default",
                        useFullMatrix=False,
                        alpha=_DEFAULT_ALPHA,
                        beta=_DEFAULT_BETA,
                        numIter=FbaParam.DEFAULT_NUMITER)

    options, _ = parser.parse_args()
    parser.check_required("-r")
    parser.check_required("-p")
    parser.check_required("-w")
    parser.check_required("-o")

    if options.wMomaFvaFile:
        if options.alpha < 0.:
            print "Error: alpha must be non-negative."
            exit()
        if options.beta <= 0.:
            print "Error: beta must be positive."
            exit()

    if options.numIter < 1:
        print "Error: Number of NLP runs must be positive."
        exit()

    # 2. Parse reaction file

    rparser = ReactionParser()
    model = MetabolicModel()
    try:
        model.addReactionsFromFile(options.reactionFile, rparser)
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(options.reactionFile))
        print strerror
        exit()
Exemplo n.º 13
0
def main():
    # Parse command line
    usage = "Usage: %prog [options]"
    version = "%prog\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-r",
                      "--reactions",
                      dest="reactionFile",
                      help="use reactions from reaction FILE",
                      metavar="FILE")
    parser.add_option("-c",
                      "--concentrations",
                      dest="concentrationFile",
                      help="use concentrations from FILE",
                      metavar="FILE")
    parser.add_option("-d",
                      "--thermodynamics",
                      dest="thermodynFile",
                      help="use thermodynamic data from FILE",
                      metavar="FILE")
    parser.add_option("-s",
                      "--synonyms",
                      dest="synonymFile",
                      help="use metabolite synonyms from FILE",
                      metavar="FILE")
    parser.add_option("-t",
                      "--temperature",
                      dest="temperature",
                      help="set temperature to VALUE (in degrees Celsius)",
                      metavar="VALUE")
    parser.add_option("-o",
                      "--output",
                      dest="outputFile",
                      help="write output (Gibbs free energies) to FILE",
                      metavar="FILE")

    options, _ = parser.parse_args()
    parser.check_required("-r")
    parser.check_required("-c")
    parser.check_required("-d")
    parser.check_required("-s")
    parser.check_required("-t")

    try:
        temperature = float(options.temperature)
    except ValueError:
        print("Error: Invalid floating point value for temperature (%s)" %
              options.temperature)
        exit()

    # Compute Gibbs free energies from the given data
    gibbsR = getReaEnthalpies(options.concentrationFile, options.thermodynFile,
                              options.synonymFile, options.reactionFile,
                              temperature)

    # Write output either to a given file or to the console
    if options.outputFile:
        try:
            with open(options.outputFile, 'w') as f:
                writeOutputToFileHandle(f, gibbsR)
        except IOError, strerror:
            print("Unable to write to file %s:" %
                  os.path.basename(options.outputFile))
            print strerror
            writeOutputToFileHandle(stdout, gibbsR)
Exemplo n.º 14
0
def main():
    # 1. Parse command line

    usage = "Usage: %prog [options]"
    version = "%prog\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-p", "--parameters", dest="inputFile",
                      help="use the given scenario FILE", metavar="FILE")
    parser.add_option("-r", "--reactions", dest="reactionFile", help="use "
                      "reversibilities from reaction FILE", metavar="FILE")
    parser.add_option("-o", "--output", dest="outputFile", help="write output "
                      "(scenario file) to FILE", metavar="FILE")

    options, _ = parser.parse_args()
    parser.check_required("-p")
    parser.check_required("-r")
    parser.check_required("-o")

    # 2. Parse reaction file

    rparser = ReactionParser()
    model = MetabolicModel()
    try:
        model.addReactionsFromFile(options.reactionFile, rparser)
    except IOError, strerror:
        print ("An error occurred while trying to read file %s:" %
               os.path.basename(options.reactionFile))
        print strerror
        exit()
Exemplo n.º 15
0
def main():
    # 1. Parse command line

    usage = "Usage: %prog [options]"
    version = "Dead end finder\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    parser.add_option("-r",
                      "--reactions",
                      dest="reactionFile",
                      help="build stoichiometric matrix from reaction FILE",
                      metavar="FILE")
    parser.add_option("-p",
                      "--parameters",
                      dest="paramFile",
                      help="use the given scenario FILE",
                      metavar="FILE")
    parser.add_option("-a",
                      "--recursive",
                      action="store_true",
                      dest="recursive",
                      help="recursively predict all fluxes"
                      "that are zero in FBA due to dead ends")
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      help="generate extra (debug) output")
    parser.add_option("-t",
                      "--transporter-regex",
                      dest="regex",
                      help="treat "
                      "reactions matching regular expression PATTERN as "
                      "transporters, i.e. temporarily ignore bounds",
                      metavar="PATTERN")
    parser.set_defaults(recursive=False, verbose=False)

    options, _ = parser.parse_args()
    parser.check_required("-r")
    parser.check_required("-p")

    # 2. Parse reaction file

    rparser = ReactionParser()
    model = MetabolicModel()
    try:
        model.addReactionsFromFile(options.reactionFile, rparser)
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(options.reactionFile))
        print strerror
        exit()
Exemplo n.º 16
0
def main():

    # Parse command line
    usage = ("Usage: %prog <delta-G-file> [options]\n\n"
             "Gibbs free energy changes are taken from the <delta-g-file> if "
             "given.\nElse, they are computed from the data specified via the "
             "-r/-c/-d/-s/-t set of\noptions.")
    version = "%prog\n" + COPYRIGHT_VERSION_STRING
    parser = OptionParser(usage=usage, version=version)
    standardOptGroup = OptionGroup(parser, "Standard parameters")
    standardOptGroup.add_option("-p",
                                "--parameters",
                                dest="paramFile",
                                help="check the given scenario FILE",
                                metavar="FILE")
    standardOptGroup.add_option("-o",
                                "--output",
                                dest="outputFile",
                                help="write modified scenario file to FILE "
                                "(must not be the same as scenario file)",
                                metavar="FILE")
    standardOptGroup.add_option(
        "-e",
        "--epsilon",
        dest="epsilon",
        help="set THRESHOLD for recognizing Gibbs free "
        "energy change as clearly positive (default 0)",
        metavar="THRESHOLD")
    parser.add_option_group(standardOptGroup)

    computeOptGroup = OptionGroup(
        parser, "Parameters for computation of "
        "Gibbs free energies", "These are only needed"
        " if delta-G values are not read from file.")
    computeOptGroup.add_option("-r",
                               "--reactions",
                               dest="reactionFile",
                               help="use reactions from reaction FILE",
                               metavar="FILE")
    computeOptGroup.add_option("-c",
                               "--concentrations",
                               dest="concentrationFile",
                               help="use "
                               "concentrations from FILE",
                               metavar="FILE")
    computeOptGroup.add_option("-d",
                               "--thermodynamics",
                               dest="thermodynFile",
                               help="use thermodynamic data from FILE",
                               metavar="FILE")
    computeOptGroup.add_option("-s",
                               "--synonyms",
                               dest="synonymFile",
                               help="use metabolite synonyms from FILE",
                               metavar="FILE")
    computeOptGroup.add_option("-t",
                               "--temperature",
                               dest="temperature",
                               help="set temperature to VALUE (in degrees "
                               "Celsius)",
                               metavar="VALUE")
    parser.add_option_group(computeOptGroup)
    parser.set_defaults(epsilon='0.')

    options, args = parser.parse_args()
    parser.check_required("-p")
    parser.check_required("-o")
    parser.check_required("-t")

    try:
        epsilon = float(options.epsilon)
    except ValueError:
        print("Error: Invalid floating point value for epsilon (%s)" %
              options.epsilon)
        exit()
    if (os.path.exists(options.outputFile)
            and os.path.samefile(options.outputFile, options.paramFile)):
        print("Error: Input and output scenario files are the same (%s)" %
              options.paramFile)
        exit()

    if epsilon < 0.:
        print "Warning: epsilon < 0. Using default value of 0 instead."
        epsilon = 0.

    if len(args) > 0:
        gibbsR = readReaEnthalpiesFromFile(args[0])
    else:
        print(
            "\nInfo: No file with Gibbs free energies given. Launching "
            "computation of values.\n")
        parser.check_required("-r")
        parser.check_required("-c")
        parser.check_required("-d")
        parser.check_required("-s")
        parser.check_required("-t")
        try:
            temperature = float(options.temperature)
        except ValueError:
            print("Error: Invalid floating point value for temperature (%s)" %
                  options.temperature)
            exit()

        # Compute Gibbs free energies from the given data
        gibbsR = getReaEnthalpies(options.concentrationFile,
                                  options.thermodynFile, options.synonymFile,
                                  options.reactionFile, temperature)

    # Parse scenario file
    pparser = ParamParser()
    try:
        # Parse file
        maxmin, obj_name, solver, numiter, lb, ub =\
            pparser.parse(options.paramFile)
    except IOError, strerror:
        print("An error occurred while trying to read file %s:" %
              os.path.basename(options.paramFile))
        print strerror
        exit()