Пример #1
0
    def format_help(self):
        """Individual formatting of sections in the help text.

        When we use the same formatter for all, we either would lose the
        explicit spacing in the epilog, or lose the formatting in other
        sections. In this function we change the formatters, render
        different sections differently, and then concatenate everything
        into a single output.
        """

        # we get our formatters here, fill them up down bleow, and finally render them at the end:
        usage_formatter = argparse.ArgumentDefaultsHelpFormatter(self.prog)
        description_formatter = argparse.RawDescriptionHelpFormatter(self.prog)
        epilog_formatter = argparse.RawDescriptionHelpFormatter(prog=self.prog)
        separator_formatter = argparse.RawDescriptionHelpFormatter(prog=self.prog)

        # usage
        usage_formatter.add_usage(self.usage, self._actions, self._mutually_exclusive_groups)

        # positionals, optionals and user-defined groups
        for action_group in self._action_groups:
            if atty:
                section_title = action_group.title + ' ' * (80 - len(action_group.title) if len(action_group.title) < 80 else 0)
                section_header = bg(250) + fg(236) + attr('bold') + section_title + attr('reset')
            else:
                section_header = action_group.title

            usage_formatter.start_section(section_header)
            usage_formatter.add_text(action_group.description)
            usage_formatter.add_arguments(action_group._group_actions)
            usage_formatter.end_section()

        # separator
        separator_formatter.add_text('━' * 80 + '\n')

        # description
        if atty:
            description_text = [attr('bold') + '🔥 Program description:' + attr('reset'), '']
        else:
            description_text = ['🔥 Program description:', '']

        description_text.extend([textwrap.indent(l, '   ') for l in textwrap.wrap(" ".join(textwrap.dedent(self.description).split()), width=77)])
        description_formatter.add_text('\n'.join(description_text))

        # epilog
        epilog_formatter.add_text(self.epilog)

        # determine help from format above
        help_text = '\n'.join([usage_formatter.format_help().replace(":\n", "\n") if atty else usage_formatter.format_help(),
                               separator_formatter.format_help(),
                               description_formatter.format_help(),
                               epilog_formatter.format_help(),
                               separator_formatter.format_help()]) + '\n'

        return help_text
Пример #2
0
def add_maxpos_arguments(parser):

    parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=40, width=90)
    description = "MaxPos identifies the position of maximum signal (from bigwig) within a given set of .bed-regions. Used to identify peak of signals such as accessibility or footprint scores.\n\n"
    description += "Usage:\nTOBIAS MaxPos --bed <regions.bed> --bigwig <signal.bw>\n\n"
    description += "The output is a 4-column .bed-file (default output is stdout, but you can use --output to set a specific output file).\n"
    parser.description = format_help_description("MaxPos", description)

    parser._action_groups.pop()  #pop -h

    #Required arguments
    required = parser.add_argument_group('Required arguments')
    required.add_argument('--bed',
                          metavar="",
                          help="Regions to search for max position within")
    required.add_argument('--bigwig',
                          metavar="",
                          help="Scores used to identify maximum value")

    #Optional arguments
    optional = parser.add_argument_group('Optional arguments')
    optional.add_argument(
        '--output',
        metavar="",
        help=
        "Path to output .bed-file (default: scored sites are written to stdout)"
    )
    optional.add_argument(
        '--invert',
        help="Find minimum position instead of maximum position",
        action='store_true',
        default=False)

    return (parser)
Пример #3
0
def add_tfbscan_arguments(parser):

	parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=35, width=90)
	description = "Find positions of Transcription Factor Binding Sites (TFBS) in FASTA sequences by scanning with motifs.\n\n" 
	description += "Usage:\nTOBIAS TFBScan --motifs <motifs.txt> --fasta <genome.fa> \n\n"
	description += "By setting --outdir, the output files are:\n- <outdir>/<TF1>.bed\n- <outdir>/<TF2>.bed\n- (...)\n\n"
	description += "By setting --outfile, all TFBS are written to one file (with motif specified in the 4th column of the .bed)."
	parser.description = format_help_description("TFBScan", description)

	parser._action_groups.pop()	#pop -h

	required_arguments = parser.add_argument_group('Required arguments')
	required_arguments.add_argument('-m', '--motifs', metavar="", help='File containing motifs in either MEME, PFM or JASPAR format')
	required_arguments.add_argument('-f', '--fasta', metavar="", help='A fasta file of sequences to use for scanning motifs') 	# whole genome file or regions of interest in FASTA format to be scanned with motifs')

	#all other arguments are optional
	optional_arguments = parser.add_argument_group('Optional arguments')
	optional_arguments.add_argument('-r', '--regions', metavar="", help='Subset scanning to regions of interest')
	optional_arguments.add_argument('--outdir', metavar="", help='Output directory for TFBS sites in one file per motif (default: ./tfbscan_output/). NOTE: Select either --outdir or --outfile.', default=None)
	optional_arguments.add_argument('--outfile', metavar="", help='Output file for TFBS sites joined in one bed-file (default: not set). NOTE: Select either --outdir or --outfile.', default=None)

	optional_arguments.add_argument('--naming', metavar="", help="Naming convention for bed-ids and output files ('id', 'name', 'name_id', 'id_name') (default: 'name_id')", choices=["id", "name", "name_id", "id_name"], default="name_id")
	optional_arguments.add_argument('--gc', metavar="", type=lambda x: restricted_float(x,0,1), help='Set the gc content for background regions (default: will be estimated from fasta)')
	optional_arguments.add_argument('--pvalue', metavar="", type=lambda x: restricted_float(x,0,1), help='Set p-value for motif matches (default: 0.0001)', default=0.0001)
	optional_arguments.add_argument('--keep-overlaps', action='store_true', help='Keep overlaps of same motifs (default: overlaps are resolved by keeping best-scoring site)')
	optional_arguments.add_argument('--add-region-columns', action='store_true', help="Add extra information columns (starting from 4th column) from --regions to the output .bed-file(s) (default: off)")

	RUN = parser.add_argument_group('Run arguments')
	RUN.add_argument('--split', metavar="<int>", type=int, help="Split of multiprocessing jobs (default: 100)", default=100)
	RUN.add_argument('--cores', metavar="", type=int, help='Number of cores to use (default: 1)', default=1)
	RUN.add_argument('--debug', action="store_true", help=argparse.SUPPRESS)
	RUN = add_logger_args(optional_arguments)

	return(parser)
