Skip to content

Commit

Permalink
added controls over header for initial values files
Browse files Browse the repository at this point in the history
  • Loading branch information
josura committed Aug 15, 2023
1 parent b69158c commit 9e91119
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/utilities.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@ std::tuple<std::vector<std::string>,std::vector<std::string>,std::vector<std::ve
//default argument for subtype is empty, if empty, use all files in the folder
if(subType.size()==0){
for(auto iter = files.cbegin();iter!=files.cend();iter++){
subType.push_back(splitString(*iter, ".")[0]);
std::vector<std::string> splitted = splitString(*iter, "/"); //split the path
std::string filename = splitted[splitted.size()-1]; //last element
subType.push_back(splitString(filename, ".")[0]);
}
}
//filter files from subtypes (first part of the filename before the extension)
Expand Down Expand Up @@ -492,6 +494,17 @@ std::tuple<std::vector<std::string>,std::vector<std::string>,std::vector<std::ve
ifstream myfile (filename);
string line;
std::vector<double> cellValues(finalNames[i].size(),0);
std::string lineHeader;
getline (myfile,lineHeader); // first line is header IMPORTANT
std::vector<std::string> splittedHeader = splitString(lineHeader, "\t");
//check if the header is correct
if(splittedHeader.size()!=2){
throw std::invalid_argument("utilities::logFoldChangeCellVectorsFromFolder: header doesn't have the same amount of columns as the data " + filename);
}
if(splittedHeader[0]!="name" || splittedHeader[1] != "value"){
throw std::invalid_argument("utilities::logFoldChangeCellVectorsFromFolder: header doesn't have the name and value columns or it does not have an header" + filename);
}
//get file contents
while ( getline (myfile,line) )
{
std::vector<std::string> entries = splitString(line, "\t");
Expand Down
2 changes: 1 addition & 1 deletion src/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ std::vector<T> vectorScalarMultiplication(std::vector<T> vec, T scalar){
}

template<typename T>
bool vectorContains(std::vector<T> vec, T element){
bool vectorContains(std::vector<T> vec, const T element){
for (uint i = 0; i < vec.size(); ++i) {
if(vec[i]==element){
return true;
Expand Down

0 comments on commit 9e91119

Please sign in to comment.