void sequence::resize(size_type new_capacity)

   // this function copies "this" into a temp object of the desired capacity,
   // deletes stale data memory (via the overloaded assignment operator), 
   // and returns the re-sized object reference to the caller
   {
      if( new_capacity < used )           // ensure new_capacity is big                          
         new_capacity = used;             // enough for current contents
      
      if( new_capacity <= 0 )             // ensure pre-condition is met
         new_capacity = 1;                // s.t. new_capacity > 0
   
      
      // create temp object w/new_capacity to hold "this" contents
      sequence tempSeq(new_capacity);
      tempSeq.used = used;
      tempSeq.current_index = current_index;
     
      // copy data from "this" into tempSeq
      size_type i;
      for( i = 0 ; i < used; i++ )
      {
         tempSeq.data[i] = data[i];
      }
	
      // send "this" and tempSeq objects to the operator=() function to
      //    * copy the tempSeq obj back into "this" 
      //    * repoint the "this" data pointer to the new memory store
      //    * delete stale memory
      
      *this = tempSeq;
   }
示例#2
0
    void Database::LoadObservationSequences(const char* gestureName, const Quantizer& quantizer, vector<TimeSlot>& seqVec)
    {
        seqVec.reserve(seqVecSpace);
        //SQL: "SELECT oLength o FROM ObservationSequenceTable WHERE gestureName==?1 AND quantizerName==?2;";
        rc = sqlite3_bind_text(loadObservationSequencesStmt, 1, gestureName, -1, SQLITE_TRANSIENT);
        if(rc!=SQLITE_OK) std::cout << "Error when binding gestureName in LoadObservationSequences()" << std::endl;
        rc = sqlite3_bind_text(loadObservationSequencesStmt, 2, quantizer.name.c_str(), quantizer.name.size(), SQLITE_TRANSIENT);
        if(rc!=SQLITE_OK) std::cout << "Error when binding quantizerName in LoadObservationSequences()" << std::endl;

        TimeSlot tempSeq(gestureName,quantizer);
        size_t oLength;
        const size_t* oPtr = 0;

        //evaluation
        rc = sqlite3_step(loadObservationSequencesStmt);
        while(rc==SQLITE_ROW){
            oLength= sqlite3_column_int(loadObservationSequencesStmt, 0);
            oPtr = (const size_t*)sqlite3_column_blob(loadObservationSequencesStmt, 1);
            seqVec.push_back(tempSeq);
            seqVec.back().o.assign(oPtr,oPtr+oLength);            
            rc = sqlite3_step(loadObservationSequencesStmt);
        }
        if(rc!=SQLITE_DONE) std::cout << "Error when evaluation in LoadObservationSequences()" << std::endl;

        //reset
        sqlite3_reset(loadObservationSequencesStmt);
        sqlite3_clear_bindings(loadObservationSequencesStmt);
    }
