Sleipnir
src/fastai.h
00001 /*****************************************************************************
00002 * This file is provided under the Creative Commons Attribution 3.0 license.
00003 *
00004 * You are free to share, copy, distribute, transmit, or adapt this work
00005 * PROVIDED THAT you attribute the work to the authors listed below.
00006 * For more information, please see the following web page:
00007 * http://creativecommons.org/licenses/by/3.0/
00008 *
00009 * This file is a component of the Sleipnir library for functional genomics,
00010 * authored by:
00011 * Curtis Huttenhower (chuttenh@princeton.edu)
00012 * Mark Schroeder
00013 * Maria D. Chikina
00014 * Olga G. Troyanskaya (ogt@princeton.edu, primary contact)
00015 *
00016 * If you use this library, the included executable tools, or any related
00017 * code in your work, please cite the following publication:
00018 * Curtis Huttenhower, Mark Schroeder, Maria D. Chikina, and
00019 * Olga G. Troyanskaya.
00020 * "The Sleipnir library for computational functional genomics"
00021 *****************************************************************************/
00022 #ifndef FASTAI_H
00023 #define FASTAI_H
00024 
00025 #include <fstream>
00026 #include <map>
00027 #include <set>
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <pthread.h>
00032 
00033 #include "file.h"
00034 
00035 namespace Sleipnir {
00036 
00041 struct SFASTABase {
00046     std::string m_strType;
00047 };
00048 
00049 
00054 struct SFASTASequence : SFASTABase {
00059     bool                        m_fIntronFirst;
00064     std::vector<std::string>    m_vecstrSequences;
00065 };
00066 
00071 struct SFASTAWiggle : SFASTABase {
00076     std::vector<float>  m_vecdValues;
00077 };
00078 
00079 class CFASTAImpl : public CFile {
00080 protected:
00081     static const char   c_acComment[];
00082     static const char   c_acHeader[];
00083 
00084     typedef std::map<std::string, size_t>       TMapStrI;
00085     typedef std::map<std::string, std::string>  TMapStrStr;
00086 
00087     CFASTAImpl( );
00088     virtual ~CFASTAImpl( );
00089 
00090     bool Get( size_t, std::vector<SFASTASequence>*, std::vector<SFASTAWiggle>* ) const;
00091     bool Get( size_t, std::vector<SFASTASequence>&, size_t, const std::string&, SFASTASequence& ) const;
00092     bool Get( size_t, std::vector<SFASTAWiggle>&, size_t, SFASTAWiggle& ) const;
00093 
00094     const std::string& GetGene( size_t iGene ) const {
00095 
00096         return m_vecstrGenes[ iGene ]; }
00097 
00098     mutable std::ifstream       m_ifsm;
00099     TMapStrI                    m_mapstriGenes;
00100     std::vector<std::string>    m_vecstrGenes;
00101     std::vector<TMapStrStr>     m_vecmapstrstrHeaders;
00102     std::vector<TMapStrI>       m_vecmapstriSequences;
00103     char*                       m_szBuffer;
00104     std::set<std::string>       m_setstrTypes;
00105     mutable pthread_mutex_t     m_mutx;
00106 };
00107 
00108 }
00109 
00110 #endif // FASTAI_H