Ejemplo n.º 1
0
def get_format_choices(input=True):
    mapper = Registry()
    input_formats = sorted(
        set([k[0 if input else 1] for k in mapper.get_conversions()]))
    if input:
        yield ('AUTO', _('auto'))
    for f in input_formats:
        yield (f, f)
Ejemplo n.º 2
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    arg_parser = argparse.ArgumentParser(
        prog="bioconvert",
        description="""Convertor infer the
                                         formats from the first command. We do
                                         not scan the input file. Therefore
                                         users must ensure that their input
                                         format files are properly
                                         formatted.""",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""
Please visit http://bioconvert.readthedocs.org for more information about the
project or formats available.

Bioconvert is an open source collaborative project. Please feel free to 
join us at https://github/biokit/bioconvert
""")

    arg_parser.add_argument(
        "-v",
        "--verbosity",
        default=bioconvert.logger.level,
        help="Set the outpout verbosity.",
        choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
    )
    arg_parser.add_argument("--no-plot", action="store_true")

    args = arg_parser.parse_args(args)

    from bioconvert.core.registry import Registry
    r = Registry()
    info = r.get_info()

    # The available unique converters
    converters = [x for x in info.items()]

    # the number of methods per converter
    data = [info[k] for k, v in info.items()]

    # the number of formats
    A1 = [x[0] for x in list(r.get_conversions())]
    A2 = [x[1] for x in list(r.get_conversions())]
    formats = set(A1 + A2)

    print("Number of formats: {}".format(len(formats)))
    print("Number of converters: {}".format(len(converters)))
    print("Number of methods : {}".format(sum(data)))

    if args.no_plot is False:
        from pylab import hist, clf, xlabel, grid, show
        clf()
        hist(data, range(17), ec="k", zorder=2, align="left")
        xlabel("Number of methods")
        grid(zorder=-1)
        show()
Ejemplo n.º 3
0
def create_graph(filename, format="svg"):
    from bioconvert.core.registry import Registry
    rr = Registry()
    dg = gv.Digraph(filename=filename, format=format)

    for a,b in rr.get_conversions():
        dg.node(a)
        dg.node(b)
        dg.edge(a, b)
    dg.render()
Ejemplo n.º 4
0
    def __call__(self, parser, namespace, values, option_string=None):
        # the -v --verbosity options may not be parsed yet (if located after -f on command line)
        # So I do it myself
        v_nb = ''.join([opt for opt in sys.argv
                        if opt.startswith("-v")]).count('v')

        mapper = Registry()
        print("Available mapping:")
        print("==================")
        for k in sorted(mapper.get_conversions()):
            print("{} -> {}".format(k[0], k[1]))
        sys.exit(0)
Ejemplo n.º 5
0
def create_graph(filename, layout="dot", use_singularity=False):
    """

    :param filename: should end in .png or .svg or .dot

    If extension is .dot, only the dot file is created.
    This is useful if you have issues installing graphviz.
    If so, under Linux you could use our singularity container
    see github.com/cokelaer/graphviz4all

    """
    from bioconvert.core.registry import Registry
    rr = Registry()

    try:
        if filename.endswith(".dot") or use_singularity is True:
            raise
        from pygraphviz import AGraph
        dg = AGraph(directed=True)

        for a, b in rr.get_conversions():
            dg.add_edge(a, b)

        dg.layout(layout)
        dg.draw(filename)

    except:

        dot = """
strict digraph{
    node [label="\\N"];

    """
        nodes = set([item for items in rr.get_conversions() for item in items])

        for node in nodes:
            dot += "\"{}\";\n".format(node)
        for a, b in rr.get_conversions():
            dot += "\"{}\" -> \"{}\";\n".format(a, b)
        dot += "}\n"

        from easydev import TempFile
        from bioconvert import shell
        dotfile = TempFile(suffix=".dot")
        with open(dotfile.name, "w") as fout:
            fout.write(dot)

        dotpath = ""
        if use_singularity:
            from bioconvert.core.downloader import download_singularity_image
            singfile = download_singularity_image(
                "graphviz.simg", "shub://cokelaer/graphviz4all:v1",
                "4288088d91c848e5e3a327282a1ab3d1")

            dotpath = "singularity run {} ".format(singfile)
            on_rtd = environ.get('READTHEDOCS', None) == 'True'
            if on_rtd:
                dotpath = ""

        ext = filename.rsplit(".", 1)[1]
        cmd = "{}dot -T{} {} -o {}".format(dotpath, ext, dotfile.name,
                                           filename)
        try:
            shell(cmd)
        except:
            import os
            os.system(cmd)
Ejemplo n.º 6
0
"""
#################################################
#
from bioconvert.core.registry import Registry

r = Registry()
info = r.get_info()

# The available unique converters
converters = [x for x in info.items()]

# the number of methods per converter
data = [info[k] for k, v in info.items()]

# the number of formats
A1 = [x[0] for x in list(r.get_conversions())]
A2 = [x[1] for x in list(r.get_conversions())]
formats = set(A1 + A2)

print("Number of formats: {}".format(len(formats)))
print("Number of converters: {}".format(len(converters)))
print("Number of methods : {}".format(sum(data)))

#####################################################
from pylab import hist, clf, xlabel, grid

clf()
hist(data, range(17), ec="k", zorder=2, align="left")
xlabel("Number of methods")
grid(zorder=-1)