예제 #1
0
void GffRecord::printNull(QuickString &outBuf) const
{
	outBuf.append(".\t.\t.\t-1\t-1\t.\t.\t.", 17);
	if (_numFields > 8) {
		outBuf.append("\t.", 2);
	}
}
예제 #2
0
bool BufferedStreamMgr::getLine(QuickString &line)
{
    line.clear();

    if (_mainBufCurrStartPos >= _mainBufCurrLen) {
        if (!readFileChunk()) {
            _eof = true;
            return false;
        }
    }
    while (1) {
        int searchPos = _mainBufCurrStartPos;
        while (searchPos < _mainBufCurrLen && _mainBuf[searchPos] != '\n') {
            searchPos++;
        }

        line.append((char *)_mainBuf + _mainBufCurrStartPos, searchPos - _mainBufCurrStartPos);
        _mainBufCurrStartPos = searchPos +1;
        if (searchPos == _mainBufCurrLen) { //hit end of buffer, but no newline yet
            if (!readFileChunk()) { //hit eof
                return true;
            }
        } else if (_mainBuf[searchPos] == '\n') {
            return true;
        }
    }
}
예제 #3
0
 OneStringBase& QuickString<quickSize>::substr(int pos, int sublen)
 {
     // Check sublen flag. If -1, then go to the end of the QuickString
     if(sublen == -1)
     {
         // Calculate the size from the position to the end of the QuickString
         sublen = size() - pos;
     }
     // Check for valid index
     if((pos >= quickSize) || (pos < 0))
     {
         ioc << cat_error << ta_bold << fg_red << "QuickString Error:" <<
         " Index Out of Bounds" << io_end;
         return *this;
     }
     // If the substring size is too large throw an error
     else if(sublen + pos > size())
     {
         ioc << cat_error << ta_bold << fg_red << "QuickString Error: " <<
         "Size exceeds limits of QuickString"<<io_end;
         return *this;
     }
     else
     {
         // Create a new OneString and append each character that is found
         // in the substring
         QuickString<quickSize>* newPaw = new QuickString();
         for(int i = 0; i < sublen; i++)
         {
             newPaw->append(master[pos]);
             pos++;
         }
         return *newPaw;
     }
 }
