def calc_scores(self, label):
"""
Combine the scores and standard errors within each condition.
"""
if self.check_store("/main/{}/scores".format(label)):
return
logging.info("Calculating per-condition scores ({})".format(label),
extra={'oname': self.name})
# set up new data frame
shared_index = self.store.select("/main/{}/scores_shared"
"".format(label),
"columns='index'").index
columns = pd.MultiIndex.from_product([sorted(self.child_names()),
sorted(["score", "SE",
"epsilon"])],
names=["condition", "value"])
data = pd.DataFrame(np.nan, index=shared_index, columns=columns)
del shared_index
del columns
# set up local variables
idx = pd.IndexSlice
score_df = self.store.select("/main/{}/scores_shared".format(label))
if self.scoring_method == "simple":
# special case for simple ratios that have no SE
# calculates the average score
for cnd in score_df.columns.levels[0]:
data.loc[:, idx[cnd, 'score']] = \
score_df.loc[:, idx[cnd, :, 'score']].mean(axis=1)
else:
for cnd in score_df.columns.levels[0]:
y = np.array(score_df.loc[:, idx[cnd, :, 'score']].values).T
sigma2i = \
np.array(score_df.loc[:, idx[cnd, :, 'SE']].values ** 2).T
# single replicate of the condition
if y.shape[0] == 1:
data.loc[:, idx[cnd, 'score']] = y.ravel()
data.loc[:, idx[cnd, 'SE']] = np.sqrt(sigma2i).ravel()
data.loc[:, idx[cnd, 'epsilon']] = 0.
# multiple replicates
else:
betaML, var_betaML, eps = rml_estimator(y, sigma2i)
data.loc[:, idx[cnd, 'score']] = betaML
data.loc[:, idx[cnd, 'SE']] = np.sqrt(var_betaML)
data.loc[:, idx[cnd, 'epsilon']] = eps
# special case for normalized wild type variant
if self.logr_method == "wt" and WILD_TYPE_VARIANT in \
data.index:
data.loc[WILD_TYPE_VARIANT, idx[:, 'SE']] = 0.
data.loc[WILD_TYPE_VARIANT, idx[:, 'score']] = 0.
data.loc[WILD_TYPE_VARIANT, idx[:, 'epsilon']] = 0.
# store the data
self.store.put("/main/{}/scores".format(label), data, format="table")
评论列表
文章目录