#ifndef __GZIP_WRITER_HPP__ #define __GZIP_WRITER_HPP__ #include #include #include "spdlog/spdlog.h" #include #include #include #include "ReadExperiment.hpp" #include "SalmonOpts.hpp" #include "SalmonSpinLock.hpp" #include "AlevinOpts.hpp" #include "Graph.hpp" #include "MappingStatistics.hpp" class GZipWriter { public: GZipWriter(const boost::filesystem::path path, std::shared_ptr logger); ~GZipWriter(); void close_all_streams(); template bool writeEquivCounts(const SalmonOpts& opts, ExpT& experiment); template bool writeEquivCounts(const AlevinOpts& aopts, ExpT& experiment); template bool writeBFH(boost::filesystem::path& outDir, ExpT& experiment, size_t umiLength, std::vector& bcSeqVec); template bool writeMeta(const SalmonOpts& opts, const ExpT& experiment, const MappingStatistics& mstats); template bool writeMetaFryMode(const SalmonOpts& opts, const SCExpT& experiment, const MappingStatistics& mstats); template bool writeMetaAlevin(const AlevinOpts& opts, boost::filesystem::path aux_dir); template bool writeEmptyMeta(const SalmonOpts& opts, const ExpT& experiment, std::vector& errors); template bool writeAbundances(const SalmonOpts& sopt, ExpT& readExp, bool explicitSum); bool writeAbundances(std::vector& alphas, std::vector& transcripts); bool writeAbundances(std::string& bcName, std::string& features, uint8_t featureCode, std::vector& alphas, std::vector& tiers, bool dumpUmiGraph); bool writeSparseAbundances(std::string& bcName, std::string& features, std::string& arboData, uint8_t featureCode, std::vector& alphas, std::vector& tiers, bool dumpArboFragCounts, bool dumpUmiGraph); bool writeBootstraps(std::string& bcName, std::vector& alphas, std::vector& variance, bool useAllBootstraps, std::vector>& sampleEstimates); bool writeSparseBootstraps(std::string& bcName, std::vector& alphas, std::vector& variance, bool useAllBootstraps, std::vector>& sampleEstimates); template bool writeEmptyAbundances(const SalmonOpts& sopt, ExpT& readExp); template bool writeBootstrap(const std::vector& abund, bool quiet = false); bool writeCellEQVec(size_t barcode, const std::vector& offsets, const std::vector& counts, bool quiet = true); bool writeDedupCellEQVec(size_t barcode, const std::vector>& labels, const std::vector& counts, bool quiet = true); bool writeUmiGraph(alevin::graph::Graph& g, std::string& trueBarcodeStr); bool setSamplingPath(const SalmonOpts& sopt); void writeMtx(std::shared_ptr& jointLog, boost::filesystem::path& outputDirectory, size_t numGenes, size_t numCells, size_t totalExpGeneCounts); private: boost::filesystem::path path_; boost::filesystem::path bsPath_; std::shared_ptr logger_; std::unique_ptr bsStream_{nullptr}; std::unique_ptr countMatrixStream_{nullptr}; std::unique_ptr meanMatrixStream_{nullptr}; std::unique_ptr varMatrixStream_{nullptr}; std::unique_ptr fullBootstrapMatrixStream_{nullptr}; std::unique_ptr tierMatrixStream_{nullptr}; std::unique_ptr umiGraphStream_{nullptr}; std::unique_ptr cellEQStream_{nullptr}; std::unique_ptr cellDedupEQStream_{nullptr}; std::unique_ptr arboMatrixStream_{nullptr}; std::unique_ptr bcNameStream_{nullptr}; std::unique_ptr bcFeaturesStream_{nullptr}; std::unique_ptr bcBootNameStream_{nullptr}; // only one writer thread at a time #if defined __APPLE__ spin_lock writeMutex_; #else std::mutex writeMutex_; #endif std::atomic numBootstrapsWritten_{0}; }; #endif //__GZIP_WRITER_HPP__