def weighted_average(weights, pep_abd, group_ix):
'''
Calculate weighted geometric means for sample groups
Inputs:
weights: weights of peptides after filtering by loading threshold
pep_abd: peptide abundances after filtering by loading threshold
group_ix: array indexes of sample groups
'''
global nGroups
abd_w = pep_abd * weights[..., None]
one_w = abd_w / abd_w * weights[..., None]
a_sums = np.nansum(abd_w, axis=0)
w_sums = np.nansum(one_w, axis=0)
expr = np.empty(nGroups)
for i in range(expr.shape[0]):
expr[i] = a_sums[group_ix[i]].sum() / w_sums[group_ix[i]].sum()
return expr
评论列表
文章目录