Beispiel #1
0
int Rarefact::driver(RarefactionCurveData* rcd, int increment, int nIters = 1000){
	try {
			
		for(int iter=0;iter<nIters;iter++){
		
			for(int i=0;i<displays.size();i++){
				displays[i]->init(label);
			}
		
			RAbundVector* lookup	= new RAbundVector(order->getNumBins());
			SAbundVector* rank	= new SAbundVector(order->getMaxRank()+1);
			random_shuffle(order->begin(), order->end());
		
			for(int i=0;i<numSeqs;i++){
			
				if (m->control_pressed) { delete lookup; delete rank; delete rcd; return 0;  }
			
				int binNumber = order->get(i);
				int abundance = lookup->get(binNumber);
			
				rank->set(abundance, rank->get(abundance)-1);
				abundance++;
		
				lookup->set(binNumber, abundance);
				rank->set(abundance, rank->get(abundance)+1);

				if((i == 0) || ((i+1) % increment == 0) || (ends.count(i+1) != 0)){
					rcd->updateRankData(rank);
				}
			}
	
			if((numSeqs % increment != 0) || (ends.count(numSeqs) != 0)){
				rcd->updateRankData(rank);
			}

			for(int i=0;i<displays.size();i++){
				displays[i]->reset();
			}
			
			delete lookup;
			delete rank;
		}

		return 0;
	}
	catch(exception& e) {
		m->errorOut(e, "Rarefact", "driver");
		exit(1);
	}
}
Beispiel #2
0
int Collect::getCurve(float percentFreq = 0.01){
        try {
            RAbundVector* lookup = new RAbundVector(order->getNumBins());
            SAbundVector* rank        = new SAbundVector(order->getMaxRank()+1);
            
            CollectorsCurveData* ccd = new CollectorsCurveData();
            
            //sets displays label
            for(int i=0;i<displays.size();i++){ displays[i]->init(label); }
            ccd->registerDisplays(displays);
            
            //convert freq percentage to number
            int increment = 1;
            if (percentFreq < 1.0) {  increment = numSeqs * percentFreq;  }
            else { increment = percentFreq;  }
            
            for(int i=0;i<numSeqs;i++){
                
                if (m->getControl_pressed()) { delete lookup; delete rank; delete ccd;  return 1;  }
                
                int binNumber = order->get(i);
                int abundance = lookup->get(binNumber);
                
                rank->set(abundance, rank->get(abundance)-1);
                
                abundance++;
                
                lookup->set(binNumber, abundance);
                rank->set(abundance, rank->get(abundance)+1); //increment rank(abundance)
                
                if((i == 0) || (i+1) % increment == 0){ ccd->updateRankData(rank); }
            }
            
            if(numSeqs % increment != 0){ ccd->updateRankData(rank); }
            
            for(int i=0;i<displays.size();i++){ displays[i]->reset(); }
            
            delete lookup; delete rank; delete ccd;
            
            return 0;
        }
        catch(exception& e) {
			m->errorOut(e, "Collect", "getCurve");
			exit(1);
        }
}
Beispiel #3
0
//**********************************************************************************************************************
int RemoveRareCommand::processSabund(){
	try {
		string thisOutputDir = outputDir;
		if (outputDir == "") {  thisOutputDir += m->hasPath(sabundfile);  }
		string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + "pick" +  m->getExtension(sabundfile);
		outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName);

		ofstream out;
		m->openOutputFile(outputFileName, out);
		
		//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
		InputData input(sabundfile, "sabund");
		SAbundVector* sabund = input.getSAbundVector();
		string lastLabel = sabund->getLabel();
		set<string> processedLabels;
		set<string> userLabels = labels;
		
		while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
			
			if (m->control_pressed) { delete sabund; out.close(); return 0; }
			
			if(allLines == 1 || labels.count(sabund->getLabel()) == 1){			
				
				m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
				processedLabels.insert(sabund->getLabel());
				userLabels.erase(sabund->getLabel());
				
				if (sabund->getMaxRank() > nseqs) {
					for(int i = 1; i <=nseqs; i++) {  sabund->set(i, 0); }
				}else {	sabund->clear(); }
				
				if (sabund->getNumBins() > 0) { sabund->print(out); }
			}
			
			if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
				string saveLabel = sabund->getLabel();
				
				delete sabund;
				sabund = input.getSAbundVector(lastLabel);
				
				m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
				processedLabels.insert(sabund->getLabel());
				userLabels.erase(sabund->getLabel());
				
				if (sabund->getMaxRank() > nseqs) {
					for(int i = 1; i <=nseqs; i++) {  sabund->set(i, 0); }
				}else {	sabund->clear(); }
				
				if (sabund->getNumBins() > 0) { sabund->print(out); }
								
				//restore real lastlabel to save below
				sabund->setLabel(saveLabel);
			}		
			
			lastLabel = sabund->getLabel();			
			
			delete sabund;
			sabund = input.getSAbundVector();
		}
		
		if (m->control_pressed) {  out.close(); return 0; }	
		
		//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 (sabund != NULL) {	delete sabund;	}
			sabund = input.getSAbundVector(lastLabel);
			
			m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
			
			if (sabund->getMaxRank() > nseqs) {
				for(int i = 1; i <=nseqs; i++) {  sabund->set(i, 0); }
			}else {	sabund->clear(); }
			
			if (sabund->getNumBins() > 0) { sabund->print(out); }
			
			delete sabund;
		}
		
		return 0;
	}
	catch(exception& e) {
		m->errorOut(e, "RemoveRareCommand", "processSabund");
		exit(1);
	}
}