libStatGen Software
1
|
00001 /* 00002 * Copyright (C) 2011 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 ////////////////////////////////////////////////////////////////////////// 00019 00020 #ifndef __NONOVERLAP_REGIONS_H__ 00021 #define __NONOVERLAP_REGIONS_H__ 00022 00023 #include <map> 00024 #include <string> 00025 #include <list> 00026 #include <stdint.h> 00027 00028 /// This class contains a list of non-overlapping regions, just positions, not 00029 /// including chromosomes (see NonOverlapRegions for chromosomes and positions). 00030 /// When regions are added that overlap, it merges them. After adding regions, 00031 /// you can check to see if a position is found in one of the regions. It is 00032 /// designed to work fastest if you make calls in sequential order. 00033 class NonOverlapRegionPos 00034 { 00035 public: 00036 friend class NonOverlapRegionsTest; 00037 NonOverlapRegionPos(); 00038 /// Copy constructor, does not copy, but initializes with an empty 00039 /// region list. 00040 NonOverlapRegionPos(const NonOverlapRegionPos& reg); 00041 00042 ~NonOverlapRegionPos(); 00043 00044 /// End position is not included in the region. 00045 /// If this region overlaps another region(s), they will be merged into 00046 /// one region. 00047 void add(int32_t start, int32_t end); 00048 00049 /// Return whether or not the position was found within a region. 00050 /// If it is found within the region, myRegionIter will point to the region 00051 /// otherwise myRegionIter will point to the region after the position 00052 /// or to the end if the position is after the last region. 00053 bool inRegion(int32_t pos); 00054 00055 private: 00056 // True if pos found in the region pointed to by myRegionIter or to 00057 // the right of myRegionIter. If the position is found in a region, 00058 // myRegionIter will point to the region containing the position. 00059 // If the position is not found in a region, myRegionIter will point 00060 // to the region after the position, or to the end if the position is 00061 // after the last region. 00062 bool findRight(int32_t pos); 00063 00064 // True if pos found in the region pointed to by myRegionIter or to 00065 // the left of myRegionIter. If the position is found in a region, 00066 // myRegionIter will point to the region containing the position. 00067 // If the position is not found in a region, myRegionIter will point 00068 // to the region after the position, or to the end if the position is 00069 // after the last region. 00070 bool findLeft(int32_t pos); 00071 00072 00073 std::list< std::pair<int32_t, int32_t> > myRegions; 00074 std::list< std::pair<int32_t, int32_t> >::iterator myRegionIter; 00075 std::list< std::pair<int32_t, int32_t> >::iterator myTmpIter; 00076 }; 00077 00078 00079 /// This class contains a list of non-overlapping regions. When regions are 00080 /// added that overlap, it merges them. After adding regions, you can check 00081 /// to see if a position is found in one of the regions. It is designed to 00082 /// work fastest if you make calls in sequential order. 00083 class NonOverlapRegions 00084 { 00085 public: 00086 friend class NonOverlapRegionsTest; 00087 00088 NonOverlapRegions(); 00089 ~NonOverlapRegions(); 00090 00091 /// End position is not included in the region. 00092 /// If this region overlaps another region(s), they will be merged into 00093 /// one region. 00094 void add(const char* chrom, int32_t start, int32_t end); 00095 00096 /// Return whether or not the position was found within a region. 00097 /// If it is found within the region, myRegionIter will point to the region 00098 /// otherwise myRegionIter will point to the region after the position 00099 /// or to the end if the position is after the last region. 00100 bool inRegion(const char* chrom, int32_t pos); 00101 00102 private: 00103 // Copy Constructor - unimplimented. 00104 NonOverlapRegions(const NonOverlapRegions& reg); 00105 00106 std::map<std::string, NonOverlapRegionPos> myRegions; 00107 }; 00108 00109 #endif