Esempio n. 1
0
def vcf2wt_main(args=None):
    prog_description = "Convert a VCF file to Wormtable format."
    parser = argparse.ArgumentParser(description=prog_description)
    cli.add_version_argument(parser)
    parser.add_argument("SOURCE",
                        help="VCF file to convert (use '-' for STDIN)")
    parser.add_argument("DEST",
                        help="""Output wormtable home directory, or schema file
            if we are generating a candidate schema using the
            --generate-schema option""")
    parser.add_argument("--quiet",
                        "-q",
                        action="store_true",
                        default=False,
                        help="Suppress progress monitor")
    parser.add_argument("--force",
                        "-f",
                        action="store_true",
                        default=False,
                        help="Force over-writing of existing wormtable")
    parser.add_argument(
        "--truncate",
        "-t",
        action="store_true",
        default=False,
        help="""Truncate values that are too large for a column and store
            the maximum the column will allow. Currently this option
            only supports truncating REF and ALT column values more than 254
            characters long. REF and ALT values are truncated to 253 characters
            and suffixed with a '+' to indicate that truncation has
            occured""")
    parser.add_argument(
        "--cache-size",
        "-c",
        default="64M",
        help="cache size in bytes; suffixes K, M and G also supported.")
    g = parser.add_mutually_exclusive_group()
    g.add_argument("--generate-schema",
                   "-g",
                   action="store_true",
                   default=False,
                   help="""Generate a schema for the source VCF file and
            write to DEST. Only reads the header of the VCF file.""")
    g.add_argument("--schema",
                   "-s",
                   default=None,
                   help="""Use schema from the file SCHEMA rather than default
                generated schema""")
    parsed_args = parser.parse_args(args)
    runner = ProgramRunner(parsed_args)
    try:
        runner.run()
    finally:
        runner.cleanup()
Esempio n. 2
0
def gtf2wt_main(args=None):
    prog_description = "Convert a GTF file to Wormtable format."
    parser = argparse.ArgumentParser(description=prog_description)
    cli.add_version_argument(parser)
    parser.add_argument("SOURCE",
        help="GTF file to convert (use '-' for STDIN)")
    parser.add_argument("DEST",
        help="Output wormtable home directory")
    parser.add_argument("--quiet", "-q", action="store_true",
        default=False,
        help="Suppress progress monitor")
    parser.add_argument("--force", "-f", action="store_true", default=False,
        help="Force over-writing of existing wormtable")
    parser.add_argument("--cache-size", "-c", default="64M",
        help="cache size in bytes; suffixes K, M and G also supported.")
    parsed_args = parser.parse_args(args)
    runner = ProgramRunner(parsed_args)
    runner.run()
Esempio n. 3
0
def wtadmin_main(cmdline_args=None):
    prog_description = "Wormtable administration program."
    parser = argparse.ArgumentParser(description=prog_description)
    cli.add_version_argument(parser)
    subparsers = parser.add_subparsers(title='subcommands',)

    # help
    show_parser = subparsers.add_parser("help",
            description = "wtadmin help",
            help="show this help message and exit")

    # show command
    show_parser = subparsers.add_parser("show",
            description = "Show the columns in the table",
            help="show details about the columns in the table")
    add_homedir_argument(show_parser)
    show_parser.set_defaults(runner=ShowRunner)

    # ls command
    ls_parser = subparsers.add_parser("ls",
            description="list details of the table and its indexes",
            help="list the indexes in the table")
    add_homedir_argument(ls_parser)
    ls_parser.set_defaults(runner=ListRunner)

    # index histogram command
    hist_parser = subparsers.add_parser("hist",
        help="""show the histogram for index NAME""",
        description="show the keys and counts from an index")
    add_homedir_argument(hist_parser)
    hist_parser.add_argument("NAME", help="name of the index")
    hist_parser.set_defaults(runner=HistRunner)

    # rm index command
    remove_parser = subparsers.add_parser("rm",
        help="delete an index",
        description="delete an index")
    add_homedir_argument(remove_parser)
    remove_parser.add_argument("NAME", help="name of the index")
    remove_parser.set_defaults(runner=DeleteRunner)

    # add index command
    add_parser = subparsers.add_parser("add",
            help="add a new index to the table",
            description="add a new index to the table")
    add_homedir_argument(add_parser)
    add_colspec_argument(add_parser)
    add_parser.add_argument("--quiet", "-q", action="store_true", default=False,
        help="suppress progress monitor and messages")
    add_parser.add_argument("--force", "-f", action="store_true", default=False,
        help="force over-writing of existing index")
    add_parser.add_argument("--name", "-n",
        help="name of the index (defaults to COLSPEC)")
    add_parser.add_argument("--cache-size", "-c", default="64M",
            help="""index cache size in bytes; suffixes K, M and G also supported.
                This option is very important for index build performance and
                should be set as large as possible; ideally, the entire index
                should fit into the cache. """)
    add_parser.set_defaults(runner=AddRunner)

    # dump command
    dump_parser = subparsers.add_parser("dump",
            help="dump the table to stdout",
            description="dump data from the table to stdout.")
    add_homedir_argument(dump_parser)
    dump_parser.add_argument("columns", metavar="COLUMN", nargs="*",
        help="Columns to dump - defaults to all columns")
    dump_parser.add_argument("--cache-size", "-c", default="64M",
            help="cache size in bytes; suffixes K, M and G also supported.")
    dump_parser.add_argument("--index", "-i", default=None,
            help="index to sort by when dumping rows")
    dump_parser.add_argument("--start", "-s", default=None,
            help="""start value to print. This is a comma delimited series
                of values for each column in the index. Eg. --start=AA,A""")
    dump_parser.add_argument("--stop", "-t", default=None,
            help="""stop value to print. This is a comma delimited series
                of values for each column in the index.""")
    dump_parser.set_defaults(runner=DumpRunner)

    if os.name == "posix":
        # Set signal handler for SIGPIPE to quietly kill the program.
        signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    args = parser.parse_args(cmdline_args)
    if "runner" not in args:
        parser.print_help()
    else:
        runner = args.runner(args)
        try:
            runner.init()
            runner.run()
        finally:
            runner.cleanup()