f-hamidlab / nuclearpy

MIT License
0 stars 0 forks source link

Analizer brings this error using iNs 14 Days #7

Closed Marcel-Salier closed 2 years ago

Marcel-Salier commented 2 years ago

exclude_feat = ['total_intensity_core_dapi', 'total_intensity_internal_ring_dapi', 'total_intensity_external_ring_dapi', 'total_intensity_dapi', 'total_intensity_beta3', 'total_intensity_rfp', 'total_intensity_ngn', 'beta3_x_rfp', 'beta3_x_ngn', 'rfp_x_ngn', 'beta3_x_rfp_x_ngn'] obj.excludeVars(vars = exclude_feat) obj.showADataVars()


KeyError Traceback (most recent call last) Input In [60], in <cell line: 4>() 1 exclude_feat = ['total_intensity_core_dapi', 'total_intensity_internal_ring_dapi', 'total_intensity_external_ring_dapi', 'total_intensity_dapi', 2 'total_intensity_beta3', 'total_intensity_rfp', 'total_intensity_ngn', 3 'beta3_x_rfp', 'beta3_x_ngn', 'rfp_x_ngn', 'beta3_x_rfp_x_ngn'] ----> 4 obj.excludeVars(vars = exclude_feat) 5 obj.showADataVars()

File /opt/anaconda3/envs/ngtools/lib/python3.10/site-packages/ngtools/analyzer.py:466, in Analyzor.excludeVars(self, vars) 464 self.excfeat.extend(vars) 465 self.excfeat = list(set(self.excfeat)) --> 466 self.updateAData()

File /opt/anaconda3/envs/ngtools/lib/python3.10/site-packages/ngtools/analyzer.py:460, in Analyzor.updateAData(self) 459 def updateAData(self): --> 460 self.buildAData(self.excfeat) 461 self.normAData()

File /opt/anaconda3/envs/ngtools/lib/python3.10/site-packages/ngtools/analyzer.py:882, in Analyzor.buildAData(self, excluded_features) 880 dat_vars = self.data['norm'].copy() 881 dat_vars = dat_vars.select_dtypes(include=['float64', 'int64']) --> 882 dat_vars = dat_vars.drop(columns=to_drop) 884 # get obs data 885 dat_obs = self.data['norm'].copy()

File /opt/anaconda3/envs/ngtools/lib/python3.10/site-packages/pandas/util/_decorators.py:311, in deprecate_nonkeyword_arguments..decorate..wrapper(*args, *kwargs) 305 if len(args) > num_allow_args: 306 warnings.warn( 307 msg.format(arguments=arguments), 308 FutureWarning, 309 stacklevel=stacklevel, 310 ) --> 311 return func(args, **kwargs)

