#ifndef __BAMQUEUE_HPP__ #define __BAMQUEUE_HPP__ //#include //#include #include #include #include #include #include #include #include #include #include #include "AlignmentGroup.hpp" #include "LibraryFormat.hpp" #include "ReadPair.hpp" #include "SalmonMath.hpp" #include "UnpairedRead.hpp" #include "concurrentqueue.h" #include "readerwriterqueue.h" #include "spdlog/spdlog.h" #include #include #include extern "C" { #include "io_lib/os.h" #include "io_lib/scram.h" #undef max #undef min } /** * Simple structure holding info about the alignment file. */ struct AlignmentFile { boost::filesystem::path fileName; std::string readMode; scram_fd* fp; SAM_hdr* header; uint32_t numParseThreads; }; /** * A queue from which to draw BAM alignments. The queue is thread-safe, and * can be written to and read from multiple threads. * * This class is templated on LibT --- the type of read library from which * the provided alignments are being generated. */ template class BAMQueue { public: BAMQueue(std::vector& fnames, LibraryFormat& libFmt, uint32_t numParseThreads, uint32_t cacheSize); ~BAMQueue(); void forceEndParsing(); SAM_hdr* header(); SAM_hdr* safeHeader(); std::vector headers(); template void start(FilterT filt, bool onlyProcessAmbiguousAlignments = false); inline bool getAlignmentGroup(AlignmentGroup*& group); // Return the number of reads processed so far by the queue size_t numObservedAlignments(); size_t numObservedFragments(); size_t numMappedFragments(); size_t numUniquelyMappedFragments(); void reset(); oneapi::tbb::concurrent_queue& getFragmentQueue(); // moodycamel::ConcurrentQueue& getFragmentQueue(); // oneapi::tbb::concurrent_bounded_queue*>& // getAlignmentGroupQueue(); moodycamel::ConcurrentQueue*>& getAlignmentGroupQueue(); private: size_t popNum{0}; /** Fill the queue with the appropriate type of alignment * depending on the template paramater T */ template void fillQueue_(FilterT, bool); /** Overload of getFrag_ for paired-end reads */ template inline bool getFrag_(ReadPair& rpair, FilterT filt); /** Overload of getFrag_ for single-end reads */ template inline bool getFrag_(UnpairedRead& sread, FilterT filt); public: bool verbose = false; private: std::vector files_; std::string fname_; LibraryFormat libFmt_; std::vector::iterator currFile_; scram_fd* fp_ = nullptr; SAM_hdr* hdr_ = nullptr; // htsFile* fp_ = nullptr; size_t totalAlignments_; size_t numUnaligned_; size_t numMappedReads_; size_t numUniquelyMappedReads_; oneapi::tbb::concurrent_queue fragmentQueue_; // moodycamel::ConcurrentQueue fragmentQueue_; // oneapi::tbb::concurrent_bounded_queue*> alnGroupPool_; moodycamel::ConcurrentQueue*> alnGroupPool_; // oneapi::tbb::concurrent_bounded_queue*> alnGroupQueue_; moodycamel::ReaderWriterQueue*> alnGroupQueue_; /* boost::lockfree::spsc_queue*, boost::lockfree::capacity<65535>> alnGroupQueue_; */ volatile bool doneParsing_; volatile bool exhaustedAlnGroupPool_; std::unique_ptr parsingThread_; std::shared_ptr logger_; size_t batchNum_; std::string readMode_; /* #if not defined(__APPLE__) std::mutex agMutex_; std::condition_variable workAvailable_; #endif */ }; #include "BAMQueue.tpp" #endif //__BAMQUEUE_HPP__