gnFragmentSpec.cpp Source File

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

# gnFragmentSpec.cpp

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