Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when plotting SNP track with no SNPs in plot range #74

Open
alexjcornish opened this issue Oct 24, 2022 · 0 comments
Open

Error when plotting SNP track with no SNPs in plot range #74

alexjcornish opened this issue Oct 24, 2022 · 0 comments

Comments

@alexjcornish
Copy link

Hi there, thanks for such a useful package.

I have encountered a bug when I try to plot a SNP track containing no SNPs in the plotted region.

If I am working with a TSV file:

chr4	15730398	1.6493369536091678e-05
chr4	15730146	1.6493369536091678e-05
chr4	15737348	1.3897495444980216e-05
chr4	15737101	1.3897495444980216e-05

And I try to plot a track like this:

import coolbox
from coolbox.api import *

snp_path = 'data.snp.bgz'
#test_range_no_error = 'chr4:15730000-15738000'
test_range_error = 'chr4:15720000-15728000'

frame = XAxis() + SNP(snp_path, col_chrom=0, col_pos=1, col_pval=2)
frame.plot(test_range_error)

Then I get the error:

[ERROR:frame.py:215 -                 plot()] Error occured when plot track:
	track name: SNP.14
	track type:<class 'coolbox.core.track.hist.snp.SNP'>
	Error: <class 'KeyError'> 'score'
	occurred in "/opt/conda/lib/python3.8/site-packages/coolbox/core/frame/frame.py", line 209
[ERROR:frame.py:222 -                 plot()] 'score'
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 3080, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas/_libs/index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 4554, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 4562, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'score'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/coolbox/core/frame/frame.py", line 209, in plot
    track.plot(ax, copy(gr), gr2=copy(gr2))
  File "/opt/conda/lib/python3.8/site-packages/coolbox/core/track/hist/base.py", line 101, in plot
    data = self.fetch_plot_data(gr, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/coolbox/core/track/hist/snp.py", line 75, in fetch_plot_data
    df['score'] = self.transform_fn()(df['score'])
  File "/opt/conda/lib/python3.8/site-packages/pandas/core/frame.py", line 3024, in __getitem__
    indexer = self.columns.get_loc(key)
  File "/opt/conda/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 3082, in get_loc
    raise KeyError(key) from err
KeyError: 'score'

Ideally, plotting a range containing no SNPs would just return an empty track?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant