libStatGen Software 1
Loading...
Searching...
No Matches
NonOverlapRegions.h
1/*
2 * Copyright (C) 2011 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18//////////////////////////////////////////////////////////////////////////
19
20#ifndef __NONOVERLAP_REGIONS_H__
21#define __NONOVERLAP_REGIONS_H__
22
23#include <map>
24#include <string>
25#include <list>
26#include <stdint.h>
27
28/// This class contains a list of non-overlapping regions, just positions, not
29/// including chromosomes (see NonOverlapRegions for chromosomes and positions).
30/// When regions are added that overlap, it merges them. After adding regions,
31/// you can check to see if a position is found in one of the regions. It is
32/// designed to work fastest if you make calls in sequential order.
34{
35public:
36 friend class NonOverlapRegionsTest;
38 /// Copy constructor, does not copy, but initializes with an empty
39 /// region list.
41
43
44 /// End position is not included in the region.
45 /// If this region overlaps another region(s), they will be merged into
46 /// one region.
47 void add(int32_t start, int32_t end);
48
49 /// Return whether or not the position was found within a region.
50 /// If it is found within the region, myRegionIter will point to the region
51 /// otherwise myRegionIter will point to the region after the position
52 /// or to the end if the position is after the last region.
53 bool inRegion(int32_t pos);
54
55private:
56 // True if pos found in the region pointed to by myRegionIter or to
57 // the right of myRegionIter. If the position is found in a region,
58 // myRegionIter will point to the region containing the position.
59 // If the position is not found in a region, myRegionIter will point
60 // to the region after the position, or to the end if the position is
61 // after the last region.
62 bool findRight(int32_t pos);
63
64 // True if pos found in the region pointed to by myRegionIter or to
65 // the left of myRegionIter. If the position is found in a region,
66 // myRegionIter will point to the region containing the position.
67 // If the position is not found in a region, myRegionIter will point
68 // to the region after the position, or to the end if the position is
69 // after the last region.
70 bool findLeft(int32_t pos);
71
72
73 std::list< std::pair<int32_t, int32_t> > myRegions;
74 std::list< std::pair<int32_t, int32_t> >::iterator myRegionIter;
75 std::list< std::pair<int32_t, int32_t> >::iterator myTmpIter;
76};
77
78
79/// This class contains a list of non-overlapping regions. When regions are
80/// added that overlap, it merges them. After adding regions, you can check
81/// to see if a position is found in one of the regions. It is designed to
82/// work fastest if you make calls in sequential order.
84{
85public:
86 friend class NonOverlapRegionsTest;
87
90
91 /// End position is not included in the region.
92 /// If this region overlaps another region(s), they will be merged into
93 /// one region.
94 void add(const char* chrom, int32_t start, int32_t end);
95
96 /// Return whether or not the position was found within a region.
97 /// If it is found within the region, myRegionIter will point to the region
98 /// otherwise myRegionIter will point to the region after the position
99 /// or to the end if the position is after the last region.
100 bool inRegion(const char* chrom, int32_t pos);
101
102private:
103 // Copy Constructor - unimplimented.
105
106 std::map<std::string, NonOverlapRegionPos> myRegions;
107};
108
109#endif
This class contains a list of non-overlapping regions, just positions, not including chromosomes (see...
void add(int32_t start, int32_t end)
End position is not included in the region.
bool inRegion(int32_t pos)
Return whether or not the position was found within a region.
This class contains a list of non-overlapping regions.
bool inRegion(const char *chrom, int32_t pos)
Return whether or not the position was found within a region.
void add(const char *chrom, int32_t start, int32_t end)
End position is not included in the region.