gnRAWSource.h Source File

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

# gnRAWSource.h

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
    00013 #ifndef _gnRAWSource_h_
    00014 #define _gnRAWSource_h_
    00015
    00016 #include "gn/gnDefs.h"
    00017
    00018 #include <string>
    00019 #include <fstream>
    00020 #include <vector>
    00021 #include "gn/gnFileSource.h"
    00022 #include "gn/gnFileContig.h"
    00023 #include "gn/gnSourceSpec.h"
    00024 #include "gn/gnSequence.h"
    00025
    00026 /**
    00027  * gnRAWSource reads raw sequence data from a text file.
    00028  * This class reads and writes raw sequence to and from files.
    00029  * A raw sequence does not contain any newlines, fragment delimiters, or other
    00030  * type of annotation.
    00031  * gnRAWSource is used by gnSourceFactory to read files and should only be used
    00032  * directly.when writing out raw files by calling gnRAWSource::Write( mySpec, "C:\\myFile.txt");
    00033  */
    00034
    00035 class GNDLLEXPORT gnRAWSource : public gnFileSource
    00036 {
    00037 public:
    00038         /**
    00039          * Empty Constructor, does nothing.
    00040          */
    00041         gnRAWSource();
    00042         /**
    00043          * Clone Constructor copies the specified gnRAWSource.
    00044          * @param s The gnRAWSource to copy.
    00045          */
    00046         gnRAWSource( const gnRAWSource& s );
    00047         /**
    00048          * Destructor, frees memory.
    00049          */
    00050         ~gnRAWSource();
    00051         /**
    00052          * Returns an exact copy of this class.
    00053          */
    00054         gnRAWSource* Clone() const;
    00055 // Contig Access methods
    00056         uint32 GetContigListLength() const;
    00057         boolean HasContig( const string& name ) const;
    00058         uint32 GetContigID( const string& name ) const;
    00059         string GetContigName( const uint32 i ) const;
    00060         gnSeqI GetContigSeqLength( const uint32 i ) const;
    00061
    00062         boolean SeqRead( const gnSeqI start, char* buf, uint32& bufLen, const uint32 contigI=ALL_CONTIGS );
    00063
    00064         /**
    00065          * Writes the specified gnSequence to a raw file named "filename".
    00066          * @param sequence The gnSequence to write out.
    00067          * @param filename The name of the file to write.
    00068          * @return True if successful, false otherwise.
    00069          */
    00070         static boolean Write(gnSequence& sequence, const string& filename);
    00071         /**
    00072          * Writes the specified source to a raw file named "filename".
    00073          * @param source The source to write out.
    00074          * @param filename The name of the file to write.
    00075          * @return True if successful, false otherwise.
    00076          */
    00077         static boolean Write(gnBaseSource *source, const string& filename);
    00078         gnGenomeSpec *GetSpec() const;
    00079         gnFileContig* GetFileContig( const uint32 contigI ) const;
    00080 private:
    00081         boolean SeqSeek( const gnSeqI start, const uint32& contigI, uint64& startPos, uint64& readableBytes );
    00082         boolean SeqStartPos( const gnSeqI start, gnFileContig& contig, uint64& startPos, uint64& readableBytes );
    00083         boolean ParseStream( istream& fin );
    00084
    00085         gnFileContig* m_contig;
    00086         gnGenomeSpec* m_spec;
    00087 };// class gnRAWSource
    00088 // Clone
    00089 inline
    00090 gnRAWSource* gnRAWSource::Clone() const
    00091 {
    00092         return new gnRAWSource( *this );
    00093 }
    00094 // Contig Access methods
    00095 inline
    00096 uint32 gnRAWSource::GetContigListLength() const
    00097 {
    00098         return m_contig == NULL? 0 : 1;
    00099 }
    00100 inline
    00101 boolean gnRAWSource::Write(gnBaseSource *source, const string& filename){
    00102         gnSequence gns(*source->GetSpec());
    00103         return Write(gns, filename);
    00104 }
    00105
    00106 #endif
    00107         // _gnRAWSource_h_