gnLocation.cpp Source File

Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

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