trevismd / statannotations

add statistical significance annotations on seaborn plots. Further development of statannot, with bugfixes, new features, and a different API.
Other
619 stars 67 forks source link

Annotator does not work if any of the groups has only NaN values #111

Open kokyriakidis opened 1 year ago

kokyriakidis commented 1 year ago

Hey @trevismd

Right now Annotator does not work if any of the groups have only NaN values. Is there a way to perform a test between the other groups and ignore the group that has only NaN values?

In order to make it work I added zero values to the group that has only NaN values. I made it look like this: image

Otherwise I get the following error when I try yo run the Annotator:

>>> Annotator(ax, pairs, data=df[['CONTROL_Edited', 'CONTROL_Not_Edited', 'AD_Edited', 'AD_Not_Edited']], order=order)
/media/kokyriakidis/RED/BCBIO/anaconda/envs/postprocessSPRINT/lib/python3.8/site-packages/seaborn/categorical.py:82: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
  plot_data = [np.asarray(s, float) for k, s in iter_data]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/media/kokyriakidis/RED/BCBIO/anaconda/envs/postprocessSPRINT/lib/python3.8/site-packages/statannotations/Annotator.py", line 106, in __init__
    self._plotter = self._get_plotter(engine, ax, pairs, plot, data,
  File "/media/kokyriakidis/RED/BCBIO/anaconda/envs/postprocessSPRINT/lib/python3.8/site-packages/statannotations/Annotator.py", line 778, in _get_plotter
    return engine_plotter(*args, **kwargs)
  File "/media/kokyriakidis/RED/BCBIO/anaconda/envs/postprocessSPRINT/lib/python3.8/site-packages/statannotations/_Plotter.py", line 94, in __init__
    self.value_maxes = self._generate_value_maxes()
  File "/media/kokyriakidis/RED/BCBIO/anaconda/envs/postprocessSPRINT/lib/python3.8/site-packages/statannotations/_Plotter.py", line 215, in _generate_value_maxes
    group_name, value_pos = self._get_value_pos(child, data_to_ax)
  File "/media/kokyriakidis/RED/BCBIO/anaconda/envs/postprocessSPRINT/lib/python3.8/site-packages/statannotations/_Plotter.py", line 316, in _get_value_pos
    return self._get_value_pos_for_path_collection(
  File "/media/kokyriakidis/RED/BCBIO/anaconda/envs/postprocessSPRINT/lib/python3.8/site-packages/statannotations/_Plotter.py", line 332, in _get_value_pos_for_path_collection
    group_pos = float(np.round(np.nanmean(
  File "<__array_function__ internals>", line 180, in nanmean
  File "/media/kokyriakidis/RED/BCBIO/anaconda/envs/postprocessSPRINT/lib/python3.8/site-packages/numpy/lib/nanfunctions.py", line 1048, in nanmean
    avg = _divide_by_count(tot, cnt, out=out)
  File "/media/kokyriakidis/RED/BCBIO/anaconda/envs/postprocessSPRINT/lib/python3.8/site-packages/numpy/lib/nanfunctions.py", line 215, in _divide_by_count
    return np.divide(a, b, out=a, casting='unsafe')
ValueError: output array is read-only

Can I somehow have the CONTROL_Edited category be empty (have only NaN values) and make Annotator work?

trevismd commented 1 year ago

Hello, Can't you remove "CONTROL_Edited" from your pairs?

kokyriakidis commented 1 year ago

I prefer to leave it on the graph and be empty. (I want someone to see that it is empty)