示例#3
0
SequenceParser::SequenceParser(string groupFile, string fastaFile, string nameFile) {
	try {
		
		m = MothurOut::getInstance();
		int error;
		
		//read group file
		groupMap = new GroupMap(groupFile);
		error = groupMap->readMap();
		
		if (error == 1) { m->control_pressed = true; }
		
		//initialize maps
		vector<string> namesOfGroups = groupMap->getNamesOfGroups();
		for (int i = 0; i < namesOfGroups.size(); i++) {
			vector<Sequence> temp;
			map<string, string> tempMap;
			seqs[namesOfGroups[i]] = temp;
			nameMapPerGroup[namesOfGroups[i]] = tempMap;
		}
		
		//read fasta file making sure each sequence is in the group file
		ifstream in;
		m->openInputFile(fastaFile, in);
		
		map<string, string> seqName; //stores name -> sequence string so we can make new "unique" sequences when we parse the name file
		while (!in.eof()) {
			
			if (m->control_pressed) { break; }
			
			Sequence seq(in); m->gobble(in);
			
			if (seq.getName() != "") {
				
				 string group = groupMap->getGroup(seq.getName());
				 if (group == "not found") {  error = 1; m->mothurOut("[ERROR]: " + seq.getName() + " is in your fasta file and not in your groupfile, please correct."); m->mothurOutEndLine();  }
				 else {	
					 seqs[group].push_back(seq);	
					 seqName[seq.getName()] = seq.getAligned();
				 }
			}
		}
		in.close();
				 
		if (error == 1) { m->control_pressed = true; }
				 
		//read name file
		ifstream inName;
		m->openInputFile(nameFile, inName);
		
		string first, second;
		int countName = 0;
		set<string> thisnames1;
		
		while(!inName.eof()) {
			
			if (m->control_pressed) { break; }
			
			inName >> first; m->gobble(inName);
			inName >> second; m->gobble(inName);
			
			vector<string> names;
			m->splitAtChar(second, names, ',');
			
			//get aligned string for these seqs from the fasta file
			string alignedString = "";
			map<string, string>::iterator itAligned = seqName.find(names[0]);
			if (itAligned == seqName.end()) {
				error = 1; m->mothurOut("[ERROR]: " + names[0] + " is in your name file and not in your fasta file, please correct."); m->mothurOutEndLine();
			}else {
				alignedString = itAligned->second;
			}
			
			//separate by group - parse one line in name file
			map<string, string> splitMap; //group -> name1,name2,...
			map<string, string>::iterator it;
			for (int i = 0; i < names.size(); i++) {
				
				string group = groupMap->getGroup(names[i]);
				if (group == "not found") {  error = 1; m->mothurOut("[ERROR]: " + names[i] + " is in your name file and not in your groupfile, please correct."); m->mothurOutEndLine();  }
				else {	
					
					it = splitMap.find(group);
					if (it != splitMap.end()) { //adding seqs to this group
						(it->second) += "," + names[i];
						thisnames1.insert(names[i]);
						countName++;
					}else { //first sighting of this group
						splitMap[group] = names[i];
						countName++;
						thisnames1.insert(names[i]);
						
						//is this seq in the fasta file?
						if (i != 0) { //if not then we need to add a duplicate sequence to the seqs for this group so the new "fasta" and "name" files will match
							Sequence tempSeq(names[i], alignedString); //get the first guys sequence string since he's in the fasta file.
							seqs[group].push_back(tempSeq);
						}
					}
				}
				
				allSeqsMap[names[i]] = names[0];
			}
			
			
			//fill nameMapPerGroup - holds all lines in namefile separated by group
			for (it = splitMap.begin(); it != splitMap.end(); it++) {
				//grab first name
				string firstName = "";
				for(int i = 0; i < (it->second).length(); i++) {
					if (((it->second)[i]) != ',') {
						firstName += ((it->second)[i]);
					}else { break; }
				}
				
				//group1 -> seq1 -> seq1,seq2,seq3
				nameMapPerGroup[it->first][firstName] = it->second;
			}
		}
		
		inName.close();
		
		if (error == 1) { m->control_pressed = true; }
		
		if (countName != (groupMap->getNumSeqs())) {
			vector<string> groupseqsnames = groupMap->getNamesSeqs();
			
			for (int i = 0; i < groupseqsnames.size(); i++) {
				set<string>::iterator itnamesfile = thisnames1.find(groupseqsnames[i]);
				if (itnamesfile == thisnames1.end()){
					cout << "missing name " + groupseqsnames[i] << '\t' << allSeqsMap[groupseqsnames[i]] << endl;
				}
			}
			
			m->mothurOutEndLine();
			m->mothurOut("[ERROR]: Your name file contains " + toString(countName) + " valid sequences, and your groupfile contains " + toString(groupMap->getNumSeqs()) + ", please correct.");
			m->mothurOutEndLine();
			m->control_pressed = true;
		}
		
	}
	catch(exception& e) {
		m->errorOut(e, "SequenceParser", "SequenceParser");
		exit(1);
	}
}