Codebase list tantan / 31713d0
New upstream version 40 Sascha Steinbiss 1 year, 6 months ago
6 changed file(s) with 100 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
2525 * Copy ``tantan`` to a standard directory: ``sudo make install``
2626 (using "sudo" to request administrator permissions).
2727
28 * Copy it to your personal bin directory: ``make install prefix=~``
28 * Copy it to your personal bin directory: ``make install prefix=~`` or
29 ``make install prefix=~/.local``
2930
3031 * Adjust your `PATH variable`_.
3132
3233 You might need to log out and back in for your computer to recognize
3334 the new program.
3435
35 **Alternative:** Install tantan from bioconda_.
36 **Alternative:** Install tantan from bioconda_ or `Debian Med`_.
3637
3738 Normal usage
3839 ------------
218219 .. _BED: https://genome.ucsc.edu/FAQ/FAQformat.html#format1
219220 .. _PATH variable: https://en.wikipedia.org/wiki/PATH_(variable)
220221 .. _bioconda: https://bioconda.github.io/
222 .. _Debian Med: https://www.debian.org/devel/debian-med/
33
44 ../bin/tantan: *.cc *.hh version.hh Makefile
55 mkdir -p ../bin
6 $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ *.cc
6 $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ *.cc -lz
77
88 clean:
99 rm -f ../bin/tantan
1010
1111 VERSION1 = git describe --dirty
12 VERSION2 = echo ' (HEAD -> main, tag: 39) ' | sed -e 's/.*tag: *//' -e 's/[,) ].*//'
12 VERSION2 = echo ' (HEAD -> main, tag: 40) ' | sed -e 's/.*tag: *//' -e 's/[,) ].*//'
1313
1414 VERSION = \"`test -e ../.git && $(VERSION1) || $(VERSION2)`\"
1515
55
66 namespace mcf {
77
8 std::istream &openIn(const std::string &fileName, std::ifstream &ifs) {
8 std::istream &openIn(const std::string &fileName, izstream &z) {
99 if (fileName == "-") return std::cin;
10 ifs.open(fileName.c_str());
11 if (!ifs) throw std::runtime_error("can't open file: " + fileName);
12 return ifs;
10 z.open(fileName.c_str());
11 if (!z) throw std::runtime_error("can't open file: " + fileName);
12 return z;
1313 }
1414
1515 std::ostream &openOut(const std::string &fileName, std::ofstream &ofs) {
11
22 #ifndef MCF_UTIL_HH
33 #define MCF_UTIL_HH
4
5 #include "mcf_zstream.hh"
46
57 #include <cassert>
68 #include <fstream>
1113 namespace mcf {
1214
1315 // open an input file, but if the name is "-", just return cin
14 std::istream &openIn(const std::string &fileName, std::ifstream &ifs);
16 std::istream &openIn(const std::string &fileName, izstream &z);
1517
1618 // open an output file, but if the name is "-", just return cout
1719 std::ostream &openOut(const std::string &fileName, std::ofstream &ofs);
3335
3436 template <typename T>
3537 void unfilify(T& x, const std::string &fileName) {
36 std::ifstream ifs;
37 std::istream &input = openIn(fileName, ifs);
38 izstream z;
39 std::istream &input = openIn(fileName, z);
3840 input >> x;
3941 if (!input) throw std::runtime_error("can't read file: " + fileName);
4042 // check for junk at end of file?
0 // Copyright 2017 Martin C. Frith
1
2 // mcf::izstream is similar to std::ifstream. The difference is, if
3 // you give it a gzip-compressed file, it will decompress what it
4 // reads.
5
6 #ifndef MCF_ZSTREAM_HH
7 #define MCF_ZSTREAM_HH
8
9 #include <zlib.h>
10
11 #include <cstdio> // BUFSIZ
12 #include <istream>
13 #include <stdexcept>
14 #include <streambuf>
15
16 namespace mcf {
17
18 class zbuf : public std::streambuf {
19 public:
20 zbuf() : input(0) {}
21
22 ~zbuf() { close(); }
23
24 bool is_open() const { return input; }
25
26 zbuf *open(const char *fileName) {
27 if (is_open()) return 0;
28 input = gzopen(fileName, "rb");
29 if (!is_open()) return 0;
30 return this;
31 }
32
33 zbuf *close() {
34 if (!is_open()) return 0;
35 int e = gzclose(input);
36 input = 0;
37 return (e == Z_OK || e == Z_BUF_ERROR) ? this : 0;
38 }
39
40 protected:
41 int underflow() {
42 if (gptr() == egptr()) {
43 int size = gzread(input, buffer, BUFSIZ);
44 if (size < 0) throw std::runtime_error("gzread error");
45 setg(buffer, buffer, buffer + size);
46 }
47 return (gptr() == egptr()) ?
48 traits_type::eof() : traits_type::to_int_type(*gptr());
49 }
50
51 private:
52 gzFile input;
53 char buffer[BUFSIZ];
54 };
55
56 class izstream : public std::istream {
57 public:
58 izstream() : std::istream(&buf) {}
59
60 izstream(const char *fileName) : std::istream(&buf) {
61 open(fileName);
62 }
63
64 bool is_open() const { return buf.is_open(); }
65
66 void open(const char *fileName) {
67 // do something special if fileName is "-"?
68 if (!buf.open(fileName)) setstate(failbit);
69 else clear();
70 }
71
72 void close() {
73 if (!buf.close()) setstate(failbit);
74 }
75
76 private:
77 zbuf buf;
78 };
79
80 }
81
82 #endif
415415 processOneFile(std::cin, output);
416416
417417 for (int i = options.indexOfFirstNonOptionArgument; i < argc; ++i) {
418 std::ifstream ifs;
419 std::istream &input = openIn(argv[i], ifs);
418 izstream z;
419 std::istream &input = openIn(argv[i], z);
420420 processOneFile(input, output);
421421 }
422422