gnStringSpec.cpp Source File

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

# gnStringSpec.cpp

Go to the documentation of this file.

    00001 /////////////////////////////////////////////////////////////////////////////
    00002 // File:            gnStringSpec.cpp
    00003 // Purpose:         implements gnContigSpec for strings
    00004 // Description:     stores sequence in memory
    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/gnStringSpec.h"
    00014 #include <string>
    00015
    00016 gnStringSpec::gnStringSpec()
    00017 {
    00018         gnContigSpec::Clear();
    00019 }
    00020
    00021 gnStringSpec::gnStringSpec( const string& m_string, gnSeqI start, gnSeqI endI, boolean revComp)
    00022 {
    00023         m_seqString = m_string;
    00024         m_start = start;
    00025         gnSeqI actual_len = m_seqString.length();
    00026
    00027         //reverse comp has the end b.p. first, then start.  switch them.
    00028         m_start = revComp ? endI : start;
    00029         gnSeqI actual_end = revComp ? start : endI;
    00030         //trim start and end down if they are too big.
    00031         actual_end = actual_end < actual_len ? actual_end : actual_len -1;
    00032         m_start = m_start < actual_len ? m_start : actual_len - 1;
    00033         if(actual_len == 0)
    00034                 m_start = 0;
    00035         //if start is after end, we're using a circular sequence.
    00036         m_circular = m_start > actual_end ? true : false;
    00037         //if circular, the length will be different.
    00038         m_length = m_circular ? (actual_len - m_start) + actual_end : actual_end - m_start + 1;
    00039
    00040         m_reverseComplement = revComp;
    00041         m_SourceContigIndex = ALL_CONTIGS;
    00042 }
    00043
    00044 gnStringSpec::gnStringSpec( const gnStringSpec& s )
    00045 {
    00046         m_seqString = s.m_seqString;
    00047         m_sourceName = s.m_sourceName;
    00048         m_name = s.m_name;
    00049         m_start = s.m_start;
    00050         m_length = s.m_length;
    00051         m_reverseComplement = s.m_reverseComplement;
    00052         m_circular = s.m_circular;
    00053         m_SourceContigIndex = s.m_SourceContigIndex;
    00054 }
    00055 gnStringSpec::~gnStringSpec()
    00056 {
    00057         Clear();
    00058 }
    00059 void gnStringSpec::Clear()
    00060 {
    00061         gnContigSpec::Clear();
    00062         m_seqString = "";
    00063 }
    00064
    00065 gnStringSpec* gnStringSpec::CloneRange( const gnSeqI startI, const gnSeqI len ) const{
    00066         gnStringSpec* destSpec = new gnStringSpec();
    00067         destSpec->m_seqString = m_seqString.substr(m_start + startI, len);
    00068         destSpec->m_sourceName = m_sourceName;
    00069         destSpec->m_name = m_name;
    00070         destSpec->m_start = 0;
    00071         destSpec->m_length = destSpec->m_seqString.length();
    00072         destSpec->m_reverseComplement = m_reverseComplement;
    00073         destSpec->m_circular = m_circular;
    00074         destSpec->m_SourceContigIndex = m_SourceContigIndex;
    00075         return destSpec;
    00076 }