eXpress “1.5”

src/mapparser.h

00001 
00009 #ifndef express_mapparser_h
00010 #define express_mapparser_h
00011 
00012 #include <api/BamReader.h>
00013 #include <api/BamWriter.h>
00014 #include <boost/scoped_ptr.hpp>
00015 #include <boost/thread.hpp>
00016 #include <boost/unordered_map.hpp>
00017 #include <string>
00018 #include <vector>
00019 
00020 #include <iostream>
00021 
00022 class Fragment;
00023 class TargetTable;
00024 class FragHit;
00025 struct ParseThreadSafety;
00026 struct ReadHit;
00027 struct Library;
00028 
00029 typedef boost::unordered_map<std::string, size_t> TransIndex;
00030 
00039 class Parser {
00040  protected:
00044   TransIndex _targ_index;
00048   TransIndex _targ_lengths;
00052   ReadHit* _read_buff;
00053 
00054  public:
00058   virtual ~Parser(){};
00063   virtual const std::string header() const=0;
00069   const TransIndex& targ_index() const { return _targ_index; }
00075   const TransIndex& targ_lengths() const { return _targ_lengths; }
00082   virtual bool next_fragment(Fragment& f)=0;
00087   virtual void reset() = 0;
00088 };
00089 
00099 class Writer {
00100  protected:
00105   bool _sample;
00106 
00107  public:
00111   virtual ~Writer(){}
00117   virtual void write_fragment(Fragment& f)=0;
00118 };
00119 
00127 class BAMParser : public Parser {
00132   boost::scoped_ptr<BamTools::BamReader> _reader;
00139   bool map_end_from_alignment(BamTools::BamAlignment& alignment);
00140 
00141  public:
00147   BAMParser(BamTools::BamReader* reader);
00152   const std::string header() const { return _reader->GetHeaderText(); }
00159   bool next_fragment(Fragment& f);
00164   void reset();
00165 };
00166 
00174 class SAMParser : public Parser
00175 {
00179   std::istream* _in;
00183   std::string _header;
00190   bool map_end_from_line(char* line);
00191 
00192 public:
00198   SAMParser(std::istream* in);
00203   const std::string header() const { return _header; }
00210   bool next_fragment(Fragment& f);
00215   void reset();
00216 };
00217 
00226 class BAMWriter : public Writer {
00231   boost::scoped_ptr<BamTools::BamWriter> _writer;
00232 
00233  public:
00244   BAMWriter(BamTools::BamWriter* writer, bool sample);
00248   ~BAMWriter();
00255   void write_fragment(Fragment& f);
00256 };
00257 
00267 class SAMWriter : public Writer {
00272   boost::scoped_ptr<std::ostream> _out;
00273 
00274  public:
00282   SAMWriter(std::ostream* out, bool sample);
00286   ~SAMWriter();
00293   void write_fragment(Fragment& f);
00294 };
00295 
00308 class MapParser
00309 {
00314   boost::scoped_ptr<Parser> _parser;
00319   boost::scoped_ptr<Writer> _writer;
00323   Library* _lib;
00328   bool _write_active;
00329 
00330  public:
00338   MapParser(Library* lib, bool write_active);
00352   void threaded_parse(ParseThreadSafety* thread_safety, size_t stop_at=0,
00353                       size_t num_neighbors=0);
00359   const TransIndex& targ_index() { return _parser->targ_index(); }
00365   const TransIndex& targ_lengths() { return _parser->targ_lengths(); }
00371   void write_active(bool b) { _write_active = b; }
00375   void reset_reader() { _parser->reset(); }
00376 };
00377 
00378 #endif
 All Classes Functions Variables