7 #include "jade.args.hpp"
8 #include "jade.version.hpp"
9 #include "jade.rema.hpp"
13 char const *
const usage = R
"(USAGE
14 filter <command> ... [<input> <output>]
17 command one of the following conversion types:
19 rema Reduces the number of markers in a matrix.
25 filter rema [options] <column-count> [<input> <output>]
28 This filter reduces the number of markers in a matrix. The number of
29 columns written to the output matrix is specified as a required argument.
30 The filter chooses the columns to remove at random, but their relative
31 order is not changed. It is possible to provide a random number seed as
32 an option; if unspecified, the program uses a time-dependent default
36 --seed,-s indicates the next argument is the random number seed; if
37 unspecified, the program uses a time-dependent default seed
40 $ filter rema 1000 in.lgm out.lgm
41 $ cat in.lgm | filter rema --seed 1864 1000 > out.lgm
44 --help,-h shows this help message and exits
45 --version,-v prints version information and exits
48 Filters input given to the program. Further details are provided in the
49 section above describing the various commands.
51 For all commands, if no arguments are given, the source data is read from
52 standard input and the output data is written to standard output. Otherwise,
53 the path to the input file and output file must be specified after the
57 $ filter rema 1000 in.lgm out.lgm
58 $ cat in.lgm | filter rema --seed 1864 1000 > out.lgm
61 Report any bugs to Jade Cheng <info@jade-cheng.com>.
63 Copyright (c) 2015-2020 Jade Cheng
69 template <
typename TController>
77 typedef TController controller_type;
78 controller_type controller (a);
87 controller.execute(std::cin, std::cout);
91 const auto src = a.
pop<std::string>();
92 const auto dst = a.
pop<std::string>();
95 std::ifstream in (src);
97 throw jade::error() <<
"failed to open '" << src <<
"'";
99 std::ofstream out (dst);
101 throw jade::error() <<
"failed to create '" << dst <<
"'";
103 controller.execute(in, out);
116 int main(
const int argc,
const char * argv[])
122 if (args.read_flag(
"--help",
"-h"))
124 std::cout << ::usage;
128 if (args.read_flag(
"--version",
"-v"))
136 const auto command = args.pop<std::string>();
138 if (command ==
"rema") return ::execute<rema_type>(args);
140 throw jade::error() <<
"unsupported command '" << command <<
"'";
142 catch (
const std::exception & e)
144 std::cerr << e.
what() << std::endl;