Пример #4
0
def get_args(args):
    program = "ledgerbil/main.py inv"
    description = dedent("""\
        Viewing shares with --exchange is kind of weird in ledger. This creates
        a report that shows share totals and dollar amounts in a nicer way.
    """)
    parser = argparse.ArgumentParser(
        prog=program,
        description=description,
        formatter_class=(lambda prog: argparse.RawDescriptionHelpFormatter(
            prog, max_help_position=40, width=71)),
    )
    default_accounts = get_setting("INVESTMENT_DEFAULT_ACCOUNTS")
    parser.add_argument(
        "-a",
        "--accounts",
        type=str,
        default=default_accounts,
        help=f"balances for specified accounts (default: {default_accounts})",
    )
    default_end_date = get_setting("INVESTMENT_DEFAULT_END_DATE")
    parser.add_argument(
        "-e",
        "--end",
        type=str,
        metavar="DATE",
        default=default_end_date,
        help=f"end date (default: {default_end_date})",
    )
    parser.add_argument("-c",
                        "--command",
                        action="store_true",
                        help="print ledger commands used")

    return parser.parse_args(args)
Пример #5
0
def createParser():
    '''create cli options'''
    myFormater = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=25, width=190)
    parser = argparse.ArgumentParser(formatter_class=myFormater)
    parser.add_argument('--debug',
                        help='Turn on debug mode',
                        action='store_true')
    polygon_group = parser.add_mutually_exclusive_group()
    polygon_group.add_argument(
        '-p',
        '--poly',
        help=
        'Polygon of area that will be used for validation. Point should be splited by spaces. Format "lat1,lon1 lat2,lon2 ...".  Example "14.01,10.1 15,10.5 14.5,12.7"'
    )
    polygon_group.add_argument('-s',
                               '--sas-polygon',
                               help='File with polygon in SASplanet format',
                               type=argparse.FileType('r'))

    #TODO
    parser.add_argument(
        '-f',
        '--file',
        help=
        'File what html will be saved. If omitted, will be print html to stdout.'
    )
    #output file format
    return parser
Пример #6
0
def parse():
    """ parse arguments """

    intro = """\
        With this script you can add/replace/destroy a CNAME record on Infoblox
        -----------------------------------------------------------------------
        Adding: iblox.py --host test-foo01.bar.com --txt "txt string here"
        Removing: iblox.py --txt foo.bar.com --destroy
        Hint: If you add a txt, you will implicitly replace any existing entry which is
              different from the one provided to the script
         """
    parser = argparse.ArgumentParser(
        formatter_class=lambda prog: argparse.RawDescriptionHelpFormatter(
            prog, max_help_position=29),
        description=textwrap.dedent(intro),
        epilog="Author: Massimiliano Adamo <*****@*****.**>")

    parser.add_argument(
        '--host', help='existing host name. Mandatory when creating a txt')
    parser.add_argument('--txt',
                        help='txt to create. Mandatory',
                        required=True)
    parser.add_argument('--network',
                        help='network Internal/External',
                        choices=['External', 'Internal'],
                        required=True)
    parser.add_argument('--destroy', help='destroy txt', action='store_true')

    return parser.parse_args()
Пример #7
0
def add_heatmap_arguments(parser):

	#---------------- Parse arguments ---------------#
	parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=40, width=90)
	description = "PlotHeatmap plots a heatmap of signals from bigwig(s) (each row is one site) as well as the aggregate signal across all sites."
	parser.description = format_help_description("PlotHeatmap", description)
	
	parser._action_groups.pop()	#pop -h
	
	IO = parser.add_argument_group('Input / output arguments')
	IO.add_argument('--TFBS', metavar="", nargs="*", action='append', help="TFBS sites per column (*required)")	#if more than one, set to next column
	IO.add_argument('--signals', metavar="", nargs="*", help="Signals in bigwig format (*required)")
	IO.add_argument('--output',  metavar="", help="Output filename (default: TOBIAS_heatmap.pdf)", default="TOBIAS_heatmap.pdf")

	PLOT = parser.add_argument_group('Plot arguments')
	PLOT.add_argument('--plot-boundaries', help="Plot TFBS boundaries", action='store_true')
	PLOT.add_argument('--share-colorbar', help="Share colorbar across all bigwigs (default: estimate colorbar per bigwig)", action='store_true')
	PLOT.add_argument('--flank', metavar="", help="", type=int, default=75)
	
	PLOT.add_argument('--title', metavar="", default="TOBIAS heatmap")
	PLOT.add_argument('--TFBS-labels', metavar="", nargs="*", action='append', help="Labels of TFBS (default: basename of --TFBS)")
	PLOT.add_argument('--signal-labels', metavar="", nargs="*", help="Labels of signals (default: basename of --signals)")

	PLOT.add_argument('--show-columns', nargs="*", metavar="", type=int, help="Show scores from TFBS column besides heatmap. Set to 0-based python coordinates (for example -1 for last column) (default: None)", default=[])
	PLOT.add_argument('--sort-by', metavar="", help="Columns in .bed to sort heatmap by (default: input .beds are not sorted)", type=int)

	RUN = parser.add_argument_group('Run arguments')
	RUN = add_logger_args(RUN)

	return(parser)
