New upstream version 40
Sascha Steinbiss
1 year, 6 months ago
25 | 25 | * Copy ``tantan`` to a standard directory: ``sudo make install`` |
26 | 26 | (using "sudo" to request administrator permissions). |
27 | 27 | |
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`` | |
29 | 30 | |
30 | 31 | * Adjust your `PATH variable`_. |
31 | 32 | |
32 | 33 | You might need to log out and back in for your computer to recognize |
33 | 34 | the new program. |
34 | 35 | |
35 | **Alternative:** Install tantan from bioconda_. | |
36 | **Alternative:** Install tantan from bioconda_ or `Debian Med`_. | |
36 | 37 | |
37 | 38 | Normal usage |
38 | 39 | ------------ |
218 | 219 | .. _BED: https://genome.ucsc.edu/FAQ/FAQformat.html#format1 |
219 | 220 | .. _PATH variable: https://en.wikipedia.org/wiki/PATH_(variable) |
220 | 221 | .. _bioconda: https://bioconda.github.io/ |
222 | .. _Debian Med: https://www.debian.org/devel/debian-med/ |
3 | 3 | |
4 | 4 | ../bin/tantan: *.cc *.hh version.hh Makefile |
5 | 5 | mkdir -p ../bin |
6 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ *.cc | |
6 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ *.cc -lz | |
7 | 7 | |
8 | 8 | clean: |
9 | 9 | rm -f ../bin/tantan |
10 | 10 | |
11 | 11 | 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/[,) ].*//' | |
13 | 13 | |
14 | 14 | VERSION = \"`test -e ../.git && $(VERSION1) || $(VERSION2)`\" |
15 | 15 |
5 | 5 | |
6 | 6 | namespace mcf { |
7 | 7 | |
8 | std::istream &openIn(const std::string &fileName, std::ifstream &ifs) { | |
8 | std::istream &openIn(const std::string &fileName, izstream &z) { | |
9 | 9 | 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; | |
13 | 13 | } |
14 | 14 | |
15 | 15 | std::ostream &openOut(const std::string &fileName, std::ofstream &ofs) { |
1 | 1 | |
2 | 2 | #ifndef MCF_UTIL_HH |
3 | 3 | #define MCF_UTIL_HH |
4 | ||
5 | #include "mcf_zstream.hh" | |
4 | 6 | |
5 | 7 | #include <cassert> |
6 | 8 | #include <fstream> |
11 | 13 | namespace mcf { |
12 | 14 | |
13 | 15 | // 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); | |
15 | 17 | |
16 | 18 | // open an output file, but if the name is "-", just return cout |
17 | 19 | std::ostream &openOut(const std::string &fileName, std::ofstream &ofs); |
33 | 35 | |
34 | 36 | template <typename T> |
35 | 37 | 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); | |
38 | 40 | input >> x; |
39 | 41 | if (!input) throw std::runtime_error("can't read file: " + fileName); |
40 | 42 | // 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 |
415 | 415 | processOneFile(std::cin, output); |
416 | 416 | |
417 | 417 | 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); | |
420 | 420 | processOneFile(input, output); |
421 | 421 | } |
422 | 422 |