Skip to content

Commit

Permalink
Merge pull request #132 from rmarkello/normwarn
Browse files Browse the repository at this point in the history
[REF] Adds option to suppress norm warnings
  • Loading branch information
rmarkello authored Nov 26, 2019
2 parents fc91343 + 01a051a commit 991226e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions abagen/allen.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,12 @@ def get_expression_data(atlas, atlas_info=None, *,

if sample_norm is not None:
microarray[subj] = correct.normalize_expression(microarray[subj].T,
norm=sample_norm).T
norm=sample_norm,
ignore_warn=True).T
if gene_norm is not None:
microarray[subj] = correct.normalize_expression(microarray[subj],
norm=gene_norm)
norm=gene_norm,
ignore_warn=True)

# get counts of samples collapsed into each ROI
labs, num = np.unique(labels, return_counts=True)
Expand Down
14 changes: 9 additions & 5 deletions abagen/correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ def _rs(data, axis=0):
# calculate sigmoid normalization
med = np.median(data, axis=axis, keepdims=True)
iqr = sstats.iqr(data, axis=axis, scale='normal', keepdims=True)
with np.errstate(divide='ignore', invalid='ignore'):
rs = 1 / (1 + np.exp(-(data - med) / iqr))
rs = 1 / (1 + np.exp(-(data - med) / iqr))

return rs

Expand Down Expand Up @@ -166,7 +165,7 @@ def _srs(data, low=0, high=1, axis=0):
)


def normalize_expression(expression, norm='srs'):
def normalize_expression(expression, norm='srs', ignore_warn=False):
"""
Performs normalization on `expression` data
Expand All @@ -178,6 +177,9 @@ def normalize_expression(expression, norm='srs'):
norm : {'rs', 'srs', 'center', 'zscore', 'minmax', 'batch'}, optional
Function with which to normalize expression data. See Notes for more
information. Default: 'srs'
ignore_warn : bool, optional
Whether to suppress potential warnings raised by normalization.
Default: False
Returns
-------
Expand Down Expand Up @@ -248,8 +250,10 @@ def normalize_expression(expression, norm='srs'):
notna = np.logical_not(exp.isna().all(axis=1))
data = np.asarray(exp)[notna]

# normalize the data (however was specified)
normed = normfunc(data) if norm != 'batch' else corrected[n]
kwargs = dict(divide='ignore', invalid='ignore') if ignore_warn else {}
with np.errstate(**kwargs):
# normalize the data (however was specified)
normed = normfunc(data) if norm != 'batch' else corrected[n]

# recreate dataframe and fill non-NaN values
normalized = pd.DataFrame(np.nan, columns=exp.columns, index=exp.index)
Expand Down

0 comments on commit 991226e

Please sign in to comment.