Skip to content

Commit

Permalink
Merge pull request #35 from sfiligoi/apiv2_230320
Browse files Browse the repository at this point in the history
Clean up v2 api
  • Loading branch information
sfiligoi authored Mar 20, 2023
2 parents 026376a + 6a46363 commit c64c65f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
26 changes: 18 additions & 8 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,19 @@ compute_status one_off_matrix_T(su::biom_interface &table, su::BPTree &tree,
compute_status one_off_matrix_v2(const char* biom_filename, const char* tree_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int nthreads,
unsigned int subsample_depth, const char *mmap_dir,
unsigned int subsample_depth, bool subsample_with_replacement, const char *mmap_dir,
mat_full_fp64_t** result) {
SETUP_TDBG("one_off_matrix")
CHECK_FILE(biom_filename, table_missing)
CHECK_FILE(tree_filename, tree_missing)
PARSE_TREE_TABLE(tree_filename, biom_filename)
TDBG_STEP("load_files")
if (subsample_depth>0) {
// We do not implement subsampling without replacement yet
if (!subsample_with_replacement) {
fprintf(stderr, "ERROR: subsampling without replacement not implemented yet.\n");
return table_empty;
}
su::skbio_biom_subsampled table_subsampled(table, subsample_depth);
if ((table_subsampled.n_samples==0) || (table_subsampled.n_obs==0)) {
return table_empty;
Expand All @@ -623,14 +628,19 @@ compute_status one_off_matrix_v2(const char* biom_filename, const char* tree_fil
compute_status one_off_matrix_fp32_v2(const char* biom_filename, const char* tree_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int nthreads,
unsigned int subsample_depth, const char *mmap_dir,
unsigned int subsample_depth, bool subsample_with_replacement, const char *mmap_dir,
mat_full_fp32_t** result) {
SETUP_TDBG("one_off_matrix_fp32")
CHECK_FILE(biom_filename, table_missing)
CHECK_FILE(tree_filename, tree_missing)
PARSE_TREE_TABLE(tree_filename, biom_filename)
TDBG_STEP("load_files")
if (subsample_depth>0) {
// We do not implement subsampling without replacement yet
if (!subsample_with_replacement) {
fprintf(stderr, "ERROR: subsampling without replacement not implemented yet.\n");
return table_empty;
}
su::skbio_biom_subsampled table_subsampled(table, subsample_depth);
TDBG_STEP("subsample")
return one_off_matrix_T<float,mat_full_fp32_t>(table_subsampled,tree,unifrac_method,variance_adjust,alpha,bypass_tips,nthreads,mmap_dir,result);
Expand All @@ -644,15 +654,15 @@ compute_status one_off_matrix(const char* biom_filename, const char* tree_filena
bool bypass_tips, unsigned int nthreads,
const char *mmap_dir,
mat_full_fp64_t** result) {
return one_off_matrix_v2(biom_filename,tree_filename,unifrac_method,variance_adjust,alpha,bypass_tips,nthreads,0,mmap_dir,result);
return one_off_matrix_v2(biom_filename,tree_filename,unifrac_method,variance_adjust,alpha,bypass_tips,nthreads,0,true,mmap_dir,result);
}

compute_status one_off_matrix_fp32(const char* biom_filename, const char* tree_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int nthreads,
const char *mmap_dir,
mat_full_fp32_t** result) {
return one_off_matrix_fp32_v2(biom_filename,tree_filename,unifrac_method,variance_adjust,alpha,bypass_tips,nthreads,0,mmap_dir,result);
return one_off_matrix_fp32_v2(biom_filename,tree_filename,unifrac_method,variance_adjust,alpha,bypass_tips,nthreads,0,true,mmap_dir,result);
}

compute_status one_off_inmem_matrix(su::biom_interface &table, su::BPTree &tree,
Expand Down Expand Up @@ -805,7 +815,7 @@ compute_status compute_permanova_fp32(const char *grouping_filename, unsigned in
compute_status unifrac_to_file_v2(const char* biom_filename, const char* tree_filename, const char* out_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int threads, const char* format,
unsigned int subsample_depth,
unsigned int subsample_depth, bool subsample_with_replacement,
unsigned int pcoa_dims,
unsigned int permanova_perms, const char *grouping_filename, const char *grouping_columns,
const char *mmap_dir)
Expand All @@ -821,7 +831,7 @@ compute_status unifrac_to_file_v2(const char* biom_filename, const char* tree_fi
mat_full_fp64_t* result = NULL;
rc = one_off_matrix_v2(biom_filename, tree_filename,
unifrac_method, variance_adjust, alpha,
bypass_tips, threads, subsample_depth, mmap_dir,
bypass_tips, threads, subsample_depth, subsample_with_replacement, mmap_dir,
&result);
TDBG_STEP("matrix_fp64 computed")

Expand Down Expand Up @@ -875,7 +885,7 @@ compute_status unifrac_to_file_v2(const char* biom_filename, const char* tree_fi
mat_full_fp32_t* result = NULL;
rc = one_off_matrix_fp32_v2(biom_filename, tree_filename,
unifrac_method, variance_adjust, alpha,
bypass_tips, threads, subsample_depth, mmap_dir,
bypass_tips, threads, subsample_depth, subsample_with_replacement, mmap_dir,
&result);
TDBG_STEP("matrix_fp32 computed")

Expand Down Expand Up @@ -938,7 +948,7 @@ compute_status unifrac_to_file(const char* biom_filename, const char* tree_filen
bool bypass_tips, unsigned int threads, const char* format,
unsigned int pcoa_dims, const char *mmap_dir) {
return unifrac_to_file_v2(biom_filename,tree_filename,out_filename,unifrac_method,variance_adjust,alpha,bypass_tips,
threads,format,0,pcoa_dims,0,NULL,NULL,mmap_dir);
threads,format,0,true,pcoa_dims,0,NULL,NULL,mmap_dir);
}


Expand Down
37 changes: 22 additions & 15 deletions src/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ EXTERN ComputeStatus one_off_inmem_fp32(const support_biom_t *table_data, const
* alpha <double> GUniFrac alpha, only relevant if method == generalized.
* bypass_tips <bool> disregard tips, reduces compute by about 50%
* n_substeps <uint> the number of substeps/blocks to use.
* subsample_depth <uint> Depth of subsampling, if >0
* subsample_with_replacement <bool> Use subsampling with replacement? (only True supported)
* mmap_dir <const char*> If not NULL, area to use for temp memory storage
* result <mat_full_fp64_t**> the resulting distance matrix in matrix form, this is initialized within the method so using **
*
Expand All @@ -253,18 +255,19 @@ EXTERN ComputeStatus one_off_inmem_fp32(const support_biom_t *table_data, const
* unknown_method : the requested method is unknown.
* table_empty : the table does not have any entries
*/
EXTERN ComputeStatus one_off_matrix_v2(const char* biom_filename, const char* tree_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int n_substeps,
unsigned int subsample_depth, bool subsample_with_replacement, const char *mmap_dir,
mat_full_fp64_t** result);

/* Older version, will be deprecated in the future */
EXTERN ComputeStatus one_off_matrix(const char* biom_filename, const char* tree_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int n_substeps,
const char *mmap_dir,
mat_full_fp64_t** result);

EXTERN ComputeStatus one_off_matrix_v2(const char* biom_filename, const char* tree_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int n_substeps,
unsigned int subsample_depth, const char *mmap_dir,
mat_full_fp64_t** result);

/* Compute UniFrac - matrix form, fp32 variant
*
* biom_filename <const char*> the filename to the biom table.
Expand All @@ -274,6 +277,8 @@ EXTERN ComputeStatus one_off_matrix_v2(const char* biom_filename, const char* tr
* alpha <double> GUniFrac alpha, only relevant if method == generalized.
* bypass_tips <bool> disregard tips, reduces compute by about 50%
* n_substeps <uint> the number of substeps/blocks to use.
* subsample_depth <uint> Depth of subsampling, if >0
* subsample_with_replacement <bool> Use subsampling with replacement? (only True supported)
* mmap_dir <const char*> If not NULL, area to use for temp memory storage
* result <mat_full_fp32_t**> the resulting distance matrix in matrix form, this is initialized within the method so using **
*
Expand All @@ -285,18 +290,18 @@ EXTERN ComputeStatus one_off_matrix_v2(const char* biom_filename, const char* tr
* unknown_method : the requested method is unknown.
* table_empty : the table does not have any entries
*/
EXTERN ComputeStatus one_off_matrix_fp32(const char* biom_filename, const char* tree_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int n_substeps,
const char *mmap_dir,
mat_full_fp32_t** result);

EXTERN ComputeStatus one_off_matrix_fp32_v2(const char* biom_filename, const char* tree_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int n_substeps,
unsigned int subsample_depth, const char *mmap_dir,
unsigned int subsample_depth, bool subsample_with_replacement, const char *mmap_dir,
mat_full_fp32_t** result);

/* Older version, will be deprecated in the future */
EXTERN ComputeStatus one_off_matrix_fp32(const char* biom_filename, const char* tree_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int n_substeps,
const char *mmap_dir,
mat_full_fp32_t** result);

/* compute Faith PD
* biom_filename <const char*> the filename to the biom table.
Expand Down Expand Up @@ -324,6 +329,8 @@ EXTERN ComputeStatus faith_pd_one_off(const char* biom_filename, const char* tre
* bypass_tips <bool> disregard tips, reduces compute by about 50%
* n_substeps <uint> the number of substeps to use.
* format <const char*> output format to use.
* subsample_depth <uint> Depth of subsampling, if >0
* subsample_with_replacement <bool> Use subsampling with replacement? (only True supported)
* pcoa_dims <uint> if not 0, number of dimensions to use or PCoA
* permanova_perms <uint> If not 0, compute PERMANOVA using that many permutations
* grouping_filename <const char*> the TSV filename containing grouping information
Expand All @@ -341,8 +348,8 @@ EXTERN ComputeStatus faith_pd_one_off(const char* biom_filename, const char* tre
*/
EXTERN ComputeStatus unifrac_to_file_v2(const char* biom_filename, const char* tree_filename, const char* out_filename,
const char* unifrac_method, bool variance_adjust, double alpha,
bool bypass_tips, unsigned int threads, const char* format,
unsigned int subsample_depth,
bool bypass_tips, unsigned int n_substeps, const char* format,
unsigned int subsample_depth, bool subsample_with_replacement,
unsigned int pcoa_dims,
unsigned int permanova_perms, const char *grouping_filename, const char *grouping_columns,
const char *mmap_dir);
Expand Down
2 changes: 1 addition & 1 deletion src/su.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ int mode_one_off(const std::string &table_filename, const std::string &tree_file

status = unifrac_to_file_v2(table_filename.c_str(), tree_filename.c_str(), output_filename.c_str(),
method_string.c_str(), vaw, g_unifrac_alpha, bypass_tips, nsubsteps, format_str.c_str(),
subsample_depth,
subsample_depth, true,
pcoa_dims, permanova_perms, grouping_c, columns_c, mmap_dir_c);

if (status != okay) {
Expand Down

0 comments on commit c64c65f

Please sign in to comment.