|
gnFragmentSpec.cppGo to the documentation of this file.00001 00002 // File: gnFragmentSpec.cpp 00003 // Purpose: implements gnMultiSpec for sequence fragments 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 00014 #include "gn/gnFragmentSpec.h" 00015 #include <string> 00016 00017 gnFragmentSpec::gnFragmentSpec() 00018 { 00019 Clear(); 00020 } 00021 00022 gnFragmentSpec::gnFragmentSpec( const gnFragmentSpec& s ) 00023 { 00024 m_sourceName = s.m_sourceName; 00025 m_name = s.m_name; 00026 m_reverseComplement = s.m_reverseComplement; 00027 m_circular = s.m_circular; 00028 //copy the header list. 00029 uint32 list_size = s.m_headerList.size(); 00030 m_headerList.reserve(list_size); 00031 for(uint32 i=0; i < list_size; i++) 00032 m_headerList.push_back(s.m_headerList[i]->Clone()); 00033 //copy the contig list. 00034 list_size = s.m_SpecList.size(); 00035 m_SpecList.reserve(list_size); 00036 uint32 i=0; 00037 for(; i < list_size; i++) 00038 m_SpecList.push_back(s.m_SpecList[i]->Clone()); 00039 //copy the feature list 00040 list_size = s.m_featureList.size(); 00041 m_featureList.reserve(list_size); 00042 for(i=0; i < list_size; i++) 00043 m_featureList.push_back(s.m_featureList[i]->Clone()); 00044 } 00045 gnFragmentSpec::~gnFragmentSpec() 00046 { 00047 Clear(); 00048 } 00049 // Clone 00050 void gnFragmentSpec::Clear() 00051 { 00052 uint32 list_size = m_SpecList.size(); 00053 for(uint32 i=0; i < list_size; i++) 00054 delete m_SpecList[i]; 00055 m_SpecList.clear(); 00056 list_size = m_featureList.size(); 00057 for(uint32 i=0; i < list_size; i++) 00058 delete m_featureList[i]; 00059 m_featureList.clear(); 00060 gnMultiSpec::Clear(); 00061 } 00062 //Fragment 00063 void gnFragmentSpec::GetContainedFeatures(const gnLocation& lt, vector<gnBaseFeature*>& feature_vector, vector<uint32>& index_vector) const{ 00064 for(uint32 i=0; i < m_featureList.size(); i++){ 00065 if(m_featureList[i]->IsContainedBy(lt)) 00066 feature_vector.push_back(m_featureList[i]->Clone()); 00067 index_vector.push_back(i); 00068 } 00069 } 00070 void gnFragmentSpec::GetIntersectingFeatures(const gnLocation& lt, vector<gnBaseFeature*>& feature_vector, vector<uint32>& index_vector) const{ 00071 for(uint32 i=0; i < m_featureList.size(); i++){ 00072 if(m_featureList[i]->Intersects(lt)) 00073 feature_vector.push_back(m_featureList[i]->Clone()); 00074 index_vector.push_back(i); 00075 } 00076 } 00077 void gnFragmentSpec::GetBrokenFeatures(const gnLocation& lt, vector<gnBaseFeature*>& feature_vector) const{ 00078 for(uint32 i=0; i < m_featureList.size(); i++) 00079 if(m_featureList[i]->IsBroken() && m_featureList[i]->IsContainedBy(lt)) 00080 feature_vector.push_back(m_featureList[i]->Clone()); 00081 } 00082 00083 //do feature cropping... done 00084 void gnFragmentSpec::CropStart( gnSeqI cropLen ){ 00085 uint32 flen = m_featureList.size(); 00086 for(uint32 featureI = 0; featureI < flen; featureI++){ 00087 m_featureList[featureI]->CropStart(cropLen); 00088 } 00089 gnMultiSpec::CropStart(cropLen); 00090 } 00091 00092 void gnFragmentSpec::CropEnd( gnSeqI cropLen ){ 00093 uint32 flen = m_featureList.size(); 00094 for(uint32 featureI = 0; featureI < flen; featureI++){ 00095 m_featureList[featureI]->CropEnd(cropLen); 00096 } 00097 gnMultiSpec::CropEnd(cropLen); 00098 } 00099 00100 gnFragmentSpec* gnFragmentSpec::CloneRange( const gnSeqI startI, const gnSeqI len ) const{ 00101 if(len == 0) 00102 return new gnFragmentSpec(); 00103 00104 //find the valid range of specs to copy 00105 uint32 firstSpec = GetSpecIndexByBase(startI); 00106 gnSeqI total_copylen = len; 00107 uint32 endSpec; 00108 if(len != GNSEQI_END){ 00109 endSpec = GetSpecIndexByBase(startI + len - 1); 00110 }else{ 00111 endSpec = GetSpecListLength() - 1; 00112 total_copylen = GetLength() - startI; 00113 } 00114 00115 //find their starting and ending bases 00116 gnSeqI firstBase = startI - GetSpecStartBase(firstSpec); 00117 gnSeqI firstSpecLen = GetSpec(firstSpec)->GetLength(); 00118 boolean spans_specs = true; 00119 gnSeqI firstCopyLen = firstSpecLen - firstBase; 00120 if(firstCopyLen >= total_copylen){ 00121 spans_specs = false; 00122 firstCopyLen = total_copylen; 00123 } 00124 gnFragmentSpec* destSpec = new gnFragmentSpec(); 00125 gnContigSpec* newSpec = m_SpecList[firstSpec]->CloneRange(firstBase, firstCopyLen); 00126 destSpec->AddSpec( newSpec ); 00127 00128 gnSeqI cur_copylen = firstCopyLen; 00129 //add all the completely covered specs in the middle 00130 for(uint32 specI = firstSpec + 2; specI <= endSpec; specI++){ 00131 destSpec->AddSpec(GetSpec(specI-1)->Clone()); 00132 cur_copylen += GetSpec(specI-1)->GetLength(); 00133 } 00134 //add the last spec if necessary 00135 if(spans_specs){ 00136 newSpec = m_SpecList[endSpec]->CloneRange( 0, total_copylen - cur_copylen); 00137 destSpec->AddSpec(newSpec); 00138 } 00139 00140 //now clone all the appropriate features 00141 gnLocation lt; 00142 vector<gnBaseFeature*> feature_vector; 00143 vector<uint32> index_vector; 00144 lt.SetStart(startI); 00145 lt.SetEnd(startI + total_copylen); 00146 GetIntersectingFeatures(lt, destSpec->m_featureList, index_vector); 00147 00148 return destSpec; 00149 } 00150 00151 /*IMPLEMENT ME!! ADD FEATURE Manipulation*/ 00152 void gnFragmentSpec::SetReverseComplement( const boolean value ) 00153 { 00154 if(value == m_reverseComplement) 00155 return; 00156 //reverse the spec list entries 00157 vector<gnContigSpec*> tmp_spec_list; 00158 for(uint32 i=0; i < GetSpecListLength(); i++){ 00159 //transmit rev_comp down the tree 00160 GetSpec(i)->SetReverseComplement(!GetSpec(i)->IsReverseComplement()); 00161 tmp_spec_list.insert(tmp_spec_list.begin(), GetSpec(i)); 00162 } 00163 m_SpecList = tmp_spec_list; 00164 m_reverseComplement = value; 00165 } Generated at Fri Nov 30 15:36:51 2001 for libGenome by 1.2.8.1 written by Dimitri van Heesch, © 1997-2001 |