コード例 #1
0
ファイル: RecordOutputMgr.cpp プロジェクト: ernfrid/bedtools2
void RecordOutputMgr::printClosest(RecordKeyVector &keyList, const vector<int> *dists) {

	//The first time we print a record is when we print any header, because the header
	//hasn't been read from the query file until after the first record has also been read.
	checkForHeader();

	const ContextClosest *context = static_cast<const ContextClosest *>(_context);
	bool deleteBlocks = false;
	const Record *keyRec = keyList.getKey();
	RecordKeyVector blockList(keyRec);
	if (keyRec->getType() == FileRecordTypeChecker::BAM_RECORD_TYPE) {
		_bamBlockMgr->getBlocks(blockList, deleteBlocks);
		_currBamBlockList = &blockList;
	}
	if (!keyList.empty()) {
		int distCount = 0;
		for (RecordKeyVector::const_iterator_type iter = keyList.begin(); iter != keyList.end(); iter = keyList.next()) {
			const Record *hitRec = *iter;
			printKey(keyRec, keyRec->getStartPosStr(), keyRec->getEndPosStr());
			tab();
			addDbFileId(hitRec->getFileIdx());
			printKey(hitRec, hitRec->getStartPosStr(), hitRec->getEndPosStr());
			if (dists != NULL) {
				tab();
				int dist = (*dists)[distCount];
				//if not using sign distance, use absolute value instead.
				dist = context->signDistance() ? dist : abs(dist);
				_outBuf.append(dist);
				distCount++;
			}
			newline();
			if (needsFlush()) flush();
		}
	} else {
		printKey(keyRec, keyRec->getStartPosStr(), keyRec->getEndPosStr());
		tab();
		// need to add a dummy file id if multiple DB files are used
		if (_context->getNumInputFiles() > 2) {
			_outBuf.append('.');
			tab();
		}		
		null(false, true);
		if (context->reportDistance()) {
			tab();
			_outBuf.append(-1);
		}
		newline();
	}
	if (deleteBlocks) {
		_bamBlockMgr->deleteBlocks(blockList);
		_currBamBlockList = NULL;
	}
	return;
}
コード例 #2
0
RecordOutputMgr::~RecordOutputMgr()
{
    // In the rare case when a file had a header but was otherwise empty,
    // we'll need to make a last check to see if the header still needs to be printed.
    checkForHeader();

    if (_outBuf.size() > 0) {
        flush();
    }
    if (_bamWriter != NULL) {
        _bamWriter->Close();
        delete _bamWriter;
        _bamWriter = NULL;
    }
    delete _bamBlockMgr;
    _bamBlockMgr = NULL;

}
コード例 #3
0
ファイル: RecordOutputMgr.cpp プロジェクト: Debian/bedtools2
void RecordOutputMgr::printRecord(const Record *record, const QuickString & value)
{	
	checkForHeader();

	_afterVal = value;
	bool recordPrinted = false;
	if (record != NULL) {
		printRecord(record);
		recordPrinted = true;
	}
	if (!value.empty()) {
		if (recordPrinted) tab();
		_outBuf.append(value);
	}
	newline();

	if (needsFlush()) flush();
}
コード例 #4
0
void RecordOutputMgr::printRecord(RecordKeyVector &keyList, RecordKeyVector *blockList)
{
    if (needsFlush()) {
        flush();
    }
    //The first time we print a record is when we print any header, because the header
    //hasn't been read from the query file until after the first record has also been read.
    checkForHeader();

    const_cast<Record *>(keyList.getKey())->undoZeroLength();
    _currBamBlockList = blockList;

    if (_context->getProgram() == ContextBase::INTERSECT) {
        if (_printable) {
            if (keyList.empty()) {
                if ((static_cast<ContextIntersect *>(_context))->getWriteAllOverlap()) {
                    // -wao the user wants to force the reporting of 0 overlap
                    if (printKeyAndTerminate(keyList)) {

                        _currBamBlockList = NULL;
                        return;
                    }
                    tab();
                    null(false, true);
                    tab();
                    _outBuf.append('0');
                    newline();
                    if (needsFlush()) flush();
                }
                else if ((static_cast<ContextIntersect *>(_context))->getLeftJoin()) {
                    if (printKeyAndTerminate(keyList)) {
                        _currBamBlockList = NULL;

                        return;
                    }
                    tab();
                    null(false, true);
                    newline();
                    if (needsFlush()) flush();
                    _currBamBlockList = NULL;

                    return;
                }
            } else {
                if (printBamRecord(keyList, true) == BAM_AS_BAM) {
                    _currBamBlockList = NULL;

                    return;
                }
                int hitIdx = 0;
                for (RecordKeyVector::const_iterator_type iter = keyList.begin(); iter != keyList.end(); iter = keyList.next()) {
                    reportOverlapDetail(keyList.getKey(), *iter, hitIdx);
                    hitIdx++;
                }
            }
        } else { // not printable
            reportOverlapSummary(keyList);
        }
        _currBamBlockList = NULL;
    } else if (_context->getProgram() == ContextBase::SAMPLE) {
        if (!printKeyAndTerminate(keyList)) {
            newline();
        }
        _currBamBlockList = NULL;

        return;
    } else if (_context->getProgram() == ContextBase::MAP) {
        printKeyAndTerminate(keyList);
        _currBamBlockList = NULL;

        return;
    } else if (_context->getProgram() == ContextBase::MERGE) {
        printKeyAndTerminate(keyList);
        _currBamBlockList = NULL;

        return;
    }
}