Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ int main(int argc, char **argv) {
OtuTable otu_table;
otu_table.load_otu_file(bootstrap_options.otu_filename);

// If bootstrap_prefix contains a directory, check that it exists
if (bootstrap_options.bootstrap_prefix.find('/') != std::string::npos) {
directory_exists(bootstrap_options.bootstrap_prefix);
}

// Generate bootstraps
get_and_write_bootstraps(otu_table, bootstrap_options.bootstrap_number, bootstrap_options.bootstrap_prefix, bootstrap_options.threads, bootstrap_options.seed);

Expand Down
17 changes: 17 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "common.h"

#ifndef _WIN32 // dirent.h is not available on windows
#include <dirent.h>
#endif

std::vector<std::string> PERMITTED_OTU_HEADERS = {"#OTU ID", "#OTU_ID", "OTU ID", "OTU_ID", "OTU_id", "OTU id"};

Expand Down Expand Up @@ -162,3 +165,17 @@ float float_from_optarg(const char *optarg) {
}
return std::atof(string_float.c_str());
}

void directory_exists(const std::string &optarg) {
#ifndef _WIN32 // implementation doesn't work on windows
std::string outfile_dir(optarg);
outfile_dir.erase(outfile_dir.rfind("/"), outfile_dir.size());
DIR* dir = opendir(outfile_dir.c_str());
if (dir) {
closedir(dir);
} else {
fprintf(stderr, "Directory does not seem to exist: %s/\n", outfile_dir.c_str());
exit(1);
}
#endif
}
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ int int_from_optarg(const char *optarg);
// Convert character to float (for commandline argument parsing)
float float_from_optarg(const char *optarg);

void directory_exists(const std::string &optarg);

#endif
8 changes: 8 additions & 0 deletions src/fastspar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ int main(int argc, char **argv) {
FastSpar fastspar(&otu_table, fastspar_options.iterations, fastspar_options.exclude_iterations,
fastspar_options.threshold, fastspar_options.threads, fastspar_options.seed);

// Check that the output files are accessible if not in current directory
if (fastspar_options.correlation_filename.find('/') != std::string::npos) {
directory_exists(fastspar_options.correlation_filename);
}
if (fastspar_options.covariance_filename.find('/') != std::string::npos) {
directory_exists(fastspar_options.covariance_filename);
}

// Run FastSpar iterations
fprintf(stdout, "Running SparCC iterations\n");
fastspar.infer_correlation_and_covariance();
Expand Down
10 changes: 10 additions & 0 deletions src/pvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ int main(int argc, char **argv) {
// Get commandline arguments
PvalOptions pval_options = get_commandline_arguments(argc, argv);

// Check that the input prefix is accessible if in a folder
if (pval_options.bootstrap_prefix.find('/') != std::string::npos) {
directory_exists(pval_options.bootstrap_prefix);
}

// Collect bootstrap correlation file paths and then make sure we have found the correct number
std::vector<std::string> bs_cor_paths = get_bootstrap_correlation_paths(pval_options.bootstrap_prefix);
if (bs_cor_paths.size() != pval_options.permutations) {
Expand All @@ -237,6 +242,11 @@ int main(int argc, char **argv) {
exit(0);
}

// Check that the output files are accessible if not in current directory
if (pval_options.out_filename.find('/') != std::string::npos) {
directory_exists(pval_options.out_filename);
}

// Read in otu tables (used to calculate total possible permutations)
printf("Reading in OTU count table\n");
OtuTable otu_table;
Expand Down