Commit d98c7f8f authored by jayhesselberth's avatar jayhesselberth
Browse files

test stub; refactor num_window calculation

parent 33d4cc21
......@@ -78,9 +78,18 @@ void WindowMaker::MakeBEDWindow(const BED& interval)
MakeFixedCountWindow(interval);
}
uint32_t WindowMaker::CalculateWindows(const BED& interval) {
uint32_t num_windows = (interval.end - interval.start) / _step;
if ((interval.end - interval.start) % _step > 0) {
// add 1 to num_windows if the last window is less than _step
num_windows += 1;
}
return num_windows;
}
void WindowMaker::MakeFixedSizeWindow(const BED& interval) {
uint32_t i=1;
uint32_t num_windows = (interval.end - interval.start) / _step;
uint32_t num_windows = CalculateWindows(interval);
for (uint32_t start = interval.start; start <= interval.end; start += _step, ++i) {
string name = GenerateID(interval, i, num_windows, _reverse);
if ((start + _size) <= interval.end) {
......@@ -95,7 +104,8 @@ 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;
uint32_t num_windows = CalculateWindows(interval);
if (window_size==0 || interval_size==0)
return;
......@@ -109,19 +119,21 @@ void WindowMaker::MakeFixedCountWindow(const BED& interval) {
string WindowMaker::GenerateID(const BED& interval, uint32_t window_index, uint32_t num_windows, bool _reverse) const {
stringstream s;
// cout << "num_windows: " << num_windows << endl;
// cout << "window_index: " << window_index << endl << endl;
switch(_id_method) {
case ID_SOURCE_ID:
s << "\t" << interval.name;
break;
case ID_WINDOW_NUMBER:
if (_reverse == true) {
if (_reverse == true && num_windows > 0) {
s << "\t" << num_windows - window_index + 1;
} else {
s << "\t" << window_index;
}
break;
case ID_SOURCE_ID_WINDOW_NUMBER:
if (_reverse == true) {
if (_reverse == true && num_windows > 0) {
s << "\t" << interval.name << "_" << num_windows - window_index + 1;
} else {
s << "\t" << interval.name << "_" << window_index;
......
......@@ -58,6 +58,7 @@ private:
void MakeFixedSizeWindow(const BED& interval);
void MakeFixedCountWindow(const BED& interval);
uint32_t CalculateWindows(const BED& interval);
string GenerateID(const BED& interval, uint32_t window_index, uint32_t num_windows, bool _reverse) const;
};
chr5 60000 70000 AAA
chr5 73000 90000 BBB
chr5 100000 101000 CCC
BT=${BT-../../bin/bedtools}
check()
{
if diff $1 $2; then
echo ok
else
echo fail
fi
}
###########################################################
# Test forward and reverse window numbering
############################################################
echo " makewindows.t01...\c"
echo
$BT makewindows -b input.bed -w 500 -i winnum > obs
check obs exp
rm obs exp
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