1 #ifndef METASTATSCOMMAND_H
2 #define METASTATSCOMMAND_H
8 * Created by westcott on 9/16/10.
9 * Copyright 2010 Schloss Lab. All rights reserved.
13 #include "command.hpp"
14 #include "inputdata.h"
15 #include "sharedrabundvector.h"
16 #include "mothurmetastats.h"
18 class MetaStatsCommand : public Command {
21 MetaStatsCommand(string);
23 ~MetaStatsCommand() {}
25 vector<string> setParameters();
26 string getCommandName() { return "metastats"; }
27 string getCommandCategory() { return "OTU-Based Approaches"; }
29 string getHelpString();
30 string getOutputPattern(string);
31 string getCitation() { return "White JR, Nagarajan N, Pop M (2009). Statistical methods for detecting differentially abundant features in clinical metagenomic samples. PLoS Comput Biol 5: e1000352. \nhttp://www.mothur.org/wiki/Metastats"; }
32 string getDescription() { return "detects differentially abundant features in clinical metagenomic samples"; }
35 void help() { m->mothurOut(getHelpString()); }
41 linePair(int i, int j) : start(i), num(j) {}
43 vector<linePair> lines;
47 vector<SharedRAbundVector*> lookup;
49 bool abort, allLines, pickedGroups;
50 set<string> labels; //holds labels to be used
51 string groups, label, outputDir, inputDir, designfile, sets, sharedfile;
52 vector<string> Groups, outputNames, Sets;
53 vector< vector<string> > namesOfGroupCombos;
54 int iters, processors;
57 int process(vector<SharedRAbundVector*>&);
58 int driver(int, int, vector<SharedRAbundVector*>&);
61 /**************************************************************************************************/
62 //custom data structure for threads to use.
63 // This is passed by void pointer so it can be any data type
64 // that can be passed using a single void pointer (LPVOID).
65 struct metastatsData {
66 vector<SharedRAbundVector*> thisLookUp;
67 vector< vector<string> > namesOfGroupCombos;
68 vector<string> designMapGroups;
69 vector<string> outputNames;
71 int num, iters, count;
78 metastatsData(string sf, string oDir, MothurOut* mout, int st, int en, vector< vector<string> > ns, vector<SharedRAbundVector*> lu, vector<string> dg, int i, float thr) {
84 namesOfGroupCombos = ns;
92 /**************************************************************************************************/
93 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
95 static DWORD WINAPI MyMetastatsThreadFunction(LPVOID lpParam){
96 metastatsData* pDataArray;
97 pDataArray = (metastatsData*)lpParam;
102 for (int c = pDataArray->start; c < (pDataArray->start+pDataArray->num); c++) {
105 string setA = pDataArray->namesOfGroupCombos[c][0];
106 string setB = pDataArray->namesOfGroupCombos[c][1];
109 string outputFileName = pDataArray->outputDir + pDataArray->m->getRootName(pDataArray->m->getSimpleName(pDataArray->sharedfile)) + pDataArray->thisLookUp[0]->getLabel() + "." + setA + "-" + setB + ".metastats";
110 pDataArray->outputNames.push_back(outputFileName);
112 vector< vector<double> > data2; data2.resize(pDataArray->thisLookUp[0]->getNumBins());
114 vector<SharedRAbundVector*> subset;
117 for (int i = 0; i < pDataArray->thisLookUp.size(); i++) {
118 //is this group for a set we want to compare??
119 //sorting the sets by putting setB at the back and setA in the front
120 if (pDataArray->designMapGroups[i] == setB) {
121 subset.push_back(pDataArray->thisLookUp[i]);
123 }else if (pDataArray->designMapGroups[i] == setA) {
124 subset.insert(subset.begin()+setACount, pDataArray->thisLookUp[i]);
129 if ((setACount == 0) || (setBCount == 0)) {
130 pDataArray->m->mothurOut("Missing shared info for " + setA + " or " + setB + ". Skipping comparison."); pDataArray->m->mothurOutEndLine();
131 pDataArray->outputNames.pop_back();
134 for (int j = 0; j < pDataArray->thisLookUp[0]->getNumBins(); j++) {
135 data2[j].resize(subset.size(), 0.0);
136 for (int i = 0; i < subset.size(); i++) {
137 data2[j][i] = (subset[i]->getAbundance(j));
141 pDataArray->m->mothurOut("Comparing " + setA + " and " + setB + "..."); pDataArray->m->mothurOutEndLine();
143 pDataArray->m->mothurOutEndLine();
144 MothurMetastats mothurMeta(pDataArray->threshold, pDataArray->iters);
145 mothurMeta.runMetastats(outputFileName, data2, setACount);
146 pDataArray->m->mothurOutEndLine();
147 pDataArray->m->mothurOutEndLine();
154 catch(exception& e) {
155 pDataArray->m->errorOut(e, "MetaStatsCommand", "MyMetastatsThreadFunction");