Created
December 14, 2018 18:45
-
-
Save hiraksarkar/da347e63a3d704478cacc982598b04c2 to your computer and use it in GitHub Desktop.
Read Binary data file without boost support (using zstr header)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <sstream> | |
#include <functional> | |
#include <sys/stat.h> | |
#include <memory> | |
#include <vector> | |
#include <numeric> | |
#include "zstr.hpp" | |
int main(int argc, char* argv[]){ | |
std::string input_file = argv[1] ; | |
size_t numCells{5343} ; | |
size_t numGenes{57875} ; | |
std::vector<std::vector<double> > data ; | |
data.resize(numCells, std::vector<double>(numGenes)) ; | |
for(auto& v : data) | |
std::memset(&v[0], 0, sizeof(v[0]) * v.size()); | |
std::unique_ptr<std::istream> in = | |
std::unique_ptr<std::istream> (new zstr::ifstream(input_file, std::ios::in | std::ios::binary)) ; | |
size_t cellCount = 0 ; | |
size_t elSize = sizeof(typename std::vector<double>::value_type); | |
for (size_t i = 0 ; i < numCells; ++i){ | |
std::vector<double> oneCell ; | |
oneCell.resize(numGenes) ; | |
cellCount += 1 ; | |
in->read(reinterpret_cast<char*>(oneCell.data()), elSize * numGenes) ; | |
double readCount = std::accumulate(oneCell.begin(), oneCell.end(), 0.0); | |
std::cout << "\nFor cell "<< cellCount << " readCount " << readCount << "\n" ; | |
} | |
return 0 ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment