Ejemplo n.º 1
0
def run_analysis(cfg, options):
    # Now try processing everything....
    method = analysis_method.choose_method(cfg.search)
    reporter.TextReporter(cfg)
    anal = method(cfg, options.force_restart, options.processes)
    results = anal.analyse()
    if options.dump_results:
        results.dump(cfg)
    elif options.compare_results:
        results.compare(cfg)
Ejemplo n.º 2
0
def run_analysis(cfg, options):
    # Now try processing everything....
    method = analysis_method.choose_method(cfg.search)
    reporter.TextReporter(cfg)
    anal = method(cfg, options.force_restart, options.processes)
    results = anal.analyse()
    if options.dump_results:
        results.dump(cfg)
    elif options.compare_results:
        results.compare(cfg)
Ejemplo n.º 3
0
def main(name, datatype, passed_args=None):
    v = version.get_version()

    # If passed_args is None, this will use sys.argv
    options, args = parse_args(datatype, passed_args)
    if not args:
        # Help has already been printed
        return 2

    log.info("------------- %s %s -----------------", name, v)
    start_time = datetime.datetime.now().replace(microsecond=0)  # start the clock ticking

    check_python_version()

    if passed_args is None:
        cmdline = "".join(sys.argv)
    else:
        cmdline = "".join(passed_args)

    log.info("Command-line arguments used: %s", cmdline)

    # Load, using the first argument as the folder
    try:
        cfg = config.Configuration(datatype, 
                                   options.phylogeny_program,
                                   options.save_phylofiles, 
                                   options.cmdline_extras,
                                   options.cluster_weights,
                                   options.cluster_percent)

        # Set up the progress callback
        progress.TextProgress(cfg)
        cfg.load_base_path(args[0])

        if options.check_only:
            log.info("Exiting without processing (because of the -c/--check-only option ...")
        else:
            try:
                # Now try processing everything....
                if not cfg.save_phylofiles:
                    clean_folder(cfg.phylofiles_path)
                method = analysis_method.choose_method(cfg.search)
                reporter.TextReporter(cfg)
                anal = method(cfg,
                            options.force_restart,
                            options.processes)
                results = anal.analyse()

                if options.dump_results:
                    results.dump(cfg)
                elif options.compare_results:
                    results.compare(cfg)
            finally:
                # Make sure that we reset the configuration
                cfg.reset()

        # Successful exit
        end_time = datetime.datetime.now().replace(microsecond=0)
        processing_time = end_time - start_time

        log.info("Total processing time: %s (h:m:s)" % processing_time)
        log.info("Processing complete.")

        return 0

    except util.PartitionFinderError:
        log.error("Failed to run. See previous errors.")
        # Reraise if we were called by call_main, or if the options is set
        if options.show_python_exceptions or passed_args is not None:
            raise

    except KeyboardInterrupt:
        log.error("User interrupted the Program")


    return 1
Ejemplo n.º 4
0
def main(name, version, datatype):
    log.info("------------- %s %s -----------------", name, version)
    usage = """usage: python %prog [options] <foldername>

    PartitionFinder and PartitionFinderProtein are designed to discover optimal 
    partitioning schemes for nucleotide and amino acid sequence alignments. 
    They are also useful for finding the best model of sequence evolution for datasets.

    The Input: <foldername>: the full path to a folder containing:
        - A configuration file (partition_finder.cfg)
        - A nucleotide/aa alignment in Phylip format
    Take a look at the included 'example' folder for more details.

    The Output: A file in the same directory as the .cfg file, named
    'analysis' This file contains information on the best
    partitioning scheme, and the best model for each partiiton

    Usage Examples: 
        >python %prog example
        Analyse what is in the 'example' sub-folder in the current folder.

        >python %prog -v example
        Analyse what is in the 'example' sub-folder in the current folder, but
        show all the debug output

        >python %prog -c ~/data/frogs
        Check the configuration files in the folder data/frogs in the current
        user's home folder.

        >python %prog --force-restart ~/data/frogs
        Deletes any data produced by the previous runs (which is in
        ~/data/frogs/output) and starts afresh
    """
    parser = OptionParser(usage)
    parser.add_option(
        "-v", "--verbose",
        action="store_true", dest="verbose",
        help="show verbose (debug) output")
    parser.add_option(
        "-c", "--check-only",
        action="store_true", dest="check_only",
        help="just check the configuration files, don't do any processing")
    parser.add_option(
        "--force-restart",
        action="store_true", dest="force_restart",
        help="delete all previous output and start afresh (!)")
    parser.add_option(
        "-p", "--processes", 
        type="int", dest="processes", default=-1, metavar="N",
        help="Number of concurrent processes to use."
        " Use -1 to match the number of cpus on the machine."
        " The default is to use -1.")
    parser.add_option(
        "--show-python-exceptions",
        action="store_true", dest="show_python_exceptions",
        help="If errors occur, print the python exceptions")
    parser.add_option(
        "--save-phyml",
        action="store_true", dest="save_phyml",
        help="save all of the phyml output. This can take a lot of space(!)")
    parser.add_option(
        "--dump-results",
        action="store_true", dest="dump_results",
        help="Dump all results to a binary file. "
        "This is only of use for testing purposes.")
    parser.add_option(
        "--compare-results",
        action="store_true", dest="compare_results",
        help="Compare the results to previously dumped binary results. "
        "This is only of use for testing purposes.")
    
    options, args = parser.parse_args()

    # Error checking
    if options.dump_results and options.compare_results:
        log.error("You can't dump and compare results in one run!")
        log.error("Please select just one of these")

    # We should have one argument: the folder to read the configuration from
    if not args:
        # Otherwise exit, printing the help
        parser.print_help()
        return 2

    #before we start, let's check the python version is above 2.7 but lower than 3.0    
    python_version = float("%d.%d" %(sys.version_info[0], sys.version_info[1]))

    log.info("You have Python version %.1f" %python_version)

    if python_version<2.7:
        log.error("Your Python version is %.1f, but this program requires Python 2.7. "
        "Please upgrade to version 2.7 by visiting www.python.org/getit, or by following"
        " the instructions in the PartitionFinder manual." % python_version)
        return 0

    if python_version>3.0:
        log.warning("Your Python version is %.1f. This program was not built to run with "
        "version 3 or higher. To guarantee success, please use Python 2.7.x" % python_version)

    # Load, using the first argument as the folder
    try:
        cfg = config.Configuration(datatype)
        cfg.load_base_path(args[0])
                
        if options.check_only:
            log.info("Exiting without processing (because of the -c/--check-only option ...")
        else:

            # For now, we just turn on debugging for the analysis section
            # For finer grain, see the logging.cfg file
            if options.verbose:
                logging.getLogger('analysis').setLevel(logging.DEBUG)
                logging.getLogger('analysis_method').setLevel(logging.DEBUG)

            # Now try processing everything....
            method = analysis_method.choose_method(cfg.search)
            rpt = reporter.TextReporter(cfg)
            anal = method(cfg, rpt, 
                          options.force_restart, 
                          options.save_phyml,
                          options.processes)
            results = anal.analyse()

            if options.dump_results:
                results.dump(cfg)
            elif options.compare_results:
                results.compare(cfg)
            
        # Successful exit
        log.info("Processing complete.")

        return 0

    except util.PartitionFinderError:
        log.error("Failed to run. See previous errors.")
        if options.show_python_exceptions:
            raise

    except KeyboardInterrupt:
        log.error("User interrupted the Program")

    return 1