void SamFormatParser::ParseSQLine(const string& line) {

    SamSequence seq;

    // split SQ line into tokens
    vector<string> tokens = Split(line, Constants::SAM_TAB);

    // iterate over tokens
    vector<string>::const_iterator tokenIter = tokens.begin();
    vector<string>::const_iterator tokenEnd  = tokens.end();
    for ( ; tokenIter != tokenEnd; ++tokenIter ) {

        // get tag/value
        const string tokenTag = (*tokenIter).substr(0,2);
        const string tokenValue = (*tokenIter).substr(3);

        // set sequence contents
        if      ( tokenTag == Constants::SAM_SQ_NAME_TAG       ) seq.Name = tokenValue;
        else if ( tokenTag == Constants::SAM_SQ_LENGTH_TAG     ) seq.Length = tokenValue;
        else if ( tokenTag == Constants::SAM_SQ_ASSEMBLYID_TAG ) seq.AssemblyID = tokenValue;
        else if ( tokenTag == Constants::SAM_SQ_CHECKSUM_TAG   ) seq.Checksum = tokenValue;
        else if ( tokenTag == Constants::SAM_SQ_SPECIES_TAG    ) seq.Species = tokenValue;
        else if ( tokenTag == Constants::SAM_SQ_URI_TAG        ) seq.URI = tokenValue;
    }

    // check for required tags
    if ( !seq.HasName() )
        throw BamException("SamFormatParser::ParseSQLine", "@SQ line is missing SN tag");
    if ( !seq.HasLength() )
        throw BamException("SamFormatParser::ParseSQLine", "@SQ line is missing LN tag");

    // store SAM sequence entry
    m_header.Sequences.Add(seq);
}
Example #2
0
void SamFormatParser::ParseSQLine(const string& line) {

    SamSequence seq;

    // split SQ line into tokens
    vector<string> tokens = Split(line, Constants::SAM_TAB);

    // iterate over tokens
    vector<string>::const_iterator tokenIter = tokens.begin();
    vector<string>::const_iterator tokenEnd  = tokens.end();
    for ( ; tokenIter != tokenEnd; ++tokenIter ) {

        // get tag/value
        const string tokenTag = (*tokenIter).substr(0,2);
        const string tokenValue = (*tokenIter).substr(3);

        // set sequence contents
        if      ( tokenTag == Constants::SAM_SQ_NAME_TAG       ) seq.Name = tokenValue;
        else if ( tokenTag == Constants::SAM_SQ_LENGTH_TAG     ) seq.Length = tokenValue;
        else if ( tokenTag == Constants::SAM_SQ_ASSEMBLYID_TAG ) seq.AssemblyID = tokenValue;
        else if ( tokenTag == Constants::SAM_SQ_URI_TAG        ) seq.URI = tokenValue;
        else if ( tokenTag == Constants::SAM_SQ_CHECKSUM_TAG   ) seq.Checksum = tokenValue;
        else if ( tokenTag == Constants::SAM_SQ_SPECIES_TAG    ) seq.Species = tokenValue;
        else
            cerr << "SamFormatParser ERROR: unknown SQ tag: " << tokenTag << endl;
    }

    // if @SQ line exists, SN must be provided
    if ( !seq.HasName() ) {
        cerr << "SamFormatParser ERROR: @SQ line is missing SN tag" << endl;
        return;
    }

    // if @SQ line exists, LN must be provided
    if ( !seq.HasLength() ) {
        cerr << "SamFormatParser ERROR: @SQ line is missing LN tag" << endl;
        return;
    }

    // store SAM sequence entry
    m_header.Sequences.Add(seq);
}