Пример #1
0
SAbundVector SharedSAbundVector::getSAbundVector(){
	try {
		RAbundVector rav;
		SAbundVector sav;
		
		rav = getRAbundVector();
		sav = rav.getSAbundVector();
		return sav;
	
	}
	catch(exception& e) {
		m->errorOut(e, "SharedSAbundVector", "getSAbundVector");
		exit(1);
	}
}
Пример #2
0
//**********************************************************************************************************************
int SummaryCommand::process(SAbundVector*& sabund, ofstream& outputFileHandle, ofstream& outAve) {
    try {

        //calculator -> data -> values
        vector< vector< vector<double> > >  results;
        results.resize(sumCalculators.size());

        outputFileHandle << sabund->getLabel();

        SubSample sample;
        for (int thisIter = 0; thisIter < iters+1; thisIter++) {

            SAbundVector* thisIterSabund = sabund;

            //we want the summary results for the whole dataset, then the subsampling
            if ((thisIter > 0) && subsample) { //subsample sabund and run it
                //copy sabund since getSample destroys it
                RAbundVector rabund = sabund->getRAbundVector();
                SAbundVector* newSabund = new SAbundVector();
                *newSabund = rabund.getSAbundVector();

                sample.getSample(newSabund, subsampleSize);
                thisIterSabund = newSabund;
            }

            for(int i=0; i<sumCalculators.size(); i++) {
                vector<double> data = sumCalculators[i]->getValues(thisIterSabund);

                if (m->control_pressed) {
                    return 0;
                }

                if (thisIter == 0) {
                    outputFileHandle << '\t';
                    sumCalculators[i]->print(outputFileHandle);
                } else {
                    //some of the calc have hci and lci need to make room for that
                    if (results[i].size() == 0) {
                        results[i].resize(data.size());
                    }
                    //save results for ave and std.
                    for (int j = 0; j < data.size(); j++) {
                        if (m->control_pressed) {
                            return 0;
                        }
                        results[i][j].push_back(data[j]);
                    }
                }
            }

            //cleanup memory
            if ((thisIter > 0) && subsample) {
                delete thisIterSabund;
            }
        }
        outputFileHandle << endl;

        if (subsample) {
            outAve << sabund->getLabel() << '\t' << "ave\t";
            //find ave and std for this label and output
            //will need to modify the createGroupSummary to combine results and not mess with the .summary file.

            //calcs -> values
            vector< vector<double> >  calcAverages;
            calcAverages.resize(sumCalculators.size());
            for (int i = 0; i < calcAverages.size(); i++) {
                calcAverages[i].resize(results[i].size(), 0);
            }

            for (int thisIter = 0; thisIter < iters; thisIter++) { //sum all groups dists for each calculator
                for (int i = 0; i < calcAverages.size(); i++) {  //initialize sums to zero.
                    for (int j = 0; j < calcAverages[i].size(); j++) {
                        calcAverages[i][j] += results[i][j][thisIter];
                    }
                }
            }

            for (int i = 0; i < calcAverages.size(); i++) {  //finds average.
                for (int j = 0; j < calcAverages[i].size(); j++) {
                    calcAverages[i][j] /= (float) iters;
                    outAve << calcAverages[i][j] << '\t';
                }
            }

            //find standard deviation
            vector< vector<double>  > stdDev;
            stdDev.resize(sumCalculators.size());
            for (int i = 0; i < stdDev.size(); i++) {
                stdDev[i].resize(results[i].size(), 0);
            }

            for (int thisIter = 0; thisIter < iters; thisIter++) { //compute the difference of each dist from the mean, and square the result of each
                for (int i = 0; i < stdDev.size(); i++) {
                    for (int j = 0; j < stdDev[i].size(); j++) {
                        stdDev[i][j] += ((results[i][j][thisIter] - calcAverages[i][j]) * (results[i][j][thisIter] - calcAverages[i][j]));
                    }
                }
            }

            outAve << endl << sabund->getLabel() << '\t' << "std\t";
            for (int i = 0; i < stdDev.size(); i++) {  //finds average.
                for (int j = 0; j < stdDev[i].size(); j++) {
                    stdDev[i][j] /= (float) iters;
                    stdDev[i][j] = sqrt(stdDev[i][j]);
                    outAve << stdDev[i][j] << '\t';
                }
            }
            outAve << endl;
        }

        return 0;
    }
    catch(exception& e) {
        m->errorOut(e, "SummaryCommand", "process");
        exit(1);
    }
}
Пример #3
0
//**********************************************************************************************************************
int GetSAbundCommand::processList(ofstream& out){
	try {
        CountTable ct;
        ct.readTable(countfile, false);
        
        InputData input(inputfile, format);
        ListVector* list = input.getListVector();
        string lastLabel = list->getLabel();
        
        //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
        set<string> processedLabels;
        set<string> userLabels = labels;
        
        if (m->control_pressed) {  delete list;  return 0; }
        
        while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
            
            if(allLines == 1 || labels.count(list->getLabel()) == 1){
                m->mothurOut(list->getLabel()); m->mothurOutEndLine();
                
                if (m->control_pressed) {   delete list;  return 0;  }
                
                RAbundVector* rabund = new RAbundVector();
                createRabund(ct, list, rabund);
                SAbundVector sabund = rabund->getSAbundVector();
                sabund.print(out);
                delete rabund;
                
                processedLabels.insert(list->getLabel());
                userLabels.erase(list->getLabel());
            }
            
            if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
                string saveLabel = list->getLabel();
                
                delete list;
                list = input.getListVector(lastLabel);
                
                m->mothurOut(list->getLabel()); m->mothurOutEndLine();
                
                if (m->control_pressed) {    delete list;  return 0;  }
                
                RAbundVector* rabund = new RAbundVector();
                createRabund(ct, list, rabund);
                SAbundVector sabund = rabund->getSAbundVector();
                sabund.print(out);
                delete rabund;
                
                processedLabels.insert(list->getLabel());
                userLabels.erase(list->getLabel());
                
                //restore real lastlabel to save below
                list->setLabel(saveLabel);
            }
            
            lastLabel = list->getLabel();
            
            delete list;
            list = input.getListVector();
        }
        
        //output error messages about any remaining user labels
        set<string>::iterator it;
        bool needToRun = false;
        for (it = userLabels.begin(); it != userLabels.end(); it++) {
            m->mothurOut("Your file does not include the label " + *it);
            if (processedLabels.count(lastLabel) != 1) {
                m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
                needToRun = true;
            }else {
                m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
            }
        }
        
        //run last label if you need to
        if (needToRun == true)  {
            if (list != NULL) {	delete list;	}
            list = input.getListVector(lastLabel);
            
            m->mothurOut(list->getLabel()); m->mothurOutEndLine();
            
            if (m->control_pressed) {   delete list;  return 0; }
            
            RAbundVector* rabund = new RAbundVector();
            createRabund(ct, list, rabund);
            SAbundVector sabund = rabund->getSAbundVector();
            sabund.print(out);
            delete rabund;
            
            delete list;
        }
        
        return 0;
    }
	catch(exception& e) {
		m->errorOut(e, "GetSAbundCommand", "processList");
		exit(1);
	}
}