示例#1
0
// Load next chromosome
ref_loc_t RefSeq::LoadNextSeq(std::ifstream &fin) {
    char c;
    char ch[1000];
    std::string s;
    fin>>c;
    if (fin.eof()) return 0;
    _length = 0;
    // get name
    fin>>_name;
    fin.getline(ch, 1000);
    // get seq
    while (!fin.eof()) {
        fin>>c;  
        if (fin.eof()) break;
        fin.unget();
        if (c == '>') break;
        fin>>s;
        if (_length + s.size() >= param.max_dbseq_size) {
            if (s.size() > param.append_dbseq_size) {
                param.max_dbseq_size += (s.size() + 10);
            } else { 
                param.max_dbseq_size += param.append_dbseq_size; 
            }
            _seq.resize(param.max_dbseq_size);
        }
        copy(s.begin(), s.end(), _seq.begin() + _length);
        _length += s.size();
    }
    return _length;
}
示例#2
0
    void load_ref( std::ifstream &is ) {
        size_t num_ref;
        is >> num_ref;
        m_ref_pvecs.resize( num_ref );
        m_ref_aux.resize( num_ref );
        
        for( size_t i = 0; i < m_ref_pvecs.size(); ++i ) {
            size_t len;
            is >> len;
            while( isspace( is.get() ) && !is.eof() ) {}
            is.unget();
            
            if( is.eof() ) {
                throw std::runtime_error( "unexpected end of file" );
            }
            
            m_ref_pvecs[i].resize(len);
            is.read( (char*)&m_ref_pvecs[i][0], len * sizeof(int) );
            
            m_ref_aux[i].resize(len);
            is.read( (char*)&m_ref_aux[i][0], len * sizeof(unsigned int) );
            
//             std::cout << "ref: " << i << " " << m_ref_pvecs[i].size() << "\n";
        }
        
    }
	void ConfigLoader::_nextToken(std::ifstream &stream)
	{
		lastTok = tok;
		lastTokVal = tokVal;
 
		//EOF token
		if (stream.eof())
		{
			tok = TOKEN_EOF;
			return;
		}
 
		//(Get next character)
		int ch = stream.get();
		if (ch == -1)
		{
			tok = TOKEN_EOF;
			return;
		}
		while ((ch == ' ' || ch == 9) && !stream.eof())
		{    //Skip leading spaces / tabs
			ch = stream.get();
		}
 
		if (stream.eof())
		{
			tok = TOKEN_EOF;
			return;
		}
 
		//Newline token
		if (ch == '\r' || ch == '\n')
		{
			do
			{
				ch = stream.get();
			} while ((ch == '\r' || ch == '\n') && !stream.eof());
 
			stream.unget();
 
			tok = TOKEN_NewLine;
			return;
		}
 
		//Open brace token
		else if (ch == '{')
		{
			tok = TOKEN_OpenBrace;
			return;
		}
 
		//Close brace token
		else if (ch == '}')
		{
			tok = TOKEN_CloseBrace;
			return;
		}
 
		//Text token
		if (ch < 32 || ch > 122)    //Verify valid char
		{
            throw std::runtime_error("Parse Error: Invalid character, ConfigLoader::load()");
		}
 
		tokVal = "";
		tok = TOKEN_Text;
		do
		{
			//Skip comments
			if (ch == '/')
			{
				int ch2 = stream.peek();
 
				//C++ style comment (//)
				if (ch2 == '/')
				{
					stream.get();
					do
					{
						ch = stream.get();
					} while (ch != '\r' && ch != '\n' && !stream.eof());
 
					tok = TOKEN_NewLine;
					return;
				}
			}
 
			//Add valid char to tokVal
			tokVal += (char)ch;
 
			//Next char
			ch = stream.get();
 
		} while (ch > 32 && ch <= 122 && !stream.eof());
 
		stream.unget();
 
		return;
	}