-
- //clear out old values
- data.resize(1,0);
- penalty.resize(t->getNumLeaves(), 0);
-
- map<string,double> unique; //group, total of all branch lengths of nodes with that group.
- double shared = 0.0000;
- double UW=0.0000;
-
- //add up the branch lengths for each group.
- for(int i=0;i<t->getNumLeaves();i++){
- if(t->tree[i].pGroups.size() > 0){
- unique[t->tree[i].pGroups.begin()->first] += t->tree[i].getBranchLength();
+ processors = p;
+ outputDir = o;
+
+ CountTable* ct = t->getCountTable();
+
+ //if the users enters no groups then give them the score of all groups
+ int numGroups = m->getNumGroups();
+
+ //calculate number of comparsions
+ int numComp = 0;
+ vector< vector<string> > namesOfGroupCombos;
+ for (int r=0; r<numGroups; r++) {
+ for (int l = 0; l < r; l++) {
+ numComp++;
+ vector<string> groups; groups.push_back((m->getGroups())[r]); groups.push_back((m->getGroups())[l]);
+ namesOfGroupCombos.push_back(groups);
+ }
+ }
+
+ if (numComp != 1) {
+ vector<string> groups;
+ if (numGroups == 0) {
+ //get score for all users groups
+ for (int i = 0; i < (ct->getNamesOfGroups()).size(); i++) {
+ if ((ct->getNamesOfGroups())[i] != "xxx") {
+ groups.push_back((ct->getNamesOfGroups())[i]);
+ }
+ }
+ namesOfGroupCombos.push_back(groups);
+ }else {
+ for (int i = 0; i < m->getNumGroups(); i++) {
+ groups.push_back((m->getGroups())[i]);
+ }
+ namesOfGroupCombos.push_back(groups);
+ }
+ }
+
+ lines.clear();
+ int numPairs = namesOfGroupCombos.size();
+ int numPairsPerProcessor = numPairs / processors;
+
+ for (int i = 0; i < processors; i++) {
+ int startPos = i * numPairsPerProcessor;
+ if(i == processors - 1){ numPairsPerProcessor = numPairs - i * numPairsPerProcessor; }
+ lines.push_back(linePair(startPos, numPairsPerProcessor));
+ }
+
+ data = createProcesses(t, namesOfGroupCombos, ct);
+
+ lines.clear();
+
+ return data;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "Unweighted", "getValues");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+
+EstOutput Unweighted::createProcesses(Tree* t, vector< vector<string> > namesOfGroupCombos, CountTable* ct) {
+ try {
+ int process = 1;
+ vector<int> processIDS;
+
+ EstOutput results;
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+
+
+ //loop through and create all the processes you want
+ while (process != processors) {
+ int pid = fork();
+
+ if (pid > 0) {
+ processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
+ process++;
+ }else if (pid == 0){
+ EstOutput myresults;
+ myresults = driver(t, namesOfGroupCombos, lines[process].start, lines[process].num, ct);
+
+ if (m->control_pressed) { exit(0); }
+
+ //m->mothurOut("Merging results."); m->mothurOutEndLine();
+
+ //pass numSeqs to parent
+ ofstream out;
+ string tempFile = outputDir + toString(getpid()) + ".unweighted.results.temp";
+ m->openOutputFile(tempFile, out);
+ out << myresults.size() << endl;
+ for (int i = 0; i < myresults.size(); i++) { out << myresults[i] << '\t'; } out << endl;
+ out.close();
+
+ exit(0);
+ }else {
+ m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
+ for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
+ exit(0);