def make_parser(): """The parser.""" parser = argparse.ArgumentParser(add_help=True) parser_grp = parser.add_argument_group('Arguments') parser_grp.add_argument('-i', '--inputfile', help="Path to the GTF file. Default to STDIN", default=sys.stdin, metavar="GTF", type=arg_formatter.FormattedFile( mode='r', file_ext=('gtf', 'gtf.gz'))) parser_grp.add_argument('-o', '--outputfile', help="Output file.", default=sys.stdout, metavar="GTF", type=arg_formatter.FormattedFile(mode='w', file_ext=('gtf'))) parser_grp.add_argument( '-n', '--number', help="The number of transcripts or gene to select.", default=1, metavar="NUMBER", type=arg_formatter.ranged_num(lowest=1, highest=None, linc=True, val_type='int'), required=False) parser_grp.add_argument('-t', '--ft-type', help="The type of feature.", default="transcript", choices=["gene", "transcript"], required=False) parser_grp.add_argument('-s', '--seed-value', help="Seed value for the random number generator.", default=None, metavar="SEED", type=arg_formatter.ranged_num(lowest=1, highest=None, linc=True, val_type='int'), required=False) return parser
def make_parser(): """The parser.""" parser = argparse.ArgumentParser(add_help=True) parser_grp = parser.add_argument_group('Arguments') parser_grp.add_argument('-i', '--inputfile', help="Path to the GTF file. Default to STDIN", default=sys.stdin, metavar="GTF", type=arg_formatter.FormattedFile( mode='r', file_ext=('gtf', 'gtf.gz'))) parser_grp.add_argument('-o', '--outputfile', help="Output file.", default=sys.stdout, metavar="GTF", type=arg_formatter.FormattedFile(mode='w', file_ext=('gtf'))) parser_grp.add_argument( '-m', '--max-transcript', help="The maximum number of transcripts to select for each gene.", default=1, metavar="MAX", type=arg_formatter.ranged_num(lowest=1, highest=None, linc=True, val_type='int'), required=False) parser_grp.add_argument('-s', '--seed-value', help="Seed value for the random number generator.", default=None, metavar="SEED", type=arg_formatter.ranged_num(lowest=1, highest=None, linc=True, val_type='int'), required=False) return parser
def make_parser(): """The main argument parser.""" parser = argparse.ArgumentParser(add_help=True) parser_grp = parser.add_argument_group('Arguments') parser_grp.add_argument('inputfiles', help="Complete paths to the OLOGRAM output files", type=arg_formatter.FormattedFile(mode='r', file_ext=('txt')), nargs='+') parser_grp.add_argument('-pw', '--pdf-width', help='Output pdf file width (inches).', type=arg_formatter.ranged_num(0, None), default=None, required=False) parser_grp.add_argument('-ph', '--pdf-height', help='Output pdf file height (inches).', type=arg_formatter.ranged_num(0, None), default=None, required=False) parser_grp.add_argument('-o', '--output', help="Pdf file name.", default=None, nargs=None, type=arg_formatter.FormattedFile(mode='w', file_ext='pdf'), required=True) parser_grp.add_argument('-l', '--labels', help="A comma separated list of labels.", default=None, type=str, required=False) return parser
def make_parser(): """The program parser.""" parser = argparse.ArgumentParser(add_help=True) parser_grp = parser.add_argument_group('Arguments') parser_grp.add_argument('-i', '--inputfile', help="Path to the GTF file. Default to STDIN", default=sys.stdin, metavar="GTF", type=arg_formatter.FormattedFile( mode='r', file_ext=('gtf', 'gtf.gz'))) parser_grp.add_argument('-o', '--outputfile', help="Output file.", default=sys.stdout, metavar="GTF", type=arg_formatter.FormattedFile(mode='w', file_ext=('gtf'))) parser_grp.add_argument('-k', '--src-key', help='The name of the source key', default=None, type=str, required=True) parser_grp.add_argument('-d', '--dest-key', help='The name of the target key.', default=None, type=str, required=True) parser_grp.add_argument('-n', '--nb-levels', help='The number of levels/classes to create.', default=2, metavar="KEY", type=arg_formatter.ranged_num(lowest=1, highest=None, linc=True, val_type='int'), required=True) parser_grp.add_argument( '-l', '--labels', help="A comma-separated list of labels of size --nb-levels.", default=None, type=str, required=False) parser_grp.add_argument( '-p', '--percentiles', help="Compute --nb-levels classes using percentiles.", action="store_true", required=False) parser_grp.add_argument('-g', '--log', help="Compute breaks based on log-scale.", action="store_true", required=False) parser_grp.add_argument( '-u', '--percentiles-of-uniq', help="Compute percentiles based on non-redondant values.", action="store_true", required=False) parser_grp.add_argument('-r', '--precision', help="The precision used in naming intervals.", type=int, default=2, required=False) return parser
def make_parser(): """The main parser.""" parser = argparse.ArgumentParser(add_help=True) parser_grp = parser.add_argument_group('Arguments') parser_grp.add_argument('-i', '--inputfile', help="A GTF file or bed file. A GTF if <stdin>.", default=sys.stdin, metavar="GTF/BED", type=arg_formatter.FormattedFile( mode='r', file_ext=('bed', 'gtf', 'gtf.gz'))) parser_grp.add_argument('-y', '--bigwiglist', help='A list of Bigwig files (last argument).', type=arg_formatter.FormattedFile( mode='r', file_ext='bigwig'), nargs='+', required=True) parser_grp.add_argument( '-o', '--outputfile', help="Output file name (.zip extension will be added).", default=sys.stdout, metavar="GTF/TXT", required=True, type=argparse.FileType('w')) parser_grp.add_argument('-l', '--labels', help='Bigwig labels (i.e short name version for ' 'plotting).', default=None, type=str, required=False) parser_grp.add_argument('-t', '--ft-type', help='If input is a GTF, the region to analyse.', default='promoter', choices=[ 'promoter', 'tts', 'transcript', 'user_regions', 'single_nuc' ], type=str, required=False) parser_grp.add_argument('-p', '--pseudo-count', help='Pseudo-count to add to all values.', default=0, type=arg_formatter.ranged_num(lowest=0, highest=None, val_type="float", linc=True), required=False) parser_grp.add_argument( '-u', '--upstream', help="Extend the region of interest in 5' by a given value.", default=1000, type=arg_formatter.ranged_num(lowest=0, highest=None, val_type="int", linc=True), required=False) parser_grp.add_argument( '-d', '--downstream', help="Extend the region of interest in 3' by a given value.", default=1000, type=arg_formatter.ranged_num(lowest=0, highest=None, val_type="int", linc=True), required=False) parser_grp.add_argument('-c', '--chrom-info', help='Tabulated file (chr as ' 'column 1, sizes as column 2.)', default=None, action=CheckChromFile, required=True) parser_grp.add_argument('-w', '--bin-nb', help='Split the region into w bins.', default=100, type=arg_formatter.ranged_num(lowest=1, highest=None, val_type="int", linc=True), required=False) parser_grp.add_argument('-k', '--nb-proc', help='Use this many threads to compute coverage.', default=1, type=arg_formatter.ranged_num(lowest=1, highest=None, val_type="int", linc=True), required=False) parser_grp.add_argument('-b', '--bin-around-frac', help="Fraction of bins used in 5' and 3' regions.", default=0.1, type=float, required=False) parser_grp.add_argument( '-zn', '--zero-to-na', help='Use NA not zero when region is undefined in bigwig.', action='store_true', required=False) parser_grp.add_argument( '-nst', '--no-stranded', help='The bins should not be oriented relative to strand.', action='store_true', required=False) return parser
def add_command(cls, cmd): """ Add new argument parser for a command. Note that verbosity, keep-temp and help arguments are added by default.""" # ---------------------------------------------------------------------- # Command help display # ---------------------------------------------------------------------- cmd_desc_list = re.split('\n[ \t]*\n', cmd.desc) cmd_desc_str = " Description: " for i in cmd_desc_list: cmd_desc_str += "\n\n " + textwrap.fill( textwrap.dedent(left_strip_str(i)).strip(), 100, initial_indent=' ', subsequent_indent=' ') cmd.desc = cmd_desc_str if cmd.notes is not None: cmd.notes = cmd.notes.lstrip("\n") cmd.notes = cmd.notes.strip() cmd.notes = cmd.notes.strip("--") cmd.notes = cmd.notes.strip(" ") tokens = cmd.notes.split("--") cmd.desc += "\n\n" + textwrap.fill( textwrap.dedent("Notes:").strip(), 100, initial_indent=' ', subsequent_indent=' ') for i in range(len(tokens)): cmd.desc += "\n" + textwrap.fill( textwrap.dedent(" * " + left_strip_str(tokens[i].strip())).strip(), 100, initial_indent=' ', subsequent_indent=' ') if cmd.references is not None: cmd.references = cmd.references.lstrip("\n") cmd.references = cmd.references.strip() cmd.references = cmd.references.strip("--") cmd.references = cmd.references.strip(" ") tokens = cmd.references.split("--") cmd.desc += "\n\n" + textwrap.fill( textwrap.dedent("References:").strip(), 100, initial_indent=' ', subsequent_indent=' ') for i in range(len(tokens)): cmd.desc += "\n" + textwrap.fill( textwrap.dedent(" * " + left_strip_str(tokens[i].strip())).strip(), 100, initial_indent=' ', subsequent_indent=' ') cmd.desc = re.sub("\-\\\-", "--", cmd.desc) # ---------------------------------------------------------------------- # Define command-wise args # ---------------------------------------------------------------------- if cmd.lang == "Python": group = cmd.parser.add_argument_group( 'Command-wise optional arguments') # help is a default argument for any command group.add_argument("-h", "--help", action="help", help="Show this help message and exit.") # verbose is a default argument of any command group.add_argument("-V", "--verbosity", default=0, type=ranged_num(lowest=0, highest=3, val_type="int", linc=True, hinc=True), help="Set output verbosity ([0-3]).", nargs='?', required=False) # verbose is a default argument of any command group.add_argument("-D", "--no-date", action="store_true", help="Do not add date to output file names.") # verbose is a default argument of any command group.add_argument( "-C", "--add-chr", action="store_true", help="Add 'chr' to chromosome names before printing output.") # keep-temp-file is a default argument of any command group.add_argument("-K", "--tmp-dir", type=str, default=None, help="Keep all temporary files into this folder.", required=False) # keep-temp-file is a default argument of any command group.add_argument( "-A", "--keep-all", action="store_true", help= "Try to keep all temporary files even if process does not terminate normally.", required=False) # logger-file can be used to store the requested command # arguments into a file. group.add_argument( "-L", "--logger-file", type=str, help='Stores the arguments passed to the command into a file.', required=False) # logger-file can be used to store the requested command # arguments into a file. group.add_argument("-W", "--write-message-to-file", type=argparse.FileType('w'), default=None, help='Store all message into a file.', required=False) # Add the command to the list of known command cls.cmd_obj_list[cmd.name] = cmd # Update the global argument parser arg_dict = { 'name': cmd.name, 'formatter_class': ArgFormatter, 'parents': [cmd.parser], 'help': cmd.message, 'add_help': False, 'description': cmd.desc } if cmd.group == 'editing': cls.grp_editing.add_parser(**arg_dict) elif cmd.group == 'information': cls.grp_info.add_parser(**arg_dict) elif cmd.group == 'selection': cls.grp_select.add_parser(**arg_dict) elif cmd.group == 'conversion': cls.grp_convert.add_parser(**arg_dict) elif cmd.group == 'coordinates': cls.grp_coord.add_parser(**arg_dict) elif cmd.group == 'annotation': cls.grp_annot.add_parser(**arg_dict) elif cmd.group == 'ologram': cls.grp_ologram.add_parser(**arg_dict) elif cmd.group == 'sequences': cls.grp_seq.add_parser(**arg_dict) elif cmd.group == 'coverage': cls.grp_cov.add_parser(**arg_dict) elif cmd.group == 'miscellaneous': cls.grp_misc.add_parser(**arg_dict) else: raise ValueError("Unknow group for command : %s" % cmd.name)
def make_parser(): """The program parser.""" parser = argparse.ArgumentParser(add_help=True) parser_grp = parser.add_argument_group('Arguments') parser_mut = parser.add_mutually_exclusive_group(required=False) parser_grp.add_argument('-i', '--inputfile', help="Path to the GTF file. Default to STDIN", default=sys.stdin, metavar="GTF", type=arg_formatter.FormattedFile( mode='r', file_ext=('gtf', 'gtf.gz'))) parser_grp.add_argument('-o', '--outputfile', help="Output file.", default=sys.stdout, metavar="GTF", type=arg_formatter.FormattedFile(mode='w', file_ext=('gtf'))) parser_grp.add_argument('-k', '--key', help='The key name.', default=None, metavar="KEY", type=str, required=False) parser_mut.add_argument('-v', '--value', help='A comma-separated list of values.', default=None, metavar="VALUE", type=str) parser_mut.add_argument( '-f', '--file-with-values', help='A file containing values as a single column.', default=None, metavar="FILE", type=argparse.FileType("r")) parser_grp.add_argument( '-c', '--col', help= 'The column number (one-based) that contains the values in the file. File is tab-delimited.', default=1, metavar="COL", type=arg_formatter.ranged_num(lowest=1, highest=None, linc=True, val_type='int'), required=False) parser_grp.add_argument( '-n', '--invert-match', help= 'Not/invert match. Select lines whose selected key is not associated' ' with the selected values.', action="store_true") parser_grp.add_argument('-b', '--bed-format', help='Ask for bed format output.', action="store_true") parser_grp.add_argument( '-m', '--names', help="If Bed output. The key(s) that should be used as name.", default="gene_id,transcript_id", metavar="NAME", type=str) parser_grp.add_argument( '-s', '--separator', help= "If Bed output. The separator to be used for separating name elements (see -n).", default="|", metavar="SEP", type=str) parser_grp.add_argument( '-l', '--log', help= 'Print some statistics about selected features. To be used in conjunction with -V 1/2.', action="store_true", required=False) parser_mut.add_argument('-t', '--select-transcripts', help='A shortcuts for "-k feature -v transcript".', action="store_true", required=False) parser_mut.add_argument('-g', '--select-genes', help='A shortcuts for "-k feature -v gene".', action="store_true", required=False) parser_mut.add_argument('-e', '--select-exons', help='A shortcuts for "-k feature -v exon".', action="store_true", required=False) parser_mut.add_argument('-d', '--select-cds', help='A shortcuts for "-k feature -v CDS".', action="store_true", required=False) parser_mut.add_argument( '-a', '--select-start-codon', help='A shortcuts for "-k feature -v start_codon".', action="store_true", required=False) return parser
def make_parser(): """The program parser.""" parser = argparse.ArgumentParser(add_help=True) parser_grp = parser.add_argument_group('Arguments') parser_grp.add_argument('--in-file', '-i', metavar='TXT', help='A two columns tab-file. See notes.', default=None, type=arg_formatter.FormattedFile(mode='r', file_ext='txt'), required=True) parser_grp.add_argument('--reference-gene-file', '-r', metavar='TXT', help='The file containing the reference gene list (1 column,' ' transcript ids).' ' No header.', default=None, type=arg_formatter.FormattedFile(mode='r', file_ext='txt'), required=True) parser_grp.add_argument('--out-dir', '-o', help='Name of the output directory.', type=str, metavar='DIR', default="control_list", required=False) parser_grp.add_argument('--log2', '-l', help='If selected, data will be log transformed.', action="store_true", required=False) parser_grp.add_argument('--pseudo-count', '-p', help='The value for a pseudo-count to be added.', type=float, default=0, required=False) parser_grp.add_argument('-pw', '--page-width', help='Output pdf file width (e.g. 7 inches).', type=arg_formatter.ranged_num(lowest=0, highest=None, linc=False, val_type='float'), default=None, required=False) parser_grp.add_argument('-ph', '--page-height', help='Output file height (e.g. 5 inches).', type=arg_formatter.ranged_num(lowest=0, highest=None, linc=False, val_type='float'), default=None, required=False) parser_grp.add_argument('-pf', '--page-format', help='Output file format.', choices=['pdf', 'png'], default='pdf', required=False) parser_grp.add_argument('-dpi', '--dpi', help='Dpi to use.', type=arg_formatter.ranged_num(lowest=0, highest=None, linc=False, val_type='int'), default=300, required=False) parser_grp.add_argument('--skip-first', '-s', help='Indicates that infile hase a header.', action="store_true", required=False) parser_grp.add_argument('--rug', '-u', help='Add rugs to the diagram.', action="store_true", required=False) parser_grp.add_argument('--jitter', '-j', help='Add jittered points.', action="store_true", required=False) parser_grp.add_argument('-if', '--user-img-file', help="Provide an alternative path for the image.", default=None, type=argparse.FileType("w"), required=False) parser_grp.add_argument('-c', '--set-colors', help='Colors for the two sets (comma-separated).', default="#b2df8a,#6a3d9a", type=str, required=False) return parser_grp