INNER CODE UNIT · Python
sizeFactor
scverse/PyDESeq2 · src/pydeseq2/dds.py:627
def sizeFactor(x):
_mask = np.logical_and(_control_mask, x > 0)
return np.exp(np.median(np.log(x[_mask]) - logmeans[_mask]))
sf = np.apply_along_axis(sizeFactor, 1, self.X)
del log_counts
# Normalize size factors to a geometric mean of 1 to match DESeq
self.obs["size_factors"] = sf / (np.exp(np.mean(np.log(sf))))
self.layers["normed_counts"] = (
self.X / self.obs["size_factors"].to_numpy()[:, None]
)
self.logmeans = logmeans
# Test whether it is possible to use median-of-ratios.
elif (self.X == 0).any(0).all():
# There is at least a zero for each gene
warnings.warn(