File /opt/anaconda3/envs/ngtools/lib/python3.10/site-packages/pandas/core/frame.py:4954, in DataFrame.drop(self, labels, axis, index, columns, level, inplace, errors) 4806 @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"]) 4807 def drop( 4808 self, (...) 4815 errors: str = "raise", 4816 ): 4817 """ 4818 Drop specified labels from rows or columns. 4819 (...) 4952 weight 1.0 0.8 4953 """ -> 4954 return super().drop( 4955 labels=labels, 4956 axis=axis, 4957 index=index, 4958 columns=columns, 4959 level=level, 4960 inplace=inplace, 4961 errors=errors, 4962 )

File /opt/anaconda3/envs/ngtools/lib/python3.10/site-packages/pandas/core/generic.py:4267, in NDFrame.drop(self, labels, axis, index, columns, level, inplace, errors) 4265 for axis, labels in axes.items(): 4266 if labels is not None: -> 4267 obj = obj._drop_axis(labels, axis, level=level, errors=errors) 4269 if inplace: 4270 self._update_inplace(obj)

File /opt/anaconda3/envs/ngtools/lib/python3.10/site-packages/pandas/core/generic.py:4311, in NDFrame._drop_axis(self, labels, axis, level, errors, consolidate, only_slice) 4309 new_axis = axis.drop(labels, level=level, errors=errors) 4310 else: -> 4311 new_axis = axis.drop(labels, errors=errors) 4312 indexer = axis.get_indexer(new_axis) 4314 # Case for non-unique axis 4315 else:

File /opt/anaconda3/envs/ngtools/lib/python3.10/site-packages/pandas/core/indexes/base.py:6644, in Index.drop(self, labels, errors) 6642 if mask.any(): 6643 if errors != "ignore": -> 6644 raise KeyError(f"{list(labels[mask])} not found in axis") 6645 indexer = indexer[~mask] 6646 return self.delete(indexer)

KeyError: "['beta3_x_rfp_x_ngn', 'total_intensity_ngn', 'beta3_x_ngn', 'rfp_x_ngn'] not found in axis"

In [61]:

fursham-h commented 2 years ago

Can you paste the output of obj.showADataVars() please.

Marcel-Salier commented 2 years ago

['avg_intensity_dapi', 'nuclear_area', 'nuclear_perimeter', 'major_axis', 'minor_axis', 'axes_ratio', 'circularity', 'eccentricity', 'solidity', 'avg_intensity_core_dapi', 'avg_intensity_internal_ring_dapi', 'avg_intensity_external_ring_dapi', 'total_intensity_core_dapi', 'total_intensity_internal_ring_dapi', 'total_intensity_external_ring_dapi', 'total_intensity_dapi', 'avg_intensity_beta3', 'total_intensity_beta3', 'avg_intensity_rfp', 'total_intensity_rfp', 'avg_intensity_laminB1', 'total_intensity_laminB1', 'beta3_x_rfp', 'beta3_x_laminB1', 'rfp_x_laminB1', 'beta3_x_rfp_x_laminB1', 'dna_peaks', 'dna_dots', 'dna_dots_size_median', 'spatial_entropy', 'iNs']

fursham-h commented 2 years ago

Yea you need to change the list of features to exlcude in the function:

exclude_feat = ['total_intensity_core_dapi', 'total_intensity_internal_ring_dapi', 
'total_intensity_external_ring_dapi', 'total_intensity_dapi', 'total_intensity_beta3', 
'total_intensity_rfp', 'total_intensity_ngn', 'beta3_x_rfp', 'beta3_x_ngn', 'rfp_x_ngn', 'beta3_x_rfp_x_ngn']

You don't have beta3_x_rfp', 'beta3_x_ngn', 'rfp_x_ngn', 'beta3_x_rfp_x_ngn' in your dataset.

Let me know if it works

Marcel-Salier commented 2 years ago

I remove them but I have to restart all. It also gave me an error in chosen cells because there were arrays with 0 cells. Which is no possible to guess in advance. File /opt/anaconda3/envs/ngtools/lib/python3.10/site-packages/sklearn/utils/validation.py:909, in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name) 907 n_samples = _num_samples(array) 908 if n_samples < ensure_min_samples: --> 909 raise ValueError( 910 "Found array with %d sample(s) (shape=%s) while a" 911 " minimum of %d is required%s." 912 % (n_samples, array.shape, ensure_min_samples, context) 913 ) 915 if ensure_min_features > 0 and array.ndim == 2: 916 n_features = array.shape[1]

ValueError: Found array with 0 sample(s) (shape=(0, 31)) while a minimum of 1 is required by StandardScaler.

fursham-h commented 2 years ago

ValueError: Found array with 0 sample(s) (shape=(0, 31)) while a minimum of 1 is required by StandardScaler.

It seems like there were no cells where chosen. Can you show me the code where you chose and filter the cells.

I remove them but I have to restart all

I think I know what you mean. I made a quick fix on this on the latest commit (3c503fb1d5899eb3971ff210957aac305a665edb). Pull this commit and you should be able to remove them on the go, without rerunning from the start.

I want to make the notebook more descriptive on how to use the workflow functions. Will do this up when I have the time.

fursham-h commented 2 years ago

Closing this since it has been fixed