Skip to content
Snippets Groups Projects
Commit ffa852df authored by Aaron's avatar Aaron
Browse files

slopBed now uses the GenomeFile class.

parent b5e9b670
No related branches found
No related tags found
No related merge requests found
......@@ -9,14 +9,14 @@ BIN_DIR = ../../bin/
# -------------------
# define our includes
# -------------------
INCLUDES = -I$(UTILITIES_DIR)/bedFile/ -I$(UTILITIES_DIR)/lineFileUtilities/ -I$(UTILITIES_DIR)/version/
INCLUDES = -I$(UTILITIES_DIR)/bedFile/ -I$(UTILITIES_DIR)/genomeFile/ -I$(UTILITIES_DIR)/lineFileUtilities/ -I$(UTILITIES_DIR)/version/
# ----------------------------------
# define our source and object files
# ----------------------------------
SOURCES= slopBedMain.cpp slopBed.cpp
OBJECTS= $(SOURCES:.cpp=.o)
_EXT_OBJECTS=bedFile.o lineFileUtilities.o
_EXT_OBJECTS=bedFile.o genomeFile.o lineFileUtilities.o
EXT_OBJECTS=$(patsubst %,$(OBJ_DIR)/%,$(_EXT_OBJECTS))
BUILT_OBJECTS= $(patsubst %,$(OBJ_DIR)/%,$(OBJECTS))
PROGRAM= slopBed
......@@ -37,7 +37,8 @@ $(BUILT_OBJECTS): $(SOURCES)
$(EXT_OBJECTS):
@$(MAKE) --no-print-directory -C $(UTILITIES_DIR)/lineFileUtilities/
@$(MAKE) --no-print-directory -C $(UTILITIES_DIR)/bedFile/
@$(MAKE) --no-print-directory -C $(UTILITIES_DIR)/genomeFile/
clean:
@echo "Cleaning up."
@rm -f $(OBJ_DIR)/* $(BIN_DIR)/*
......
......@@ -12,9 +12,7 @@
#include "lineFileUtilities.h"
#include "slopBed.h"
/*
Constructor
*/
BedSlop::BedSlop(string &bedFile, string &genomeFile, bool &forceStrand, int &leftSlop, int &rightSlop) {
this->bedFile = bedFile;
......@@ -24,14 +22,11 @@ BedSlop::BedSlop(string &bedFile, string &genomeFile, bool &forceStrand, int &le
this->leftSlop = leftSlop;
this->rightSlop = rightSlop;
this->bed = new BedFile(bedFile);
this->bed = new BedFile(bedFile);
this->genome = new GenomeFile(genomeFile);
}
/*
Destructor
*/
BedSlop::~BedSlop(void) {
}
......@@ -49,7 +44,6 @@ void BedSlop::SlopBed(istream &bedInput) {
lineNum++;
BED bedEntry; // used to store the current BED line from the BED file.
if (this->bed->parseLine(bedEntry, bedFields, lineNum)) {
AddSlop(bedEntry);
bed->reportBedNewLine(bedEntry);
......@@ -60,18 +54,18 @@ void BedSlop::SlopBed(istream &bedInput) {
void BedSlop::AddSlop(BED &bed) {
/*
special handling if the BED entry is on the negative
strand and the user cares about strandedness.
*/
if ((this->forceStrand) && (bed.strand == "-")) {
// special handling if the BED entry is on the negative
// strand and the user cares about strandedness.
int chromSize = genome->getChromSize(bed.chrom);
if ( (this->forceStrand) && (bed.strand == "-") ) {
// inspect the start
if ((bed.start - rightSlop) > 0) bed.start -= rightSlop;
else bed.start = 0;
// inspect the start
if ((bed.end + leftSlop) <= this->chromSizes[bed.chrom]) bed.end += leftSlop;
else bed.end = this->chromSizes[bed.chrom];
if ((bed.end + leftSlop) <= chromSize) bed.end += leftSlop;
else bed.end = chromSize;
}
else {
// inspect the start
......@@ -79,35 +73,14 @@ void BedSlop::AddSlop(BED &bed) {
else bed.start = 0;
// inspect the end
if ((bed.end + rightSlop) <= this->chromSizes[bed.chrom]) bed.end += rightSlop;
else bed.end = this->chromSizes[bed.chrom];
if ((bed.end + rightSlop) <= chromSize) bed.end += rightSlop;
else bed.end = chromSize;
}
}
void BedSlop::DetermineBedInput() {
/* open the GENOME file for reading.
if successful, load each chrom and it's size into
the "chromSize" map. also compute the total size of the genome
and store in "genomeSize"
*/
ifstream genome(this->genomeFile.c_str(), ios::in);
if ( !genome ) {
cerr << "Error: The requested genome file (" <<this->genomeFile << ") could not be opened. Exiting!" << endl;
exit (1);
}
else {
string chrom;
unsigned int size;
while (genome >> chrom >> size) {
if (chrom.size() > 0 && size > 0) {
this->chromSizes[chrom] = size;
}
}
}
if (this->bedFile != "stdin") { // process a file
ifstream beds(this->bedFile.c_str(), ios::in);
if ( !beds ) {
......
#include "bedFile.h"
#include <vector>
#include <iostream>
#include <fstream>
#include <map>
#include <cstdlib>
/*****************************************************************************
slopBed.h
......@@ -15,6 +9,15 @@
Licenced under the GNU General Public License 2.0+ license.
******************************************************************************/
#include "bedFile.h"
#include "genomeFile.h"
#include <vector>
#include <iostream>
#include <fstream>
#include <map>
#include <cstdlib>
#include <ctime>
using namespace std;
......@@ -49,6 +52,5 @@ private:
int rightSlop;
BedFile *bed;
map<string, int, less<string> > chromSizes;
GenomeFile *genome;
};
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