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

gnRAWSource.cpp

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 // File:            gnRAWSource.h
00003 // Purpose:         Implements gnBaseSource for raw data files
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/gnFilter.h"
00013 #include "gn/gnRAWSource.h"
00014 #include "gn/gnGenomeSpec.h"
00015 #include "gn/gnFragmentSpec.h"
00016 #include "gn/gnSourceSpec.h"
00017 #include "gn/gnStringTools.h"
00018 #include "gn/gnDebug.h"
00019 
00020 gnRAWSource::gnRAWSource()
00021 {
00022         m_openString = "";
00023         m_contig = NULL;
00024 }
00025 
00026 gnRAWSource::gnRAWSource( const gnRAWSource& s ) : gnFileSource(s)
00027 {
00028         if(s.m_contig != NULL)
00029                 m_contig = s.m_contig->Clone();
00030 }
00031 
00032 gnRAWSource::~gnRAWSource()
00033 {
00034         m_ifstream.close();
00035         delete m_contig;
00036 }
00037 
00038 boolean gnRAWSource::HasContig( const string& name ) const
00039 {
00040         if( name.length() == 0 )
00041                 return true;
00042         return false;
00043 }
00044 
00045 uint32 gnRAWSource::GetContigID( const string& name ) const
00046 {
00047         return ALL_CONTIGS;
00048 }
00049 
00050 string gnRAWSource::GetContigName( const uint32 i ) const
00051 {
00052         return "";
00053 }
00054 
00055 gnSeqI gnRAWSource::GetContigSeqLength( const uint32 i ) const
00056 {
00057         if( m_contig && (i == 0 || i == ALL_CONTIGS))
00058                 return m_contig->GetSeqLength();
00059         return GNSEQI_ERROR;
00060 }
00061 
00062 boolean gnRAWSource::SeqRead( const gnSeqI start, char* buf, uint32& bufLen, const uint32 contigI ){
00063         return Read( start, buf, bufLen );
00064 }
00065 
00066 gnGenomeSpec *gnRAWSource::GetSpec() const{
00067         return m_spec->Clone();
00068 }
00069 
00070 boolean gnRAWSource::Write(gnSequence& seq, const string& filename){
00071         ofstream m_ofstream(filename.c_str(), ios::out | ios::binary);
00072         if(!m_ofstream.is_open())
00073                 return false;
00074 
00075         gnSeqC buf[BUFFER_SIZE + 1];
00076         buf[BUFFER_SIZE] = 0;
00077         gnSeqI readOffset = 0;
00078         gnSeqI readLength = seq.length();
00079 
00080         while(readLength > 0){  //buffer the read/writes
00081                 gnSeqI writeLen = readLength < BUFFER_SIZE ? readLength : BUFFER_SIZE;
00082                 
00083                 if(!seq.ToArray(buf, writeLen, readOffset))
00084                         return false;
00085                 m_ofstream << buf;
00086                 readLength -= writeLen;
00087                 readOffset += writeLen;
00088         }
00089         return true;
00090 }
00091 
00092 gnFileContig* gnRAWSource::GetFileContig( const uint32 contigI ) const{
00093         if(contigI > 0)
00094                 return NULL;
00095         return m_contig;
00096 }
00097 
00098 //File parsing access routine
00099 boolean gnRAWSource::ParseStream( istream& fin )
00100 {
00101         // init variables
00102         uint64 streamPos = 0;
00103         uint64 bufReadLen = 0;
00104         Array<char> array_buf( BUFFER_SIZE );
00105         char* buf = array_buf.data;
00106         gnSeqI seqLength = 0;
00107         
00108         m_contig->SetRepeatSeqGap(true);
00109         m_contig->SetSectStart(gnContigSequence, 0);
00110 
00111         while( !fin.eof() )
00112         {
00113                   // read chars
00114                 fin.read( buf , BUFFER_SIZE );
00115                 bufReadLen = fin.gcount();
00116                 
00117                 for( uint32 i=0 ; i < bufReadLen ; i++ )
00118                 {
00119                         if(m_pFilter->IsValid(buf[i]))
00120                                 seqLength++;
00121                         else
00122                                 m_contig->SetRepeatSeqGap(false);
00123                         break;
00124                 }
00125                 streamPos += bufReadLen;
00126         }
00127         m_contig->SetSectEnd(gnContigSequence, streamPos);
00128         m_contig->SetSeqLength(seqLength);
00129         m_spec = new gnGenomeSpec();
00130         gnFragmentSpec* fragspec = new gnFragmentSpec();
00131         gnSourceSpec* sspec = new gnSourceSpec(this);
00132         sspec->SetSourceName(m_openString);
00133         m_spec->AddSpec(fragspec);
00134         fragspec->AddSpec(sspec);
00135 
00136         m_ifstream.clear();
00137         return true;
00138 }

Generated on Mon Feb 3 02:34:40 2003 for libGenome by doxygen1.3-rc3