Commit 6eada05c authored by jayhesselberth's avatar jayhesselberth
Browse files

clean compile, need to test

parent 64b95927
......@@ -11,10 +11,11 @@ Licenced under the GNU General Public License 2.0 license.
******************************************************************************/
#include "windowMaker.h"
WindowMaker::WindowMaker(string &fileName, ID_METHOD id_method, INPUT_FILE_TYPE input_file_type, uint32_t size, uint32_t step)
WindowMaker::WindowMaker(string &fileName, ID_METHOD id_method, INPUT_FILE_TYPE input_file_type, uint32_t size, uint32_t step, bool reverse)
: _size(size)
, _step(step)
, _count(0)
, _reverse(reverse)
, _window_method(FIXED_WINDOW_SIZE)
, _id_method(id_method)
{
......@@ -24,10 +25,11 @@ WindowMaker::WindowMaker(string &fileName, ID_METHOD id_method, INPUT_FILE_TYPE
MakeWindowsFromBED(fileName);
}
WindowMaker::WindowMaker(string &fileName, ID_METHOD id_method, INPUT_FILE_TYPE input_file_type, uint32_t count)
WindowMaker::WindowMaker(string &fileName, ID_METHOD id_method, INPUT_FILE_TYPE input_file_type, uint32_t count, bool reverse)
: _size(0)
, _step(0)
, _count(count)
, _reverse(reverse)
, _window_method(FIXED_WINDOW_COUNT)
, _id_method(id_method)
{
......@@ -78,8 +80,9 @@ void WindowMaker::MakeBEDWindow(const BED& interval)
void WindowMaker::MakeFixedSizeWindow(const BED& interval) {
uint32_t i=1;
uint32_t num_windows = (interval.end - interval.start) / _step;
for (uint32_t start = interval.start; start <= interval.end; start += _step, ++i) {
string name = GenerateID(interval,i);
string name = GenerateID(interval, i, num_windows, _reverse);
if ((start + _size) <= interval.end) {
cout << interval.chrom << "\t" << start << "\t" << start + _size << name << endl;
}
......@@ -92,28 +95,37 @@ void WindowMaker::MakeFixedSizeWindow(const BED& interval) {
void WindowMaker::MakeFixedCountWindow(const BED& interval) {
uint32_t interval_size = interval.end - interval.start ;
uint32_t window_size = (interval_size-1)/_count + 1; // integer version of ceil(interval_size/_count)
uint32_t num_windows = interval_size / window_size;
if (window_size==0 || interval_size==0)
return;
uint32_t i=1;
for (uint32_t start = interval.start; start < interval.end; start += window_size, ++i) {
string name = GenerateID(interval,i);
string name = GenerateID(interval, i, num_windows, _reverse);
uint32_t end = min(start + window_size,interval.end);
cout << interval.chrom << "\t" << start << "\t" << end << name << endl;
}
}
string WindowMaker::GenerateID(const BED& interval, uint32_t window_index) const {
string WindowMaker::GenerateID(const BED& interval, uint32_t window_index, uint32_t num_windows, bool _reverse) const {
stringstream s;
switch(_id_method) {
case ID_SOURCE_ID:
s << "\t" << interval.name;
break;
case ID_WINDOW_NUMBER:
s << "\t" << window_index;
if (_reverse == true) {
s << "\t" << num_windows - window_index;
} else {
s << "\t" << window_index;
}
break;
case ID_SOURCE_ID_WINDOW_NUMBER:
s << "\t" << interval.name << "_" << window_index;
if (_reverse == true) {
s << "\t" << interval.name << "_" << num_windows - window_index;
} else {
s << "\t" << interval.name << "_" << window_index;
}
default:
case ID_NONE:
break;
......
......@@ -37,8 +37,8 @@ public:
};
// constructor
WindowMaker(string &fileName, ID_METHOD id_method, INPUT_FILE_TYPE input_file_type, uint32_t count);
WindowMaker(string &fileName, ID_METHOD id_method, INPUT_FILE_TYPE input_file_type, uint32_t size, uint32_t step);
WindowMaker(string &fileName, ID_METHOD id_method, INPUT_FILE_TYPE input_file_type, uint32_t count, bool reverse);
WindowMaker(string &fileName, ID_METHOD id_method, INPUT_FILE_TYPE input_file_type, uint32_t size, uint32_t step, bool reverse);
// destructor
~WindowMaker(void);
......@@ -50,6 +50,7 @@ private:
uint32_t _size;
uint32_t _step;
uint32_t _count;
bool _reverse; // should window numbering be reversed?
WINDOW_METHOD _window_method;
ID_METHOD _id_method;
......@@ -58,5 +59,5 @@ private:
void MakeFixedSizeWindow(const BED& interval);
void MakeFixedCountWindow(const BED& interval);
string GenerateID(const BED& interval, uint32_t window_index) const;
string GenerateID(const BED& interval, uint32_t window_index, uint32_t num_windows, bool _reverse) const;
};
......@@ -43,6 +43,7 @@ int windowmaker_main(int argc, char* argv[]) {
bool haveBed = false;
bool haveSize = false;
bool haveCount = false;
bool reverse = false;
for(int i = 1; i < argc; i++) {
int parameterLength = (int)strlen(argv[i]);
......@@ -97,6 +98,11 @@ int windowmaker_main(int argc, char* argv[]) {
i++;
}
}
else if(PARAMETER_CHECK("-reverse", 1, parameterLength)) {
if ((i+1) < argc) {
reverse = true;
}
}
else if(PARAMETER_CHECK("-i", 2, parameterLength)) {
if ((i+1) < argc) {
if (strcmp(argv[i+1],"winnum")==0)
......@@ -142,9 +148,11 @@ int windowmaker_main(int argc, char* argv[]) {
if (!showHelp) {
WindowMaker *wm = NULL;
if (haveCount)
wm = new WindowMaker(inputFile, idMethod, inputFileType, count);
wm = new WindowMaker(inputFile, idMethod,
inputFileType, count, reverse);
if (haveSize)
wm = new WindowMaker(inputFile, idMethod, inputFileType, size, step);
wm = new WindowMaker(inputFile, idMethod,
inputFileType, size, step, reverse);
delete wm;
}
else {
......@@ -198,6 +206,10 @@ void windowmaker_help(void) {
cerr << "\t\t \"-i srcwinnum\" - use the source interval's name with the window number." << endl;
cerr << "\t\tSee below for usage examples." << endl << endl;
cerr << "\t-reverse" << endl;
cerr << "\t\t Reverse numbering of windows in the output, i.e. report " << endl;
cerr << "\t\t windows in decreasing order" << endl << endl;
cerr << "Notes: " << endl;
cerr << "\t(1) The genome file should tab delimited and structured as follows:" << endl;
cerr << "\t <chromName><TAB><chromSize>" << endl << endl;
......@@ -276,6 +288,25 @@ void windowmaker_help(void) {
cerr << " ..." << endl;
cerr << endl;
cerr << " # Reverse window numbers: "<< endl;
cerr << " $ cat input.bed" << endl;
cerr << " chr5 60000 70000 AAA" << endl;
cerr << " chr5 73000 90000 BBB" << endl;
cerr << " chr5 100000 101000 CCC" << endl;
cerr << " $ " << PROGRAM_NAME << " -b input.bed -n 3 -i winnum -reverse" << endl;
cerr << " chr5 60000 63334 3" << endl;
cerr << " chr5 63334 66668 2" << endl;
cerr << " chr5 66668 70000 1" << endl;
cerr << " chr5 73000 78667 3" << endl;
cerr << " chr5 78667 84334 2" << endl;
cerr << " chr5 84334 90000 1" << endl;
cerr << " chr5 100000 100334 3" << endl;
cerr << " chr5 100334 100668 2" << endl;
cerr << " chr5 100668 101000 1" << endl;
cerr << " ..." << endl;
cerr << endl;
cerr << " # Add a name column, based on the source ID + window number: "<< endl;
cerr << " $ cat input.bed" << endl;
cerr << " chr5 60000 70000 AAA" << endl;
......
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