diff --git a/src/api.cpp b/src/api.cpp index 7e69a13..80c5df5 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -81,12 +81,7 @@ table.get_obs_ids().end()); \ su::BPTree tree_sheared = tree.shear(to_keep).collapse(); -#define PARSE_TREE_TABLE(tree_filename, table_filename) std::ifstream ifs(tree_filename); \ - std::string content = std::string(std::istreambuf_iterator(ifs), \ - std::istreambuf_iterator()); \ - su::BPTree tree(content); \ - su::biom table(biom_filename); \ - if(table.n_samples <= 0 | table.n_obs <= 0) { \ +#define VALIDATE_TREE_TABLE(tree, table) if(table.n_samples <= 0 | table.n_obs <= 0) { \ return table_empty; \ } \ std::string bad_id = su::test_table_ids_are_subset_of_tree(table, tree); \ @@ -94,6 +89,13 @@ return table_and_tree_do_not_overlap; \ } +#define PARSE_TREE_TABLE(tree_filename, table_filename) std::ifstream ifs(tree_filename); \ + std::string content = std::string(std::istreambuf_iterator(ifs), \ + std::istreambuf_iterator()); \ + su::BPTree tree(content); \ + su::biom table(biom_filename); \ + VALIDATE_TREE_TABLE(tree, table) + #define PARSE_SYNC_TREE_TABLE(tree_filename, table_filename) PARSE_TREE_TABLE(tree_filename, table_filename) \ SYNC_TREE_TABLE(tree, table) @@ -693,6 +695,10 @@ compute_status one_off_matrix_inmem_v2(const support_biom_t *table_data, const s return rc; } + if(table_data->n_samples <= 0 | table_data->n_obs <= 0) { + return table_empty; + } + su::biom_inmem table(table_data->obs_ids, table_data->sample_ids, table_data->indices, @@ -706,6 +712,8 @@ compute_status one_off_matrix_inmem_v2(const support_biom_t *table_data, const s tree_data->names, tree_data->n_parens); + VALIDATE_TREE_TABLE(tree,table) + if (subsample_depth>0) { su::skbio_biom_subsampled table_subsampled(table, subsample_with_replacement, subsample_depth); TDBG_STEP("subsample") @@ -741,6 +749,10 @@ compute_status one_off_matrix_inmem_fp32_v2(const support_biom_t *table_data, co return rc; } + if(table_data->n_samples <= 0 | table_data->n_obs <= 0) { + return table_empty; + } + su::biom_inmem table(table_data->obs_ids, table_data->sample_ids, table_data->indices, @@ -754,6 +766,8 @@ compute_status one_off_matrix_inmem_fp32_v2(const support_biom_t *table_data, co tree_data->names, tree_data->n_parens); + VALIDATE_TREE_TABLE(tree,table) + if (subsample_depth>0) { su::skbio_biom_subsampled table_subsampled(table, subsample_with_replacement, subsample_depth); TDBG_STEP("subsample")