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