Commit 2b1df940 authored by arq5x's avatar arq5x
Browse files

right, the actual spacing code.

parent 3bea2a71
UTILITIES_DIR = ../utils/
OBJ_DIR = ../../obj/
BIN_DIR = ../../bin/
# -------------------
# define our includes
# -------------------
INCLUDES = -I$(UTILITIES_DIR)/Contexts/ \
-I$(UTILITIES_DIR)/general/ \
-I$(UTILITIES_DIR)/fileType/ \
-I$(UTILITIES_DIR)/gzstream/ \
-I$(UTILITIES_DIR)/GenomeFile/ \
-I$(UTILITIES_DIR)/BamTools/include \
-I$(UTILITIES_DIR)/BamTools/src \
-I$(UTILITIES_DIR)/BlockedIntervals \
-I$(UTILITIES_DIR)/BamTools-Ancillary \
-I$(UTILITIES_DIR)/FileRecordTools/ \
-I$(UTILITIES_DIR)/FileRecordTools/FileReaders/ \
-I$(UTILITIES_DIR)/FileRecordTools/Records/ \
-I$(UTILITIES_DIR)/KeyListOps/ \
-I$(UTILITIES_DIR)/RecordOutputMgr/ \
-I$(UTILITIES_DIR)/version/
# ----------------------------------
# define our source and object files
# ----------------------------------
SOURCES= spacingMain.cpp SpacingFile.cpp SpacingFile.h
OBJECTS= spacingMain.o SpacingFile.o
BUILT_OBJECTS= $(patsubst %,$(OBJ_DIR)/%,$(OBJECTS))
PROGRAM= spacing
all: $(BUILT_OBJECTS)
.PHONY: all
$(BUILT_OBJECTS): $(SOURCES)
@echo " * compiling" $(*F).cpp
@$(CXX) -c -o $@ $(*F).cpp $(LDFLAGS) $(CXXFLAGS) $(DFLAGS) $(INCLUDES)
clean:
@echo "Cleaning up."
@rm -f $(OBJ_DIR)/sampleMain.o $(OBJ_DIR)/SpacingFile.o
.PHONY: clean
/*
* SpacingFile.cpp
*
* Created on: Nov 18, 2013
* Author: nek3d
*/
#include "SpacingFile.h"
#include "ContextSpacing.h"
#include "FileRecordMgr.h"
#include "RecordOutputMgr.h"
SpacingFile::SpacingFile(ContextSpacing *context)
: _context(context),
_inputFile(NULL),
_outputMgr(NULL)
{}
SpacingFile::~SpacingFile() {
}
bool SpacingFile::getSpacing()
{
//we're only operating on one file, so the idx is zero.
_inputFile = _context->getFile(0);
_outputMgr = new RecordOutputMgr();
_outputMgr->init(_context);
Record *prev = NULL;
Record *curr = NULL;
QuickString distance;
while (!_inputFile->eof()) {
Record *curr = _inputFile->getNextRecord();
// no more records
if (curr == NULL) {
continue;
}
// first record in file.
if (prev == NULL) {
distance.append(".");
}
// the meat of the file
else {
// current and previous records are on the same chromosome.
if (curr->getChrName() == prev->getChrName())
{
// do curr and prev overlap?
if (curr->sameChromIntersects(prev, false, false, 1E-9, false))
distance.append(0);
else
distance.append(curr->getStartPos() - prev->getEndPos());
}
// we have changed chromosomes
else if (curr->getChrName() != prev->getChrName())
{
distance.append(".");
}
}
// report distance between current and previous intervals
_outputMgr->printRecord(curr, distance);
// memory cleanup
_inputFile->deleteRecord(prev);
distance.clear();
// current become previous in prep for next record in file.
prev = curr;
}
// cleanup
delete _outputMgr;
_inputFile->close();
return true;
}
/*
* SpacingFile.h
*
* Created on: Nov 18, 2013
* Author: nek3d
*/
#ifndef SPACINGFILE_H_
#define SPACINGFILE_H_
#include "ContextSpacing.h"
#include "Record.h"
#include <vector>
using namespace std;
class FileRecordMgr;
class Context;
class RecordOutputMgr;
class SpacingFile {
public:
SpacingFile(ContextSpacing *context);
~SpacingFile();
bool getSpacing();
private:
ContextSpacing *_context;
FileRecordMgr *_inputFile;
RecordOutputMgr *_outputMgr;
};
#endif /* SPACINGFILE_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment