Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking if the input string while parsing the SAM header is not empty #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 71 additions & 67 deletions src/api/internal/sam/SamFormatParser_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,21 @@ void SamFormatParser::ParseHDLine(const string& line) {
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 header contents
if ( tokenTag == Constants::SAM_HD_VERSION_TAG ) m_header.Version = tokenValue;
else if ( tokenTag == Constants::SAM_HD_SORTORDER_TAG ) m_header.SortOrder = tokenValue;
else if ( tokenTag == Constants::SAM_HD_GROUPORDER_TAG ) m_header.GroupOrder = tokenValue;
else { // custom tag
CustomHeaderTag otherTag;
otherTag.TagName = tokenTag;
otherTag.TagValue = tokenValue;
m_header.CustomTags.push_back(otherTag);
if (!(*tokenIter).empty()){
// get tag/value
const string tokenTag = (*tokenIter).substr(0, 2);
const string tokenValue = (*tokenIter).substr(3);

// set header contents
if (tokenTag == Constants::SAM_HD_VERSION_TAG) m_header.Version = tokenValue;
else if (tokenTag == Constants::SAM_HD_SORTORDER_TAG) m_header.SortOrder = tokenValue;
else if (tokenTag == Constants::SAM_HD_GROUPORDER_TAG) m_header.GroupOrder = tokenValue;
else { // custom tag
CustomHeaderTag otherTag;
otherTag.TagName = tokenTag;
otherTag.TagValue = tokenValue;
m_header.CustomTags.push_back(otherTag);
}
}
}

