CBICA Toolkit  1.0.0
cbicaUtilities.h File Reference

Some basic utility functions. More...

#include <string>
#include <typeinfo>
#include <vector>
#include <set>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <iterator>
#include <cmath>
#include <numeric>
#include <memory.h>
#include <map>
#include <random>
#include <iomanip>
#include <limits>
Include dependency graph for cbicaUtilities.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CSVDict
 A Dictionary structure to for CSV parsing. More...
 
struct  FileNameParts
 Holds the different parts of a file name (path, base and extension) More...
 

Functions

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. More...
 
char * constCharToChar (const std::string &input)
 Convert const char* to char*. More...
 
char * constCharToChar (const char *input)
 Convert const char* to char*. More...
 
template<typename TConvertType >
TConvertType convertCharacter (const std::string &input_string)
 Convert first character to integer, double, unsigned int, etc. More...
 
template<typename TConvertType = int>
std::vector< TConvertType > convertString (const std::string &input_string)
 Convert entire string to integer, double, unsigned int, etc. More...
 
bool copyDir (const std::string &inputFolder, const std::string &destination, bool recursion=true)
 Copy a folder and if recursion enabled, all its contents. More...
 
bool copyDirectory (const std::string &inputFolder, const std::string &destination, bool recursion=true)
 Copy a folder and if recursion enabled, all its contents. More...
 
bool copyFile (const std::string &inputFile, const std::string &destination)
 Copy a folder and if recursion enabled, all its contents. More...
 
bool copyFolder (const std::string &inputFolder, const std::string &destination, bool recursion=true)
 Copy a folder and if recursion enabled, all its contents. More...
 
bool createDir (const std::string &dir_name)
 Create a directory. More...
 
bool createDirectory (const std::string &dir_name)
 Create a directory. More...
 
bool createFolder (const std::string &dir_name)
 Create a directory. More...
 
std::string createTemporaryDirectory ()
 Create a temporary directory. More...
 
std::string createTmpDir ()
 Create a temporary directory. More...
 
bool deleteDir (const std::string &path)
 Delete a folder and contents. More...
 
bool deleteEnvironmentVariable (const std::string &variable_name)
 Delete the environment variable. More...
 
bool directoryExists (const std::string &dName)
 Check if directory exists. More...
 
void dos2unix (const std::string inputFile)
 Ensuring files written using Windows don't mess stuff up. More...
 
bool exists (const std::string &path)
 Return True if path exists and false for broken symbolic links. More...
 
bool fileExists (const std::string &fName)
 Check if file exists using istream. More...
 
std::vector< std::string > filesInDirectory (const std::string &dirName, bool returnFullPath=true)
 Find all files inside a directory. More...
 
template<typename TContainerType = std::string>
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. More...
 
std::string getCurrentGMT ()
 Get current GMT as string delineated as HH:MM:SS.
 
std::string getCurrentGMTDate ()
 Get current GMT as string delineated as YYYY:MM:DD.
 
std::string getCurrentGMTDateAndTime ()
 Get current GMT as string delineated as YYYY:MM:DD,HH:MM:SS.
 
std::string getCurrentLocalDate ()
 Get current local time as string delineated as YYYY:MM:DD.
 
std::string getCurrentLocalDateAndTime ()
 Get current local time as string delineated as YYYY:MM:DD,HH:MM:SS.
 
std::string getCurrentLocalTime ()
 Get current local time as string delineated as HH:MM:SS.
 
std::string getCurrentProcessID ()
 Get the current process ID. More...
 
std::string getCurrentYear ()
 Get current Year as string delineated as YYYY.
 
std::string getCWD ()
 Get the current working directory. More...
 
std::vector< std::string > getCWLFilesInApplicationDir ()
 
size_t getDirectorySize (const std::string &rootFolder)
 Get the size of the folder. More...
 
size_t getDirSize (const std::string &rootFolder)
 Get the size of the folder. More...
 
std::string getEnvironmentVariableValue (const std::string &environmentVariable)
 Gets the value of the specified environment variable.
 
std::string getExecutableName ()
 Get the name of the Executable which is calling the function. More...
 
