File: ival_list.cpp

package info (click to toggle)
bowtie2 2.3.0-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 21,568 kB
  • sloc: cpp: 58,327; perl: 7,310; sh: 1,054; python: 946; makefile: 441; ansic: 122
file content (165 lines) | stat: -rw-r--r-- 5,174 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * Copyright 2011, Ben Langmead <langmea@cs.jhu.edu>
 *
 * This file is part of Bowtie 2.
 *
 * Bowtie 2 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Bowtie 2 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Bowtie 2.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "ival_list.h"

#ifdef MAIN_IVAL_DS

#include <iostream>
#include "random_source.h"

using namespace std;

int main(void) {
	cerr << "Case 1 ... ";
	{
		EIvalMergeList list((size_t)5);
		list.add(Interval(0, 10, true, 10));
		list.add(Interval(0, 30, true, 10));
		list.add(Interval(0, 20, true, 10));
		assert(!list.locusPresent(Coord(0, 5, true)));
		assert(!list.locusPresent(Coord(0, 9, true)));
		assert(list.locusPresent(Coord(0, 10, true)));
		assert(list.locusPresent(Coord(0, 11, true)));
		assert(list.locusPresent(Coord(0, 19, true)));
		assert(list.locusPresent(Coord(0, 20, true)));
		assert(list.locusPresent(Coord(0, 21, true)));
		assert(list.locusPresent(Coord(0, 29, true)));
		assert(list.locusPresent(Coord(0, 30, true)));
		assert(list.locusPresent(Coord(0, 31, true)));
		assert(list.locusPresent(Coord(0, 39, true)));
		assert(!list.locusPresent(Coord(0, 40, true)));
		assert(!list.locusPresent(Coord(0, 41, true)));
	}
	cerr << " PASSED" << endl;

	cerr << "Case 2 ... ";
	{
		EIvalMergeList list((size_t)5);
		list.add(Interval(0, 10, true, 10));
		for(size_t i = 5; i < 45; i++) {
			assert(list.locusPresent(Coord(0, i, true)) == (i >= 10 && i < 20));
		}
		list.clear();
		list.add(Interval(0, 15, true, 10));
		for(size_t i = 5; i < 45; i++) {
			assert(list.locusPresent(Coord(0, i, true)) == (i >= 15 && i < 25));
		}
	}
	cerr << " PASSED" << endl;

	cerr << "Case 3 ... ";
	{
		EIvalMergeList list((size_t)5);
		for(size_t i = 0; i < 20; i++) {
			list.add(Interval(0, 10*i, true, 9));
		}
		for(size_t i = 0; i < 200; i++) {
			assert(list.locusPresent(Coord(0, i, true)) == ((i % 10) != 9));
			assert(!list.locusPresent(Coord(0, i, false)));
			assert(!list.locusPresent(Coord(1, i, true)));
		}
	}
	cerr << " PASSED" << endl;

	cerr << "Case 4 ... ";
	{
		EIvalMergeList list((size_t)5);
		for(int i = 19; i >= 0; i--) {
			list.add(Interval(0, 10*i, true, 9));
		}
		for(size_t i = 0; i < 200; i++) {
			assert(list.locusPresent(Coord(0, i, true)) == ((i % 10) != 9));
			assert(!list.locusPresent(Coord(0, i, false)));
			assert(!list.locusPresent(Coord(1, i, true)));
		}
	}
	cerr << " PASSED" << endl;

	cerr << "Random testing (1 ref) ... ";
	{
		RandomSource rnd(34523);
		for(size_t c = 0; c < 10; c++) {
			EIvalMergeList list1((size_t)16);
			EIvalMergeList list2((size_t)2000);
			size_t num_intervals = 20;
			uint32_t max_width = 100;
			for(size_t i = 0; i < num_intervals; i++) {
				uint32_t start = rnd.nextU32() % max_width/2;
				uint32_t end = (rnd.nextU32() % (max_width - start - 1) + start)+1;
				assert_lt(end, max_width);
				assert_gt(end, start);
				list1.add(Interval(0, start, false, end-start));
				list2.add(Interval(0, start, false, end-start));
			}
			assert_geq(num_intervals, list1.size());
			assert_geq(num_intervals, list2.size());
			assert(list1.repOk());
			assert(list2.repOk());
			for(uint32_t i = 0; i < max_width+1; i++) {
				assert(list1.repOk());
				assert(list2.repOk());
				ASSERT_ONLY(bool l1 = list1.locusPresent(Coord(0, i, true)));
				ASSERT_ONLY(bool l2 = list2.locusPresent(Coord(0, i, true)));
				assert_eq(l1, l2);
			}
		}
	}
	cerr << " PASSED" << endl;

	cerr << "Random testing (few refs) ... ";
	{
		RandomSource rnd(34523);
		for(size_t c = 0; c < 10; c++) {
			EIvalMergeList list1((size_t)16);
			EIvalMergeList list2((size_t)2000);
			size_t num_intervals = 20;
			uint32_t max_width = 100;
			for(size_t i = 0; i < num_intervals; i++) {
				uint32_t start = rnd.nextU32() % max_width/2;
				uint32_t end = (rnd.nextU32() % (max_width - start - 1) + start)+1;
				assert_lt(end, max_width);
				assert_gt(end, start);
				bool orient = (rnd.nextU2() == 0);
				TRefId ref = (TRefId)(rnd.nextU32() % 5);
				list1.add(Interval(ref, start, orient, end-start));
				list2.add(Interval(ref, start, orient, end-start));
			}
			assert_geq(num_intervals, list1.size());
			assert_geq(num_intervals, list2.size());
			assert(list1.repOk());
			assert(list2.repOk());
			for(uint32_t i = 0; i < max_width+1; i++) {
				assert(list1.repOk());
				assert(list2.repOk());
				for(int fwi = 0; fwi < 2; fwi++) {
					bool fw = (fwi == 0);
					for(TRefId refi = 0; refi < 5; refi++) {
						ASSERT_ONLY(bool l1 = list1.locusPresent(Coord(refi, i, fw)));
						ASSERT_ONLY(bool l2 = list2.locusPresent(Coord(refi, i, fw)));
						assert_eq(l1, l2);
					}
				}
			}
		}
	}
	cerr << " PASSED" << endl;
}

#endif /*def MAIN_IVAL_DS*/