NonOverlapRegionPos Class Reference

This class contains a list of non-overlapping regions, just positions, not including chromosomes (see NonOverlapRegions for chromosomes and positions). More...

#include <NonOverlapRegions.h>

Collaboration diagram for NonOverlapRegionPos:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 NonOverlapRegionPos (const NonOverlapRegionPos &reg)
 Copy constructor, does not copy, but initializes with an empty region list.
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.

Friends

class NonOverlapRegionsTest

Detailed Description

This class contains a list of non-overlapping regions, just positions, not including chromosomes (see NonOverlapRegions for chromosomes and positions).

When regions are added that overlap, it merges them. After adding regions, you can check to see if a position is found in one of the regions. It is designed to work fastest if you make calls in sequential order.

Definition at line 66 of file NonOverlapRegions.h.


Constructor & Destructor Documentation

NonOverlapRegionPos::NonOverlapRegionPos ( const NonOverlapRegionPos reg  ) 

Copy constructor, does not copy, but initializes with an empty region list.

Definition at line 59 of file NonOverlapRegions.cpp.

00060     : myRegions()
00061 {
00062     myRegionIter = myRegions.begin();
00063     myTmpIter = myRegions.begin();
00064 }


Member Function Documentation

void NonOverlapRegionPos::add ( int32_t  start,
int32_t  end 
)

End position is not included in the region.

If this region overlaps another region(s), they will be merged into one region.

Definition at line 75 of file NonOverlapRegions.cpp.

References inRegion().

00076 {
00077     // Check to see if the start/end are valid in relation.
00078     if(start >= end)
00079     {
00080         std::cerr << "NonOverlapRegionPos::add: Invalid Range, "
00081                   << "start must be < end, but " << start << " >= " << end 
00082                   << std::endl;
00083         return;
00084     }
00085 
00086     bool added = false;
00087     // Locate the correct position in the region list for this start/end.
00088     if(inRegion(start))
00089     {
00090         // Check if the region end needs to be updated.
00091         if(end > myRegionIter->second)
00092         {
00093             myRegionIter->second = end;
00094         }
00095         added = true;
00096     }
00097     else
00098     {
00099         // Check to see if we are at the end.
00100         if(myRegionIter != myRegions.end())
00101         {
00102             // Not at the end.
00103             // Check to see if the region overlaps the current region.
00104             if(end >= myRegionIter->first)
00105             {
00106                 // Overlaps, so update the start.
00107                 myRegionIter->first = start;
00108                 // Check if the end needs to be updated.
00109                 if(myRegionIter->second < end)
00110                 {
00111                     myRegionIter->second = end;
00112                 }
00113                 added = true;
00114             }
00115         }
00116     }
00117 
00118     // If we already added the record, check to see if the end of the
00119     // new region overlaps any additional regions (know that myRegionIter is
00120     // not at the end.
00121     if(added)
00122     {
00123         // Check to see if any other regions were overlapped by this record.
00124         myTmpIter = myRegionIter;
00125         ++myTmpIter;
00126         while(myTmpIter != myRegions.end())
00127         {
00128             // If the region starts before the end of this one, consume it.
00129             if(myTmpIter->first <= end)
00130             {
00131                 if(myTmpIter->second > myRegionIter->second)
00132                 {
00133                     // Update this region with the new end.
00134                     myRegionIter->second = myTmpIter->second;
00135                 }
00136                 
00137                 myTmpIter = myRegions.erase(myTmpIter);
00138             }
00139             else
00140             {
00141                 // This region is not overlapped by the new region, so stop.
00142                 break;
00143             }
00144         }
00145     }
00146     else
00147     {
00148         // Add the region.
00149         myRegionIter = myRegions.insert(myRegionIter, 
00150                                          std::make_pair(start, end));
00151     }
00152 }

bool NonOverlapRegionPos::inRegion ( int32_t  pos  ) 

Return whether or not the position was found within a region.

If it is found within the region, myRegionIter will point to the region otherwise myRegionIter will point to the region after the position or to the end if the position is after the last region.

Definition at line 155 of file NonOverlapRegions.cpp.

Referenced by add().

00156 {
00157     // Return whether or not the position was found within a region.
00158     // If it is found within the region, myRegionIter will point to the region
00159     // otherwise myRegionIter will point to the region after the position 
00160     // or to the end if the position is after the last region.
00161 
00162     // Determine if it needs to search to the left
00163     //   a) it is at the end
00164     //   b) the region starts after the position.
00165     if(myRegionIter == myRegions.end())
00166     {
00167         // If the iterator is at the end, search to the left.
00168         return(findLeft(pos));
00169     }
00170     else if(pos < myRegionIter->first)
00171     {
00172         // Not at the end, so search left if the position is less
00173         // than this region's start.
00174         return(findLeft(pos));
00175     }
00176     else
00177     {
00178         return(findRight(pos));
00179     }
00180 }


The documentation for this class was generated from the following files:
Generated on Mon Feb 11 13:45:24 2013 for libStatGen Software by  doxygen 1.6.3