X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=unifracweightedcommand.h;h=a5507cdb6cc2d95152eec0241f386acd66de1aab;hp=ea2c41814ac1940a61bd8c48995ecebcff30f324;hb=b206f634aae1b4ce13978d203247fb64757d5482;hpb=f18d75f9c996cb619a5051a7664620c0c5ae05fb diff --git a/unifracweightedcommand.h b/unifracweightedcommand.h index ea2c418..a5507cd 100644 --- a/unifracweightedcommand.h +++ b/unifracweightedcommand.h @@ -12,56 +12,145 @@ #include "command.hpp" #include "weighted.h" -#include "treemap.h" +#include "counttable.h" #include "progress.hpp" - -using namespace std; - -class GlobalData; +#include "sharedutilities.h" +#include "fileoutput.h" +#include "readtree.h" class UnifracWeightedCommand : public Command { public: - UnifracWeightedCommand(); - ~UnifracWeightedCommand() { delete weighted; } - int execute(); + UnifracWeightedCommand(string); + UnifracWeightedCommand(); + ~UnifracWeightedCommand() {} + + vector setParameters(); + string getCommandName() { return "unifrac.weighted"; } + string getCommandCategory() { return "Hypothesis Testing"; } + + string getHelpString(); + string getOutputPattern(string); + string getCitation() { return "Lozupone CA, Hamady M, Kelley ST, Knight R (2007). Quantitative and qualitative beta diversity measures lead to different insights into factors that structure microbial communities. Appl Environ Microbiol 73: 1576-85. \nhttp://www.mothur.org/wiki/Unifrac.weighted"; } + string getDescription() { return "generic tests that describes whether two or more communities have the same structure"; } + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; + struct linePair { + int start; + int num; + linePair(int i, int j) : start(i), num(j) {} + }; + vector lines; + CountTable* ct; + FileOutput* output; vector T; //user trees vector utreeScores; //user tree unweighted scores vector WScoreSig; //tree weighted score signifigance when compared to random trees - percentage of random trees with that score or lower. vector groupComb; // AB. AC, BC... - Tree* randT; //random tree - TreeMap* tmap; - Weighted* weighted; - string weightedFile, weightedFileout, sumFile; + string sumFile, outputDir; int iters, numGroups, numComp, counter; - EstOutput userData; //weighted score info for user tree - EstOutput randomData; //weighted score info for random trees vector< vector > rScores; //vector each group comb has an entry vector< vector > uScores; //vector each group comb has an entry - vector< map > rScoreFreq; //map -vector entry for each combination. - vector< map > rCumul; //map -vector entry for each c - map validScores; //map contains scores from random - map::iterator it2; - map::iterator it; + vector< map > rScoreFreq; //map -vector entry for each combination. + vector< map > rCumul; //map -vector entry for each c + map validScores; //map contains scores from random - ofstream outSum, out; - ifstream inFile; + bool abort, phylip, random, includeRoot, subsample, consensus; + string groups, itersString, outputForm, treefile, groupfile, namefile, countfile; + vector Groups, outputNames; //holds groups to be used + int processors, subsampleSize, subsampleIters; + ofstream outSum; + map nameMap; void printWSummaryFile(); void printWeightedFile(); + void createPhylipFile(); //void removeValidScoresDuplicates(); int findIndex(float, int); - void setGroups(); void calculateFreqsCumuls(); - void initFile(string); - void output(vector); - void resetFile(); + int createProcesses(Tree*, vector< vector >, vector< vector >&); + int driver(Tree*, vector< vector >, int, int, vector< vector >&); + int runRandomCalcs(Tree*, vector); + vector buildTrees(vector< vector >&, int, CountTable&); + int getConsensusTrees(vector< vector >&, int); + int getAverageSTDMatrices(vector< vector >&, int); + +}; +/***********************************************************************/ +struct weightedRandomData { + int start; + int num; + MothurOut* m; + vector< vector > scores; + vector< vector > namesOfGroupCombos; + Tree* t; + CountTable* ct; + bool includeRoot; + + weightedRandomData(){} + weightedRandomData(MothurOut* mout, int st, int en, vector< vector > ngc, Tree* tree, CountTable* count, bool ir, vector< vector > sc) { + m = mout; + start = st; + num = en; + namesOfGroupCombos = ngc; + t = tree; + ct = count; + includeRoot = ir; + scores = sc; + } }; +/**************************************************************************************************/ +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) +#else +static DWORD WINAPI MyWeightedRandomThreadFunction(LPVOID lpParam){ + weightedRandomData* pDataArray; + pDataArray = (weightedRandomData*)lpParam; + try { + + Tree* randT = new Tree(pDataArray->ct); + + Weighted weighted(pDataArray->includeRoot); + + for (int h = pDataArray->start; h < (pDataArray->start+pDataArray->num); h++) { + + if (pDataArray->m->control_pressed) { return 0; } + + //initialize weighted score + string groupA = pDataArray->namesOfGroupCombos[h][0]; + string groupB = pDataArray->namesOfGroupCombos[h][1]; + + //copy T[i]'s info. + randT->getCopy(pDataArray->t); + + //create a random tree with same topology as T[i], but different labels + randT->assembleRandomUnifracTree(groupA, groupB); + + if (pDataArray->m->control_pressed) { delete randT; return 0; } + + //get wscore of random tree + EstOutput randomData = weighted.getValues(randT, groupA, groupB); + + if (pDataArray->m->control_pressed) { delete randT; return 0; } + + //save scores + pDataArray->scores[h].push_back(randomData[0]); + } + + delete randT; + + return 0; + } + catch(exception& e) { + pDataArray->m->errorOut(e, "Weighted", "MyWeightedRandomThreadFunction"); + exit(1); + } +} +#endif #endif