Cloufield / gwaslab

A Python package for handling and visualizing GWAS summary statistics. https://cloufield.github.io/gwaslab/
GNU General Public License v3.0
118 stars 22 forks source link

Regional plot: AttributeError: 'NoneType' object has no attribute '_get_renderer'" #64

Open noeri-mohamed-hoesein opened 8 months ago

noeri-mohamed-hoesein commented 8 months ago

Hi I have an issue while trying to make a regional plot. I just a loaded in a GL-sumstats object of which I already did a basic_check(). Before this I made a normal Manhattan plot with which I had no issues. I am using the following code:

data_sumstats.plot_mqq(
     mode="r",
    region=(12,111711833,112711833),
    region_grid=True,
    vcf_path="/path/to/vcf/file/for/LD/reference",
    verbose=True,
)

Output: Tue Oct 31 22:56:11 2023 Start to plot manhattan/qq plot with the following basic settings: Tue Oct 31 22:56:11 2023 -Genomic coordinates version: 19... Tue Oct 31 22:56:11 2023 -Genome-wide significance level is set to 5e-08 ... Tue Oct 31 22:56:11 2023 -Raw input contains 8381964 variants... Tue Oct 31 22:56:11 2023 -Plot layout mode is : r Tue Oct 31 22:56:11 2023 -Region to plot : chr12:111711833-112711833. Tue Oct 31 22:56:11 2023 -Checking prefix for chromosomes in vcf files... Tue Oct 31 22:56:12 2023 -No prefix for chromosomes in the VCF files. Tue Oct 31 22:56:17 2023 -Extract SNPs in region : chr12:111711833-112711833... Tue Oct 31 22:56:22 2023 -Extract SNPs in specified regions: 1243 Tue Oct 31 22:56:23 2023 Finished loading specified columns from the sumstats. Tue Oct 31 22:56:23 2023 Start conversion and sanity check: Tue Oct 31 22:56:23 2023 -Removed 0 variants with nan in CHR or POS column ... Tue Oct 31 22:56:23 2023 -Removed 0 varaints with CHR <=0... Tue Oct 31 22:56:23 2023 -Removed 0 variants with nan in P column ... Tue Oct 31 22:56:23 2023 -Sanity check after conversion: 0 variants with P value outside of (0,1] will be removed... Tue Oct 31 22:56:23 2023 -Sumstats P values are being converted to -log10(P)... Tue Oct 31 22:56:23 2023 -Sanity check: 0 na/inf/-inf variants will be removed... Tue Oct 31 22:56:24 2023 -Maximum -log10(P) values is 8.098265896491405 . Tue Oct 31 22:56:24 2023 Finished data conversion and sanity check. Tue Oct 31 22:56:24 2023 Start to load reference genotype... Tue Oct 31 22:56:24 2023 -reference vcf path : /Users/..etc/ Wed Nov 1 00:39:11 2023 -Retrieving index... Wed Nov 1 00:39:11 2023 -Ref variants in the region: 24209 Wed Nov 1 00:39:11 2023 -Matching variants using POS, NEA, EA ... Wed Nov 1 00:39:11 2023 -Calculating Rsq... Wed Nov 1 00:39:11 2023 Finished loading reference genotype successfully! Wed Nov 1 00:39:11 2023 Start to create manhattan plot with 1243 variants: Wed Nov 1 00:39:11 2023 -Extracting lead variant... Wed Nov 1 00:39:12 2023 -Loading gtf files from:default INFO:root:Extracted GTF attributes: ['gene_id', 'gene_name', 'gene_biotype'] Wed Nov 1 00:40:33 2023 -plotting gene track.. Wed Nov 1 00:40:34 2023 -Finished plotting gene track.. Wed Nov 1 00:40:36 2023 -Found 1 significant variants with a sliding window size of 500 kb... Wed Nov 1 00:40:36 2023 Finished creating Manhattan plot successfully! Wed Nov 1 00:40:36 2023 -Skip annotating Wed Nov 1 00:40:36 2023 -Skip saving figures!

Error: { "name": "AttributeError", "message": "'NoneType' object has no attribute '_get_renderer'", "stack": "--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) File ~/miniconda3/envs/gwaslab/lib/python3.8/site-packages/IPython/core/formatters.py:340, in BaseFormatter.call(self, obj) 338 pass 339 else: --> 340 return printer(obj) 341 # Finally look for special method names 342 method = get_real_method(obj, self.print_method)

File ~/miniconda3/envs/gwaslab/lib/python3.8/site-packages/IPython/core/pylabtools.py:152, in print_figure(fig, fmt, bbox_inches, base64, kwargs) 149 from matplotlib.backend_bases import FigureCanvasBase 150 FigureCanvasBase(fig) --> 152 fig.canvas.print_figure(bytes_io, kw) 153 data = bytes_io.getvalue() 154 if fmt == 'svg':

File ~/miniconda3/envs/gwaslab/lib/python3.8/site-packages/matplotlib/backend_bases.py:2353, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs) 2350 bbox_inches = bbox_inches.padded(pad_inches) 2352 # call adjust_bbox to save only the given area -> 2353 restore_bbox = _tight_bbox.adjust_bbox( 2354 self.figure, bbox_inches, self.figure.canvas.fixed_dpi) 2356 _bbox_inches_restore = (bbox_inches, restore_bbox) 2357 else:

File ~/miniconda3/envs/gwaslab/lib/python3.8/site-packages/matplotlib/_tight_bbox.py:28, in adjust_bbox(fig, bbox_inches, fixed_dpi) 26 locator = ax.get_axes_locator() 27 if locator is not None: ---> 28 ax.apply_aspect(locator(ax, None)) 29 locator_list.append(locator) 30 current_pos = ax.get_position(original=False).frozen()

File ~/miniconda3/envs/gwaslab/lib/python3.8/site-packages/matplotlib/colorbar.py:156, in _ColorbarAxesLocator.call(self, ax, renderer) 154 def call(self, ax, renderer): 155 if self._orig_locator is not None: --> 156 pos = self._orig_locator(ax, renderer) 157 else: 158 pos = ax.get_position(original=True)

File ~/miniconda3/envs/gwaslab/lib/python3.8/site-packages/mpl_toolkits/axes_grid1/inset_locator.py:73, in AnchoredLocatorBase.call(self, ax, renderer) 71 def call(self, ax, renderer): 72 self.axes = ax ---> 73 bbox = self.get_window_extent(renderer) 74 px, py = self.get_offset(bbox.width, bbox.height, 0, 0, renderer) 75 bbox_canvas = Bbox.from_bounds(px, py, bbox.width, bbox.height)

File ~/miniconda3/envs/gwaslab/lib/python3.8/site-packages/matplotlib/offsetbox.py:399, in OffsetBox.get_window_extent(self, renderer) 396 def get_window_extent(self, renderer=None): 397 # docstring inherited 398 if renderer is None: --> 399 renderer = self.figure._get_renderer() 400 bbox = self.get_bbox(renderer) 401 try: # Some subclasses redefine get_offset to take no args.

AttributeError: 'NoneType' object has no attribute '_get_renderer'" }

Does this have something to do with the data that is loaded in? Or is there something with my code? I already updated matplotlib.

Cloufield commented 8 months ago

Hi, I am wondering which version of matplotlib you are using now? Previously I met the same error when using matplotlib v3.7.2. But v3.7.1 works fine. Would you please try matplotlib v3.7.1 first?

noeri-mohamed-hoesein commented 8 months ago

Thanks! This seemed to have fixed the problem.