예제 #4
0
void VcfRecord::print(QuickString &outBuf, const QuickString & start, const QuickString & end) const {
	outBuf.append(_chrName);
	outBuf.append('\t');
	outBuf.append(_startPosStr);
	printOtherFields(outBuf);

}
예제 #5
0
void Bed3Interval::print(QuickString &outBuf) const
{
	outBuf.append(_chrName);
	outBuf.append('\t');
	outBuf.append(_startPos);
	outBuf.append('\t');
	outBuf.append(_endPos);
}
예제 #6
0
void Bed3Interval::print(QuickString &outBuf, const QuickString & start, const QuickString & end) const
{
	outBuf.append(_chrName);
	outBuf.append('\t');
	outBuf.append(start);
	outBuf.append('\t');
	outBuf.append(end);
}
예제 #7
0
void BedPlusInterval::print(QuickString &outBuf, const QuickString & start, const QuickString & end) const
{
	Bed6Interval::print(outBuf, start, end);
	for (int i=0; i < (int)_otherIdxs.size(); i++) {
		outBuf.append('\t');
		outBuf.append(*(_otherIdxs[i]));
	}
}
예제 #8
0
void ContextBase::setErrorMsg(QuickString &msg, bool onlyWarn, const Record * record, QuickString str1, const QuickString str2, const QuickString str3) {
	if (onlyWarn) {
		msg = "\n***** WARNING: ";
	} else {
		msg = "\n***** ERROR: ";
	}
	msg.append(str1);
	msg.append(str2);
	msg.append(str3);
	msg.append(" Exiting...\n");
	if (record != NULL) {
		record->print(msg);
	}
}
예제 #9
0
void VcfRecord::printOtherFields(QuickString &outBuf) const {
	outBuf.append('\t');
	outBuf.append(_name);
	outBuf.append('\t');
	outBuf.append(_varAlt);
	outBuf.append('\t');
	outBuf.append(_varRef);
	outBuf.append('\t');
	outBuf.append(_score);
	for (int i= 0; i < (int)_otherIdxs.size(); i++) {
		outBuf.append('\t');
		outBuf.append(*(_otherIdxs[i]));
	}

}
예제 #10
0
void GffRecord::print(QuickString &outBuf, const QuickString & start, const QuickString & end) const
{
	outBuf.append(_chrName);
	outBuf.append('\t');
	outBuf.append(_source);
	outBuf.append('\t');
	outBuf.append(_name);
	outBuf.append('\t');
	outBuf.append(start);
	outBuf.append('\t');
	outBuf.append(end);
	outBuf.append('\t');

	printRemainingFields(outBuf);
}
예제 #11
0
void GffRecord::print(QuickString &outBuf) const
{
	outBuf.append(_chrName);
	outBuf.append('\t');
	outBuf.append(_source);
	outBuf.append('\t');
	outBuf.append(_name);
	outBuf.append('\t');
	outBuf.append(_startPosStr);
	outBuf.append('\t');
	outBuf.append(_endPosStr);
	outBuf.append('\t');

	printRemainingFields(outBuf);
}
예제 #12
0
void VcfRecord::printOtherFields(QuickString &outBuf) const {
	outBuf.append('\t');
	outBuf.append(_name);
	outBuf.append('\t');
	outBuf.append(_varRef);
	outBuf.append('\t');
	outBuf.append(_varAlt);
	outBuf.append('\t');
	outBuf.append(_score);
	outBuf.append('\t');
	_plusFields.printFields(outBuf);
}
예제 #13
0
void BedPlusInterval::print(QuickString &outBuf, const QuickString & start, const QuickString & end) const
{
	Bed3Interval::print(outBuf, start, end);
	outBuf.append('\t');
	printBed6PlusFields(outBuf);
	_plusFields.printFields(outBuf);
}
예제 #14
0
void ComplementFile::printRecord(int endPos)
{
	_outRecord.setStartPos(_currStartPos);
	QuickString startStr;
	startStr.append(_currStartPos);
	_outRecord.setStartPosStr(startStr);

	_outRecord.setEndPos(endPos);
	QuickString endStr;
	endStr.append(endPos);
	_outRecord.setEndPosStr(endStr);

	_outputMgr->printRecord(&_outRecord);
	_outputMgr->newline();

}
예제 #15
0
bool BufferedStreamMgr::getTypeData()
{
    QuickString currScanBuffer;
    _inputStreamMgr->getSavedData(currScanBuffer);
    do {
        if (!_typeChecker.scanBuffer(currScanBuffer.c_str(), currScanBuffer.size()) && !_typeChecker.needsMoreData()) {
            return false;
        } else if (_typeChecker.needsMoreData()) {
            _inputStreamMgr->populateScanBuffer();
            currScanBuffer.clear();
            _inputStreamMgr->getSavedData(currScanBuffer);
        }
    } while (_typeChecker.needsMoreData());
    _inputStreamMgr->reset();
    return true;
}
예제 #16
0
void BedPlusInterval::printNull(QuickString &outBuf) const
{
	Bed6Interval::printNull(outBuf);
	for (int i=startOtherIdx; i < _numPrintFields; i++) {
		outBuf.append("\t.");
	}
}
예제 #17
0
void GffPlusRecord::printNull(QuickString &outBuf) const
{
	GffRecord::printNull(outBuf);
	for (int i=_numFields; i < _numPrintFields; i++) {
		outBuf.append("\t.");
	}
}
예제 #18
0
void GroupBy::processHits(RecordOutputMgr *outputMgr, RecordKeyVector &hits)
{

	const Record *rec = hits.getKey();
	const QuickString &opVal  = _context->getColumnOpsVal(hits);
	if (upCast(_context)->printFullCols()) {
		outputMgr->printRecord(rec, opVal);
	} else {
		QuickString outBuf;
		for (int i=0; i < (int)_groupCols.size(); i++) {
			outBuf.append(rec->getField(_groupCols[i]));
			outBuf.append('\t');
		}
		outBuf.append(opVal);
		outputMgr->printRecord(NULL, outBuf);
	}
}
예제 #19
0
void BedPlusInterval::printNull(QuickString &outBuf) const
{
	Bed3Interval::printNull(outBuf);
	printBed6PlusNullFields(outBuf);
	for (int i=_numFixedFields; i < _numPrintFields; i++) {
		outBuf.append("\t.");
	}
}
예제 #20
0
//This functions recognizes only numbers with digits, plus sign, minus sign, decimal point, e, or E. Hexadecimal and pointers not currently supported.
bool isNumeric(const QuickString &str) {
	for (int i=0; i < (int)str.size(); i++) {
		char currChar = str[i];
		if (!(isdigit(currChar) || currChar == '-' || currChar == '.' || currChar == '+' || currChar == 'e' || currChar == 'E')) {
			return false;
		}
	}
	return true;
}
예제 #21
0
void NewGenomeFile::loadGenomeFileIntoMap() {


	ifstream genFile(_genomeFileName.c_str());
	if (!genFile.good()) {
		cerr << "Error: Can't open genome file" << _genomeFileName << "Exiting..." << endl;
		exit(1);
	}
	string sLine;
	Tokenizer fieldTokens;
	CHRPOS chrSize = 0;
	QuickString chrName;
	while (!genFile.eof()) {
		sLine.clear();
		chrSize = 0;
		chrName.clear();
		getline(genFile, sLine);
		int numFields = fieldTokens.tokenize(sLine.c_str());
		if (numFields != 2) {
			continue;
		}
		chrName = fieldTokens.getElem(0);
		chrSize = str2chrPos(fieldTokens.getElem(1));
		_maxId++;
		_chromSizeIds[chrName] = pair<CHRPOS, int>(chrSize, _maxId);
		_startOffsets.push_back(_genomeLength);
		_genomeLength += chrSize;
		_chromList.push_back(chrName);
	}
	if (_maxId == -1) {
		cerr << "Error: The genome file " << _genomeFileName << " has no valid entries. Exiting." << endl;
		exit(1);
	}
	// Special: BAM files can have unmapped reads, which show as no chromosome, or an empty chrom string.
	// Add in an empty chrom so these don't error.
	_maxId++;
	_chromSizeIds[""] = pair<CHRPOS, int>(0, _maxId);
	_chromList.push_back("");


	_startOffsets.push_back(_genomeLength); //insert the final length as the last element
	//to help with the lower_bound call in the projectOnGenome method.
	genFile.close();
}
예제 #22
0
void QuickString::substr (QuickString &newStr, size_t pos, size_t len) const
{
	if (pos >= _currSize) {
		return;
	}
	if (pos + len >= _currSize) {
		len = _currSize - pos;
	}
	newStr.set(_buffer + pos, len);
}
예제 #23
0
Record *BlockMgr::allocateAndAssignRecord(const Record *keyRecord, int startPos, int endPos)
{
	Record *record = _blockRecordsMgr->allocateRecord();
	record->setChrName(keyRecord->getChrName());
	record->setChromId(keyRecord->getChromId());
	record->setStartPos(startPos);
	record->setEndPos(endPos);
	QuickString startPosStr;
	QuickString endPosStr;
	startPosStr.append(startPos);
	endPosStr.append(endPos);
	record->setStartPosStr(startPosStr);
	record->setEndPosStr(endPosStr);
	record->setName(keyRecord->getName());
	record->setScore(keyRecord->getScore());
	record->setStrand(keyRecord->getStrand());

	return record;
}
예제 #24
0
bool QuickString::stricmp(const QuickString &str) const {
	if (str.size() != _currSize) {
		return true;
	}
	for (size_t i=0; i < _currSize; i++) {
		if (tolower(str[i]) != tolower(_buffer[i])) {
			return true;
		}
	}
	return false;
}
예제 #25
0
void RecordOutputMgr::printRecord(const Record *record, const QuickString & value)
{
    _afterVal = value;
    printRecord(record);
    if (!value.empty()) {
        tab();
        _outBuf.append(value);
    }
    newline();

    if (needsFlush()) flush();
}
예제 #26
0
bool isHeaderLine(const QuickString &line) {
	if (line[0] == '>') {
		return true;
	}
	if (line[0] == '!') {
		return true;
	}
	if (line[0] == '#') {
		return true;
	}
	//GFF file headers can also start with the words "browser" or "track", followed by a whitespace character.
	if (memcmp(line.c_str(), "browser", 7) == 0 && isspace(line[7])) {
		return true;
	}
	if (memcmp(line.c_str(), "track", 5) == 0 && isspace(line[5])) {
		return true;
	}
	if (memcmp(line.c_str(), "visibility", 10) == 0) {
		return true;
	}
	return false;
}
예제 #27
0
void BamRecord::printUnmapped(QuickString &outBuf) const {
        outBuf.append(_chrName.empty() ? "." : _chrName);
        outBuf.append("\t-1\t-1\t");
        outBuf.append(_name.empty() ? "." : _name);
        outBuf.append('\t');
        outBuf.append(_score.empty() ? "." : _score);
        outBuf.append("\t.\t-1\t-1\t-1\t0,0,0\t0\t.\t."); // dot for strand, -1 for blockStarts and blockEnd
}
예제 #28
0
void GffRecord::printRemainingFields(QuickString &outBuf) const
{
	outBuf.append(_score);
	outBuf.append('\t');
	outBuf.append(_strand);
	outBuf.append('\t');
	outBuf.append(_frame);
	if (_numFields == 9) {
		outBuf.append('\t');
		outBuf.append(_group);
	}
}
예제 #29
0
bool BufferedStreamMgr::getLine(QuickString &line)
{
	line.clear();

	if (_mainBufCurrStartPos >= _mainBufCurrLen) {
		if (!readFileChunk()) {
			_eof = true;
			return false;
		}
	}
	bool retVal = true;
	while (1) {
		int searchPos = _mainBufCurrStartPos;
		while (searchPos < _mainBufCurrLen && _mainBuf[searchPos] != '\n') {
			searchPos++;
		}

		line.append((char *)_mainBuf + _mainBufCurrStartPos, searchPos - _mainBufCurrStartPos);

		_mainBufCurrStartPos = searchPos +1;
		if (searchPos == _mainBufCurrLen) { //hit end of buffer, but no newline yet
			if (!readFileChunk()) { //hit eof
				retVal = true;
				break;
			}
		} else if (_mainBuf[searchPos] == '\n') {
			retVal = true;
			break;
		}
	}
	//strip any whitespace characters, such as DOS newline characters or extra tabs,
	//from the end of the line
	int lastPos = line.size();
	while (isspace(line[lastPos-1])) lastPos--;
	line.resize(lastPos);

	return retVal;
}
예제 #30
0
bool ComplementFile::fastForward(const QuickString &newChrom) {
	if (!newChrom.empty() && !_genomeFile->hasChrom(newChrom)) return false;

	int i= _currPosInGenomeList +1;
	while (i < (int)_chromList.size() && _chromList[i] != newChrom) {
		_outRecord.setChrName(_chromList[i]);
		_currStartPos = 0;
		int endPos = _genomeFile->getChromSize(_chromList[i]);
		printRecord(endPos);
		i++;
	}
	if (newChrom.empty()) return true;

	if (i== (int)_chromList.size()) {
		//reached end but didn't find new chrom. Genome and DB are not sorted in same order.
		cerr << "***** ERROR: genome file and input file are not sorted in same order. Exiting..." << endl;
		exit(1);
		//this is where we'd return false if we weren't exiting.
	}
	_currChrom = newChrom;
	_currPosInGenomeList = i;
	return true;
}