Skip to content
Snippets Groups Projects
Commit 3baa8db2 authored by nkindlon's avatar nkindlon
Browse files

Changed handling of strand in records to allow non-strand strings in sixth field of records.

parent 434901e5
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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);
}
......
......@@ -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]));
......
......@@ -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) {
......
......@@ -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.
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment