diff --git a/src/sampleFile/SampleFile.cpp b/src/sampleFile/SampleFile.cpp index 2c4c1a7d90ff17cba7c23413d4b5e95ba6fb4dc9..8f532c5f47a8eb89da81fac4d5c3a35f15a17187 100644 --- a/src/sampleFile/SampleFile.cpp +++ b/src/sampleFile/SampleFile.cpp @@ -120,10 +120,10 @@ bool SampleFile::strandComplies(const Record * record) { if (!_context->getSameStrand()) { return true; } - if (_context->getForwardOnly() && record->getStrand() == Record::FORWARD) { + if (_context->getForwardOnly() && record->getStrandVal() == Record::FORWARD) { return true; } - if (_context->getReverseOnly() && record->getStrand() == Record::REVERSE) { + if (_context->getReverseOnly() && record->getStrandVal() == Record::REVERSE) { return true; } return false; diff --git a/src/utils/FileRecordTools/Records/Bed6Interval.cpp b/src/utils/FileRecordTools/Records/Bed6Interval.cpp index 0f9e7ea4183981acf281156e5dd85fe88edd10cd..b486333a66757b4d36896c273d0d46d9798e9ab6 100644 --- a/src/utils/FileRecordTools/Records/Bed6Interval.cpp +++ b/src/utils/FileRecordTools/Records/Bed6Interval.cpp @@ -18,10 +18,8 @@ bool Bed6Interval::initFromFile(SingleLineDelimTextFileReader *fileReader) fileReader->getField(3, _name); fileReader->getField(4, _score); - char strandChar = 0; - fileReader->getField(5, strandChar); - setStrand(strandChar); - + fileReader->getField(5, _strand); + adjustStrandVal(); return baseRetFlag; } @@ -34,7 +32,7 @@ void Bed6Interval::print(QuickString &outBuf) const outBuf.append('\t'); outBuf.append(_score); outBuf.append('\t'); - outBuf.append(getStrandChar()); + outBuf.append(_strand); } void Bed6Interval::print(QuickString &outBuf, int start, int end) const @@ -45,7 +43,7 @@ void Bed6Interval::print(QuickString &outBuf, int start, int end) const outBuf.append('\t'); outBuf.append(_score); outBuf.append('\t'); - outBuf.append(getStrandChar()); + outBuf.append(_strand); } void Bed6Interval::print(QuickString &outBuf, const QuickString & start, const QuickString & end) const @@ -56,7 +54,7 @@ void Bed6Interval::print(QuickString &outBuf, const QuickString & start, const Q outBuf.append('\t'); outBuf.append(_score); outBuf.append('\t'); - outBuf.append(getStrandChar()); + outBuf.append(_strand); } diff --git a/src/utils/FileRecordTools/Records/BedPlusInterval.cpp b/src/utils/FileRecordTools/Records/BedPlusInterval.cpp index f062075361957ba655a84218ecc69b183697d724..d3e0c01ad9df1ac218cc15c310affba359e0d199 100644 --- a/src/utils/FileRecordTools/Records/BedPlusInterval.cpp +++ b/src/utils/FileRecordTools/Records/BedPlusInterval.cpp @@ -114,19 +114,15 @@ QuickString BedPlusInterval::getField(int fieldNum) const //chrom, start, end, name, score, and strand, in that order. //A request for field 6+ will go to the otherIdxs. - QuickString buffer; - switch (fieldNum) { case 0: return _chrName; break; //redundant after a return, but good practice anyway. case 1: - int2str(_startPos, buffer); - return buffer; + return _startPosStr; break; case 2: - int2str(_endPos, buffer); - return buffer; + return _endPosStr; break; case 3: return _name; @@ -135,8 +131,7 @@ QuickString BedPlusInterval::getField(int fieldNum) const return _score; break; case 5: - buffer.append(getStrandChar()); - return buffer; + return _strand; break; default: return (*(_otherIdxs[fieldNum - startOtherIdx])); diff --git a/src/utils/FileRecordTools/Records/GffRecord.cpp b/src/utils/FileRecordTools/Records/GffRecord.cpp index cceb01ac140e37372bf039bb55e99256f1159418..f13c8fd8c59f357eaefb4136ddb5a1a4fa8d72cb 100644 --- a/src/utils/FileRecordTools/Records/GffRecord.cpp +++ b/src/utils/FileRecordTools/Records/GffRecord.cpp @@ -38,9 +38,8 @@ bool GffRecord::initFromFile(SingleLineDelimTextFileReader *fileReader) fileReader->getField(5, _score); //GFF allows a '.' for the strandChar, signifying it is not known. - char strandChar = 0; - fileReader->getField(6, strandChar); - setStrand(strandChar); + fileReader->getField(6, _strand); + adjustStrandVal(); fileReader->getField(7, _frame); _numFields = fileReader->getNumFields(); @@ -104,7 +103,7 @@ void GffRecord::printRemainingFields(QuickString &outBuf) const { outBuf.append(_score); outBuf.append('\t'); - outBuf.append(getStrandChar()); + outBuf.append(_strand); outBuf.append('\t'); outBuf.append(_frame); if (_numFields == 9) { diff --git a/src/utils/FileRecordTools/Records/Record.cpp b/src/utils/FileRecordTools/Records/Record.cpp index cb5e5f445480c0f8eb57481f5fa753e84c04ebf8..6bad45dd232c6e06db3fa169986518d640538188 100644 --- a/src/utils/FileRecordTools/Records/Record.cpp +++ b/src/utils/FileRecordTools/Records/Record.cpp @@ -6,7 +6,7 @@ Record::Record() : _chrId(-1), _startPos(-1), _endPos(-1), - _strand(UNKNOWN), + _strandVal(UNKNOWN), _zeroLength(false), _isUnmapped(false), _isMateUnmapped(false) @@ -23,6 +23,7 @@ const Record &Record::operator=(const Record &other) _startPos = other._startPos; _endPos = other._endPos; _strand = other._strand; + _strandVal = other._strandVal; _name = other._name; return *this; } @@ -34,7 +35,8 @@ void Record::clear() { _endPos = -1; _name.clear(); _score.clear(); - _strand = UNKNOWN; + _strand.clear(); + _strandVal = UNKNOWN; _startPosStr.clear(); _endPosStr.clear(); _zeroLength = false; @@ -42,37 +44,6 @@ void Record::clear() { _isMateUnmapped = false; } -void Record::setStrand(char val) -{ - switch (val) { - case '+': - _strand = FORWARD; - break; - case '-': - _strand = REVERSE; - break; - default: - _strand = UNKNOWN; - break; - } -} - -char Record::getStrandChar() const -{ - switch (_strand) { - case FORWARD: - return '+'; - break; - case REVERSE: - return '-'; - break; - case UNKNOWN: - default: - return '.'; - } -// return '.'; -} - bool Record::operator < (const Record &other) const { @@ -144,8 +115,8 @@ bool Record::sameChromIntersects(const Record *record, //rule out different strandedness first. //If the strand is unknown in either case, then queries regarding strandedness //can not be answered, so we return false; - bool isSameStrand = (_strand == record->_strand && _strand != UNKNOWN); - bool isDiffStrand = ( _strand != UNKNOWN && record->_strand != UNKNOWN && _strand != record->_strand); + bool isSameStrand = (_strandVal == record->_strandVal && _strandVal != UNKNOWN); + bool isDiffStrand = ( _strandVal != UNKNOWN && record->_strandVal != UNKNOWN && _strandVal != record->_strandVal); if (wantSameStrand && !isSameStrand) { return false; //want same, but they're not same. diff --git a/src/utils/FileRecordTools/Records/Record.h b/src/utils/FileRecordTools/Records/Record.h index 9f80a960d6aba491d5f050c20c8a52153c5350fe..92df4bad97dadde7e8a9e6b1d6d4b0dacd88dad0 100644 --- a/src/utils/FileRecordTools/Records/Record.h +++ b/src/utils/FileRecordTools/Records/Record.h @@ -59,10 +59,18 @@ public: virtual bool getZeroLength() const { return _zeroLength; } virtual void setZeroLength(bool val) { _zeroLength = val; } - virtual strandType getStrand() const { return _strand; } - virtual void setStrand(strandType val) { _strand = val; } - virtual void setStrand(char val); - virtual char getStrandChar() const; + virtual const QuickString &getStrand() const { return _strand; } + virtual void setStrand(const QuickString &val) { _strand = val; + _strandVal = (val == "+" ? FORWARD : (val == "-" ? REVERSE : UNKNOWN)); + } + virtual void setStrand(char val) { _strand = val; + _strandVal = (val == '+' ? FORWARD : (val == '-' ? REVERSE : UNKNOWN)); + } + virtual void adjustStrandVal() { + _strandVal = (_strand == "+" ? FORWARD : (_strand == "-" ? REVERSE : UNKNOWN)); + } + + virtual strandType getStrandVal() const {return _strandVal; } virtual const QuickString &getName() const { return _name; } virtual void setName(const QuickString &chr) { _name = chr; } @@ -132,7 +140,8 @@ protected: QuickString _endPosStr; QuickString _name; QuickString _score; - strandType _strand; + QuickString _strand; + strandType _strandVal; bool _zeroLength; bool _isUnmapped; bool _isMateUnmapped;