-
-void Pintail::createProcessesSpots() {
- try {
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
- int process = 0;
- vector<int> processIDS;
-
- //loop through and create all the processes you want
- while (process != processors) {
- int pid = fork();
-
- if (pid > 0) {
- processIDS.push_back(pid);
- process++;
- }else if (pid == 0){
-
- for (int j = lines[process]->start; j < lines[process]->end; j++) {
-
- //chops off beginning and end of sequences so they both start and end with a base
- map<int, int> trim;
-
- decalc->trimSeqs(querySeqs[j], bestfit[j], trim);
- trimmed[j] = trim;
-
- }
-
- mothurOut("Finding window breaks for sequences " + toString(lines[process]->start) + " to " + toString(lines[process]->end)); mothurOutEndLine();
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- it = trimmed[i].begin();
- windowsForeachQuery[i] = decalc->findWindows(querySeqs[i], it->first, it->second, windowSizes[i], increment);
- }
- mothurOut("Done finding window breaks for sequences " + toString(lines[process]->start) + " to " + toString(lines[process]->end)); mothurOutEndLine();
-
- //write out data to file so parent can read it
- ofstream out;
- string s = toString(getpid()) + ".temp";
- openOutputFile(s, out);
-
- //output windowsForeachQuery
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- out << windowsForeachQuery[i].size() << '\t';
- for (int j = 0; j < windowsForeachQuery[i].size(); j++) {
- out << windowsForeachQuery[i][j] << '\t';
- }
- out << endl;
- }
-
- //output windowSizes
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- out << windowSizes[i] << '\t';
- }
- out << endl;
-
- //output trimmed values
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- it = trimmed[i].begin();
- out << it->first << '\t' << it->second << endl;
- }
- out.close();
-
- exit(0);
- }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); }
- }
-
- //force parent to wait until all the processes are done
- for (int i=0;i<processors;i++) {
- int temp = processIDS[i];
- wait(&temp);
- }
-
- //get data created by processes
- for (int i=0;i<processors;i++) {
- ifstream in;
- string s = toString(processIDS[i]) + ".temp";
- openInputFile(s, in);
-
- int size = lines[i]->end - lines[i]->start;
-
- int count = lines[i]->start;
- for (int m = 0; m < size; m++) {
- int num;
- in >> num;
-
- vector<int> win; int w;
- for (int j = 0; j < num; j++) {
- in >> w;
- win.push_back(w);
- }
-
- windowsForeachQuery[count] = win;
- count++;
- gobble(in);
- }
-
- gobble(in);
- count = lines[i]->start;
- for (int m = 0; m < size; m++) {
- int num;
- in >> num;
-
- windowSizes[count] = num;
- count++;
- }
-
- gobble(in);
-
- count = lines[i]->start;
- for (int m = 0; m < size; m++) {
- int front, back;
- in >> front >> back;
-
- map<int, int> t;
-
- t[front] = back;
-
- trimmed[count] = t;
- count++;
-
- gobble(in);
- }
-
-
- in.close();
- remove(s.c_str());
- }
-
-
-#else
- for (int j = 0; j < bestfit.size(); j++) {
- //chops off beginning and end of sequences so they both start and end with a base
- decalc->trimSeqs(querySeqs[j], bestfit[j], trimmed[j]);
- }
-
- for (int i = lines[0]->start; i < lines[0]->end; i++) {
- it = trimmed[i].begin();
- vector<int> win = decalc->findWindows(querySeqs[i], it->first, it->second, windowSizes[i], increment);
- windowsForeachQuery[i] = win;
- }
-
-#endif
- }
- catch(exception& e) {
- errorOut(e, "Pintail", "createProcessesSpots");
- exit(1);
- }
-}
-/**************************************************************************************************/
-
-void Pintail::createProcessesPairs() {
- try {
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
- int process = 0;
- vector<int> processIDS;
-
- //loop through and create all the processes you want
- while (process != processors) {
- int pid = fork();
-
- if (pid > 0) {
- processIDS.push_back(pid);
- process++;
- }else if (pid == 0){
-
- mothurOut("Finding pairs for sequences " + toString(lines[process]->start) + " to " + toString(lines[process]->end)); mothurOutEndLine();
- bestfit = findPairs(lines[process]->start, lines[process]->end);
- mothurOut("Done finding pairs for sequences " + toString(lines[process]->start) + " to " + toString(lines[process]->end)); mothurOutEndLine();
-
- //write out data to file so parent can read it
- ofstream out;
- string s = toString(getpid()) + ".temp";
- openOutputFile(s, out);
-
- //output range and size
- out << bestfit.size() << endl;
-
- //output pairs
- for (int i = 0; i < bestfit.size(); i++) {
- out << ">" << bestfit[i]->getName() << endl << bestfit[i]->getAligned() << endl;
- }
- out.close();
-
- exit(0);
- }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); }
- }
-
- //force parent to wait until all the processes are done
- for (int i=0;i<processors;i++) {
- int temp = processIDS[i];
- wait(&temp);
- }
-
- //get data created by processes
- for (int i=0;i<processors;i++) {
- ifstream in;
- string s = toString(processIDS[i]) + ".temp";
- openInputFile(s, in);
-
- int size;
- in >> size; gobble(in);
-
- //get pairs
- int count = lines[i]->start;
- for (int m = 0; m < size; m++) {
- Sequence* temp = new Sequence(in);
- bestfit[count] = temp;
-
- count++;
- gobble(in);
- }
-
- in.close();
- remove(s.c_str());
- }
-
-
-#else
- bestfit = findPairs(lines[0]->start, lines[0]->end);
-#endif
- }
- catch(exception& e) {
- errorOut(e, "Pintail", "createProcessesPairs");
- exit(1);
- }
-}
-/**************************************************************************************************/
-
-void Pintail::createProcesses() {
- try {
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
- int process = 0;
- vector<int> processIDS;
-
- //loop through and create all the processes you want
- while (process != processors) {
- int pid = fork();
-
- if (pid > 0) {
- processIDS.push_back(pid);
- process++;
- }else if (pid == 0){
-
- mothurOut("Calculating observed, expected and de values for sequences " + toString(lines[process]->start) + " to " + toString(lines[process]->end)); mothurOutEndLine();
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
-
- vector<float> obsi = decalc->calcObserved(querySeqs[i], bestfit[i], windowsForeachQuery[i], windowSizes[i]);
- obsDistance[i] = obsi;
-
- //calc Qav
- vector<float> q = decalc->findQav(windowsForeachQuery[i], windowSizes[i], probabilityProfile);
-
- //get alpha
- float alpha = decalc->getCoef(obsDistance[i], q);
-
- //find expected
- vector<float> exp = decalc->calcExpected(q, alpha);
- expectedDistance[i] = exp;
-
- //get de and deviation
- float dei = decalc->calcDE(obsi, exp);
- DE[i] = dei;
-
- it = trimmed[i].begin();
- float dist = decalc->calcDist(querySeqs[i], bestfit[i], it->first, it->second);
- deviation[i] = dist;
- }
- mothurOut("Done calculating observed, expected and de values for sequences " + toString(lines[process]->start) + " to " + toString(lines[process]->end)); mothurOutEndLine();
-
- //write out data to file so parent can read it
- ofstream out;
- string s = toString(getpid()) + ".temp";
- openOutputFile(s, out);
-
- int size = lines[process]->end - lines[process]->start;
- out << size << endl;
-
- //output observed distances
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- out << obsDistance[i].size() << '\t';
- for (int j = 0; j < obsDistance[i].size(); j++) {
- out << obsDistance[i][j] << '\t';
- }
- out << endl;
- }
-
-
- //output expected distances
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- out << expectedDistance[i].size() << '\t';
- for (int j = 0; j < expectedDistance[i].size(); j++) {
- out << expectedDistance[i][j] << '\t';
- }
- out << endl;
- }
-
-
- //output de values
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- out << DE[i] << '\t';
- }
- out << endl;
-
- //output de values
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- out << deviation[i] << '\t';
- }
- out << endl;
-
- out.close();
-
- exit(0);
- }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); }
- }
-
- //force parent to wait until all the processes are done
- for (int i=0;i<processors;i++) {
- int temp = processIDS[i];
- wait(&temp);
- }
-
- //get data created by processes
- for (int i=0;i<processors;i++) {
- ifstream in;
- string s = toString(processIDS[i]) + ".temp";
- openInputFile(s, in);
-
- int size;
- in >> size; gobble(in);
-
- //get observed distances
- int count = lines[i]->start;
- for (int m = 0; m < size; m++) {
- int num;
- in >> num;
-
- vector<float> obs; float w;
- for (int j = 0; j < num; j++) {
- in >> w;
- obs.push_back(w);
- }
-
- obsDistance[count] = obs;
- count++;
- gobble(in);
- }
-
- gobble(in);
-
- //get expected distances
- count = lines[i]->start;
- for (int m = 0; m < size; m++) {
- int num;
- in >> num;
-
- vector<float> exp; float w;
- for (int j = 0; j < num; j++) {
- in >> w;
- exp.push_back(w);
- }
-
- expectedDistance[count] = exp;
- count++;
- gobble(in);
- }
-
- gobble(in);
-
- count = lines[i]->start;
- for (int m = 0; m < size; m++) {
- float num;
- in >> num;
-
- DE[count] = num;
- count++;
- }
-
- gobble(in);
-
- count = lines[i]->start;
- for (int m = 0; m < size; m++) {
- float num;
- in >> num;
-
- deviation[count] = num;
- count++;
- }
-
- in.close();
- remove(s.c_str());
- }
-
-
-#else
- mothurOut("Calculating observed distance... "); cout.flush();
- for (int i = lines[0]->start; i < lines[0]->end; i++) {
- vector<float> obsi = decalc->calcObserved(querySeqs[i], bestfit[i], windowsForeachQuery[i], windowSizes[i]);
- obsDistance[i] = obsi;
- }
- mothurOut("Done."); mothurOutEndLine();
-
-
-
- mothurOut("Finding variability... "); cout.flush();
- for (int i = lines[0]->start; i < lines[0]->end; i++) {
- vector<float> q = decalc->findQav(windowsForeachQuery[i], windowSizes[i], probabilityProfile);
- Qav[i] = q;
- }
- mothurOut("Done."); mothurOutEndLine();
-
-
-
- mothurOut("Calculating alpha... "); cout.flush();
- for (int i = lines[0]->start; i < lines[0]->end; i++) {
- float alpha = decalc->getCoef(obsDistance[i], Qav[i]);
- seqCoef.push_back(alpha);
- }
- mothurOut("Done."); mothurOutEndLine();
-
-
-
- mothurOut("Calculating expected distance... "); cout.flush();
- for (int i = lines[0]->start; i < lines[0]->end; i++) {
- vector<float> exp = decalc->calcExpected(Qav[i], seqCoef[i]);
- expectedDistance[i] = exp;
- }
- mothurOut("Done."); mothurOutEndLine();
-
-
-
- mothurOut("Finding deviation... "); cout.flush();
- for (int i = lines[0]->start; i < lines[0]->end; i++) {
- float de = decalc->calcDE(obsDistance[i], expectedDistance[i]);
- DE[i] = de;
-
- it = trimmed[i].begin();
- float dist = decalc->calcDist(querySeqs[i], bestfit[i], it->first, it->second);
- deviation[i] = dist;
- }
- mothurOut("Done."); mothurOutEndLine();
-
-#endif
- }
- catch(exception& e) {
- errorOut(e, "Pintail", "createProcesses");
- exit(1);
- }
-}
-
-
-/**************************************************************************************************/
-