示例#1
0
文件: GenBank.cpp 项目: pjotrp/biopp
void GenBank::appendFromStream(istream & input, VectorSequenceContainer & vsc) const throw (Exception)
{
    if (!input) {
        throw IOException ("GenBank::read: fail to open file");
    }

    string temp, name, sequence = "";  // Initialization

    // Main loop : for all file lines
    while (!input.eof())
    {
        getline(input, temp, '\n');  // Copy current line in temporary string

        if(temp.size() >= 9 && temp.substr(0,9) == "ACCESSION")
        {
            name = TextTools::removeSurroundingWhiteSpaces(temp.substr(10));
            StringTokenizer st(name, " ");
            name = st.nextToken();
            //cout << name << endl;
        }
        if(temp.size() >=6 && temp.substr(0,6) == "ORIGIN")
        {
            sequence = "";
            getline(input, temp, '\n');  // Copy current line in temporary string
            while(!input.eof() && temp.size() > 2 && temp.substr(0,2) != "//")
            {
                sequence += TextTools::removeWhiteSpaces(temp.substr(10));
                getline(input, temp, '\n');  // Copy current line in temporary string
            }
            if(name == "") throw Exception("GenBank::read(). Sequence with no ACCESSION number!");
            Sequence * seq = new Sequence(name, sequence, vsc.getAlphabet());
            vsc.addSequence(* seq);
            name = "";
        }
    }
}
示例#2
0
文件: Mase.cpp 项目: pjotrp/biopp
void Mase::appendFromStream(istream & input, VectorSequenceContainer & vsc) const throw (Exception)
{
	if (!input) { throw IOException ("Mase::read : fail to open file"); }
	
	// Initialization
	Comments seqComments, fileComments;
	string temp, name, sequence = "";
	bool comments = false;

	// Get current general comments is VectorSequenceContainer
	fileComments = vsc.getGeneralComments();

	// Main loop : for all file lines
	while(!input.eof())
  {
		getline(input, temp, '\n');  // Copy current line in temporary string
		
		// If first character is ;
		if(temp[0] == ';')
    {
			// If second character is also ;
			if(temp[1] == ';')
      {
				// File comments isolation
				temp.erase(0,2);  // Characters ;; deletion
				if(temp != "") fileComments.push_back(temp);
			}
      else
      {
				// If a name and a sequence were founded
				if((name != "") && (sequence != ""))
        {
					// New sequence creation, and addition in existing VectorSequenceContainer
					vsc.addSequence(Sequence(name, sequence, seqComments, vsc.getAlphabet()), _checkNames);
					name = "";
					sequence = "";
					seqComments.clear();
				}
				
				// Sequence commentaries isolation
				temp.erase(temp.begin());  // Character ; deletion
				if(temp != "") seqComments.push_back(temp);
				comments = true;
			}
		}
    else
    {
			// If sequence commentaries were just isolated
			if(comments)
      {
				// Sequence name isolation
				name = temp;
				comments = false;
			}
      else sequence += temp;  // Sequence isolation
		}
	}
	
	// Addition of the last sequence in file
	if((name != "") && (sequence != ""))
  {
		vsc.addSequence(Sequence(name, sequence, seqComments, vsc.getAlphabet()), _checkNames);
	}

	// Set new general comments in VectorSequenceContainer (old + new comments)
	vsc.setGeneralComments(fileComments);
}