gnBaseFeature.cpp Source File

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

# gnBaseFeature.cpp

Go to the documentation of this file.

    00001
    00002 // File:            gnBaseFeature.cpp
    00003 // Purpose:         implements the gnBaseFeature
    00004 // Description:
    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/gnBaseFeature.h"
    00014 #include "gn/gnLocation.h"
    00015 #include "gn/gnStringQualifier.h"
    00016 #include "gn/gnDebug.h"
    00017 #include <list>
    00018
    00019 gnBaseFeature::gnBaseFeature( )
    00020 {
    00021         m_id = 0;
    00022         m_name = "";
    00023         m_locationType = gnLocation::LT_Nothing;
    00024         m_broken = false;
    00025         m_spec = NULL;
    00026 }
    00027 gnBaseFeature::gnBaseFeature( string& name, uint32 id, gnFragmentSpec* spec, gnLocation::gnLocationType lt, boolean broken )
    00028 {
    00029         m_id = id;
    00030         m_name = name;
    00031         m_locationType = lt;
    00032         m_broken = broken;
    00033         m_spec = NULL;
    00034 }
    00035 gnBaseFeature::~gnBaseFeature()
    00036 {
    00037         for( uint32 i=0; i < m_qualifierList.size(); i++)
    00038                 delete m_qualifierList[i];
    00039 }
    00040 // Clone
    00041 // Location Modification methods
    00042 boolean gnBaseFeature::MovePositive( const gnSeqI i )
    00043 {
    00044         boolean still_valid = true;
    00045         for(uint32 locationI=0; locationI< m_locationList.size(); locationI++){
    00046                 still_valid = still_valid && m_locationList[locationI].MovePositive(i);
    00047         }
    00048         return still_valid;
    00049 }
    00050 boolean gnBaseFeature::MoveNegative( const gnSeqI i )
    00051 {
    00052         boolean still_valid = true;
    00053         for(uint32 locationI=0; locationI< m_locationList.size(); locationI++){
    00054                 still_valid = still_valid && m_locationList[locationI].MoveNegative(i);
    00055         }
    00056         return still_valid;
    00057 }
    00058 //delete everything bigger than i
    00059 boolean gnBaseFeature::CropEnd( const gnSeqI i )
    00060 {
    00061         boolean still_valid = true;
    00062         for(uint32 locationI=0; locationI< m_locationList.size(); locationI++){
    00063                 still_valid = still_valid && m_locationList[locationI].CropEnd(i);
    00064         }
    00065         return still_valid;
    00066 }
    00067 //delete everything less than i
    00068 boolean gnBaseFeature::CropStart( const gnSeqI i ){
    00069         boolean still_valid = true;
    00070         for(uint32 locationI=0; locationI< m_locationList.size(); locationI++){
    00071                 still_valid = still_valid && m_locationList[locationI].CropStart(i);
    00072         }
    00073         return still_valid;
    00074 }
    00075 uint32 gnBaseFeature::FirstIndexOfQualifier( const string& name, uint32 listI ) const{
    00076         if(listI >= m_qualifierList.size())
    00077                 return GNSEQI_END;
    00078
    00079         uint32 i=listI;
    00080         for(; i < m_qualifierList.size(); i++){
    00081                 string qname = m_qualifierList[i]->GetName();
    00082                 if(qname == name)
    00083                         break;
    00084         }
    00085         return i;
    00086 }
    00087 uint32 gnBaseFeature::LastIndexOfQualifier( const string& name, uint32 listI ) const{
    00088         if(listI >= m_qualifierList.size())
    00089                 return GNSEQI_END;
    00090
    00091         uint32 i=m_qualifierList.size()-1;
    00092         for(; i >= listI; i--)
    00093                 if(m_qualifierList[i]->GetName() == name)
    00094                         break;
    00095         return i;
    00096 }
    00097 boolean gnBaseFeature::RemoveQualifier( uint32 listI ){
    00098         if(listI < m_qualifierList.size()){
    00099                 m_qualifierList.erase(m_qualifierList.begin() + listI);
    00100                 return true;
    00101         }
    00102         return false;
    00103 }
    00104 boolean gnBaseFeature::SetQualifier( string& name, string& value, uint32 listI ){
    00105         if(listI < m_qualifierList.size()){
    00106                 m_qualifierList[listI] = new gnStringQualifier(name, value);
    00107                 return true;
    00108         }
    00109         return false;
    00110 }
    00111 boolean gnBaseFeature::SetQualifierName( string& name, uint32 listI ){
    00112         if(listI < m_qualifierList.size()){
    00113                 gnStringQualifier* new_qual = new gnStringQualifier(name, m_qualifierList[listI]->GetValue());
    00114                 delete m_qualifierList[listI];
    00115                 m_qualifierList[listI] = new_qual;
    00116                 return true;
    00117         }
    00118         return false;
    00119 }
    00120 boolean gnBaseFeature::SetQualifierValue( string& value, uint32 listI ){
    00121         if(listI < m_qualifierList.size()){
    00122                 gnStringQualifier* new_qual = new gnStringQualifier(m_qualifierList[listI]->GetName(), value);
    00123                 delete m_qualifierList[listI];
    00124                 m_qualifierList[listI] = new_qual;
    00125                 return true;
    00126         }
    00127         return false;
    00128 }
    00129 // Compare methods
    00130 boolean gnBaseFeature::Contains( gnSeqI i ) const{
    00131         for(uint32 locationI=0; locationI< m_locationList.size(); locationI++){
    00132                 if((m_locationList[locationI].GetStart() <= i) &&
    00133                         (m_locationList[locationI].GetEnd() >= i))
    00134                         return true;
    00135         }
    00136         return false;
    00137 }
    00138 boolean gnBaseFeature::Contains( const gnLocation& l ) const{
    00139         for(uint32 locationI=0; locationI< m_locationList.size(); locationI++){
    00140                 if(m_locationList[locationI].Contains(l))
    00141                         return true;
    00142         }
    00143         return false;
    00144 }
    00145 boolean gnBaseFeature::Contains( gnBaseFeature* feature ) const{
    00146         for(uint32 locationI=0; locationI< m_locationList.size(); locationI++){
    00147                 uint32 i=0;
    00148                 for(; i < feature->GetLocationListLength(); i++){
    00149                         if(m_locationList[locationI].Contains(feature->GetLocation(i)))
    00150                                 break;  //it's contained so we'll break the loop early
    00151                 }
    00152                 if(i == feature->GetLocationListLength())
    00153                         return false;   //the loop went full cycle.  we found an uncontained location
    00154         }
    00155         return true;
    00156 }
    00157 boolean gnBaseFeature::IsContainedBy( const gnLocation& l ) const{
    00158         for(uint32 locationI=0; locationI< m_locationList.size(); locationI++){
    00159                 if(!l.Contains(m_locationList[locationI]))
    00160                         return false;
    00161         }
    00162         return true;
    00163 }
    00164
    00165 boolean gnBaseFeature::Intersects( const gnLocation& l ) const{
    00166         for(uint32 locationI=0; locationI< m_locationList.size(); locationI++){
    00167                 if(!l.Intersects(m_locationList[locationI]))
    00168                         return false;
    00169         }
    00170         return true;
    00171 }
    00172 boolean gnBaseFeature::Intersects( gnBaseFeature* feature ) const{
    00173         for(uint32 locationI=0; locationI< m_locationList.size(); locationI++){
    00174                 uint32 i=0;
    00175                 for(; i < feature->GetLocationListLength(); i++){
    00176                         if(m_locationList[locationI].Intersects(feature->GetLocation(i)))
    00177                                 break;  //it's contained so we'll break the loop early
    00178                 }
    00179                 if(i == feature->GetLocationListLength())
    00180                         return false;   //the loop went full cycle.  we found an uncontained location
    00181         }
    00182         return true;
    00183 }
    00184 inline
    00185 boolean gnBaseFeature::AddLocation( const gnLocation& l, uint32 listI ){
    00186         if(listI <= m_locationList.size()){
    00187                 m_locationList.insert(m_locationList.begin() + listI, l);
    00188                 return true;
    00189         }
    00190         return false;
    00191 }
    00192
    00193 gnLocation gnBaseFeature::GetLocation( uint32 listI ) const{
    00194         if(listI < m_locationList.size())
    00195                 return m_locationList[listI];
    00196         return gnLocation();
    00197 }
    00198
    00199 boolean gnBaseFeature::RemoveLocation( uint32 listI ){
    00200         if(listI < m_locationList.size()){
    00201                 m_locationList.erase(m_locationList.begin() + listI);
    00202                 return true;
    00203         }
    00204         return false;
    00205 }
    00206
    00207 boolean gnBaseFeature::SetLocation( const gnLocation& l, uint32 listI ){
    00208         if(listI < m_locationList.size()){
    00209                 m_locationList[listI] = l;
    00210                 return true;
    00211         }
    00212         return false;
    00213 }
    00214
    00215 boolean gnBaseFeature::AddQualifier( gnBaseQualifier* qualifier ){
    00216         if(qualifier != NULL){
    00217                 m_qualifierList.push_back(qualifier);
    00218                 return true;
    00219         }
    00220         return false;
    00221 }
    00222
    00223 boolean gnBaseFeature::HasQualifier( const string& name ) const{
    00224         for(uint32 i=0; i < m_qualifierList.size(); i++)
    00225                 if(m_qualifierList[i]->GetName() == name)
    00226                         return true;
    00227         return false;
    00228 }
    00229
    00230 string gnBaseFeature::GetQualifierName( uint32 listI ) const{
    00231         if(listI < m_qualifierList.size())
    00232                 return m_qualifierList[listI]->GetName();
    00233         return string();
    00234 }
    00235
    00236 string gnBaseFeature::GetQualifierValue( uint32 listI ) const{
    00237         if(listI < m_qualifierList.size())
    00238                 return m_qualifierList[listI]->GetValue();
    00239         return string();
    00240 }
    00241
    00242 gnBaseQualifier* gnBaseFeature::GetQualifier( uint32 listI ){
    00243         if(listI < m_qualifierList.size())
    00244                 return m_qualifierList[listI];
    00245         return NULL;
    00246 }