Commit ce612252719ae0b6410d1ed1e5518d6f5b2168f1

Authored by Jean-Michel Garant
1 parent 79ab76f2
Exists in stable-0.3 and in 1 other branch master

argparse adapted

Showing 1 changed file with 129 additions and 0 deletions   Show diff stats
screen.py
... ... @@ -18,6 +18,7 @@
18 18  
19 19 from g4base import *
20 20 import os
  21 +import argparse
21 22  
22 23 def apply_network(ann,
23 24 fasta,
... ... @@ -212,5 +213,133 @@ def main():
212 213 else:
213 214 screen_usage(50, 'An option is missing, incorrect or not authorized')
214 215  
  216 +class Formatter(argparse.ArgumentDefaultsHelpFormatter):
  217 + # use defined argument order to display usage
  218 + def _format_usage(self, usage, actions, groups, prefix):
  219 + if prefix is None:
  220 + prefix = 'usage: '
  221 +
  222 + # if usage is specified, use that
  223 + if usage is not None:
  224 + usage = usage % dict(prog=self._prog)
  225 +
  226 + # if no optionals or positionals are available, usage is just prog
  227 + elif usage is None and not actions:
  228 + usage = '%(prog)s' % dict(prog=self._prog)
  229 + elif usage is None:
  230 + prog = '%(prog)s' % dict(prog=self._prog)
  231 + # build full usage string
  232 + action_usage = self._format_actions_usage(actions, groups) # NEW
  233 + usage = ' '.join([s for s in [prog, action_usage] if s])
  234 + # omit the long line wrapping code
  235 + # prefix with 'usage:'
  236 + return '%s%s\n\n' % (prefix, usage)
  237 +
  238 +def arguments():
  239 + """
  240 + Handles arguments
  241 + """
  242 + parser = argparse.ArgumentParser(formatter_class=Formatter,
  243 + prog="screen.py",
  244 + description="Identification of potential RNA G-quadruplexes",
  245 + epilog="G4RNA screener Copyright (C) 2018 Jean-Michel Garant "\
  246 + "This program comes with ABSOLUTELY NO WARRANTY. This is free "\
  247 + "software, and you are welcome to redistribute it under certain "\
  248 + "conditions <http://www.gnu.org/licenses/>.")
  249 + parser.add_argument('FASTA',
  250 + type=argparse.FileType('r'),
  251 + help='FASTA file (.fa .fas)')
  252 + parser.add_argument("-a", "--ann",
  253 + type=argparse.FileType('r'),
  254 + default=os.path.dirname(__file__)+"/G4RNA_2016-11-07.pkl",
  255 + help="Supply a picled ANN (.pkl format)")
  256 + parser.add_argument("-w", "--window",
  257 + type=int,
  258 + default=60,
  259 + help="Window length",
  260 + metavar="INT")
  261 + parser.add_argument("-s", "--step",
  262 + type=int,
  263 + default=10,
  264 + help="Step length between windows",
  265 + metavar="INT")
  266 + parser.add_argument("-b", "--bedgraph",
  267 + action="store_true",
  268 + default=False,
  269 + help="Display output as BedGraph, user must provides columns")
  270 + parser.add_argument("-c", "--columns",
  271 + nargs="+",
  272 + choices=["list", "all", "description", "gene_symbol",
  273 + "mrnaAcc",
  274 + "protAcc",
  275 + "gene_stable_id",
  276 + "transcript_stable_id",
  277 + "full_name",
  278 + "HGNC_id",
  279 + "identifier",
  280 + "source",
  281 + "genome_assembly",
  282 + "chromosome",
  283 + "start",
  284 + "end",
  285 + "strand",
  286 + "range",
  287 + "length",
  288 + "sequence",
  289 + "cGcC",
  290 + "G4H",
  291 + "G4NN",
  292 + ],
  293 + default="description",
  294 + help="Columns to display. To browse available columns use: -c list",
  295 + metavar="")
  296 + parser.add_argument("-v", "--verbose",
  297 + action="store_true",
  298 + default=False,
  299 + help="Verbose output with timed operations")
  300 + parser.add_argument("-e", "--error",
  301 + action="store_true",
  302 + default=False,
  303 + help="Raise errors and exceptions")
  304 +
  305 + return parser
  306 +
  307 +def to_replace_main():
  308 + """
  309 + Functions calls
  310 + """
  311 + args = arguments().parse_args()
  312 + if args.columns == ["list"]:
  313 + splitted_help = arguments().format_help().split(". To browse available columns use:\n\
  314 + -c list (default: description)")
  315 + print("\n\t".join([splitted_help[0],
  316 + "Available columns:",
  317 + "description\t\tDescription as available in fasta (Default)",
  318 + "all \t\tAll of the following except description\n",
  319 + "gene_symbol\t\tGene symbol",
  320 + "mrnaAcc \t\tRefSeq mRNA accession number",
  321 + "protAcc \t\tRefseq protein accession number",
  322 + "gene_stable_id\tEnsembl gene stable ID",
  323 + "transcript_stable_id\tEnsembl transcript stable ID",
  324 + "full_name \t\tGene full name (From HGNC)",
  325 + "HGNC_id \t\tHGNC numeric ID",
  326 + "identifier \t\tIdentifier",
  327 + "source \t\tSource of the data",
  328 + "genome_assembly\tGenome build version",
  329 + "chromosome \t\tChromosome",
  330 + "start \t\tStart position",
  331 + "end \t\tEnd position",
  332 + "strand \t\tCoding strand",
  333 + "range \t\tInitial chromosomic range",
  334 + "length \t\tLength of sequence analyzed",
  335 + "sequence \t\tSequence analyzed",
  336 + "cGcC \t\tcGcC score",
  337 + "G4H \t\tG4Hunter score",
  338 + "G4NN \t\tG4NN score of similitude",
  339 + " \t\t(must be specified to use ANN)",
  340 + splitted_help[1]]))
  341 + print(args)
  342 +
215 343 if __name__ == '__main__':
216 344 main()
  345 +# to_replace_main()
... ...