Пример #8
0
def parse():
    """ parse arguments """

    intro = """\
        With this script you can add/replace/destroy A and AAAA record on Infoblox
        --------------------------------------------------------------------------
        Adding: iblox_record.py --host foo.bar.com --ipv4 192.168.0.10 --ipv6 2a00:1450:4009:810::2009
        Removing: iblox_record --host foo.bar.com --destroy
        Hint: If you add a record, you will implicitly replace any existing entry which is
              different from the one provided to the script
         """
    parser = argparse.ArgumentParser(
        formatter_class=lambda prog: argparse.RawDescriptionHelpFormatter(
            prog, max_help_position=33),
        description=textwrap.dedent(intro),
        epilog="Author: Massimiliano Adamo <*****@*****.**>")

    parser.add_argument('--host', help='host name', required=True)
    parser.add_argument('--network',
                        help='network Internal/External',
                        choices=['External', 'Internal'],
                        required=True)
    parser.add_argument('--ipv6', help='IPv6, optional', required=False)
    parser.add_argument('--ipv4',
                        help='IPv4, mandatory when creating a record',
                        required=False)
    parser.add_argument('--destroy',
                        help='destroy record',
                        action='store_true')

    return parser.parse_args()
Пример #9
0
def add_log2table_arguments(parser):

    parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=40, width=90)
    description = "Log2Table creates tables of footprint depth (FPD) and aggregate correlations from the PlotAggregate logfiles."
    parser.description = format_help_description("Log2Table", description)

    parser._action_groups.pop()  #pop -h

    #Required arguments
    required = parser.add_argument_group('Required arguments')
    required.add_argument('--logfiles',
                          nargs="*",
                          metavar="",
                          help="Logfiles from PlotAggregate")
    required.add_argument(
        '--outdir',
        metavar="",
        help="Output directory for tables (default: current dir)",
        default=".")
    required.add_argument('--prefix',
                          metavar="",
                          help="Prefix of output files",
                          default="aggregate")

    return (parser)
Пример #10
0
def add_tracks_arguments(parser):

	parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=40, width=90)
	description = "Plot genomic tracks (such as cutsite or footprint scores) in specific genomic regions.\n"
	description += "This function is a wrapper for the svist4get package (Artyom A. Egorov, \"svist4get: a simple visualization tool for genomic tracks from sequencing experiments\", BMC Bioinformatics, Volume 20, 2019, 113)"
	description += " which allows for automatic creation of multiple plots by using bigwigs/bedfiles."
	parser.description = format_help_description("PlotTracks", description)
	parser._action_groups.pop()		#pop -h

	IO = parser.add_argument_group('Input / output arguments')
	IO.add_argument('--bigwigs', metavar="",  action='append', nargs="*", help="One or more bigwigs to show. Note: All bigwigs within one \"--bigwigs\" argument will be normalized to each other. " + 
																				"It is possible to give multiple \"--bigwigs\" arguments, which will be normalized independently per group (required)", default=[])
	IO.add_argument('--regions', metavar="", help="Genomic regions to plot (required)")
	IO.add_argument('--sites', metavar="", help="Genomic sites to show in plot (optional)")
	IO.add_argument('--highlight', metavar="", help="Regions to highlight in plot (optional)")
	IO.add_argument('--gtf', metavar="", help="GTF file containing genes to show (optional)")

	IO.add_argument('--width', metavar="", help="Width of plot in cm (default 15)", type=float, default=15)
	#IO.add_argument('--height', metavar="")
	IO.add_argument('--colors', metavar="", nargs="*", help="List of specific colors to use for plotting tracks", default=None)
	IO.add_argument('--labels', metavar="", nargs="*", help="Labels for tracks (default: prefix of bigwig)")
	IO.add_argument('--max-transcripts', metavar="", type=int, help="Set a limit on number of transcripts per gene shown in plot (default: 1)", default=1)

	IO.add_argument('--outdir', metavar="", help="Output folder (default: plottracks_output)", default="plottracks_output")
	IO = add_logger_args(IO)
	
	return(parser)
Пример #11
0
def process_options(args: List[str]) -> Options:
    options = Options()
    # Make the help output a little less jarring.
    help_factory = (lambda prog: argparse.RawDescriptionHelpFormatter(
        prog=prog, max_help_position=28))

    parser = argparse.ArgumentParser(prog='create_pyproj',
                                     fromfile_prefix_chars='@',
                                     formatter_class=help_factory)
    parser.add_argument(
            "-p", "--path", metavar='create template file path',
            nargs=1, help="[optional] create template file path")
    # parser.add_argument('--text', action='store_true')

    parser.add_argument(
            "-a", "--auth", metavar='set auth name',
            nargs=1, help="[optional] auth name")
 
    args = parser.parse_args()

    if args.path:
        options.path = args.path[0]

    if args.auth:
        options.auth = args.auth[0]

    return options
Пример #12
0
def cli():

    import textwrap
    import argparse

    if "--version" in sys.argv:
        print(__version__)
        sys.exit(0)

    description = textwrap.dedent(
        """
    Example Usage:

    Convert single docx file in-place from myfile.docx to myfile.pdf:
        docx2pdf myfile.docx

    Batch convert docx folder in-place. Output PDFs will go in the same folder:
        docx2pdf myfolder/

    Convert single docx file with explicit output filepath:
        docx2pdf input.docx output.docx

    Convert single docx file and output to a different explicit folder:
        docx2pdf input.docx output_dir/

    Batch convert docx folder. Output PDFs will go to a different explicit folder:
        docx2pdf input_dir/ output_dir/
    """
    )

    formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=32
    )
    parser = argparse.ArgumentParser(
        description=description, formatter_class=formatter_class
    )
    parser.add_argument(
        "input",
        help="input file or folder. batch converts entire folder or convert single file",
    )
    parser.add_argument("output", nargs="?", help="output file or folder")
    parser.add_argument(
        "--keep-active",
        action="store_true",
        default=False,
        help="prevent closing word after conversion",
    )
    parser.add_argument(
        "--version", action="store_true", default=False, help="display version and exit"
    )

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(0)
    else:
        args = parser.parse_args()

    convert(args.input, args.output, args.keep_active)
