5 // Created by SarahsWork on 5/10/13.
6 // Copyright (c) 2013 Schloss Lab. All rights reserved.
9 #ifndef Mothur_sparcccommand_h
10 #define Mothur_sparcccommand_h
12 #include "command.hpp"
13 #include "inputdata.h"
14 #include "calcsparcc.h"
16 /**************************************************************************************************/
18 class SparccCommand : public Command {
20 SparccCommand(string);
24 vector<string> setParameters();
25 string getCommandName() { return "sparcc"; }
26 string getCommandCategory() { return "OTU-Based Approaches"; }
28 string getOutputPattern(string);
29 //commmand category choices: Sequence Processing, OTU-Based Approaches, Hypothesis Testing, Phylotype Analysis, General, Clustering and Hidden
30 string getHelpString();
31 string getCitation() { return "Friedman J, Alm EJ (2012) Inferring Correlation Networks from Genomic Survey Data. PLoS Comput Biol 8(9): e1002687. doi:10.1371/journal.pcbi.1002687 http://www.mothur.org/wiki/Sparcc"; }
32 string getDescription() { return "brief description"; }
35 void help() { m->mothurOut(getHelpString()); }
39 string outputDir, sharedfile, normalizeMethod;
40 int numSamplings, maxIterations, numPermutations, processors;
42 vector<string> Groups;
43 vector<string> outputNames;
45 int process(vector<SharedRAbundVector*>&);
46 vector<vector<float> > createProcesses(vector<vector<float> >&, vector<vector<float> >&);
47 vector<vector<float> > driver(vector<vector<float> >&, vector<vector<float> >&, int);
48 vector<vector<float> > shuffleSharedVector(vector<vector<float> >&);
51 /**************************************************************************************************/
56 vector< vector<float> > sharedVector;
57 vector< vector<float> > origCorrMatrix;
58 vector<vector<float> > pValues;
59 int numSamplings, maxIterations, numPermutations;
60 string normalizeMethod;
63 sparccData(MothurOut* mout, int it, vector< vector<float> > cs, vector< vector<float> > co, int ns, int mi, int np, string nm) {
74 /**************************************************************************************************/
75 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
77 static DWORD WINAPI MySparccThreadFunction(LPVOID lpParam){
78 sparccData* pDataArray;
79 pDataArray = (sparccData*)lpParam;
83 int numOTUs = pDataArray->sharedVector[0].size();
84 vector<vector<float> > sharedShuffled = pDataArray->sharedVector;
85 pDataArray->pValues.resize(numOTUs);
86 for(int i=0;i<numOTUs;i++){ pDataArray->pValues[i].assign(numOTUs, 0); }
88 for(int i=0;i<pDataArray->numPerms;i++){
89 if (pDataArray->m->control_pressed) { return 0; }
91 //sharedShuffled = shuffleSharedVector(sharedVector);
92 //////////////////////////////////////////////////////////
93 int numGroups = (int)pDataArray->sharedVector.size();
94 sharedShuffled = pDataArray->sharedVector;
96 for(int k=0;k<numGroups;k++){
97 for(int j=0;j<numOTUs;j++){
98 sharedShuffled[k][j] = pDataArray->sharedVector[rand()%numGroups][j];
101 /////////////////////////////////////////////////////////
103 CalcSparcc permutedData(sharedShuffled, pDataArray->maxIterations, pDataArray->numSamplings, pDataArray->normalizeMethod);
104 vector<vector<float> > permuteCorrMatrix = permutedData.getRho();
106 for(int j=0;j<numOTUs;j++){
107 for(int k=0;k<j;k++){
108 double randValue = permuteCorrMatrix[j][k];
109 double observedValue = pDataArray->origCorrMatrix[j][k];
110 if(observedValue >= 0 && randValue > observedValue) { pDataArray->pValues[j][k]++; }//this method seems to deflate the
111 else if(observedValue < 0 && randValue < observedValue){ pDataArray->pValues[j][k]++; }//pvalues of small rho values
114 if((i+1) % (int)(pDataArray->numPermutations * 0.05) == 0){ cout << i+1 << endl; }
120 catch(exception& e) {
121 pDataArray->m->errorOut(e, "SparccCommand", "MySparccThreadFunction");
128 /**************************************************************************************************/