How to call module written with argparse in iPython notebook

Niels picture Niels · Jun 5, 2015 · Viewed 31.4k times · Source

I am trying to pass BioPython sequences to Ilya Stepanov's implementation of Ukkonen's suffix tree algorithm in iPython's notebook environment. I am stumbling on the argparse component.

I have never had to deal directly with argparse before. How can I use this without rewriting main()?

By the by, this writeup of Ukkonen's algorithm is fantastic.

Answer

tbrittoborges picture tbrittoborges · Jun 5, 2015

An alternative to use argparse in Ipython notebooks is passing a string to:

args = parser.parse_args() (line 303 from the git repo you referenced.)

Would be something like:

parser = argparse.ArgumentParser(
        description='Searching longest common substring. '
                    'Uses Ukkonen\'s suffix tree algorithm and generalized suffix tree. '
                    'Written by Ilya Stepanov (c) 2013')

parser.add_argument(
        'strings',
        metavar='STRING',
        nargs='*',
        help='String for searching',
    )

parser.add_argument(
        '-f',
        '--file',
        help='Path for input file. First line should contain number of lines to search in'
    )

and

args = parser.parse_args("AAA --file /path/to/sequences.txt".split())

Edit: It works