Skip to content

Commit

Permalink
Remove gzstream
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed Nov 10, 2024
1 parent 22a232d commit 111d893
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 779 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ include_directories(lib/simde)

include_directories(lib)
include_directories(lib/simd)
include_directories(lib/gzstream)
include_directories(lib/alp)
include_directories(lib/cacode)
include_directories(lib/ksw2)
Expand Down
504 changes: 0 additions & 504 deletions lib/gzstream/LICENSE

This file was deleted.

7 changes: 0 additions & 7 deletions lib/gzstream/README

This file was deleted.

209 changes: 0 additions & 209 deletions lib/gzstream/gzstream.h

This file was deleted.

93 changes: 93 additions & 0 deletions src/commons/GzReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "Debug.h"

#include <cstdio>
#include <string>
#include <cstring>

#ifdef HAVE_ZLIB
#include <zlib.h>
#endif

class GzReader {
public:
enum Mode {
FILE_MODE,
#ifdef HAVE_ZLIB
GZ_MODE
#endif
};

GzReader(const std::string &filename) {
if (filename.size() >= 3 && filename.substr(filename.size() - 3) == ".gz") {
#ifdef HAVE_ZLIB
mode = GZ_MODE;
gzHandle = gzopen(filename.c_str(), "r");
openFailed = !gzHandle;
return;
#else
Debug(Debug::ERROR) << "MMseqs2 was not compiled with zlib support. Cannot read compressed input\n";
EXIT(EXIT_FAILURE);
#endif
}
mode = FILE_MODE;
file = fopen(filename.c_str(), "r");
openFailed = !file;
}

~GzReader() {
if (mode == FILE_MODE && file) fclose(file);
#ifdef HAVE_ZLIB
else if (mode == GZ_MODE && gzHandle) gzclose(gzHandle);
#endif
}

bool fail() const {
return openFailed;
}

bool getline(std::string &line) {
line.clear();
if (openFailed) return false;

char buffer[4096];
bool complete = false;
while (!complete) {
if (mode == FILE_MODE) {
if (fgets(buffer, sizeof(buffer), file) != NULL) {
if (char *newline = strchr(buffer, '\n')) {
line.append(buffer, newline - buffer);
complete = true;
} else {
line.append(buffer);
}
} else {
return !line.empty();
}
}
#ifdef HAVE_ZLIB
else if (mode == GZ_MODE) {
if (gzgets(gzHandle, buffer, sizeof(buffer)) != NULL) {
if (char *newline = strchr(buffer, '\n')) {
line.append(buffer, newline - buffer);
complete = true;
} else {
line.append(buffer);
}
} else {
return !line.empty();
}
}
#endif
}

return true;
}

private:
Mode mode;
bool openFailed = false;
FILE *file = NULL;
#ifdef HAVE_ZLIB
gzFile gzHandle = NULL;
#endif
};
23 changes: 4 additions & 19 deletions src/util/convertkb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#include "FileUtil.h"
#include "Debug.h"
#include "UniprotKB.h"

#ifdef HAVE_ZLIB
#include "gzstream.h"
#endif
#include "GzReader.h"

#include <fstream>
#include <set>
Expand Down Expand Up @@ -102,27 +99,16 @@ int convertkb(int argc, const char **argv, const Command &command) {

Debug::Progress progress;
for (std::vector<std::string>::const_iterator it = par.filenames.begin(); it != par.filenames.end(); ++it) {
std::istream *kbIn;
if (Util::endsWith(".gz", *it)) {
#ifdef HAVE_ZLIB
kbIn = new igzstream((*it).c_str());
#else
Debug(Debug::ERROR) << "MMseqs2 was not compiled with zlib support. Can not read compressed input\n";
EXIT(EXIT_FAILURE);
#endif
} else {
kbIn = new std::ifstream(*it);
}

if (kbIn->fail()) {
GzReader kbIn(*it);
if (kbIn.fail()) {
Debug(Debug::ERROR) << "File " << (*it) << " not found\n";
EXIT(EXIT_FAILURE);
}

Debug(Debug::INFO) << "Extracting data from " << (*it) << "\n";
std::string line;
unsigned int i = 0;
while (std::getline(*kbIn, line)) {
while (kbIn.getline(line)) {
if (line.length() < 2) {
Debug(Debug::WARNING) << "Invalid entry\n";
continue;
Expand Down Expand Up @@ -156,7 +142,6 @@ int convertkb(int argc, const char **argv, const Command &command) {
i++;
}
}
delete kbIn;
}

for (std::vector<unsigned int>::const_iterator it = enabledColumns.begin(); it != enabledColumns.end(); ++it) {
Expand Down
Loading

0 comments on commit 111d893

Please sign in to comment.