Пример #13
0
def add_scorebed_arguments(parser):

    parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=40, width=90)
    description = "ScoreBed is a utility to score .bed-file regions with values from a .bigwig-file. The output is a .bed-file with the bigwig value(s) as extra column(s). Options --position and --math can be used to adjust scoring scheme."
    parser.description = format_help_description("ScoreBed", description)

    parser._action_groups.pop()  #pop -h

    #Required arguments
    required = parser.add_argument_group('Required arguments')
    required.add_argument('--bed',
                          metavar="",
                          help="Sites to score (.bed file)")
    required.add_argument(
        '--bigwigs',
        metavar="",
        nargs="*",
        help="Scores to assign to regions in .bed (.bw file(s))")

    #Optional arguments
    optional = parser.add_argument_group('Optional arguments')
    optional.add_argument(
        '--output',
        metavar="",
        help=
        "Path to output .bed-file (default: scored sites are written to stdout)"
    )
    optional.add_argument(
        '--subset',
        metavar="",
        help=
        "Subset scoring to .bed regions and set all other sites to --null value (default: all sites in input file will be scored)"
    )
    optional.add_argument(
        '--null',
        metavar="",
        help=
        "If --subset is given, which score/label to add to non-scored regions (default: 0)",
        default="0",
        type=float)
    optional.add_argument(
        '--position',
        metavar="",
        help="Position in sites to score (start/mid/end/full) (default: full)",
        choices=["mid", "start", "end", "full"],
        default="full")
    optional.add_argument(
        '--math',
        metavar="",
        help=
        "If position == full, choose math to perform on signal (min/max/mean/sum) (default: mean)",
        choices=["min", "max", "mean", "sum"],
        default="mean")
    optional = add_logger_args(optional)
    #optional.add_argument('--buffer', metavar="", help="Lines to buffer before writing (default: 10000)", type=int, default=10000)

    return (parser)
Пример #14
0
def parse():
    """Parse options thru argparse and run it..."""
    intro = """\
         Use this script to bootstrap, join nodes within a Galera Cluster
         ----------------------------------------------------------------
           Avoid joining more than one node at once!
         """
    parser = argparse.ArgumentParser(
        formatter_class=lambda prog: argparse.RawDescriptionHelpFormatter(
            prog, max_help_position=29),
        description=textwrap.dedent(intro),
        epilog="Author: Massimiliano Adamo <*****@*****.**>")
    parser.add_argument('-cg',
                        '--check-galera',
                        help='check if all nodes are healthy',
                        action='store_true',
                        dest='Cluster(None, None).checkonly()',
                        required=False)
    parser.add_argument('-dr',
                        '--dry-run',
                        help='show SQL statements to run on this cluster',
                        action='store_true',
                        dest='Cluster(None, None).show_statements()',
                        required=False)
    parser.add_argument('-je',
                        '--join-existing',
                        help='join existing Cluster',
                        action='store_true',
                        dest='Cluster("existing", "existing").joincluster()',
                        required=False)
    parser.add_argument('-be',
                        '--bootstrap-existing',
                        help='bootstrap existing Cluster',
                        action='store_true',
                        dest='Cluster(None, "existing").createcluster()',
                        required=False)
    parser.add_argument('-jn',
                        '--join-new',
                        help='join new Cluster',
                        action='store_true',
                        dest='Cluster("new", "new").joincluster()',
                        required=False)
    parser.add_argument('-bn',
                        '--bootstrap-new',
                        action='store_true',
                        help='bootstrap new Cluster',
                        dest='Cluster(None, "new").createcluster()',
                        required=False)
    parser.add_argument('-f',
                        '--force',
                        action='store_true',
                        help='force bootstrap new or join new Cluster',
                        required=False)

    return parser.parse_args()
Пример #15
0
def add_subsample_arguments(parser):

    parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=40, width=100)
    description = "Subsample a .bam-file into random subsets (of percentage size --start to --end with step --step).\n"
    description = "NOTE: Requires 'samtools' command available at runtime."
    parser.description = format_help_description("SubsampleBam", description)

    parser._action_groups.pop()  #pop -h

    #Required arguments
    args = parser.add_argument_group('Input arguments')
    args.add_argument('--bam', metavar="", help="Path to .bam-file")
    args.add_argument('--no_rand',
                      metavar="",
                      type=int,
                      help="Number of randomizations (per step) (default: 3)",
                      default=3)
    args.add_argument('--start',
                      metavar="",
                      type=int,
                      help="Start of percent subsample (default: 0)",
                      default=0)
    args.add_argument('--end',
                      metavar="",
                      type=int,
                      help="End of percent subsample (default: 100)",
                      default=100)
    args.add_argument('--step',
                      metavar="",
                      type=int,
                      help="Step between --start and --end (default: 10)",
                      default=10)
    args.add_argument('--cores',
                      metavar="",
                      type=int,
                      help="Cores for multiprocessing (default: 1)",
                      default=1)
    args.add_argument('--outdir',
                      metavar="",
                      help="Output directory (default: subsamplebam_output)",
                      default="subsamplebam_output")
    args.add_argument('--prefix',
                      metavar="",
                      help="Prefix for output files (default: prefix of .bam)")
    args.add_argument(
        '--force',
        action="store_true",
        help=
        "Force creation of subsampled .bam-files (default: only create if not existing)"
    )
    args = add_logger_args(args)

    return (parser)