std::string getExecutablePath ()
 Get the path of the Executable which is calling the function. More...
 
std::string getFilenameBase (const std::string &filename, bool checkFile=true)
 Gets the base of the supplied file name using splitFileName() More...
 
std::string getFilenameExtension (const std::string &filename, bool checkFile=true)
 Gets the extension of the supplied file name using splitFileName() More...
 
std::string getFilenamePath (const std::string &filename, bool checkFile=true)
 Gets the path of the supplied file name using splitFileName() More...
 
size_t getFileSize (const std::string &inputFile)
 Get the size of the file in bytes. More...
 
size_t getFolderSize (const std::string &rootFolder)
 Get the size of the folder. More...
 
std::string getFullPath ()
 Get the name of the Executable which is calling the function. More...
 
template<class TDataType = std::string>
std::vector< TDataType > GetUniqueElements (const std::vector< TDataType > &inputVector)
 Find the unique elements in a vector. More...
 
std::string getUserHomeDirectory ()
 Get the home directory of the user. More...
 
std::string getUserName ()
 Get the name of the user who is calling the function. More...
 
bool IsCompatible (const std::string inputVersionFile)
 
bool isDir (const std::string &path)
 Return True if path is an existing directory. More...
 
bool isFile (const std::string &path)
 Return True if path is an existing regular file. More...
 
bool isLink (const std::string &path)
 Return True if path refers to a directory entry that is a symbolic link. More...
 
bool isSymbolicLink (const std::string &path)
 Check if path refers to a symbolic entry. More...
 
bool makeDir (const std::string &dir_name)
 Create a directory. More...
 
bool makeDirectory (const std::string &dir_name)
 Create a directory. More...
 
bool makeFolder (const std::string &dir_name)
 Create a directory. More...
 
bool makeSymbolicLink (const std::string &input_fileName, const std::string &ouput_fileName)
 Make a symbolic link from file to another. More...
 
std::string makeTempDir ()
 Create a temporary directory. More...
 
std::string makeTemporaryDirectory ()
 Create a temporary directory. More...
 
std::string normalizePath (const std::string &path)
 Normalize a pathname by collapsing redundant separators and up-level references. More...
 
std::string normPath (const std::string &path)
 Normalize a pathname by collapsing redundant separators and up-level references. More...
 
size_t numberOfColsInFile (const std::string &csvFileName, const std::string &delim=",")
 Find number of cols in CSV file.
 
size_t numberOfRowsInFile (const std::string &csvFileName, const std::string &delim="\n")
 Find number of rows in CSV file.
 
std::vector< CSVDictparseCSVFile (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. More...
 
template<class TDataType = float>
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. More...
 
template<class TDataType = float>
std::vector< TDataType > randn (size_t sizeOfReturn=1)
 A good random number generator using c++11 that gives a random value within a range. More...
 
template<class TDataType = double>
std::vector< std::vector< TDataType > > readCSVDataFile (const std::string &csvFileName, bool columnMajor=false)
 Read a CSV file which has no header information. More...
 
std::vector< std::vector< std::string > > readCSVDataFile (const std::string &csvFileName)
 Read a CSV file which has no header information. More...
 
std::string realPath (const std::string &path)
 Return the canonical path of the specified filename. More...
 
std::string relativePath (const std::string &path, const std::string &base)
 Return a relative filepath to path. More...
 
std::string relPath (const std::string &path, const std::string &base)
 Return a relative filepath to path. More...
 
bool removeDir (const std::string &path)
 Delete a folder and contents. More...
 
int removeDirectoryRecursively (const std::string &dirname, bool bDeleteSubdirectories)
 Recursively delete a folder and contents [internal function]. More...
 
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. More...
 
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 estimates) for a set of real and predicted labels. More...
 
bool setEnvironmentVariable (const std::string &variable_name, const std::string &variable_value)
 Sets the environment variable. More...
 
void sleep (size_t ms=std::rand() % 1000+1)
 Cross platform sleep. More...
 
