Skip to content

Commit

Permalink
add vg validate (resolves #126)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekg committed Oct 23, 2015
1 parent 65a1939 commit 529385c
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 108 deletions.
107 changes: 105 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,106 @@ using namespace std;
using namespace google::protobuf;
using namespace vg;

void help_validate(char** argv) {
cerr << "usage: " << argv[0] << " validate [options] graph" << endl
<< "Validate the graph." << endl
<< endl
<< "options:" << endl
<< " default: check all aspects of the graph, if options are specified do only those" << endl
<< " -n, --nodes verify that we have the expected number of nodes" << endl
<< " -e, --edges verify that the graph contains all nodes that are referred to by edges" << endl
<< " -p, --paths verify that contiguous path segments are connected by edges" << endl
<< " -o, --orphans verify that all nodes have edges" << endl;
}

int main_validate(int argc, char** argv) {

if (argc <= 2) {
help_validate(argv);
return 1;
}

bool check_nodes = false;
bool check_edges = false;
bool check_orphans = false;
bool check_paths = false;

int c;
optind = 2; // force optind past command positional argument
while (true) {
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
{"nodes", no_argument, 0, 'n'},
{"edges", no_argument, 0, 'e'},
{"paths", no_argument, 0, 'o'},
{"orphans", no_argument, 0, 'p'},
{0, 0, 0, 0}
};

int option_index = 0;
c = getopt_long (argc, argv, "hneop",
long_options, &option_index);

// Detect the end of the options.
if (c == -1)
break;

switch (c)
{

case 'n':
check_nodes = true;
break;

case 'e':
check_edges = true;
break;

case 'o':
check_orphans = true;
break;

case 'p':
check_paths = true;
break;

case 'h':
case '?':
help_validate(argv);
exit(1);
break;

default:
abort ();
}
}

VG* graph;
string file_name = argv[optind];
if (file_name == "-") {
graph = new VG(std::cin);
} else {
ifstream in;
in.open(file_name.c_str());
graph = new VG(in);
}

// if we chose a specific subset, do just them
if (check_nodes || check_edges || check_orphans || check_paths) {
if (graph->is_valid(check_nodes, check_edges, check_orphans, check_paths)) {
return 0;
} else {
return 1;
}
// otherwise do everything
} else if (graph->is_valid()) {
return 0;
} else {
return 1;
}
}

void help_compare(char** argv) {
cerr << "usage: " << argv[0] << " compare [options] graph1 graph2" << endl
<< "Compare kmer sets of two graphs" << endl
Expand Down Expand Up @@ -900,7 +1000,7 @@ int main_msga(int argc, char** argv) {
// use this step to simplify the graph so we can efficiently normalize it
graph->remove_non_path();
graph->paths.clear();
graph->graph.clear_path();
graph->graph.clear_path(); // paths.clear() should do this too
graph->normalize();
graph->dice_nodes(node_max);
graph->sort();
Expand Down Expand Up @@ -4674,7 +4774,8 @@ void vg_help(char** argv) {
<< " -- msga multiple sequence graph alignment" << endl
<< " -- pileup build a pileup from a set of alignments" << endl
<< " -- call prune the graph by genotyping a pileup" << endl
<< " -- compare compare the kmer space of two graphs" << endl;
<< " -- compare compare the kmer space of two graphs" << endl
<< " -- validate validate the semantics of a graph" << endl;
}

int main(int argc, char *argv[])
Expand Down Expand Up @@ -4726,6 +4827,8 @@ int main(int argc, char *argv[])
return main_call(argc, argv);
} else if (command == "compare") {
return main_compare(argc, argv);
} else if (command == "validate") {
return main_validate(argc, argv);
} else {
cerr << "error:[vg] command " << command << " not found" << endl;
vg_help(argv);
Expand Down
File renamed without changes.
Loading

0 comments on commit 529385c

Please sign in to comment.