Пример #16
0
def add_mergepdf_arguments(parser):

	parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=40, width=90)
	description = "Merge single PDF-files to one file"
	parser.description = format_help_description("MergePDF", description)
	parser._action_groups.pop()	#pop -h

	reqargs = parser.add_argument_group('Required arguments')
	reqargs.add_argument('--input', metavar="", nargs="*", help="PDF files to join")
	reqargs.add_argument('--output', metavar="", help="Path to output file (default: ./merged.pdf)", default="merged.pdf")

	return(parser)
Пример #17
0
def add_clustering_arguments(parser):

    parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=40, width=90)
    description = ""
    parser.description = format_help_description("ClusterTFBS", description)

    parser._action_groups.pop()  #pop -h

    args = parser.add_argument_group('Arguments')
    args.add_argument(
        '-b',
        '--bedfiles',
        metavar="",
        nargs="*",
        help="Bedfile(s) containing TFBS sites with name in the 4th column")
    args.add_argument(
        '-o',
        '--outdir',
        metavar="",
        help="Path of output folder (default: current directory)",
        default=".")
    args.add_argument('-p',
                      '--prefix',
                      metavar="",
                      help="Prefix of output files (default: ClusterTFBS)",
                      default="ClusterTFBS")
    args.add_argument(
        '-c',
        '--cores',
        metavar="<int>",
        type=int,
        help="Number of cores to use for computation (default: 1)",
        default=1)
    args.add_argument('--threshold',
                      metavar="<float>",
                      help="Threshold for clustering (default: 0.5)",
                      type=lambda f: restricted_float(f, 0, 1),
                      default=0.5)
    args.add_argument(
        '--method',
        metavar="",
        help=
        "Method for hierarchical clustering (single/complete/average/weighted/centroid/median/ward) (default: complete)",
        choices=[
            "single", "complete", "average", "weighted", "centroid", "median",
            "ward"
        ],
        default="complete")
    args = add_logger_args(args)

    return (parser)
Пример #18
0
def add_subsample_arguments(parser):

    parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=40, width=100)
    description = ""
    parser.description = format_help_description("SubsampleBam", description)

    parser._action_groups.pop()  #pop -h

    #Required arguments
    args = parser.add_argument_group('Input arguments')
    args.add_argument('--bam', metavar="", help="Path to .bam-file")
    args.add_argument('--no_rand',
                      metavar="",
                      type=int,
                      help="Number of randomizations (per step) (default: 3)",
                      default=3)
    args.add_argument('--start',
                      metavar="",
                      type=int,
                      help="Start of percent subsample (default: 0)",
                      default=0)
    args.add_argument('--end',
                      metavar="",
                      type=int,
                      help="End of percent subsample (default: 100)",
                      default=100)
    args.add_argument('--step',
                      metavar="",
                      type=int,
                      help="Step between --start and --end (default: 10)",
                      default=10)
    args.add_argument('--cores',
                      metavar="",
                      type=int,
                      help="Cores for multiprocessing (default: 1)",
                      default=1)
    args.add_argument(
        '--outdir',
        metavar="",
        help="Output directory (default: current working directory)",
        default=".")
    args.add_argument('--prefix',
                      metavar="",
                      help="Prefix for output files (default: prefix of .bam)")
    args = add_logger_args(args)

    return (parser)
Пример #19
0
def get_args(args):
    program = 'ledgerbil/main.py pass'
    description = dedent('''\
        Pass through args to ledger, running ledger with config from
        settings.py
    ''')
    parser = argparse.ArgumentParser(
        prog=program,
        description=description,
        formatter_class=(lambda prog: argparse.RawDescriptionHelpFormatter(
            prog, max_help_position=40, width=71)))
    parser.add_argument('--command',
                        action='store_true',
                        help='print ledger command used')
    args, ledger_args = parser.parse_known_args(args)
    return args, tuple(ledger_args)
Пример #20
0
def add_downloaddata_arguments(parser):

    parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=40, width=90)
    description = "Download test data for the TOBIAS commandline examples"
    parser.description = format_help_description("DownloadData", description)

    parser._action_groups.pop()  #pop -h

    arguments = parser.add_argument_group('Arguments')
    arguments.add_argument(
        '--endpoint',
        metavar="",
        help="Link to the s3 server (default: The loosolab s3 server)",
        default="https://s3.mpi-bn.mpg.de")
    arguments.add_argument(
        '--bucket',
        metavar="",
        help="Name of bucket to download (default: data-tobias-2020)",
        default="data-tobias-2020")
    #arguments.add_argument('--target', metavar="", help="Name of directory to save files to (default: name of bucket)")
    arguments.add_argument(
        '--patterns',
        metavar="",
        help="List of patterns for files to download e.g. '*.txt' (default: *)",
        default="*")
    arguments.add_argument('--username',
                           metavar="",
                           help="Username for endpoint (default: None set)")
    arguments.add_argument("--key",
                           metavar="",
                           help="Access key for endpoint (default: None set)")
    arguments.add_argument(
        "--yaml",
        metavar="",
        help=
        "Set the endpoint/bucket/access information through a config file in .yaml format (NOTE: overwrites commandline arguments)"
    )
    arguments.add_argument(
        "--force",
        action="store_true",
        help="Force download of already existing files (default: warn and skip)"
    )

    arguments = add_logger_args(arguments)

    return parser
Пример #21
0
def add_formatmotifs_arguments(parser):

    parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=40, width=90)
    description = ""
    parser.description = format_help_description("FormatMotifs", description)

    parser._action_groups.pop()  #pop -h

    #Required arguments
    required = parser.add_argument_group('Required arguments')
    required.add_argument('--input',
                          metavar="",
                          nargs="*",
                          help="One or more input motif files (required)")
    required.add_argument(
        '--output',
        metavar="",
        help=
        "If task == join, output is the joined output file; if task == split, output is a directory (required)"
    )

    additional = parser.add_argument_group('Additional arguments')
    additional.add_argument(
        '--format',
        metavar="",
        help=
        "Desired motif output format (pfm, jaspar, meme) (default: \"jaspar\")",
        choices=["pfm", "jaspar", "meme"],
        default="jaspar")
    additional.add_argument(
        '--task',
        metavar="",
        help=
        "Which task to perform on motif files (join/split) (default: join)",
        choices=["join", "split"],
        default="join")
    additional.add_argument(
        '--filter',
        metavar="",
        help=
        "File containing list of motif names/ids to filter on. Only motifs fitting entries in filter will be output."
    )
    additional = add_logger_args(additional)

    return (parser)
