The coding part where the occurences of the codons are counted is still wrong and extremely inefficient.
Remove statement 'ifstream myFile("mouse.dat");' because myFile was not used in the loop.
Don't use a for loop from 0 to 64 to look for the occurrences of each of the 64 codes because one single loop is sufficient (see below).
Don't use FileContents.find(codon). the find function will find occurences which are not valid because the position in the contents is not a multiple of 3.
Counting can be done with one loop:
std::map<std::string, int> countMap; std::string codon(3, '\0'); len = FileContents.length(); for (int i = 0; i < len-2; i += 3) { codon = FileContents.substr(i, 3); countMap[codon]++; }
this code relies on a proper input. e. g. the file must not contain spaces or garbage lines or letters different from "acgt".
you could check that when reading the file rather than in the counting part
double start = omp_get_wtime(); std::ifstream myfile("mouse.dat"); std::string FileContents; std::string line; std::string whites = " \nr\t"; int len = 0; while (std::getline(myfile, line)) { //check line and trim right len = (int)line.length(); // we either should find no garbage or at most some trailing whitespace int end = (int)line.find_first_not_of("acgt"); if (end != std::string::npos) { // check that the garbage is only whitespace if (line.substr(end).find_first_not_of(whites) != std::string::npos) { std::cout << "wrong input line\n" << line << "\n"; return -2; }; line.resize(end); // trim line if trailing white space } FileContents += line; } // finally the whole text length must be a multiple of 3 len = FileContents.length(); if (len%3 != 0) { std::cout << "contents is not a multiple of 3" << "\n"; return -3; }
a)
Replace:
}
return 0;
printf("Time: \t %f \n", omp_get_wtime() - start);
}
With:
}
printf("Time: \t %f \n", omp_get_wtime() - start);
return 0;
}
and recompile to get the Time.
b)
// Always initialize a variable.
int id = 0;