Ejemplo n.º 1
0
def run():
    """
    Entry point for the script.
    """
    if len(sys.argv) < 2:
        sys.argv.append("-h")
    plac.call(main)
Ejemplo n.º 2
0
def router():
    """
    Route the tasks based on subcommands parameters.
    """

    # Print usage when no parameters are passed.
    if len(sys.argv) == 1:
        print(USAGE)
        sys.exit(1)

    # Lowercase the subcommand.
    sys.argv[1] = sys.argv[1].lower()

    # Check the subcommand.
    cmd = sys.argv[1]

    # Maintain compatibility with a prior use case (convert == view).
    cmd = "convert" if cmd == "view" else cmd

    # Raise an error is not a valid subcommand.
    if cmd not in SUB_COMMANDS:
        print(USAGE, file=sys.stderr)
        logger.error(f"invalid command: {cmd}")
        sys.exit(-1)

    # Remove the command from the list.
    sys.argv.remove(cmd)

    # Allow multiple forms of parameters to be used.
    sys.argv = list(map(proof_reader, sys.argv))

    # Delegate to the imported method
    modfunc, flag, help = SUB_COMMANDS[cmd]

    # Add the help flag if no other information is present beyond command.
    if flag and len(sys.argv) == 1:
        sys.argv.append("-h")

    # Format: module.function
    mod_name, func_name = modfunc.rsplit(".", maxsplit=1)

    # Dynamic imports to allow other functionality
    # to work even when required for certain subcommands may be missing.
    mod = importlib.import_module(mod_name)

    # Get the function of the module
    func = getattr(mod, func_name)

    # Execute the function with plac.
    plac.call(func)
Ejemplo n.º 3
0
def run(cmd, capsys, fname=None):
    """
    Runs a command and returns its out.
    """

    # Ensure the counter starts at zero each time.
    jsonrec.reset_counter()

    # Drop the leading command (bio)
    params = cmd.split()[1:]

    # Different functions to be called based on the command.
    if params and const.ALIGN_COMMAND in params:
        # Run the alignment tests.
        params.remove(const.ALIGN_COMMAND)
        assert plac.call(align.run, params) is None
    elif params and const.TAXON_COMMAND in params:
        # Run the alignment tests.
        params.remove(const.TAXON_COMMAND)
        assert plac.call(taxdb.run, params) is None
    elif params and const.DBLINK_COMMAND in params:
        # Run the alignment tests.
        params.remove(const.DBLINK_COMMAND)
        assert plac.call(dblink.run, params) is None
    else:
        # Run converter commands.
        assert plac.call(convert.run, params) is None

    # Read the standard out
    stream = capsys.readouterr()
    result = stream.out

    # Check the output if we pass expected value here.
    if fname:
        expect = read(fname)
        if expect != result:
            lines1 = expect.splitlines()
            lines2 = result.splitlines()
            diffs = difflib.unified_diff(lines1, lines2)
            print(cmd)
            print(f"File: {fname}")
            print("-" * 10)
            for diff in diffs:
                print(diff)
            assert result == expect

    return result
Ejemplo n.º 4
0
Archivo: main.py Proyecto: Natay/bio-2
def router():
    """
    Routes the tasks based on incoming parameters.
    """

    # Allow multiple forms of parameters to be used.
    sys.argv = list(map(proofreader, sys.argv))

    # Delayed imports to allow other functionality to work even when some required libraries may be missing.

    if const.ALIGN_COMMAND in sys.argv:
        # Run alignment related functionality..
        sys.argv.remove(const.ALIGN_COMMAND)
        from biorun.methods import align
        plac.call(align.run)

    elif const.TAXON_COMMAND in sys.argv:
        # Run taxonomy related functionality.
        from biorun.models import taxdb
        sys.argv.remove(const.TAXON_COMMAND)
        plac.call(taxdb.run)

    elif const.DBLINK_COMMAND in sys.argv:
        # Run SRA specific functionality.
        from biorun.models import dblink
        sys.argv.remove(const.DBLINK_COMMAND)
        plac.call(dblink.run)

    elif const.ONTOLOGY_COMMAND in sys.argv:
        # Run SRA specific functionality.
        from biorun.models import ontology
        sys.argv.remove(const.ONTOLOGY_COMMAND)
        plac.call(ontology.run)

    else:
        # Default action is to convert a file.
        from biorun import convert

        # Add the help flag if no other information is present.
        if len(sys.argv) == 1:
            sys.argv.append("-h")

        # Delegate parameter parsing to converter.
        plac.call(convert.run)
Ejemplo n.º 5
0
def run():
    """
    Entry point for the script.
    """
    plac.call(main)
Ejemplo n.º 6
0
    for word in words:
        json = fetch.get_json(word)
        doubles = [jsonrec.find_taxid(rec) for rec in json] if json else [[]]
        taxids = [elem for sublist in doubles for elem in sublist]
        if taxids:
            terms.extend(taxids)
        else:
            terms.append(word)

    for word in terms:

        if lineage:
            print_lineage(word, names=names, flat=flat)
        else:
            query(word, names=names, graph=graph)

    # No terms listed. Print database stats.
    if not terms:
        print_stats(names=names, graph=graph)


if __name__ == '__main__':
    # Bony fish: 117565
    # Betacoronavirus: 694002
    # SARS-COV2: 2697049

    # Jawless vertebrates: 1476529
    # Vertebrata: 7742

    plac.call(run)
Ejemplo n.º 7
0
def main():
    plac.call(run)