Skip to content

Commit 6c20888

Browse files
src/radmeth/radmeth_model.cpp: updated the function to print a model so that it only prints each sample's factor levels if there are few enough samples and so it prints a summary of group factor levels along with the number of samples per group
1 parent c70a84f commit 6c20888

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

src/radmeth/radmeth_model.cpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,37 @@ Design::drop_factor(const std::size_t factor_idx) {
169169

170170
std::ostream &
171171
operator<<(std::ostream &out, const Design &design) {
172-
for (std::size_t factor = 0; factor < design.factor_names.size(); ++factor) {
173-
if (factor != 0)
174-
out << '\t';
175-
out << design.factor_names[factor];
172+
static constexpr std::uint32_t max_samples_to_report = 100;
173+
const auto n_samples = design.n_samples();
174+
const auto n_factors = design.n_factors();
175+
if (n_samples <= max_samples_to_report) {
176+
for (std::size_t factor = 0; factor < n_factors; ++factor) {
177+
if (factor != 0)
178+
out << '\t';
179+
out << design.factor_names[factor];
180+
}
181+
out << '\n';
182+
183+
for (std::size_t i = 0; i < n_samples; ++i) {
184+
out << design.sample_names[i];
185+
for (std::size_t j = 0; j < n_factors; ++j)
186+
out << '\t' << static_cast<std::uint32_t>(design.matrix[i][j]);
187+
out << '\n';
188+
}
176189
}
177-
out << '\n';
178190

179-
for (std::size_t i = 0; i < design.n_samples(); ++i) {
180-
out << design.sample_names[i];
181-
for (std::size_t j = 0; j < design.n_factors(); ++j)
182-
out << "\t" << static_cast<std::uint32_t>(design.matrix[i][j]);
183-
out << "\n";
191+
// compute the number of samples per group
192+
const auto n_groups = design.n_groups();
193+
std::vector<std::uint32_t> n_samples_per_group(n_groups, 0);
194+
for (auto s_idx = 0u; s_idx < n_samples; ++s_idx)
195+
++n_samples_per_group[design.group_id[s_idx]];
196+
197+
out << "group_id | factor_levels (" << n_factors << " factors) | n_samples\n";
198+
for (std::size_t g_idx = 0; g_idx < n_groups; ++g_idx) {
199+
out << g_idx;
200+
for (std::size_t f_idx = 0; f_idx < n_factors; ++f_idx)
201+
out << '\t' << static_cast<std::uint32_t>(design.groups[g_idx][f_idx]);
202+
out << '\t' << n_samples_per_group[g_idx] << '\n';
184203
}
185204

186205
return out;

0 commit comments

Comments
 (0)