Expand All @@ -98,23 +99,24 @@ void SamFormatParser::ParseSQLine(const string& line) {
vector<string>::const_iterator tokenIter = tokens.begin();
vector<string>::const_iterator tokenEnd = tokens.end();
for ( ; tokenIter != tokenEnd; ++tokenIter ) {

if (!(*tokenIter).empty()){
// 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;
else { // custom tag
CustomHeaderTag otherTag;
otherTag.TagName = tokenTag;
otherTag.TagValue = tokenValue;
seq.CustomTags.push_back(otherTag);
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;
else { // custom tag
CustomHeaderTag otherTag;
otherTag.TagName = tokenTag;
otherTag.TagValue = tokenValue;
seq.CustomTags.push_back(otherTag);
}
}
}

Expand All @@ -139,29 +141,30 @@ void SamFormatParser::ParseRGLine(const string& line) {
vector<string>::const_iterator tokenIter = tokens.begin();
vector<string>::const_iterator tokenEnd = tokens.end();
for ( ; tokenIter != tokenEnd; ++tokenIter ) {

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

// set read group contents
if ( tokenTag == Constants::SAM_RG_ID_TAG ) rg.ID = tokenValue;
else if ( tokenTag == Constants::SAM_RG_DESCRIPTION_TAG ) rg.Description = tokenValue;
else if ( tokenTag == Constants::SAM_RG_FLOWORDER_TAG ) rg.FlowOrder = tokenValue;
else if ( tokenTag == Constants::SAM_RG_KEYSEQUENCE_TAG ) rg.KeySequence = tokenValue;
else if ( tokenTag == Constants::SAM_RG_LIBRARY_TAG ) rg.Library = tokenValue;
else if ( tokenTag == Constants::SAM_RG_PLATFORMUNIT_TAG ) rg.PlatformUnit = tokenValue;
else if ( tokenTag == Constants::SAM_RG_PREDICTEDINSERTSIZE_TAG ) rg.PredictedInsertSize = tokenValue;
else if ( tokenTag == Constants::SAM_RG_PRODUCTIONDATE_TAG ) rg.ProductionDate = tokenValue;
else if ( tokenTag == Constants::SAM_RG_PROGRAM_TAG ) rg.Program = tokenValue;
else if ( tokenTag == Constants::SAM_RG_SAMPLE_TAG ) rg.Sample = tokenValue;
else if ( tokenTag == Constants::SAM_RG_SEQCENTER_TAG ) rg.SequencingCenter = tokenValue;
else if ( tokenTag == Constants::SAM_RG_SEQTECHNOLOGY_TAG ) rg.SequencingTechnology = tokenValue;
else { // custom tag
CustomHeaderTag otherTag;
otherTag.TagName = tokenTag;
otherTag.TagValue = tokenValue;
rg.CustomTags.push_back(otherTag);
const string tokenTag = (*tokenIter).substr(0, 2);
const string tokenValue = (*tokenIter).substr(3);

// set read group contents
if (tokenTag == Constants::SAM_RG_ID_TAG) rg.ID = tokenValue;
else if (tokenTag == Constants::SAM_RG_DESCRIPTION_TAG) rg.Description = tokenValue;
else if (tokenTag == Constants::SAM_RG_FLOWORDER_TAG) rg.FlowOrder = tokenValue;
else if (tokenTag == Constants::SAM_RG_KEYSEQUENCE_TAG) rg.KeySequence = tokenValue;
else if (tokenTag == Constants::SAM_RG_LIBRARY_TAG) rg.Library = tokenValue;
else if (tokenTag == Constants::SAM_RG_PLATFORMUNIT_TAG) rg.PlatformUnit = tokenValue;
else if (tokenTag == Constants::SAM_RG_PREDICTEDINSERTSIZE_TAG) rg.PredictedInsertSize = tokenValue;
else if (tokenTag == Constants::SAM_RG_PRODUCTIONDATE_TAG) rg.ProductionDate = tokenValue;
else if (tokenTag == Constants::SAM_RG_PROGRAM_TAG) rg.Program = tokenValue;
else if (tokenTag == Constants::SAM_RG_SAMPLE_TAG) rg.Sample = tokenValue;
else if (tokenTag == Constants::SAM_RG_SEQCENTER_TAG) rg.SequencingCenter = tokenValue;
else if (tokenTag == Constants::SAM_RG_SEQTECHNOLOGY_TAG) rg.SequencingTechnology = tokenValue;
else { // custom tag
CustomHeaderTag otherTag;
otherTag.TagName = tokenTag;
otherTag.TagValue = tokenValue;
rg.CustomTags.push_back(otherTag);
}
}
}

Expand All @@ -184,22 +187,23 @@ void SamFormatParser::ParsePGLine(const string& line) {
vector<string>::const_iterator tokenIter = tokens.begin();
vector<string>::const_iterator tokenEnd = tokens.end();
for ( ; tokenIter != tokenEnd; ++tokenIter ) {

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

// set program record contents
if ( tokenTag == Constants::SAM_PG_ID_TAG ) pg.ID = tokenValue;
else if ( tokenTag == Constants::SAM_PG_NAME_TAG ) pg.Name = tokenValue;
else if ( tokenTag == Constants::SAM_PG_COMMANDLINE_TAG ) pg.CommandLine = tokenValue;
else if ( tokenTag == Constants::SAM_PG_PREVIOUSPROGRAM_TAG ) pg.PreviousProgramID = tokenValue;
else if ( tokenTag == Constants::SAM_PG_VERSION_TAG ) pg.Version = tokenValue;
else { // custom tag
CustomHeaderTag otherTag;
otherTag.TagName = tokenTag;
otherTag.TagValue = tokenValue;
pg.CustomTags.push_back(otherTag);
const string tokenTag = (*tokenIter).substr(0, 2);
const string tokenValue = (*tokenIter).substr(3);

// set program record contents
if (tokenTag == Constants::SAM_PG_ID_TAG) pg.ID = tokenValue;
else if (tokenTag == Constants::SAM_PG_NAME_TAG) pg.Name = tokenValue;
else if (tokenTag == Constants::SAM_PG_COMMANDLINE_TAG) pg.CommandLine = tokenValue;
else if (tokenTag == Constants::SAM_PG_PREVIOUSPROGRAM_TAG) pg.PreviousProgramID = tokenValue;
else if (tokenTag == Constants::SAM_PG_VERSION_TAG) pg.Version = tokenValue;
else { // custom tag
CustomHeaderTag otherTag;
otherTag.TagName = tokenTag;
otherTag.TagValue = tokenValue;
pg.CustomTags.push_back(otherTag);
}
}
}

Expand Down