bool splitFileName (const std::string &dataFile, std::string &path, std::string &baseName, std::string &extension)
 Splits the input file name into its constituents. More...
 
std::vector< std::string > stringSplit (const std::string &str, const std::string &delim)
 Splits the string. More...
 
std::vector< std::string > subdirectoriesInDirectory (const std::string &dirName, bool recursiveSearch=false, bool returnFullPath=false)
 Find all sub-directories inside a directory. More...
 

Detailed Description

Some basic utility functions.

This needs c++11 flag enabled in gcc < 5.

https://www.med.upenn.edu/sbia/software///
softw.nosp@m.are@.nosp@m.cbica.nosp@m..upe.nosp@m.nn.ed.nosp@m.u

Copyright (c) 2018 University of Pennsylvania. All rights reserved.
See COPYING file or https://www.med.upenn.edu/cbica/software-agreement.html

Function Documentation

◆ ConfusionMatrix()

std::map< std::string, size_t > cbica::ConfusionMatrix ( const std::vector< float > &  inputRealLabels,
const std::vector< float > &  inputPredictedLabels 
)

Calculates the Confusion Matrix for a set of real and predicted labels.

Values returned: True Positive (TP), False Positive (FP), True Negative (TN), False Negative (FN), Real Positive (RP), Preditcted Positive (PP)

Parameters
inputRealLabelsVector structure containing real labels
inputPredictedLabelsVector structure containing predicted labels
Returns
std::map< string, size_t > A map of string and corresponding non-negative values

◆ constCharToChar() [1/2]

char* cbica::constCharToChar ( const std::string &  input)

Convert const char* to char*.

Parameters
inputconstant std::string
Returns
character pointer

◆ constCharToChar() [2/2]

char* cbica::constCharToChar ( const char *  input)

Convert const char* to char*.

Parameters
inputconstant character pointer
Returns
character pointer

◆ convertCharacter()

TConvertType cbica::convertCharacter ( const std::string &  input_string)

Convert first character to integer, double, unsigned int, etc.

Parameters
input_stringInput character to be converted
Returns
Templated to the type of return required

References cbica::convertCharacter().

Referenced by cbica::convertCharacter().

◆ convertString()

std::vector< TConvertType> cbica::convertString ( const std::string &  input_string)

Convert entire string to integer, double, unsigned int, etc.

Parameters
input_stringInput character to be converted
Returns
Templated vector to the type of return required

References cbica::convertString().

Referenced by cbica::convertString().

◆ copyDir()

bool cbica::copyDir ( const std::string &  inputFolder,
const std::string &  destination,
bool  recursion = true 
)

Copy a folder and if recursion enabled, all its contents.

https://msdn.microsoft.com/en-us/library/hh874694.aspx?f=255&MSPPError=-2147217396

Parameters
inputFolderFolder to copy
destinationWhere to copy to
recursionDo recursion and copy, defaults to true
Returns
true for success

◆ copyDirectory()

bool cbica::copyDirectory ( const std::string &  inputFolder,
const std::string &  destination,
bool  recursion = true 
)

Copy a folder and if recursion enabled, all its contents.

https://msdn.microsoft.com/en-us/library/hh874694.aspx?f=255&MSPPError=-2147217396

Parameters
inputFolderFolder to copy
destinationWhere to copy to
recursionDo recursion and copy, defaults to true
Returns
true for success

◆ copyFile()

bool cbica::copyFile ( const std::string &  inputFile,
const std::string &  destination 
)

Copy a folder and if recursion enabled, all its contents.

Parameters
inputFileFile to copy
destinationWhere to copy to
Returns
true for success

◆ copyFolder()

bool cbica::copyFolder ( const std::string &  inputFolder,
const std::string &  destination,
bool  recursion = true 
)

Copy a folder and if recursion enabled, all its contents.

https://msdn.microsoft.com/en-us/library/hh874694.aspx?f=255&MSPPError=-2147217396

Parameters
inputFolderFolder to copy
destinationWhere to copy to
recursionDo recursion and copy, defaults to true
Returns
true for success

◆ createDir()

bool cbica::createDir ( const std::string &  dir_name)

Create a directory.