Пример #22
0
def get_args(args):
    program = "ledgerbil/main.py pass"
    description = dedent("""\
        Pass through args to ledger, running ledger with config from
        settings.py
    """)
    parser = argparse.ArgumentParser(
        prog=program,
        description=description,
        formatter_class=(lambda prog: argparse.RawDescriptionHelpFormatter(
            prog, max_help_position=40, width=71)),
    )
    parser.add_argument("--command",
                        action="store_true",
                        help="print ledger command used")
    args, ledger_args = parser.parse_known_args(args)
    return args, tuple(ledger_args)
Пример #23
0
def cli():
    global_description = """
    examples:
    mris search ...
    """
    global_description = textwrap.dedent(global_description)
    formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=32)

    parser = CustomArgumentParser(prog='mris',
                                  description=global_description,
                                  formatter_class=formatter_class)
    subparsers = parser.add_subparsers(dest='command',
                                       parser_class=CustomArgumentParser)
    subparsers.required = True

    shared_parser = argparse.ArgumentParser(add_help=False)
    shared_parser.add_argument('--verbose', default=False, action='store_true')

    def create_search_parser(parent_subparsers, shared_parsers=[]):
        def cli_search(args):
            for listing in itertools.islice(search(), args.limit):
                print(json.dumps(listing))

        parser = parent_subparsers.add_parser('search',
                                              description=global_description,
                                              formatter_class=formatter_class,
                                              help='search',
                                              parents=shared_parsers)

        parser.add_argument('--limit', type=int)
        parser.set_defaults(func=cli_search)

    create_search_parser(subparsers, shared_parsers=[shared_parser])

    args = parser.parse_args()

    if args.verbose:
        logging.basicConfig(
            level=logging.DEBUG,
            format="[%(name)s | Thread: %(thread)d %(threadName)s | "
            "Process: %(process)d %(processName)s] %(asctime)s %(message)s")
        logging.getLogger('requests').setLevel(logging.WARNING)
        logging.getLogger('urllib3').setLevel(logging.WARNING)

    return args
Пример #24
0
def _parse_arguments():
    '''
    Parses the command-line arguments into a global namespace called "args".
    '''
    argparser = argparse.ArgumentParser(
        description=HELP_DESCRIPTION,
        epilog=HELP_EPILOG,
        usage='loot [-c FILE] [-C INT] [-t TABLE]',
        add_help=False,
        formatter_class=lambda prog: argparse.RawDescriptionHelpFormatter(
            prog, max_help_position=45, width=100))
    argparser.add_argument(
        '-c',
        '--config-file',
        default=os.getenv('LOOT_CONFIG_FILE', 'loot.yaml'),
        dest='config_file',
        help=
        'Specifies the configuration file to load loot table definitions from. Defaults to "loot.yaml".',
        metavar='FILE')
    argparser.add_argument(
        '-C',
        '--count',
        default=1,
        dest='count',
        help='Specifies the number of loot rolls to generate. Defaults to "1".',
        metavar='INT',
        type=int)
    argparser.add_argument(
        '-t',
        '--table',
        default='',
        dest='table',
        help=
        'Specifies the name table to start with. Subtables may be specified using a path-like syntax. Defaults to the root table.',
        metavar='TABLE')
    argparser.add_argument('-h',
                           '--help',
                           action='help',
                           help='Displays help and usage information.')
    argparser.add_argument('--no-color',
                           action='store_false',
                           dest='color_output',
                           help='Disables color output to stdout/stderr.')
    global args
    args = argparser.parse_args()
Пример #25
0
def add_atacorrect_arguments(parser):

	parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=35, width=90)

	description = "ATACorrect corrects the cutsite-signal from ATAC-seq with regard to the underlying sequence preference of Tn5 transposase.\n\n"
	description += "Usage:\nTOBIAS ATACorrect --bam <reads.bam> --genome <genome.fa> --peaks <peaks.bed>\n\n"
	description += "Output files:\n"
	description += "\n".join(["- <outdir>/<prefix>_{0}.bw".format(track) for track in ["uncorrected", "bias", "expected", "corrected"]]) + "\n"
	description += "- <outdir>/<prefix>_atacorrect.pdf"
	parser.description = format_help_description("ATACorrect", description)

	parser._action_groups.pop()	#pop -h

	#Required arguments
	reqargs = parser.add_argument_group('Required arguments')
	reqargs.add_argument('-b', '--bam', metavar="<bam>", help="A .bam-file containing reads to be corrected")
	reqargs.add_argument('-g', '--genome', metavar="<fasta>", help="A .fasta-file containing whole genomic sequence")
	reqargs.add_argument('-p', '--peaks', metavar="<bed>", help="A .bed-file containing ATAC peak regions")

	#Optional arguments
	optargs = parser.add_argument_group('Optional arguments')
	optargs.add_argument('--regions-in', metavar="<bed>", help="Input regions for estimating bias (default: regions not in peaks.bed)")
	optargs.add_argument('--regions-out', metavar="<bed>", help="Output regions (default: peaks.bed)")
	optargs.add_argument('--blacklist', metavar="<bed>", help="Blacklisted regions in .bed-format (default: None)") #file containing blacklisted regions to be excluded from analysis")
	optargs.add_argument('--extend', metavar="<int>", type=int, help="Extend output regions with basepairs upstream/downstream (default: 100)", default=100)
	optargs.add_argument('--split-strands', help="Write out tracks per strand", action="store_true")
	optargs.add_argument('--norm-off', help="Switches off normalization based on number of reads", action='store_true')
	optargs.add_argument('--track-off', metavar="<track>", help="Switch off writing of individual .bigwig-tracks (uncorrected/bias/expected/corrected)", nargs="*", choices=["uncorrected", "bias", "expected", "corrected"], default=[])

	optargs = parser.add_argument_group('Advanced ATACorrect arguments (no need to touch)')
	optargs.add_argument('--k_flank', metavar="<int>", help="Flank +/- of cutsite to estimate bias from (default: 12)", type=int, default=12)
	optargs.add_argument('--read_shift', metavar="<int>", help="Read shift for forward and reverse reads (default: 4 -5)", nargs=2, type=int, default=[4,-5])
	optargs.add_argument('--bg_shift', metavar="<int>", type=int, help="Read shift for estimation of background frequencies (default: 100)", default=100)
	optargs.add_argument('--window', metavar="<int>", help="Window size for calculating expected signal (default: 100)", type=int, default=100)
	optargs.add_argument('--score_mat', metavar="<mat>", help="Type of matrix to use for bias estimation (PWM/DWM) (default: DWM)", choices=["PWM", "DWM"], default="DWM")

	runargs = parser.add_argument_group('Run arguments')
	runargs.add_argument('--prefix', metavar="<prefix>", help="Prefix for output files (default: same as .bam file)")
	runargs.add_argument('--outdir', metavar="<directory>", help="Output directory for files (default: current working directory)", default="")
	runargs.add_argument('--cores', metavar="<int>", type=int, help="Number of cores to use for computation (default: 1)", default=1)
	runargs.add_argument('--split', metavar="<int>", type=int, help="Split of multiprocessing jobs (default: 100)", default=100)
	
	runargs = add_logger_args(runargs)

	return(parser)
