示例#1
0
static void loadFile(huffTableEntry **table, const char *filename)
{
	char buf[1024];
	char *from;
	char *to;
	char *binary;
	char *colon;

	CFile fp(filename, "r");
	if ( fp )
	{
		while ( fgets(buf,sizeof(buf),fp) != NULL )
		{
			// Tokenize string "in place"
			from = buf;
			colon = strchr(buf, ':');
			if (colon == NULL)
				continue;
			binary = colon + 1;
			*colon = 0;
			colon = strchr(binary, ':');
			if (colon == NULL)
				continue;
			*colon = 0;
			to = colon + 1;
			colon = strchr(to, ':');
			if (colon != NULL)
				*colon = 0;
			{
				int bin_len = strlen(binary);
				int from_char = resolveChar(from);
				char to_char = resolveChar(to);
				unsigned long bin = decodeBinary(binary);

				// Add entry to end of bucket
				huffTableEntry **pCurrent = &table[from_char];
				while ( *pCurrent != NULL )
				{
					pCurrent = &((*pCurrent)->nextEntry);
				}
				*pCurrent = new huffTableEntry(bin, bin_len, to_char);
			}
		}
	}
#ifdef FREESATV2_DEBUG
	else
	{
		eDebug("[FREESAT] Cannot load '%s'",filename);
	}
#endif
}
  void parseSequenceLine(){
    if(fastdist){
      parseSequenceLineFastDist();
      return;
    }
    if(firstSequence){
      // find the length of the sequence
      parseSequenceName();      
      while (curChar != 10){	
        if(curChar > 32) {
          charBuffer.push_back(curChar);	 
        }
        curChar = getNextChar();
      }
      // We have the length. Use char arrays to store the char data in.
      sequenceLength = charBuffer.size();
      char* data = new char[sequenceLength];
      sequences->push_back(data);

	  for(unsigned int i = 0; i < sequenceLength; i++){	
        data[i] =  resolveChar(charBuffer[i]);
      }
      charBuffer.clear();
      discoverInputType(sequences->at(0));      
      firstSequence = false;
    } else {
      parseSequenceName();      
      unsigned int counter = 0;
      char* data = new char[sequenceLength];
      sequences->push_back(data);
      while (curChar != 10){        
        if(curChar > 32){
          data[counter] = resolveChar(curChar);
          counter++;
        }
        curChar = getNextChar();
      }
      if(counter != sequenceLength){
        cerr << "ERROR: Sequence " << sequenceCount << " has length " << counter << " while the preceding sequences in the alignment has length " << sequenceLength << "." << endl;
        exit(1);
      }
    }
    sequenceCount++;
  }
 inline void encodeProteinSequence(unsigned int* bitString, vector<char>& data){
   for(unsigned int i = 0; i < sequenceLength+paddingLength; i++) {
     int offset = i % 4;
     unsigned int bitStringIdx = i / 4;
     if(offset == 0){
       bitString[bitStringIdx] = 0;
     }
     char c = resolveChar(data[i]);
     bitString[bitStringIdx] += (c << (offset*8));
   }
 }