Skip to content

Commit

Permalink
Allow validating only the GAM
Browse files Browse the repository at this point in the history
  • Loading branch information
adamnovak committed Mar 23, 2023
1 parent 45987cc commit 1916a65
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/subcommand/validate_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ void help_validate(char** argv) {
<< "options:" << endl
<< " default: check all aspects of the graph, if options are specified do only those" << endl
<< " -o, --orphans verify that all nodes have edges" << endl
<< " -a, --gam FILE verify that edits in the alignment fit on nodes in the graph" << endl;
<< " -a, --gam FILE verify that edits in the alignment fit on nodes in the graph" << endl
<< " -A, --gam-only do not verify the graph itself, only the alignment" << endl;
}

int main_validate(int argc, char** argv) {
Expand All @@ -39,6 +40,7 @@ int main_validate(int argc, char** argv) {

bool check_orphans = false;
string gam_path;
bool gam_only = false;

int c;
optind = 2; // force optind past command positional argument
Expand All @@ -48,11 +50,12 @@ int main_validate(int argc, char** argv) {
{"help", no_argument, 0, 'h'},
{"orphans", no_argument, 0, 'o'},
{"gam", required_argument, 0, 'a'},
{"gam-only", no_argument, 0, 'A'},
{0, 0, 0, 0}
};

int option_index = 0;
c = getopt_long (argc, argv, "hoa:",
c = getopt_long (argc, argv, "hoa:A",
long_options, &option_index);

// Detect the end of the options.
Expand All @@ -68,6 +71,10 @@ int main_validate(int argc, char** argv) {
case 'a':
gam_path = optarg;
break;

case 'A':
gam_only = true;
break;

case 'h':
case '?':
Expand Down Expand Up @@ -107,14 +114,17 @@ int main_validate(int argc, char** argv) {

// VG's a little less structured, so try its own logic
bool valid_graph = true;
VG* vg_graph = dynamic_cast<VG*>(graph.get());
if (vg_graph != nullptr) {
if (!vg_graph->is_valid(true, true, check_orphans, true)) {
valid_graph = false;

if (!gam_only) {
VG* vg_graph = dynamic_cast<VG*>(graph.get());
if (vg_graph != nullptr) {
if (!vg_graph->is_valid(true, true, check_orphans, true)) {
valid_graph = false;
}
}
}

if (valid_graph) {
if (!gam_only && valid_graph) {
// I don't think this is possible with any libbdsg implementations, but check edges just in case
graph->for_each_edge([&](const edge_t& edge) {
if (!graph->has_node(graph->get_id(edge.first))) {
Expand Down Expand Up @@ -171,7 +181,9 @@ int main_validate(int argc, char** argv) {
if (!gam_path.empty()) {
cerr << "alignment: " << (valid_aln ? "valid" : "invalid") << endl;
}
cerr << "graph: " << (valid_graph ? "valid" : "invalid") << endl;
if (!gam_only) {
cerr << "graph: " << (valid_graph ? "valid" : "invalid") << endl;
}

return valid_aln && valid_graph ? 0 : 1;
}
Expand Down

1 comment on commit 1916a65

@adamnovak
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vg CI tests complete for branch support-matteo. View the full report here.

16 tests passed, 0 tests failed and 0 tests skipped in 10164 seconds

Please sign in to comment.