Exemplo n.º 1
0
def fmt(prog):
    return br.CustomHelpFormatter(prog)

parser = argparse.ArgumentParser(prog="PhyloBuddy.py", formatter_class=fmt, add_help=False, usage=argparse.SUPPRESS,
                                 description='''\
\033[1mPhyloBuddy\033[m
Put a little bonsai into your phylogeny.

\033[1mUsage examples\033[m:
PhyloBuddy.py "/path/to/tree_file" -<cmd>
PhyloBuddy.py "/path/to/tree_file" -<cmd> | PhyloBuddy.py -<cmd>
PhyloBuddy.py "(A,(B,C));" -f "raw" -<cmd>
''')

br.flags(parser, ("trees", "Supply file path(s) or raw tree string, If piping trees into PhyloBuddy "
                           "this argument can be left blank."), br.pb_flags, br.pb_modifiers, VERSION)

# This is to allow py.test to work with the -x flag
parser.add_argument("-x", nargs="?")
parser.add_argument("-m", nargs="?")
parser.add_argument("-n", nargs="?")
parser.add_argument("--cov", nargs="?")
parser.add_argument("--cov-report", nargs="?")
in_args = parser.parse_args()


def phylo_to_hash(_phylobuddy, mode='hash'):
    if mode != "hash":
        return str(_phylobuddy)
    _hash = md5("{0}\n".format(str(_phylobuddy).rstrip()).encode()).hexdigest()
    return _hash
Exemplo n.º 2
0
parser = argparse.ArgumentParser(prog="DbBuddy.py", formatter_class=fmt, add_help=False, usage=argparse.SUPPRESS,
                                 description='''
\033[1mDatabaseBuddy\033[m
Go forth to the servers of sequence, and discover.

\033[1mUsage examples\033[m:
DbBuddy.py -ls (launch empty live session)
DbBuddy.py "<accn1,accn2,accn3,...>" -<cmd>
DbBuddy.py "<search term1, search term2,...>" -<cmd>
DbBuddy.py "<accn1,search term1>" -<cmd>
DbBuddy.py "/path/to/file_of_accns" -<cmd>
''')

br.db_modifiers["database"]["choices"] = Db.DATABASES
br.flags(parser, ("user_input", "Specify accession numbers or search terms, "
                                "either in a file or as a comma separated list"),
         br.db_flags, br.db_modifiers, Db.VERSION)

# This is to allow py.test to work with its own flags
in_args = parser.parse_args([])


def mock_cmdloop(*args):
    print(args)
    return True


class MockUsage(object):
    def __init__(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
Exemplo n.º 3
0
def test_flags(capsys, hf):
    contributors = list()
    contributors.append(
        br.Contributor("Bud", "Suite", "D", commits=10, github="buddysuite"))
    contributors.append(
        br.Contributor("Sweet", "Water", commits=5, github="sweetwater"))
    version = br.Version("BudddySuite",
                         "3",
                         "5",
                         contributors,
                         release_date={
                             "day": 13,
                             "month": 7,
                             "year": 2016
                         })

    parser = argparse.ArgumentParser(prog="SeqBuddy.py", add_help=False)
    pos_dict = ("sequence",
                "Supply file path(s) or raw sequence. If piping sequences "
                "into SeqBuddy this argument can be left blank.")
    flag_dict = {
        "annotate": {
            "flag":
            "ano",
            "nargs":
            "*",
            "metavar":
            "args",
            "help":
            "Add a feature (annotation) to selected sequences. "
            "Args: <name>, <location (start1-end1,start2-end2...)>, [strand (+|-)], "
            "[qualifier (foo=bar) [qualifier]], [regex_pattern [regex_[pattern]]}"
        },
        "ave_seq_length": {
            "flag":
            "asl",
            "action":
            "append",
            "nargs":
            "?",
            "metavar":
            "'clean'",
            "help":
            "Calculate average sequence length. Specify 'clean' to remove gaps etc "
            "first"
        }
    }
    mod_dict = {
        "alpha": {
            "flag": "a",
            "action": "store",
            "help": "If you want the file read with a specific alphabet"
        },
        "in_format": {
            "flag":
            "f",
            "action":
            "store",
            "help":
            "If SeqBuddy can't guess the file format, try specifying it directly"
        }
    }

    br.flags(parser,
             _positional=pos_dict,
             _flags=flag_dict,
             _modifiers=mod_dict,
             version=version)
    parser.print_help()
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "9ea2d4ac842b1712687034ea0abf497b"
Exemplo n.º 4
0
def fmt(prog):
    return br.CustomHelpFormatter(prog)

parser = argparse.ArgumentParser(prog="alignBuddy", formatter_class=fmt, add_help=False, usage=argparse.SUPPRESS,
                                 description='''\
\033[1mAlignBuddy\033[m
  Sequence alignments with a splash of kava.

\033[1mUsage examples\033[m:
  AlignBuddy.py "/path/to/align_file" -<cmd>
  AlignBuddy.py "/path/to/align_file" -<cmd> | AlignBuddy.py -<cmd>
  AlignBuddy.py "/path/to/seq_file" -ga "mafft" -p "--auto --thread 8"
''')

br.flags(parser, ("alignments", "The file(s) you want to start working on"),
         br.alb_flags, br.alb_modifiers, VERSION)

# This is to allow py.test to work with its own flags
in_args = parser.parse_args([])


# ###################### argparse_init() ###################### #
def test_argparse_init(capsys, monkeypatch, alb_resources, hf, alb_odd_resources):
    monkeypatch.setattr(sys, 'argv', ['AlignBuddy.py', alb_resources.get_one("o p py", "paths"), "-con",
                                      "-o", "stockholm"])
    temp_in_args, alignbuddy = Alb.argparse_init()
    assert hf.buddy2hash(alignbuddy) == "5d9a03d9e1b4bf72d991257d3a696306"

    monkeypatch.setattr(sys, 'argv', ['AlignBuddy.py', alb_resources.get_one("o p py", "paths"), "-con", "-o", "foo"])
    with pytest.raises(SystemExit):
        Alb.argparse_init()
Exemplo n.º 5
0
                                 formatter_class=fmt,
                                 add_help=False,
                                 usage=argparse.SUPPRESS,
                                 description='''\
\033[1mPhyloBuddy\033[m
Put a little bonsai into your phylogeny.

\033[1mUsage examples\033[m:
PhyloBuddy.py "/path/to/tree_file" -<cmd>
PhyloBuddy.py "/path/to/tree_file" -<cmd> | PhyloBuddy.py -<cmd>
PhyloBuddy.py "(A,(B,C));" -f "raw" -<cmd>
''')

br.flags(
    parser,
    ("trees",
     "Supply file path(s) or raw tree string, If piping trees into PhyloBuddy "
     "this argument can be left blank."), br.pb_flags, br.pb_modifiers,
    VERSION)

# This is to allow py.test to work with its own flags
in_args = parser.parse_args([])


def mock_fileexistserror(*args, **kwargs):
    raise FileExistsError(args, kwargs)


def mock_filenotfounderror(*args, **kwargs):
    raise FileNotFoundError(args, kwargs)