Example #1
0
ProgramInfo ProgramInfo::FromSam(const std::string& sam)
{
    // pop off '@PG\t', then split rest of line into tokens
    const std::vector<std::string>& tokens = internal::Split(sam.substr(4), '\t');
    if (tokens.empty())
        return ProgramInfo();

    ProgramInfo prog;
    std::map<std::string, std::string> custom;

    // iterate over tokens
    for (const std::string& token : tokens) {
        const std::string& tokenTag   = token.substr(0,2);
        const std::string& tokenValue = token.substr(3);

        // set program contents
        if      (tokenTag == internal::token_ID) prog.Id(tokenValue);
        else if (tokenTag == internal::token_CL) prog.CommandLine(tokenValue);
        else if (tokenTag == internal::token_DS) prog.Description(tokenValue);
        else if (tokenTag == internal::token_PN) prog.Name(tokenValue);
        else if (tokenTag == internal::token_PP) prog.PreviousProgramId(tokenValue);
        else if (tokenTag == internal::token_VN) prog.Version(tokenValue);

        // otherwise, "custom" tag
        else
            custom[tokenTag] = tokenValue;
    }

    prog.CustomTags(custom);
    return prog;
}