Commit 31b2e166c57c12259095073e1cd3b02fb38e96e5

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

move formatter class towards utils to use in merge program

Showing 2 changed files with 30 additions and 29 deletions   Show diff stats
screen.py
... ... @@ -212,40 +212,12 @@ def legacy_main():
212 212 else:
213 213 screen_usage(50, 'An option is missing, incorrect or not authorized')
214 214  
215   -class Formatter(argparse.HelpFormatter):
216   - """
217   - Extended HelpFormatter class in order to correct the greediness of --columns
218   - that includes the last positional argument. This extension of HelpFormatter
219   - brings the positional argument to the beginning of the command and the
220   - optonal arguments are send to the end.
221   -
222   - This snippet of code was adapted from user "hpaulj" from StackOverflow.
223   - """
224   - # use defined argument order to display usage
225   - def _format_usage(self, usage, actions, groups, prefix):
226   - if prefix is None:
227   - prefix = 'usage: '
228   - # if usage is specified, use that
229   - if usage is not None:
230   - usage = usage % dict(prog=self._prog)
231   - # if no optionals or positionals are available, usage is just prog
232   - elif usage is None and not actions:
233   - usage = '%(prog)s' % dict(prog=self._prog)
234   - elif usage is None:
235   - prog = '%(prog)s' % dict(prog=self._prog)
236   - # build full usage string
237   - action_usage = self._format_actions_usage(actions, groups) # NEW
238   - usage = ' '.join([s for s in [prog, action_usage] if s])
239   - # omit the long line wrapping code
240   - # prefix with 'usage:'
241   - return '%s%s\n\n' % (prefix, usage)
242   -
243 215 def arguments():
244 216 """
245 217 Arguments management
246 218 """
247 219 # declare argument parser using the above adapted HelpFormatter
248   - parser = argparse.ArgumentParser(formatter_class=Formatter,
  220 + parser = argparse.ArgumentParser(formatter_class=utils.Formatter,
249 221 prog=os.path.basename(__file__),
250 222 description="Identification of potential RNA G-quadruplexes",
251 223 epilog="G4RNA screener Copyright (C) 2018 Jean-Michel Garant "\
... ...
utils.py
... ... @@ -18,10 +18,39 @@
18 18  
19 19 import sys
20 20 import regex
  21 +import argparse
21 22 import pandas as pd
22 23 import numpy as np
23 24 from collections import Counter, OrderedDict
24 25  
  26 +class Formatter(argparse.HelpFormatter):
  27 + """
  28 + Extended HelpFormatter class in order to correct the greediness of --columns
  29 + that includes the last positional argument. This extension of HelpFormatter
  30 + brings the positional argument to the beginning of the command and the
  31 + optonal arguments are send to the end.
  32 +
  33 + This snippet of code was adapted from user "hpaulj" from StackOverflow.
  34 + """
  35 + # use defined argument order to display usage
  36 + def _format_usage(self, usage, actions, groups, prefix):
  37 + if prefix is None:
  38 + prefix = 'usage: '
  39 + # if usage is specified, use that
  40 + if usage is not None:
  41 + usage = usage % dict(prog=self._prog)
  42 + # if no optionals or positionals are available, usage is just prog
  43 + elif usage is None and not actions:
  44 + usage = '%(prog)s' % dict(prog=self._prog)
  45 + elif usage is None:
  46 + prog = '%(prog)s' % dict(prog=self._prog)
  47 + # build full usage string
  48 + action_usage = self._format_actions_usage(actions, groups) # NEW
  49 + usage = ' '.join([s for s in [prog, action_usage] if s])
  50 + # omit the long line wrapping code
  51 + # prefix with 'usage:'
  52 + return '%s%s\n\n' % (prefix, usage)
  53 +
25 54 def verbosify(verbose, message, flush=False):
26 55 """
27 56 Take care of the verbosity for the user.
... ...