Parameters
dir_nameName of directory to be created with full path
Returns
True if success

Referenced by cbica::WriteDicomImage().

◆ createDirectory()

bool cbica::createDirectory ( const std::string &  dir_name)

Create a directory.

Parameters
dir_nameName of directory to be created with full path
Returns
True if success

◆ createFolder()

bool cbica::createFolder ( const std::string &  dir_name)

Create a directory.

Parameters
dir_nameName of directory to be created with full path
Returns
True if success

◆ createTemporaryDirectory()

std::string cbica::createTemporaryDirectory ( )

Create a temporary directory.

Wrap for createTmpDir()

Returns
True if success

◆ createTmpDir()

std::string cbica::createTmpDir ( )

Create a temporary directory.

Creates a user-writable file using the following format: USER_HOME_DIR + EXE_NAME + tmp_ + processID;

If this file is existing, for whatever reason, then a new is created which has the time stamp appended.

Returns
Path of temporary directory

◆ deleteDir()

bool cbica::deleteDir ( const std::string &  path)

Delete a folder and contents.

Parameters
pathFolder to delete
Returns
true for success

◆ deleteEnvironmentVariable()

bool cbica::deleteEnvironmentVariable ( const std::string &  variable_name)

Delete the environment variable.

Parameters
variable_nameName of the Variable
Returns
True if successful

◆ directoryExists()

bool cbica::directoryExists ( const std::string &  dName)

Check if directory exists.

Parameters
dNameString to check
Returns
True if directory exists

◆ dos2unix()

void cbica::dos2unix ( const std::string  inputFile)

Ensuring files written using Windows don't mess stuff up.

Base implementation from https://www.digitalpeer.com/blog/simple-text-processing-with-cpp-dos2unix-example

◆ exists()

bool cbica::exists ( const std::string &  path)

Return True if path exists and false for broken symbolic links.

Reimplementation of python's "os.path.exists": On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.

Parameters
pathPath to check
Returns
True if path is valid and false for broken symbolic links

◆ fileExists()

bool cbica::fileExists ( const std::string &  fName)

Check if file exists using istream.

Parameters
fNameFilename to check
Returns
True if file exists

◆ filesInDirectory()

std::vector< std::string > cbica::filesInDirectory ( const std::string &  dirName,
bool  returnFullPath = true 
)

Find all files inside a directory.

Parameters
dirNameThe directory to do the search in

Referenced by cbica::GetImageReader().

◆ findInVector()

std::pair<bool, int> cbica::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.

Templated function to take in any kind of vector and element.

Parameters
vector_to_search_inVector to do the search in
element_to_search_forElement to search for
positionLast position of found element in vector (-1) if not found
Returns
True if found
Position if found (-1) if not

References cbica::findInVector().

Referenced by cbica::findInVector().

◆ getCurrentProcessID()

std::string cbica::getCurrentProcessID ( )

Get the current process ID.

Provides wraps to _getpid() in OS-specific ways

◆ getCWD()

std::string cbica::getCWD ( )

Get the current working directory.

[Wrap for cbica::getcwd()]

Returns
Current working directory

◆ getDirectorySize()

size_t cbica::getDirectorySize ( const std::string &  rootFolder)

Get the size of the folder.

Parameters
rootFolderThe input folder

◆ getDirSize()

size_t cbica::getDirSize ( const std::string &  rootFolder)

Get the size of the folder.

Parameters
rootFolderThe input folder

◆ getExecutableName()

std::string cbica::getExecutableName ( )

Get the name of the Executable which is calling the function.

Returns
exe name

◆ getExecutablePath()

std::string cbica::getExecutablePath ( )

Get the path of the Executable which is calling the function.

returns the path after calling splitFileName on getFullPath

Returns
exe name

◆ getFilenameBase()

std::string cbica::getFilenameBase ( const std::string &  filename,
bool  checkFile = true 
)

Gets the base of the supplied file name using splitFileName()

Prefer to use "/" as file path delimiter.

Parameters
filenameThe input filename
checkFileChecks existence of file using fileExists
Returns
std::string which has the file extension