Пример #26
0
def add_filterfragments_arguments(parser):

	parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=40, width=90)
	description = "FilterFragments can filter out fragments from a .bam-file of paired-end reads based on the overlap with regions in the given .bed-file."
	#description += "Usage: "
	parser.description = format_help_description("FilterFragments", description)

	parser._action_groups.pop()	#pop -h

	IO = parser.add_argument_group('Input / output arguments')
	IO.add_argument('--bam', metavar="", help=".bam-file to filter")
	IO.add_argument('--regions', metavar="", help=".bed-file containing regions to filter fragments from")
	IO.add_argument('--mode', help="Mode 1: Remove fragment if both reads overlap .bed-regions. Mode 2: Remove whole fragment if one read is overlapping .bed-regions (default: 1)", choices=[1,2], default=1)
	IO.add_argument('--output', metavar="", help="Path to the filtered .bam-file (default: <prefix of --bam>_filtered.bam)")
	IO.add_argument('--threads', metavar="", type=int, help="Number of threads used for decompressing/compressing bam (default: 10)", default=10)

	IO = add_logger_args(IO)

	return(parser)
Пример #27
0
def add_bindetect_arguments(parser):

	parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=35, width=90)
	description = "BINDetect takes motifs, signals (footprints) and genome as input to estimate bound transcription factor binding sites and differential binding between conditions. "
	description += "The underlying method is a modified motif enrichment test to see which motifs have the largest differences in signal across input conditions. "
	description += "The output is an in-depth overview of global changes as well as the individual binding site signal-differences.\n\n"
	description += "Usage:\nTOBIAS BINDetect --signals <bigwig1> (<bigwig2> (...)) --motifs <motifs.txt> --genome <genome.fasta> --peaks <peaks.bed>\n\n"
	description += "Output files:\n- <outdir>/<prefix>_figures.pdf\n- <outdir>/<prefix>_results.{txt,xlsx}\n- <outdir>/<prefix>_distances.txt\n"
	description += "- <outdir>/<TF>/<TF>_overview.{txt,xlsx} (per motif)\n- <outdir>/<TF>/beds/<TF>_all.bed (per motif)\n"
	description += "- <outdir>/<TF>/beds/<TF>_<condition>_bound.bed (per motif-condition pair)\n- <outdir>/<TF>/beds/<TF>_<condition>_unbound.bed (per motif-condition pair)\n\n"
	parser.description = format_help_description("BINDetect", description)

	parser._action_groups.pop()	#pop -h
	
	required = parser.add_argument_group('Required arguments')
	required.add_argument('--signals', metavar="<bigwig>", help="Signal per condition (.bigwig format)", nargs="*")
	required.add_argument('--peaks', metavar="<bed>", help="Peaks.bed containing open chromatin regions across all conditions")
	required.add_argument('--motifs', metavar="<motifs>", help="Motif file(s) in pfm/jaspar/meme format", nargs="*")
	required.add_argument('--genome', metavar="<fasta>", help="Genome .fasta file")

	optargs = parser.add_argument_group('Optional arguments')
	optargs.add_argument('--cond-names', metavar="<name>", nargs="*", help="Names of conditions fitting to --signals (default: prefix of --signals)")
	optargs.add_argument('--peak-header', metavar="<file>", help="File containing the header of --peaks separated by whitespace or newlines (default: peak columns are named \"_additional_<count>\")")
	optargs.add_argument('--naming', metavar="<string>", help="Naming convention for TF output files ('id', 'name', 'name_id', 'id_name') (default: 'name_id')", choices=["id", "name", "name_id", "id_name"], default="name_id")
	optargs.add_argument('--motif-pvalue', metavar="<float>", type=lambda x: restricted_float(x, 0, 1), help="Set p-value threshold for motif scanning (default: 1e-4)", default=0.0001)
	optargs.add_argument('--bound-pvalue', metavar="<float>", type=lambda x: restricted_float(x, 0, 1), help="Set p-value threshold for bound/unbound split (default: 0.001)", default=0.001)
	#optargs.add_argument('--volcano-diff-thresh', metavar="<float>", help="", default=0.2)	#not yet implemented
	#optargs.add_argument('--volcano-p-thresh', metavar="<float>", help="", default=0.05)	#not yet implemented

	optargs.add_argument('--pseudo', type=float, metavar="<float>", help="Pseudocount for calculating log2fcs (default: estimated from data)", default=None)
	optargs.add_argument('--time-series', action='store_true', help="Will only compare signals1<->signals2<->signals3 (...) in order of input, and skip all-against-all comparison.")
	optargs.add_argument('--skip-excel', action='store_true', help="Skip creation of excel files - for large datasets, this will speed up BINDetect considerably")

	runargs = parser.add_argument_group("Run arguments")
	runargs.add_argument('--outdir', metavar="<directory>", help="Output directory to place TFBS/plots in (default: bindetect_output)", default="bindetect_output")
	optargs.add_argument('--prefix', metavar="<prefix>", help="Prefix for overview files in --outdir folder (default: bindetect)", default="bindetect")
	runargs.add_argument('--cores', metavar="<int>", type=int, help="Number of cores to use for computation (default: 1)", default=1)
	runargs.add_argument('--split', metavar="<int>", type=int, help="Split of multiprocessing jobs (default: 100)", default=100)
	runargs.add_argument('--debug', help=argparse.SUPPRESS, action='store_true')
	
	runargs = add_logger_args(runargs)

	return(parser)
