91template<
typename Stat_>
159template<
typename Stat_>
165 std::vector<std::vector<Stat_> >
mean;
211template<
typename Index_,
typename Stat_>
212void process_simple_pairwise_effects(
214 const std::size_t ngroups,
215 const std::size_t nblocks,
216 const std::size_t ncombos,
217 std::vector<Stat_>& combo_means,
218 std::vector<Stat_>& combo_vars,
219 std::vector<Stat_>& combo_detected,
221 const std::vector<Stat_>& combo_weights,
222 const double threshold,
223 const int num_threads)
225 std::vector<Stat_> total_weights_per_group;
226 const Stat_* total_weights_ptr = combo_weights.data();
228 total_weights_per_group = compute_total_weight_per_group(ngroups, nblocks, combo_weights.data());
229 total_weights_ptr = total_weights_per_group.data();
231 PrecomputedPairwiseWeights<Stat_> preweights(ngroups, nblocks, combo_weights.data());
234 for (Index_ gene = start, end = start + length; gene < end; ++gene) {
235 auto in_offset = sanisizer::product_unsafe<std::size_t>(gene, ncombos);
236 const auto tmp_means = combo_means.data() + in_offset;
237 const auto tmp_variances = combo_vars.data() + in_offset;
238 const auto tmp_detected = combo_detected.data() + in_offset;
239 average_group_stats(gene, ngroups, nblocks, tmp_means, tmp_detected, combo_weights.data(), total_weights_ptr, output.
mean, output.
detected);
242 const auto out_offset = sanisizer::product_unsafe<std::size_t>(gene, ngroups, ngroups);
244 compute_pairwise_cohens_d(tmp_means, tmp_variances, ngroups, nblocks, preweights, threshold, output.
cohens_d + out_offset);
248 compute_pairwise_simple_diff(tmp_detected, ngroups, nblocks, preweights, output.
delta_detected + out_offset);
252 compute_pairwise_simple_diff(tmp_means, ngroups, nblocks, preweights, output.
delta_mean + out_offset);
255 }, ngenes, num_threads);
258template<
typename Index_,
typename Stat_>
259ScoreMarkersPairwiseBuffers<Stat_> fill_pairwise_results(
const Index_ ngenes,
const std::size_t ngroups, ScoreMarkersPairwiseResults<Stat_>& store,
const ScoreMarkersPairwiseOptions& opt) {
260 ScoreMarkersPairwiseBuffers<Stat_> output;
262 fill_average_results(ngenes, ngroups, store.mean, store.detected, output.mean, output.detected);
264 const auto num_effect_sizes = sanisizer::product<typename std::vector<Stat_>::size_type>(ngenes, ngroups, ngroups);
266 if (opt.compute_cohens_d) {
267 store.cohens_d.resize(num_effect_sizes
268#ifdef SCRAN_MARKERS_TEST_INIT
269 , SCRAN_MARKERS_TEST_INIT
272 output.cohens_d = store.cohens_d.data();
274 if (opt.compute_auc) {
275 store.auc.resize(num_effect_sizes
276#ifdef SCRAN_MARKERS_TEST_INIT
277 , SCRAN_MARKERS_TEST_INIT
280 output.auc = store.auc.data();
282 if (opt.compute_delta_mean) {
283 store.delta_mean.resize(num_effect_sizes
284#ifdef SCRAN_MARKERS_TEST_INIT
285 , SCRAN_MARKERS_TEST_INIT
288 output.delta_mean = store.delta_mean.data();
290 if (opt.compute_delta_detected) {
291 store.delta_detected.resize(num_effect_sizes
292#ifdef SCRAN_MARKERS_TEST_INIT
293 , SCRAN_MARKERS_TEST_INIT
296 output.delta_detected = store.delta_detected.data();
312 const std::size_t ngroups,
313 const Group_*
const group,
314 const std::size_t nblocks,
315 const Block_*
const block,
316 const std::size_t ncombos,
317 const std::size_t*
const combo,
318 const std::vector<Index_>& combo_sizes,
319 const ScoreMarkersPairwiseOptions& options,
320 const ScoreMarkersPairwiseBuffers<Stat_>& output
322 const auto ngenes = matrix.
nrow();
323 const auto payload_size = sanisizer::product<typename std::vector<Stat_>::size_type>(ngenes, ncombos);
324 std::vector<Stat_> combo_means(payload_size), combo_vars(payload_size), combo_detected(payload_size);
330 options.block_weight_policy,
331 options.variable_block_weight_parameters
335 scan_matrix_by_row_full_auc<single_block_>(
354 scan_matrix_by_column(
357 if constexpr(single_block_) {
364 if constexpr(single_block_) {
378 process_simple_pairwise_effects(
468template<
typename Value_,
typename Index_,
typename Group_,
typename Stat_>
471 const Group_*
const group,
475 const Index_ NC = matrix.
ncol();
476 const auto group_sizes = tatami_stats::tabulate_groups(group, NC);
477 const auto ngroups = sanisizer::cast<std::size_t>(group_sizes.size());
479 internal::score_markers_pairwise<true>(
484 static_cast<int*
>(NULL),
486 static_cast<std::size_t*
>(NULL),
532template<
typename Value_,
typename Index_,
typename Group_,
typename Block_,
typename Stat_>
535 const Group_*
const group,
536 const Block_*
const block,
540 const Index_ NC = matrix.
ncol();
541 const auto ngroups = output.
mean.size();
542 const auto nblocks = tatami_stats::total_groups(block, NC);
544 const auto combinations = internal::create_combinations(ngroups, group, block, NC);
545 const auto combo_sizes = internal::tabulate_combinations<Index_>(ngroups, nblocks, combinations);
546 const auto ncombos = combo_sizes.size();
548 internal::score_markers_pairwise<false>(
550 sanisizer::cast<std::size_t>(ngroups),
552 sanisizer::cast<std::size_t>(nblocks),
554 sanisizer::cast<std::size_t>(ncombos),
578template<
typename Stat_ =
double,
typename Value_,
typename Index_,
typename Group_>
580 const auto ngroups = tatami_stats::total_groups(group, matrix.
ncol());
582 auto buffers = internal::fill_pairwise_results(matrix.
nrow(), ngroups, res, options);
606template<
typename Stat_ =
double,
typename Value_,
typename Index_,
typename Group_,
typename Block_>
609 const Group_*
const group,
610 const Block_*
const block,
613 const auto ngroups = tatami_stats::total_groups(group, matrix.
ncol());
615 const auto buffers = internal::fill_pairwise_results(matrix.
nrow(), ngroups, res, options);