◆ getFilenameExtension()

std::string cbica::getFilenameExtension ( const std::string &  filename,
bool  checkFile = true 
)

Gets the extension of the supplied file name using splitFileName()

Prefer to use "/" as file path delimiter.

Parameters
filenameThe input filename
checkFileChecks existence of file using fileExists
Returns
std::string which has the file extension

Referenced by cbica::GetImageReader(), cbica::ReadImageWithOrientFix(), and cbica::WriteImage().

◆ getFilenamePath()

std::string cbica::getFilenamePath ( const std::string &  filename,
bool  checkFile = true 
)

Gets the path of the supplied file name using splitFileName()

Prefer to use "/" as file path delimiter.

Parameters
filenameThe input filename
checkFileChecks existence of file using fileExists
Returns
std::string which has the file extension

Referenced by cbica::GetDicomImageReader(), and cbica::GetImageReader().

◆ getFileSize()

size_t cbica::getFileSize ( const std::string &  inputFile)

Get the size of the file in bytes.

Parameters
inputFileThe input file

◆ getFolderSize()

size_t cbica::getFolderSize ( const std::string &  rootFolder)

Get the size of the folder.

Parameters
rootFolderThe input folder

◆ getFullPath()

std::string cbica::getFullPath ( )

Get the name of the Executable which is calling the function.

Returns
exe name

◆ GetUniqueElements()

std::vector< TDataType > cbica::GetUniqueElements ( const std::vector< TDataType > &  inputVector)

Find the unique elements in a vector.

Implementation incorporated from the SO answer in https://stackoverflow.com/a/1041939/1228757

Parameters
inputVectorThe vector on which to search for unique elements
Returns
An std::vector with unique elements

References cbica::GetUniqueElements().

Referenced by cbica::GetDicomImageReader(), and cbica::GetUniqueElements().

◆ getUserHomeDirectory()

std::string cbica::getUserHomeDirectory ( )

Get the home directory of the user.

Windows - C:/Users/XYZ Linux - /home/XYZ

Returns
user directory

◆ getUserName()

std::string cbica::getUserName ( )

Get the name of the user who is calling the function.

Returns
user name

◆ isDir()

bool cbica::isDir ( const std::string &  path)

Return True if path is an existing directory.

Reimplementation of python's "os.path.isdir": This follows symbolic links, so both islink() and isdir() can be true for the same path.

[Wrap of cbica::directoryExists()]

Parameters
pathDirectory name to check
Returns
True of path is an existing directory

Referenced by cbica::GetDicomImageReader(), and cbica::WriteDicomImage().

◆ isFile()

bool cbica::isFile ( const std::string &  path)

Return True if path is an existing regular file.

Reimplementation for python's "os.path.isfile": This follows symbolic links, so both islink() and isfile() can be true for the same path.

[Wrap of cbica::fileExists()]

Parameters
pathFilename of file to check
Returns
True if path is an existing regular file

Referenced by cbica::readCSVDataFile().

◆ isLink()

bool cbica::isLink ( const std::string &  path)

Return True if path refers to a directory entry that is a symbolic link.

Reimplementation of python's "os.path.islink": Always False if symbolic links are not supported by the python runtime.

Parameters
pathPath to check
Returns
True if path is symbolic link

◆ isSymbolicLink()

bool cbica::isSymbolicLink ( const std::string &  path)

Check if path refers to a symbolic entry.

[Wrap of cbica::isLink()]

Parameters
pathPath to check
Returns
True if path is symbolic link

◆ makeDir()

bool cbica::makeDir ( const std::string &  dir_name)

Create a directory.

Parameters
dir_nameName of directory to be created with full path

◆ makeDirectory()

bool cbica::makeDirectory ( const std::string &  dir_name)

Create a directory.

Parameters
dir_nameName of directory to be created with full path

◆ makeFolder()

bool cbica::makeFolder ( const std::string &  dir_name)

Create a directory.

Parameters
dir_nameName of directory to be created with full path

◆ makeSymbolicLink()

bool cbica::makeSymbolicLink ( const std::string &  input_fileName,
const std::string &  ouput_fileName 
)

