示例#1
0
def classifications(ctx, classifications, results, readlevel, readlevel_path):
    """Retrieve performed metagenomic classifications"""

    # basic operation -- just print
    if not readlevel and not results:
        cli_resource_fetcher(ctx, "classifications", classifications)

    # fetch the results
    elif not readlevel and results:
        if len(classifications) != 1:
            log.error(
                "Can only request results data on one Classification at a time"
            )
        else:
            classification = ctx.obj['API'].Classifications.get(
                classifications[0])
            if not classification:
                log.error('Could not find classification {} (404 status code)'.
                          format(classifications[0]))
                return
            results = classification.results(json=True)
            pprint(results, ctx.obj['NOPPRINT'])

    # fetch the readlevel
    elif readlevel is not None and not results:
        if len(classifications) != 1:
            log.error(
                "Can only request read-level data on one Classification at a time"
            )
        else:
            classification = ctx.obj['API'].Classifications.get(
                classifications[0])
            if not classification:
                log.error('Could not find classification {} (404 status code)'.
                          format(classifications[0]))
                return
            tsv_url = classification.readlevel()['url']
            log.info("Downloading tsv data from: {}".format(tsv_url))
            download_file_helper(tsv_url, readlevel_path)

    # both given -- complain
    else:
        log.error(
            "Can only request one of read-level data or results data at a time"
        )
示例#2
0
文件: cli.py 项目: onecodex/onecodex
def documents_list(ctx, json):
    docs_list = cli_resource_fetcher(ctx, "documents", [], print_results=json)

    if json:
        return

    if not docs_list:
        click.echo("You haven't uploaded any files yet, and no files have been shared with you.")
    else:

        def _size_formatter(size):
            suffix = "B"
            if size > 1e9:
                suffix = "GB"
                size /= 1e9
            elif size >= 1e6:
                suffix = "MB"
                size /= 1e6
            elif size >= 1e3:
                suffix = "KB"
                size /= 1e3

            return "%g %s" % (round(size, 2), suffix)

        formatters = ["%-18s", "%-34s", "%-25s", "%-11s", "%-12s"]
        table = [
            ["ID", "Name", "Owner", "Size", "Created On"],
            ["-" * 16, "-" * 32, "-" * 23, "-" * 9, "-" * 10],
        ]

        docs_list = sorted(
            docs_list,
            reverse=True,
            key=lambda x: time.mktime(dateutil.parser.parse(x["created_at"]).timetuple()),
        )

        for doc in docs_list:
            fname = doc["filename"]
            owner = doc["uploader"].email
            table.append(
                [
                    doc["$uri"].split("/")[-1],
                    fname if len(fname) <= 32 else fname[:29] + "...",
                    owner if len(owner) <= 23 else owner[:20] + "...",
                    _size_formatter(doc["size"]) if doc["size"] else "N/A",
                    dateutil.parser.parse(doc["created_at"]).strftime("%Y-%m-%d"),
                ]
            )

        for row in table:
            formatted_row = []
            for formatter, content in zip(formatters, row):
                formatted_row.append(formatter % content)
            click.echo("".join(formatted_row))
示例#3
0
def documents_list(ctx, json):
    docs_list = cli_resource_fetcher(ctx, "documents", [], print_results=json)

    if json:
        return

    if not docs_list:
        click.echo("You haven't uploaded any files yet, and no files have been shared with you.")
    else:

        def _size_formatter(size):
            suffix = "B"
            if size > 1e9:
                suffix = "GB"
                size /= 1e9
            elif size >= 1e6:
                suffix = "MB"
                size /= 1e6
            elif size >= 1e3:
                suffix = "KB"
                size /= 1e3

            return "%g %s" % (round(size, 2), suffix)

        formatters = ["%-18s", "%-34s", "%-25s", "%-11s", "%-12s"]
        table = [
            ["ID", "Name", "Owner", "Size", "Created On"],
            ["-" * 16, "-" * 32, "-" * 23, "-" * 9, "-" * 10],
        ]

        docs_list = sorted(
            docs_list,
            reverse=True,
            key=lambda x: time.mktime(dateutil.parser.parse(x["created_at"]).timetuple()),
        )

        for doc in docs_list:
            fname = doc["filename"]
            owner = doc["uploader"].email
            table.append(
                [
                    doc["$uri"].split("/")[-1],
                    fname if len(fname) <= 32 else fname[:29] + "...",
                    owner if len(owner) <= 23 else owner[:20] + "...",
                    _size_formatter(doc["size"]) if doc["size"] else "N/A",
                    dateutil.parser.parse(doc["created_at"]).strftime("%Y-%m-%d"),
                ]
            )

        for row in table:
            formatted_row = []
            for formatter, content in zip(formatters, row):
                formatted_row.append(formatter % content)
            click.echo("".join(formatted_row))
示例#4
0
文件: cli.py 项目: onecodex/onecodex
def classifications(ctx, classifications, results, readlevel, readlevel_path):
    """Retrieve performed metagenomic classifications"""

    # basic operation -- just print
    if not readlevel and not results:
        cli_resource_fetcher(ctx, "classifications", classifications)

    # fetch the results
    elif not readlevel and results:
        if len(classifications) != 1:
            log.error("Can only request results data on one Classification at a time")
        else:
            classification = ctx.obj["API"].Classifications.get(classifications[0])
            if not classification:
                log.error(
                    "Could not find classification {} (404 status code)".format(classifications[0])
                )
                return
            results = classification.results(json=True)
            pprint(results, ctx.obj["NOPPRINT"])

    # fetch the readlevel
    elif readlevel is not None and not results:
        if len(classifications) != 1:
            log.error("Can only request read-level data on one Classification at a time")
        else:
            classification = ctx.obj["API"].Classifications.get(classifications[0])
            if not classification:
                log.error(
                    "Could not find classification {} (404 status code)".format(classifications[0])
                )
                return
            tsv_url = classification._readlevel()["url"]
            log.info("Downloading tsv data from: {}".format(tsv_url))
            download_file_helper(tsv_url, readlevel_path)

    # both given -- complain
    else:
        log.error("Can only request one of read-level data or results data at a time")
示例#5
0
文件: cli.py 项目: onecodex/onecodex
def samples(ctx, samples):
    """Retrieve uploaded samples"""
    cli_resource_fetcher(ctx, "samples", samples)
示例#6
0
文件: cli.py 项目: onecodex/onecodex
def panels(ctx, panels):
    """Retrieve performed in silico panel results"""
    cli_resource_fetcher(ctx, "panels", panels)
示例#7
0
文件: cli.py 项目: onecodex/onecodex
def analyses(ctx, analyses):
    """Retrieve performed analyses"""
    cli_resource_fetcher(ctx, "analyses", analyses)
示例#8
0
def samples(ctx, samples):
    """Retrieve uploaded samples"""
    cli_resource_fetcher(ctx, "samples", samples)
示例#9
0
def panels(ctx, panels):
    """Retrieve performed in silico panel results"""
    cli_resource_fetcher(ctx, "panels", panels)
示例#10
0
def analyses(ctx, analyses):
    """Retrieve performed analyses"""
    cli_resource_fetcher(ctx, "analyses", analyses)