1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/** Convert a graph to dot format.
* Written by Shaun Jackman <sjackman@bcgsc.ca>.
*/
#include "ContigGraph.h"
#include "DirectedGraph.h"
#include "GraphIO.h"
#include "GraphUtil.h"
#include "IOUtil.h"
#include "Uncompress.h"
#include <fstream>
#include <getopt.h>
#include <iostream>
using namespace std;
#define PROGRAM "abyss-gc"
static const char VERSION_MESSAGE[] =
PROGRAM " (" PACKAGE_NAME ") " VERSION "\n"
"Written by Shaun Jackman.\n"
"\n"
"Copyright 2014 Canada's Michael Smith Genome Sciences Centre\n";
static const char USAGE_MESSAGE[] =
"Usage: " PROGRAM " [FILE]...\n"
"Count the number of vertices and edges in a graph.\n"
"\n"
" Options:\n"
"\n"
" -v, --verbose display verbose output\n"
" --help display this help and exit\n"
" --version output version information and exit\n"
"\n"
"Report bugs to <" PACKAGE_BUGREPORT ">.\n";
namespace opt {
unsigned k; // used by DotIO
static int verbose;
}
static const char shortopts[] = "v";
enum { OPT_HELP = 1, OPT_VERSION };
static const struct option longopts[] = {
{ "verbose", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, OPT_HELP },
{ "version", no_argument, NULL, OPT_VERSION },
{ NULL, 0, NULL, 0 }
};
/** Read a graph from the specified file. */
template <typename Graph, typename BetterEP>
static void readGraph(const string& path, Graph& g, BetterEP betterEP)
{
if (opt::verbose > 0)
cout << "Reading `" << path << "'...\n";
ifstream fin(path.c_str());
istream& in = path == "-" ? cin : fin;
assert_good(in, path);
read_graph(in, g, betterEP);
assert(in.eof());
printGraphStats(cout, g);
g_contigNames.lock();
}
/** Read a graph from the specified files. */
template <typename Graph, typename It, typename BetterEP>
void readGraphs(Graph& g, It first, It last, BetterEP betterEP)
{
if (first != last) {
for (It it = first; it < last; ++it)
readGraph(*it, g, betterEP);
} else
readGraph("-", g, betterEP);
}
int main(int argc, char** argv)
{
bool die = false;
for (int c; (c = getopt_long(argc, argv,
shortopts, longopts, NULL)) != -1;) {
istringstream arg(optarg != NULL ? optarg : "");
switch (c) {
case '?': die = true; break;
case 'v': opt::verbose++; break;
case OPT_HELP:
cout << USAGE_MESSAGE;
exit(EXIT_SUCCESS);
case OPT_VERSION:
cout << VERSION_MESSAGE;
exit(EXIT_SUCCESS);
}
if (optarg != NULL && !arg.eof()) {
cerr << PROGRAM ": invalid option: `-"
<< (char)c << optarg << "'\n";
exit(EXIT_FAILURE);
}
}
if (die) {
cerr << "Try `" << PROGRAM
<< " --help' for more information.\n";
exit(EXIT_FAILURE);
}
ContigGraph<DirectedGraph<NoProperty, NoProperty> > g;
readGraphs(g, argv + optind, argv + argc,
DisallowParallelEdges());
assert_good(cout, "-");
return 0;
}
|