src/gnLocation.cpp

Go to the documentation of this file.
00001 
00002 // File:            gnLocation.cpp
00003 // Purpose:         Standard Location for Feature
00004 // Description:     Feature location
00005 // Changes:        
00006 // Version:         libGenome 0.5.1 
00007 // Author:          Aaron Darling 
00008 // Modified by:     
00009 // Copyright:       (c) Aaron Darling 
00010 // Licenses:        See COPYING file for details
00012 #include "gn/gnLocation.h"
00013 #include "gn/gnDebug.h"
00014 
00015 gnLocation::gnLocation()
00016 {
00017         Clear();
00018 }
00019 gnLocation::gnLocation( const gnLocation& s)
00020 {
00021         SetBounds( s.m_start, s.m_startLength, s.m_end, s.m_endLength );
00022         m_type = s.m_type;
00023 }
00024 gnLocation::gnLocation( const gnSeqI start, const gnSeqI startLength, const gnSeqI end, const gnSeqI endLength, gnLocationType type, string contigName)
00025 {
00026         SetBounds( start, startLength, end, endLength );
00027         m_type = type;
00028         m_name = contigName;
00029 }
00030 gnLocation::gnLocation( const gnSeqI start, const gnSeqI end, const gnLocationType type, string contigName )
00031 {
00032         SetBounds( start, 0, end, 0 );
00033         m_type = type;
00034         m_name = contigName;
00035 }
00036 
00037 gnLocation* gnLocation::Clone() const
00038 {
00039         return new gnLocation(*this);
00040 }
00041 
00042 void gnLocation::Clear()
00043 {
00044         m_start = 0;
00045         m_end = 0;
00046         m_startLength = 0;
00047         m_endLength = 0;
00048         m_type = LT_Nothing;
00049 }
00050 
00051 
00052 void gnLocation::GetBounds( gnSeqI &s, gnSeqI &sl, gnSeqI &e, gnSeqI &el ) const
00053 {
00054         s = m_start;
00055         sl = m_startLength;
00056         e = m_end;
00057         el = m_endLength;
00058 }
00059 
00060 void gnLocation::SetBounds( const gnSeqI start, const gnSeqI startLength, const gnSeqI end, const gnSeqI endLength)
00061 {
00062         SetStart(start, startLength);
00063         SetEnd(end, endLength);
00064 }
00065 void gnLocation::SetBounds( const gnSeqI start, const gnSeqI end)
00066 {
00067         m_start = start;
00068         m_end = end;
00069 }
00070 
00071 boolean gnLocation::CropTo( const gnLocation &l )
00072 {
00073         gnSeqI tmp;
00074         gnSeqI start = l.GetStart();
00075         gnSeqI end = l.GetEnd();
00076         if(m_start < start){
00077                 tmp = start < m_end ? start : m_end;
00078                 m_startLength += tmp - m_start;
00079                 m_start = tmp;
00080         }
00081         if(m_end < end){
00082                 tmp = end > m_start ? end : m_start;
00083                 m_endLength += m_end - tmp;
00084                 m_end = tmp;
00085         }
00086 
00087         if( (l.GetFirst() > GetFirst()) )
00088         {
00089                 if( l.GetFirst() <= m_end )
00090                         m_startLength = m_start - l.GetFirst();
00091                 else if( l.GetFirst() <= GetLast() )
00092                 {
00093                         m_end = l.GetFirst();
00094                         m_start = l.GetFirst() + 1;
00095                         m_startLength = 0;
00096                 }       
00097                 else
00098                         Clear();
00099         }
00100         if( l.GetLast() < GetLast() )
00101         {
00102                 if( l.GetLast() >= m_start )
00103                         m_endLength = l.GetLast() - m_end;
00104                 else if( l.GetLast() >= GetFirst() )
00105                 {
00106                         m_start = l.GetLast();
00107                         m_end = l.GetLast() - 1;
00108                         m_endLength = 0;
00109                 }       
00110                 else
00111                         Clear();
00112         }
00113         if(m_start == m_end)
00114                 return false;
00115         return true;
00116 }
00117 
00118 boolean gnLocation::CropStart( const gnSeqI start ){
00119         gnSeqI tmp;
00120         if(m_start < start){
00121                 tmp = start < m_end ? start : m_end;
00122                 m_startLength += tmp - m_start;
00123                 m_start = tmp;
00124         }
00125         if(m_start == m_end)
00126                 return false;
00127         return true;
00128 }
00129 
00130 boolean gnLocation::CropEnd( const gnSeqI end ){
00131         gnSeqI tmp;
00132         if(m_end < end){
00133                 tmp = end > m_start ? end : m_start;
00134                 m_endLength += m_end - tmp;
00135                 m_end = tmp;
00136         }
00137         if(m_start == m_end)
00138                 return false;
00139         return true;
00140 }
00141 
00142 // Intersects
00143 boolean gnLocation::Intersects( const gnLocation &l, const intersectRestriction ir ) const{
00144         
00145         if( ir == determinedRegions )
00146         {
00147                 if( (l.GetFirst() <= m_end) && (l.GetLast() >= m_start) )
00148                         return true;
00149         }
00150         else if( ir == undeterminedRegions )
00151         {
00152                 if( (l.GetFirst() <= m_start) && (l.GetLast() >= GetFirst()) )
00153                         return true;
00154                 if( (l.GetFirst() <= GetLast()) && (l.GetLast() >= m_end) )
00155                         return true;
00156         }
00157         else if( ir == allRegions )
00158         {
00159                 if( (l.GetFirst() <= GetLast()) && (l.GetLast() >= GetFirst()) )
00160                         return true;
00161         }
00162         return false;
00163 }
00164 
00165 boolean gnLocation::Contains( const gnLocation &l, const intersectRestriction ir ) const{
00166         if(ir == determinedRegions)
00167                 return m_start <= l.GetFirst() && l.GetLast() <= m_end;
00168         else if(ir == undeterminedRegions)
00169                 return  (GetFirst() <= l.GetFirst() && l.GetLast() < m_start) ||
00170                                 (m_end < l.GetFirst() && l.GetLast() <= GetLast());
00171         return GetFirst() <= l.GetFirst() && l.GetLast() <= GetLast();
00172 }
00173 
00174 
00175 // Move
00176 boolean gnLocation::MovePositive( const gnSeqI diff )
00177 {
00178         if(m_start > GNSEQI_END - diff || m_end > GNSEQI_END - diff)
00179                 return false;
00180         m_start += diff;
00181         m_end += diff;
00182         return true;
00183 }
00184 boolean gnLocation::MoveNegative( const gnSeqI diff )
00185 {
00186         if(m_start < diff || m_end < diff)
00187                 return false;
00188         m_start -= diff;
00189         m_end -= diff;
00190         return true;
00191 }
00192 boolean gnLocation::MoveTo( const int direction, const gnSeqI diff )
00193 {
00194         if( direction > 0 )
00195                 return MovePositive( diff );
00196         return MoveNegative( diff );
00197 }
00198 
00199 gnLocation gnLocation::GetUnion( const gnLocation &l ) const
00200 {
00201         ErrorMsg("gnLocation::getUnion -- not implemented\n");
00202         return l;
00203 }
00204 
00205 // Intersects
00206 gnLocation gnLocation::GetIntersection( const gnLocation &l, const intersectRestriction ir ) const{
00207         gnLocation inter_loc;
00208         if( ir == determinedRegions )
00209         {
00210                 if( (l.GetFirst() <= m_end) && (l.GetLast() >= m_start) ){
00211                         inter_loc.m_start = l.m_start > m_start ? l.m_start : m_start;
00212                         inter_loc.m_end = l.m_end < m_end ? l.m_end : m_end;
00213                 }
00214         }
00215         else if( ir == undeterminedRegions )
00216         {
00217                 ErrorMsg("Not implemented!");
00218         }
00219         else if( ir == allRegions )
00220         {
00221                 ErrorMsg("Not implemented!");
00222         }
00223         return inter_loc;
00224 }

Generated on Mon Mar 28 06:00:21 2005 for libGenome by doxygen 1.3.6