Make a symbolic link from file to another.

Parameters
input_fileNameInput file name for which symbolic link needs to be created
output_fileNameOutput file name which is the symbolic link for input_fileName
Returns
True if symbolic link successfully created

◆ makeTempDir()

std::string cbica::makeTempDir ( )

Create a temporary directory.

Wrap for createTmpDir()

Returns
True if success

◆ makeTemporaryDirectory()

std::string cbica::makeTemporaryDirectory ( )

Create a temporary directory.

Wrap for createTmpDir()

Returns
True if success

◆ normalizePath()

std::string cbica::normalizePath ( const std::string &  path)

Normalize a pathname by collapsing redundant separators and up-level references.

[Wrap for cbica::normPath()]

Parameters
pathPath to normalize
Returns
std::string Normalized path

◆ normPath()

std::string cbica::normPath ( const std::string &  path)

Normalize a pathname by collapsing redundant separators and up-level references.

Reimplementation of python's "os.path.normpath": Normalize a pathname by collapsing redundant separators and up-level references so that A//B, A/B/, A/./B and A/foo/../B all become A/B. This string manipulation may change the meaning of a path that contains symbolic links. On Windows, it converts forward slashes to backward slashes.

Parameters
pathPath to normalize
Returns
std::string Normalized path

Referenced by cbica::GetDicomImageReader(), and cbica::GetImageReader().

◆ parseCSVFile()

std::vector< CSVDict > cbica::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.

Assumptions:

  1. Header information is in first row
  2. Full paths of images are given
  3. Image paths are either absolute (default behaviour) OR relative to the location of CSV file OR relative to CWD
Parameters
csvFileNameThe full path of the file to parse, all paths are absolute or relative to current working directory
inputColumnsThe string of input columns which contain the data to be used for further processing
inputLabelsThe string of input labels per subject based on which further processing is to be done; if this is empty, it is initialized as 1 for all subjects
checkFileCheck the validity of the file; defaults to true
pathsRelativeToCSVThe paths in the CSV file are relative to the location of CSV file otherwise, they are checked relative to the CWD
rowsDelimiterThe delimiters used to distinguish rows in the file
colsDelimiterThe delimiters used to distinguish cols in the file
optionsDelimiterThe delimiters used in inputColumns and inputLabel
Returns
Vector of CSV Dictionary items: Collection of input images are respective labels

◆ randn() [1/2]

std::vector< TDataType > cbica::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.

Parameters
startStart value of range; defaults to 0
endEnd value of range; defaults to 1
sizeOfReturnSize of the returned vector

References cbica::randn().

Referenced by cbica::randn().

◆ randn() [2/2]

std::vector< TDataType > cbica::randn ( size_t  sizeOfReturn = 1)

A good random number generator using c++11 that gives a random value within a range.

Parameters
sizeOfReturnSize of the returned vector

References cbica::randn().

◆ readCSVDataFile() [1/2]

std::vector< std::vector< TDataType > > cbica::readCSVDataFile ( const std::string &  csvFileName,
bool  columnMajor = false 
)

Read a CSV file which has no header information.

To read CSV file with header information, check parseCSVFile() function. This should not be used for obtaining strings

Parameters
csvFileNameThe full path of the file to parse, all paths are absolute or relative to current working directory
columnMajorIf true, then return is a vector of all the columns; otherwise it is a vector of the rows

References cbica::isFile(), cbica::numberOfColsInFile(), cbica::numberOfRowsInFile(), and cbica::readCSVDataFile().

Referenced by cbica::readCSVDataFile().

◆ readCSVDataFile() [2/2]

std::vector< std::vector< std::string > > cbica::readCSVDataFile ( const std::string &  csvFileName)

Read a CSV file which has no header information.

To read CSV file with header information, check parseCSVFile() function. This should be used for obtaining strings

Parameters
csvFileNameThe full path of the file to parse, all paths are absolute or relative to current working directory

◆ realPath()

std::string cbica::realPath ( const std::string &  path)

Return the canonical path of the specified filename.

