69 CSVDict(
const std::vector< std::string > &inputImagesVector,
const std::vector< double > &inputLabelVector) :
87 bool splitFileName(
const std::string &dataFile, std::string &path,
88 std::string &baseName, std::string &extension);
97 std::vector<std::string>
stringSplit(
const std::string &str,
const std::string &delim);
109 const std::string &toReplace,
110 const std::string &replaceWith);
160 bool isFile(
const std::string &path);
174 bool isDir(
const std::string &path);
187 bool exists(
const std::string &path);
189 std::vector<std::string> getCWLFilesInApplicationDir();
236 bool createDir(
const std::string &dir_name);
243 bool makeDir(
const std::string &dir_name);
315 bool copyDir(
const std::string &inputFolder,
const std::string &destination,
bool recursion =
true);
328 bool copyDirectory(
const std::string &inputFolder,
const std::string &destination,
bool recursion =
true);
341 bool copyFolder(
const std::string &inputFolder,
const std::string &destination,
bool recursion =
true);
350 bool copyFile(
const std::string &inputFile,
const std::string &destination);
364 bool IsCompatible(
const std::string inputVersionFile);
378 size_t getDirSize(
const std::string &rootFolder);
407 std::string
getFilenameBase(
const std::string &filename,
bool checkFile =
true);
418 std::string
getFilenamePath(
const std::string &filename,
bool checkFile =
true);
481 std::string
normPath(
const std::string &path);
506 std::string
relPath(
const std::string &path,
const std::string &base);
518 std::string
relativePath(
const std::string &path,
const std::string &base);
531 std::string
realPath(
const std::string &path);
543 bool isLink(
const std::string &path);
564 bool makeSymbolicLink(
const std::string &input_fileName,
const std::string &ouput_fileName);
595 std::vector< std::string >
filesInDirectory(
const std::string &dirName,
bool returnFullPath =
true);
603 std::vector<std::string>
subdirectoriesInDirectory(
const std::string &dirName,
bool recursiveSearch =
false,
bool returnFullPath =
false);
608 size_t numberOfRowsInFile(
const std::string &csvFileName,
const std::string &delim =
"\n");
613 size_t numberOfColsInFile(
const std::string &csvFileName,
const std::string &delim =
",");
633 std::vector< CSVDict >
parseCSVFile(
const std::string &csvFileName,
const std::string &inputColumns,
const std::string &inputLabels,
bool checkFile =
true,
bool pathsRelativeToCSV =
false,
const std::string &rowsDelimiter =
"\n",
const std::string &colsDelimiter =
",",
const std::string &optionsDelimiter =
",");
643 template<
class TDataType =
double >
644 std::vector< std::vector< TDataType > >
readCSVDataFile(
const std::string &csvFileName,
bool columnMajor =
false)
646 std::vector< std::vector< TDataType > > returnVector;
649 std::cerr <<
"Supplied file wasn't found.\n";
656 std::ifstream data(csvFileName.c_str());
657 std::string line, cell;
661 returnVector.resize(cols);
665 returnVector.resize(rows);
669 while (std::getline(data, line))
674 returnVector[i].resize(cols);
676 std::stringstream lineStream(line);
677 while (std::getline(lineStream, cell,
','))
679 if (columnMajor && returnVector[j].empty())
681 returnVector[j].resize(rows);
684 auto temp = static_cast<TDataType>(std::atof(cell.c_str()));
688 returnVector[j][i] = temp;
692 returnVector[i][j] = temp;
710 template<
class TDataType = std::
string >
713 std::set< TDataType > s;
714 std::vector< TDataType > returnVector;
715 for (
size_t i = 0; i < inputVector.size(); i++)
717 s.insert(inputVector[i]);
719 returnVector.assign(s.begin(), s.end());
731 std::vector< std::vector< std::string > > readCSVDataFile(
const std::string &csvFileName);
736 std::string getCurrentLocalDate();
741 std::string getCurrentLocalTime();
746 std::string getCurrentLocalDateAndTime();
751 std::string getCurrentGMTDate();
756 std::string getCurrentGMT();
761 std::string getCurrentGMTDateAndTime();
766 std::string getCurrentYear();
773 std::string getCurrentProcessID();
780 void sleep(
size_t ms = std::rand() % 1000 + 1);
787 void dos2unix(
const std::string inputFile);
803 template<
typename TContainerType = std::
string >
804 std::pair<bool, int>
findInVector(std::vector<TContainerType> &vector_to_search_in,
805 TContainerType element_to_search_for)
809 typename std::vector<TContainerType>::const_iterator iterator =
810 std::find(vector_to_search_in.begin(), vector_to_search_in.end(), element_to_search_for);
811 if (iterator != vector_to_search_in.end())
813 position = iterator - vector_to_search_in.begin();
814 return std::make_pair(
true, position);
817 return std::make_pair(
false, position);
826 template <
typename TConvertType
827 #if (_MSC_VER >= 1800) || (__GNUC__ > 4) 833 return static_cast<TConvertType>(input_string[0]);
842 template<
typename TConvertType =
int >
845 std::vector<TConvertType>return_vector;
846 for (
int i = 0; i < input_string.length(); ++i)
847 return_vector.push_back(static_cast<TConvertType>(input_string[i]));
849 return return_vector;
852 #if (_MSC_VER >= 1800) || (__cplusplus >= 201103L) 856 template <
typename A =
int,
typename B = A>
857 inline bool compareEqual(
const A x,
const B y)
865 template <
typename A = int,
typename B = A,
typename... Others>
866 bool compareEqual(
const A x,
const B y, Others
const ... args)
868 return (x == y) && compareEqual(y, args...);
874 template <
typename A =
int,
typename B = A>
875 inline bool compareGreater(
const A x,
const B y)
883 template <
typename A = int,
typename B = A,
typename... Others>
884 bool compareGreater(
const A x,
const B y, Others
const ... args)
886 return (x > y) && compareGreater(y, args...);
892 template <
typename A =
int,
typename B = A>
893 inline bool compareLesser(
const A x,
const B y)
901 template <
typename A = int,
typename B = A,
typename... Others>
902 bool compareLesser(
const A x,
const B y, Others
const ... args)
904 return (x < y) && compareLesser(y, args...);
912 template<
typename TDataType =
double >
913 std::string to_string_precision(
const TDataType a_value,
const int n = 10)
915 std::ostringstream out;
916 out << std::setprecision(n) << a_value;
933 std::map< std::string, size_t >
ConfusionMatrix(
const std::vector< float > &inputRealLabels,
const std::vector< float > &inputPredictedLabels);
950 std::map< std::string, float >
ROC_Values(
const std::vector< float > &inputRealLabels,
const std::vector< float > &inputPredictedLabels);
959 template<
class TDataType =
float >
960 std::vector< TDataType >
randn(
const TDataType start,
const TDataType end,
size_t sizeOfReturn = 1)
962 std::vector< TDataType > returnVec;
963 returnVec.resize(sizeOfReturn);
964 std::random_device rd;
965 std::mt19937 eng(rd());
966 std::normal_distribution< TDataType > distr(start, end);
968 for (
size_t i = 0; i < returnVec.size(); i++)
970 returnVec[i] = distr(eng);
981 template<
class TDataType =
float >
982 std::vector< TDataType >
randn(
size_t sizeOfReturn = 1)
984 std::vector< TDataType > returnVec;
985 returnVec.resize(sizeOfReturn);
986 std::random_device rd;
987 std::mt19937 eng(rd());
988 std::normal_distribution< TDataType > distr();
990 for (
size_t i = 0; i < returnVec.size(); i++)
992 returnVec[i] = distr(eng);
1009 std::string fullFileName, path, base, extension;
1021 cbica::replaceString(fullFileName,
"\\",
"/");
1022 if (cbica::fileExists(inputFileName))
1023 cbica::splitFileName(fullFileName, path, base, extension);
1026 std::cerr <<
"The input file '" << inputFileName <<
"' wasn't found on disk.\n";
1037 fullFileName = inputFileName;
1038 cbica::replaceString(fullFileName,
"\\",
"/");
1039 if (cbica::fileExists(fullFileName))
1040 cbica::splitFileName(fullFileName, path, base, extension);
1043 std::cerr <<
"The input file '" << inputFileName <<
"' wasn't found on disk.\n";
size_t numberOfRowsInFile(const std::string &csvFileName, const std::string &delim="\n")
Find number of rows in CSV file.
bool setEnvironmentVariable(const std::string &variable_name, const std::string &variable_value)
Sets the environment variable.
std::map< std::string, size_t > ConfusionMatrix(const std::vector< float > &inputRealLabels, const std::vector< float > &inputPredictedLabels)
Calculates the Confusion Matrix for a set of real and predicted labels.
bool isDir(const std::string &path)
Return True if path is an existing directory.
bool makeFolder(const std::string &dir_name)
Create a directory.
bool isSymbolicLink(const std::string &path)
Check if path refers to a symbolic entry.
std::string makeTempDir()
Create a temporary directory.
std::vector< std::string > stringSplit(const std::string &str, const std::string &delim)
Splits the string.
bool makeSymbolicLink(const std::string &input_fileName, const std::string &ouput_fileName)
Make a symbolic link from file to another.
std::vector< std::string > inputImages
Contains input image file names.
Definition: cbicaUtilities.h:51
std::string getFilenameBase(const std::string &filename, bool checkFile=true)
Gets the base of the supplied file name using splitFileName()
std::string realPath(const std::string &path)
Return the canonical path of the specified filename.
CSVDict(const std::vector< std::string > &inputImagesVector, const std::vector< double > &inputLabelVector)
Constructor.
Definition: cbicaUtilities.h:69
size_t getFileSize(const std::string &inputFile)
Get the size of the file in bytes.
std::string getExecutablePath()
Get the path of the Executable which is calling the function.
size_t getDirectorySize(const std::string &rootFolder)
Get the size of the folder.
std::string replaceString(const std::string &entireString, const std::string &toReplace, const std::string &replaceWith)
Searches for smaller string in larger string and then replaces it with user-defined input.
bool isFile(const std::string &path)
Return True if path is an existing regular file.
TConvertType convertCharacter(const std::string &input_string)
Convert first character to integer, double, unsigned int, etc.
Definition: cbicaUtilities.h:831
size_t getFolderSize(const std::string &rootFolder)
Get the size of the folder.
bool fileExists(const std::string &fName)
Check if file exists using istream.
bool removeDir(const std::string &path)
Delete a folder and contents.
bool makeDir(const std::string &dir_name)
Create a directory.
bool directoryExists(const std::string &dName)
Check if directory exists.
Holds the different parts of a file name (path, base and extension)
Definition: cbicaUtilities.h:1007
std::string getUserHomeDirectory()
Get the home directory of the user.
std::vector< TConvertType > convertString(const std::string &input_string)
Convert entire string to integer, double, unsigned int, etc.
Definition: cbicaUtilities.h:843
std::vector< double > inputLabels
Contains Labels that correspond to each file.
Definition: cbicaUtilities.h:54
CSVDict(const CSVDict &origin)
Constructor.
Definition: cbicaUtilities.h:57
std::pair< bool, int > findInVector(std::vector< TContainerType > &vector_to_search_in, TContainerType element_to_search_for)
Searches for an element in a vector and returns true/false and position.
Definition: cbicaUtilities.h:804
size_t getDirSize(const std::string &rootFolder)
Get the size of the folder.
bool splitFileName(const std::string &dataFile, std::string &path, std::string &baseName, std::string &extension)
Splits the input file name into its constituents.
std::string normalizePath(const std::string &path)
Normalize a pathname by collapsing redundant separators and up-level references.
bool deleteEnvironmentVariable(const std::string &variable_name)
Delete the environment variable.
std::map< std::string, float > ROC_Values(const std::vector< float > &inputRealLabels, const std::vector< float > &inputPredictedLabels)
Calculates the ROC Values (see https://en.wikipedia.org/wiki/Receiver_operating_characteristic of all...
char * constCharToChar(const std::string &input)
Convert const char* to char*.
std::string createTemporaryDirectory()
Create a temporary directory.
bool makeDirectory(const std::string &dir_name)
Create a directory.
CSVDict()
Constructor.
Definition: cbicaUtilities.h:62
bool createDirectory(const std::string &dir_name)
Create a directory.
bool createFolder(const std::string &dir_name)
Create a directory.
std::vector< CSVDict > parseCSVFile(const std::string &csvFileName, const std::string &inputColumns, const std::string &inputLabels, bool checkFile=true, bool pathsRelativeToCSV=false, const std::string &rowsDelimiter="\n", const std::string &colsDelimiter=",", const std::string &optionsDelimiter=",")
Parse the supplied CSV File and obtain Row and Column information.
std::string getCWD()
Get the current working directory.
std::vector< std::string > filesInDirectory(const std::string &dirName, bool returnFullPath=true)
Find all files inside a directory.
std::string normPath(const std::string &path)
Normalize a pathname by collapsing redundant separators and up-level references.
bool exists(const std::string &path)
Return True if path exists and false for broken symbolic links.
std::string getFilenameExtension(const std::string &filename, bool checkFile=true)
Gets the extension of the supplied file name using splitFileName()
std::vector< TDataType > randn(const TDataType start, const TDataType end, size_t sizeOfReturn=1)
A good random number generator using c++11 that gives a random value within a range.
Definition: cbicaUtilities.h:960
A Dictionary structure to for CSV parsing.
Definition: cbicaUtilities.h:48
bool copyFolder(const std::string &inputFolder, const std::string &destination, bool recursion=true)
Copy a folder and if recursion enabled, all its contents.
bool copyFile(const std::string &inputFile, const std::string &destination)
Copy a folder and if recursion enabled, all its contents.
std::string getExecutableName()
Get the name of the Executable which is calling the function.
FileNameParts()
Default Constructor.
bool deleteDir(const std::string &path)
Delete a folder and contents.
size_t numberOfColsInFile(const std::string &csvFileName, const std::string &delim=",")
Find number of cols in CSV file.
std::string relPath(const std::string &path, const std::string &base)
Return a relative filepath to path.
std::string getFilenamePath(const std::string &filename, bool checkFile=true)
Gets the path of the supplied file name using splitFileName()
std::string getFullPath()
Get the name of the Executable which is calling the function.
void SetFileName(const std::string &inputFileName)
Member function to set the fullFileName.
Definition: cbicaUtilities.h:1035
std::string relativePath(const std::string &path, const std::string &base)
Return a relative filepath to path.
int removeDirectoryRecursively(const std::string &dirname, bool bDeleteSubdirectories)
Recursively delete a folder and contents [internal function].
std::string getUserName()
Get the name of the user who is calling the function.
FileNameParts(const std::string &inputFileName)
Constructor with input file string.
Definition: cbicaUtilities.h:1019
bool createDir(const std::string &dir_name)
Create a directory.
bool copyDir(const std::string &inputFolder, const std::string &destination, bool recursion=true)
Copy a folder and if recursion enabled, all its contents.
bool isLink(const std::string &path)
Return True if path refers to a directory entry that is a symbolic link.
bool copyDirectory(const std::string &inputFolder, const std::string &destination, bool recursion=true)
Copy a folder and if recursion enabled, all its contents.
std::vector< std::string > subdirectoriesInDirectory(const std::string &dirName, bool recursiveSearch=false, bool returnFullPath=false)
Find all sub-directories inside a directory.
std::string getEnvironmentVariableValue(const std::string &environmentVariable)
Gets the value of the specified environment variable.
std::vector< std::vector< TDataType > > readCSVDataFile(const std::string &csvFileName, bool columnMajor=false)
Read a CSV file which has no header information.
Definition: cbicaUtilities.h:644
std::string createTmpDir()
Create a temporary directory.
std::vector< TDataType > GetUniqueElements(const std::vector< TDataType > &inputVector)
Find the unique elements in a vector.
Definition: cbicaUtilities.h:711
std::string makeTemporaryDirectory()
Create a temporary directory.