Ejemplo n.º 1
0
def main():
    import sys
    import os
    h = 6.6260689633e-34
    c = 299792458
    electron  = 1.60217653141e-19

    def toenergy(wave):
        energy = (h*c)/(float(wave)*1e-10*electron)
        return energy

    def towave(energy):
        wave = (h*c)/(float(energy)*electron)
        return wave

    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("--energy","-e",dest="energy",metavar="energy ev",help="Energy in ev")
    parser.add_option("--wave","-w",dest="wave",metavar="wave A",help="wavelenbth in Angstrom")
    (options,spillover) = parser.parse_args()


    if options.energy is not None:
        energy = options.energy
        wave = towave(energy)
        print "The input %s energy in ev corresponds to %s wavelength" % ( energy , wave)


    elif options.wave is not None:
        wave = sys.argv[2]
        energy = toenergy(wave)
        print "The input %s wavelength corressponds to %s ev " % (wave,energy)
    else:
        parser.print_help()
        exit()
Ejemplo n.º 2
0
def badArgs(parser):
	print "Incorrect Arguments"
	parser.print_help()
	exit(0)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    (options, args) = parser.parse_args()

     # create my parameter container
    params = roi.ROI_Data()

    params.extraTargetCode = options.extraTargetCode
    if options.testing:
        params.roiName = 'IncaCity'
        params.obsID = 'PSP_003092_0985'
        params.ccdColour = 'RED'
        params.inputSample = '6849'
        params.inputLine = '18426'
        params.extraTargetCode = '0815'
    elif len(args) == 0:
        parser.print_help()
        sys.exit(1)
    else:
        try:
            params.roiName, params.obsID, params.ccdColour, params.inputSample, \
            params.inputLine = args
        except:
            try:
                params.roiName, params.obsID, params.inputSample, \
                params.inputLine = args
                params.ccdColour = ''
            except:
                print('\n Something wrong with parameters.')
                parser.print_help()
                sys.exit(1)