Reimplementation of python's "os.path.realpath": Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path (if they are supported by the operating system).

Parameters
pathFilename to check
Returns
canonical path of path

◆ relativePath()

std::string cbica::relativePath ( const std::string &  path,
const std::string &  base 
)

Return a relative filepath to path.

Wrap of cbica::relPath()

Parameters
pathPath to check
baseBase file name
Returns
Relative filepath to path either from current directory or from an optional start dir

◆ relPath()

std::string cbica::relPath ( const std::string &  path,
const std::string &  base 
)

Return a relative filepath to path.

Reimplementation for python's "os.path.relpath": Return a relative filepath to path either from the current directory or from an optional start directory. This is a path computation: the filesystem is not accessed to confirm the existence or nature of path or start.

Parameters
pathPath to check
baseBase file name
Returns
Relative filepath to path either from current directory or from an optional start dir

◆ removeDir()

bool cbica::removeDir ( const std::string &  path)

Delete a folder and contents.

Parameters
pathFolder to delete
Returns
true for success

◆ removeDirectoryRecursively()

int cbica::removeDirectoryRecursively ( const std::string &  dirname,
bool  bDeleteSubdirectories 
)

Recursively delete a folder and contents [internal function].

Parameters
dirnameFolder to delete
Returns
true for success

◆ replaceString()

std::string cbica::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.

Parameters
entireStringString to search
toReplaceString to replace
replaceWithString to replace toReplace with
Returns
std::string of result

◆ ROC_Values()

std::map< std::string, float > cbica::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 estimates) for a set of real and predicted labels.

Values returned: True Positive (TP), False Positive (FP), True Negative (TN), False Negative (FN), Real Positive (RP), Preditcted Positive (PP) [all from ConfusionMatrix()], Accuracy, Positive Predictive Value (PPV) [aka Precision], False Discovery Rate (FDR), False Omission Rate (FOR), Negative Predictive Value (NPV), Prevalence, True Positive Rate (TPR) [aka Sensitivity, Recall, Probability of Detection (POD)], False Positive Rate (FPR) [aka Fall-out], False Negative Rate (FNR) [aka Miss Rate (MR)], True Negative Rate (TNR) [aka Specificity], Positive Likelihood Ratio (LR+), Negative Likelihood Ratio (LR−), Diagnostic Odds Ratio (DOR), Dice Score (Dice), Jaccard ratio/index (JR)

Parameters
inputRealLabelsVector structure containing real labels
inputPredictedLabelsVector structure containing predicted labels
Returns
std::map< string, size_t > A map of string and corresponding float values

◆ setEnvironmentVariable()

bool cbica::setEnvironmentVariable ( const std::string &  variable_name,
const std::string &  variable_value 
)

Sets the environment variable.

Parameters
variable_nameName of the Variable
variable_valueValue of variable_name
Returns
True if successful

◆ sleep()

void cbica::sleep ( size_t  ms = std::rand() % 1000+1)

Cross platform sleep.

Defaults to "std::rand() % 1000 + 1"

◆ splitFileName()

bool cbica::splitFileName ( const std::string &  dataFile,
std::string &  path,
std::string &  baseName,
std::string &  extension 
)

Splits the input file name into its constituents.

Parameters
dataFileThe full file name which is the input
baseNameOverwritten with file name without extension
extensionOverwritten with extension without '.'
pathOverwritten with path to file
Returns
True if successful

◆ stringSplit()

std::vector<std::string> cbica::stringSplit ( const std::string &  str,
const std::string &  delim 
)

Splits the string.

Parameters
strString to split
delimDelimiter on the basis of which splitting is to be done
Returns
results Output in the form of vector of strings

Referenced by cbica::ChangeImageValues(), and cbica::GetImageReader().

◆ subdirectoriesInDirectory()

std::vector<std::string> cbica::subdirectoriesInDirectory ( const std::string &  dirName,
bool  recursiveSearch = false,
bool  returnFullPath = false 
)

Find all sub-directories inside a directory.

Parameters
dirNameThe directory to do the search in
recursiveSearchWhether to do a recursive search or on a single level