7 #include "jade.args.hpp"
8 #include "jade.bgl2lgm.hpp"
9 #include "jade.cov2nwk.hpp"
10 #include "jade.nwk2cov.hpp"
11 #include "jade.nwk2svg.hpp"
12 #include "jade.ped2dgm.hpp"
13 #include "jade.version.hpp"
17 char const *
const usage = R
"(USAGE
18 convert <command> [<input> <output>]
21 command one of the following conversion types:
29 bgl2lgm Converts a beagle file to an lgm matrix. Each line of the beagle
30 file is split into a number of fields. The first three fields are
31 ignored. The remaining fields are split into individuals, each of
32 which must contain three genotype likelihoods.
34 cov2nwk Converts a covariance matrix to a Newick-formatted tree. First the
35 covariance matrix is converted into a distance matrix, which is then
36 approximated into a Newick-formatted tree using the Neighbor Joining
39 nwk2cov Converts a Newick-formatted tree to a covariance matrix. Each tree
40 structure is mapped to a covariance matrix unambiguously.
42 nwk2svg Converts a Newick-formatted tree to an SVG representation. To find
43 an appealing arrangement of a tree, this converter takes inspiration
44 from an electrostatic field and models tree components as like-signed
45 charged particles with nodes constrained by the branches that connect
46 them. It then utilizes the Nelder-Mead algorithm to minimize the
47 total potential energy of this system and achieve an optimal tree
50 ped2dgm Converts a plink ped file to a dgm matrix. Each line of the ped file
51 is split into a number of fields, separated by tabs. The first six
52 fields are ignored, but the remaining fields must consist of two
53 symbols separated by a space. Each pair of symbols is considered a
56 For all commands, if no arguments are given, the source file is read from
57 standard input and the output file is written to standard output. Otherwise,
58 the path to the input file and output file must be specified after the
59 conversion type argument.
62 --help,-h shows this help message and exits
68 $ convert nwk2svg foo.nwk foo.svg
69 $ cat bar.bgl | convert bgl2lgm > bar.lgm
72 Report any bugs to Jade Cheng <info@jade-cheng.com>.
74 Copyright (c) 2015-2020 Jade Cheng
80 template <
typename TController>
90 TController::execute(std::cin, std::cout);
94 const auto src = a.
pop<std::string>();
95 const auto dst = a.
pop<std::string>();
98 std::ifstream in (src);
100 throw jade::error() <<
"failed to open '" << src <<
"'";
102 std::ofstream out (dst);
104 throw jade::error() <<
"failed to create '" << dst <<
"'";
106 TController::execute(in, out);
119 int main(
const int argc,
const char * argv[])
125 if (args.read_flag(
"--help",
"-h"))
127 std::cout << ::usage;
131 if (args.read_flag(
"--version",
"-v"))
137 typedef double value_type;
144 const auto command = args.pop<std::string>();
146 if (command ==
"bgl2lgm") return ::execute<bgl2lgm_type>(args);
147 if (command ==
"cov2nwk") return ::execute<cov2nwk_type>(args);
148 if (command ==
"nwk2cov") return ::execute<nwk2cov_type>(args);
149 if (command ==
"nwk2svg") return ::execute<nwk2svg_type>(args);
150 if (command ==
"ped2dgm") return ::execute<ped2dgm_type>(args);
152 throw jade::error() <<
"unsupported command '" << command <<
"'";
154 catch (
const std::exception & e)
156 std::cerr << e.
what() << std::endl;