def draw(filestems, gformat, logger=None):
    """Draw ANIb/ANIm/TETRA results

    - filestems - filestems for output files
    - gformat - the format for output graphics
    """
    # Draw heatmaps
    for filestem in filestems:
        fullstem = os.path.join(args.outdirname, filestem)
        outfilename = fullstem + '.%s' % gformat
        infilename = fullstem + '.tab'
        df = pd.read_csv(infilename, index_col=0, sep="\t")
        if logger:
            logger.info("Writing heatmap to %s", outfilename)
        params = pyani_graphics.Params(
            params_mpl(df)[filestem], pyani_tools.get_labels(args.labels),
            pyani_tools.get_labels(args.classes))
        if args.gmethod == "mpl":
            pyani_graphics.heatmap_mpl(df,
                                       outfilename=outfilename,
                                       title=filestem,
                                       params=params)
        elif args.gmethod == "seaborn":
            pyani_graphics.heatmap_seaborn(df,
                                           outfilename=outfilename,
                                           title=filestem,
                                           params=params)
def draw(args: Namespace, filestems: List[str], gformat: str) -> None:
    """Draw ANIb/ANIm/TETRA results.

    :param args:  Namespace, command-line arguments
    :param logger: logging object
    :param filestems: - filestems for output files
    :param gformat: - the format for output graphics
    """
    logger = logging.getLogger(__name__)

    # Draw heatmaps
    for filestem in filestems:
        fullstem = args.outdirname / filestem
        outfilename = fullstem.with_suffix(".%s" % gformat)
        infilename = fullstem.with_suffix(".tab")
        dfm = pd.read_csv(infilename, index_col=0, sep="\t")
        logger.info("Writing heatmap to %s", outfilename)
        print(args.labels, args.classes)
        params = pyani_graphics.Params(
            params_mpl(dfm)[filestem],
            pyani_tools.get_labels(args.labels, logger=logger),
            pyani_tools.get_labels(args.classes, logger=logger),
        )
        if args.gmethod == "mpl":
            pyani_graphics.mpl.heatmap(dfm,
                                       outfilename=outfilename,
                                       title=filestem,
                                       params=params)
        elif args.gmethod == "seaborn":
            pyani_graphics.sns.heatmap(dfm,
                                       outfilename=outfilename,
                                       title=filestem,
                                       params=params)
Beispiel #3
0
def draw_format_method(fmt, mth):
    """Render graphics format and method output."""
    inputs = define_inputs()
    outfilename = os.path.join(OUTDIR, "%s.%s" % (mth, fmt))
    stem = "ANIm_percentage_identity"
    df = pd.read_csv(inputs['infilename'], index_col=0, sep="\t")
    os.makedirs(OUTDIR, exist_ok=True)
    fn = {"mpl": pyani_graphics.heatmap_mpl,
          "seaborn": pyani_graphics.heatmap_seaborn}
    params = {"mpl": pyani_config.params_mpl,
              "seaborn": pyani_config.params_mpl}
    method_params = pyani_graphics.Params(params[mth](df)[stem],
                                          inputs['labels'], inputs['classes'])
    fn[mth](df, outfilename, title="%s:%s test" % (mth, fmt),
            params=method_params)
Beispiel #4
0
def draw_format_method(fmt, mth):
    """Render graphics format and method output."""
    inputs = define_inputs()
    outfilename = OUTDIR / f"{mth}.{fmt}"
    stem = "ANIm_percentage_identity"
    df = pd.read_csv(inputs["infilename"], index_col=0, sep="\t")
    OUTDIR.mkdir(exist_ok=True)
    fn = {
        "mpl": pyani_graphics.mpl.heatmap,
        "seaborn": pyani_graphics.sns.heatmap
    }
    params = {
        "mpl": pyani_config.params_mpl,
        "seaborn": pyani_config.params_mpl
    }
    method_params = pyani_graphics.Params(params[mth](df)[stem],
                                          inputs["labels"], inputs["classes"])
    fn[mth](df, outfilename, title=f"{mth}:{fmt} test", params=method_params)
Beispiel #5
0
def draw_format_method(fmt, mth, graphics_inputs, tmp_path):
    """Render graphics format and method output."""
    df = pd.read_csv(graphics_inputs.filename, index_col=0, sep="\t")
    fn = {
        "mpl": pyani_graphics.mpl.heatmap,
        "seaborn": pyani_graphics.sns.heatmap
    }
    params = {
        "mpl": pyani_config.params_mpl,
        "seaborn": pyani_config.params_mpl
    }
    method_params = pyani_graphics.Params(
        params[mth](df)["ANIm_percentage_identity"],
        graphics_inputs.labels,
        graphics_inputs.classes,
    )
    fn[mth](df,
            tmp_path / f"{mth}.{fmt}",
            title=f"{mth}:{fmt} test",
            params=method_params)
Beispiel #6
0
def write_heatmap(
    run_id: int,
    matdata: MatrixData,
    result_labels: Dict,
    result_classes: Dict,
    outfmts: List[str],
    args: Namespace,
    logger: Logger,
) -> None:
    """Write a single heatmap for a pyani run.

    :param run_id:  int, run_id for this run
    :param matdata:  MatrixData object for this heatmap
    :param result_labels:  dict of result labels
    :param result_classes: dict of result classes
    :param args:  Namespace for command-line arguments
    :param outfmts:  list of output formats for files
    :param logger:  logging object
    """
    logger.info(f"Writing {matdata.name} matrix heatmaps")
    cmap = pyani_config.get_colormap(matdata.data, matdata.name)
    for fmt in outfmts:
        outfname = Path(
            args.outdir) / f"matrix_{matdata.name}_run{run_id}.{fmt}"
        logger.info(f"\tWriting graphics to {outfname}")
        params = pyani_graphics.Params(cmap, result_labels, result_classes)
        # Draw heatmap
        GMETHODS[args.method](
            matdata.data,
            outfname,
            title=f"matrix_{matdata.name}_run{run_id}",
            params=params,
        )

    # Be tidy with matplotlib caches
    plt.close("all")