Пример #28
0
 def parse_args(self, system_arguments: list) -> argparse.Namespace:
     logger.debug('Gathering arguments')
     epilog = """Thank you for using AWSume! Check us out at https://trek10.com"""
     description = """Awsume - A cli that makes using AWS IAM credentials easy"""
     argument_parser = argparse.ArgumentParser(
         prog='awsume',
         description=description,
         epilog=epilog,
         formatter_class=lambda prog: (argparse.RawDescriptionHelpFormatter(
             prog, max_help_position=80, width=80)),  # pragma: no cover
     )
     self.plugin_manager.hook.pre_add_arguments(config=self.config, )
     self.plugin_manager.hook.add_arguments(
         config=self.config,
         parser=argument_parser,
     )
     logger.debug('Parsing arguments')
     args = argument_parser.parse_args(system_arguments)
     logger.debug('Handling arguments')
     if args.refresh_autocomplete:
         autocomplete_file = Path(
             '~/.awsume/autocomplete.json').expanduser()
         result = self.plugin_manager.hook.get_profile_names(
             config=self.config,
             arguments=args,
         )
         profile_names = [y for x in result for y in x]
         json.dump({'profile-names': profile_names},
                   open(autocomplete_file, 'w'))
         exit(0)
     if args.list_plugins:
         for plugin_name, _ in self.plugin_manager.list_name_plugin():
             if 'default_plugins' not in plugin_name:
                 safe_print(plugin_name, color=colorama.Fore.LIGHTCYAN_EX)
         exit(0)
     self.plugin_manager.hook.post_add_arguments(
         config=self.config,
         arguments=args,
         parser=argument_parser,
     )
     args.system_arguments = system_arguments
     return args
Пример #29
0
def add_network_arguments(parser):

    parser.formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=40, width=90)
    description = "Creates a TF-TF gene regulation network from annotated transcription factor binding sites"
    parser.description = format_help_description("CreateNetwork", description)

    parser._action_groups.pop()  #pop -h

    #Required arguments
    required = parser.add_argument_group('Required arguments')
    required.add_argument(
        '--TFBS',
        metavar="",
        help="File(s) containing TFBS (with annotation) to create network from",
        nargs="*")
    required.add_argument('--origin',
                          metavar="",
                          help="File containing mapping of TF <-> origin gene")

    #Optional arguments
    optional = parser.add_argument_group('Optional arguments')
    optional.add_argument('--start',
                          metavar="",
                          help="Name of node to start in (default: all nodes)")
    optional.add_argument(
        '--max-len',
        metavar="",
        help="Maximum number of nodes in paths through graph (default: 4)",
        type=int,
        default=4)
    #optional.add_argument('--unique', action='store_true', help="Only include edges once (default: edges can occur multiple times in case of multiple binding sites)")

    runargs = parser.add_argument_group("Run arguments")
    runargs.add_argument(
        '--outdir',
        metavar="",
        help="Path to output directory (default: createnetwork_output)",
        default="createnetwork_output")
    runargs = add_logger_args(runargs)

    return (parser)
Пример #30
0
def main():

    global_description = """
    examples:

    ssm list
    ssm list --json
    ssm list --path '/prod'
    ssm get /prod/sftp-to-s3/sftp-user-password
    """
    global_description = textwrap.dedent(global_description)

    formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(
        prog, max_help_position=32)

    parser = CustomArgumentParser(description=global_description,
                                  formatter_class=formatter_class)
    parser.register('action', 'parsers', AliasedSubParsersAction)

    shared_parser = argparse.ArgumentParser(add_help=False)
    shared_parser.add_argument('--verbose', default=False, action='store_true')

    subparsers = parser.add_subparsers(dest='command',
                                       parser_class=CustomArgumentParser)
    subparsers.required = True

    make_get_cmd(subparsers, [shared_parser])
    make_list_cmd(subparsers, [shared_parser])
    make_put_cmd(subparsers, [shared_parser])
    make_help_cmd(subparsers, [shared_parser], parent_parser=parser)
    args = parser.parse_args()

    if args.verbose:
        logging.basicConfig(
            level=logging.DEBUG,
            format="[%(name)s | Thread: %(thread)d %(threadName)s | "
            "Process: %(process)d %(processName)s] %(asctime)s %(message)s")
        logging.getLogger('requests').setLevel(logging.WARNING)
        logging.getLogger('urllib3').setLevel(logging.WARNING)

    args.func(args)