diff --git a/jcvi/apps/base.py b/jcvi/apps/base.py index 100642c3..b1734073 100644 --- a/jcvi/apps/base.py +++ b/jcvi/apps/base.py @@ -54,14 +54,14 @@ def debug(level=logging.DEBUG): debug() -def get_logger(name: str): +def get_logger(name: str, level: int = logging.DEBUG): """Return a logger with a default ColoredFormatter.""" logger = logging.getLogger(name) if logger.hasHandlers(): logger.handlers.clear() - logger.addHandler(RichHandler()) + logger.addHandler(RichHandler(console=Console(stderr=True))) logger.propagate = False - logger.setLevel(logging.INFO) + logger.setLevel(level) return logger diff --git a/jcvi/graphics/base.py b/jcvi/graphics/base.py index 5569a70a..7e9d0ef2 100644 --- a/jcvi/graphics/base.py +++ b/jcvi/graphics/base.py @@ -34,7 +34,6 @@ FancyArrowPatch, FancyBboxPatch, ) -from matplotlib.path import Path from typing import Optional from ..apps.base import datadir, glob, listify, logger, sample_N, which @@ -313,7 +312,6 @@ def savefig(figname, dpi=150, iopts=None, cleanup=True): format = "pdf" try: logger.debug("Matplotlib backend is: %s", mpl.get_backend()) - logger.debug("Attempting save as: %s", figname) plt.savefig(figname, dpi=dpi, format=format) except Exception as e: logger.error("savefig failed with message:\n%s", e) @@ -324,9 +322,9 @@ def savefig(figname, dpi=150, iopts=None, cleanup=True): remove(figname) sys.exit(1) - msg = "Figure saved to `{0}`".format(figname) + msg = f"Figure saved to `{figname}`" if iopts: - msg += " {0}".format(iopts) + msg += f" {iopts}" logger.debug(msg) if cleanup: diff --git a/jcvi/graphics/chromosome.py b/jcvi/graphics/chromosome.py index f726a76e..5f590283 100644 --- a/jcvi/graphics/chromosome.py +++ b/jcvi/graphics/chromosome.py @@ -5,20 +5,20 @@ Legacy script to plot distribution of certain classes onto chromosomes. Adapted from the script used in the Tang et al. PNAS 2010 paper, sigma figure. """ -import logging import sys from itertools import groupby from math import ceil -from natsort import natsorted from typing import Tuple import numpy as np -from jcvi.apps.base import OptionGroup, OptionParser, datafile, sample_N -from jcvi.formats.base import DictFile, get_number -from jcvi.formats.bed import Bed -from jcvi.formats.sizes import Sizes -from jcvi.graphics.base import ( +from natsort import natsorted + +from ..apps.base import OptionGroup, OptionParser, datafile, logger, sample_N +from ..formats.base import DictFile, get_number +from ..formats.bed import Bed +from ..formats.sizes import Sizes +from ..graphics.base import ( CirclePolygon, Polygon, Rectangle, @@ -29,7 +29,7 @@ set1_n, set3_n, ) -from jcvi.graphics.glyph import BaseGlyph, plot_cap +from ..graphics.glyph import BaseGlyph, plot_cap class Chromosome(BaseGlyph): @@ -236,7 +236,7 @@ def __init__( # tip = length of the ticks y1, y2 = sorted((y1, y2)) ax.plot([x, x], [y1, y2], "-", color=fc, lw=2) - max_marker_name, max_chr_len = max(markers, key=lambda x: x[-1]) + _, max_chr_len = max(markers, key=lambda x: x[-1]) r = y2 - y1 ratio = r / max_chr_len marker_pos = {} @@ -314,7 +314,7 @@ def write_ImageMapLine(tlx, tly, brx, bry, w, h, dpi, chr, segment_start, segmen """ tlx, brx = [canvas2px(x, w, dpi) for x in (tlx, brx)] tly, bry = [canvas2px(y, h, dpi) for y in (tly, bry)] - chr, bac_list = chr.split(":") + chr, _ = chr.split(":") return ( '", file=mapfh) mapfh.close() - logging.debug("Image map written to `{0}`".format(mapfh.name)) + logger.debug("Image map written to `%s`", mapfh.name) if gauge: xstart, ystart = 0.9, 0.85 diff --git a/jcvi/graphics/synteny.py b/jcvi/graphics/synteny.py index a344b039..671c757a 100644 --- a/jcvi/graphics/synteny.py +++ b/jcvi/graphics/synteny.py @@ -22,6 +22,7 @@ import numpy as np import matplotlib.transforms as transforms +from matplotlib.path import Path from ..apps.base import OptionParser, logger from ..compara.synteny import BlockFile @@ -31,7 +32,6 @@ markup, plt, savefig, - Path, PathPatch, AbstractLayout, )