Skip to content

Commit

Permalink
allow zero values in remove_trend
Browse files Browse the repository at this point in the history
  • Loading branch information
parashardhapola committed Nov 23, 2023
1 parent b797058 commit 60e04f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion scarf/assay.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,9 @@ def set_feature_stats(self, cell_key: str) -> None:
overwrite=True,
location=identifier,
)
nz_mean = np.divide(tot, n_cells, out=np.zeros_like(tot).astype(float), where=n_cells != 0)
nz_mean = np.divide(
tot, n_cells, out=np.zeros_like(tot).astype(float), where=n_cells != 0
)
self.feats.insert(
"nz_mean",
nz_mean.astype(float),
Expand Down
21 changes: 16 additions & 5 deletions scarf/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,12 @@ def grep(self, pattern: str, only_valid=False) -> List[str]:
)

def remove_trend(
self, x: str, y: str, n_bins: int = 200, lowess_frac: float = 0.1
self,
x: str,
y: str,
n_bins: int = 200,
lowess_frac: float = 0.1,
fill_value: float = 0,
) -> np.ndarray:
"""
Expand All @@ -575,17 +580,23 @@ def remove_trend(
y:
n_bins:
lowess_frac:
fill_value:
Returns:
"""
a = fit_lowess(
self.fetch(x).astype(float),
self.fetch(y).astype(float),
a = self.fetch(x).astype(float)
b = self.fetch(y).astype(float)
idx = a > 0
c = fit_lowess(
a[idx],
b[idx],
n_bins,
lowess_frac,
)
return a
ret_val = np.repeat(fill_value, len(a)).astype(float)
ret_val[idx] = c
return ret_val

def __repr__(self):
return f"MetaData of {self.fetch_all('I').sum()}({self.N}) elements"

0 comments on commit 60e04f1

Please sign in to comment.