Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output GFA in correct order (S then L then P/W) #4528

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions src/gfa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ void graph_to_gfa(const PathHandleGraph* graph, ostream& out, const set<string>&
out << "\n"; // Writing `std::endl` would flush the buffer.
return true;
});

graph->for_each_edge([&](const edge_t& h) {

nid_t from_id = graph->get_id(h.first);
bool from_is_reverse = graph->get_is_reverse(h.first);
nid_t to_id = graph->get_id(h.second);
bool to_is_reverse = graph->get_is_reverse(h.second);

if (from_is_reverse && (to_is_reverse || to_id < from_id)) {
// Canonicalize edges to be + orientation first if possible, and
// then low-ID to high-ID if possible, for testability. This edge
// needs to flip.

// Swap the nodes
std::swap(from_id, to_id);
// Swap the orientations
std::swap(from_is_reverse, to_is_reverse);
// Reverse the orientations
from_is_reverse = !from_is_reverse;
to_is_reverse = !to_is_reverse;
}

out << "L\t" << from_id << "\t" << (from_is_reverse ? '-' : '+')
<< "\t" << to_id << "\t" << (to_is_reverse ? '-' : '+') << "\t0M\n"; // Writing `std::endl` would flush the buffer.
return true;
}, false);

// Sort the paths by name, making sure to treat subpath coordinates numerically
vector<path_handle_t> path_handles;
Expand Down Expand Up @@ -144,32 +170,6 @@ void graph_to_gfa(const PathHandleGraph* graph, ostream& out, const set<string>&
write_w_line(graph, out, h, fake_subrange_end);
}
}

graph->for_each_edge([&](const edge_t& h) {

nid_t from_id = graph->get_id(h.first);
bool from_is_reverse = graph->get_is_reverse(h.first);
nid_t to_id = graph->get_id(h.second);
bool to_is_reverse = graph->get_is_reverse(h.second);

if (from_is_reverse && (to_is_reverse || to_id < from_id)) {
// Canonicalize edges to be + orientation first if possible, and
// then low-ID to high-ID if possible, for testability. This edge
// needs to flip.

// Swap the nodes
std::swap(from_id, to_id);
// Swap the orientations
std::swap(from_is_reverse, to_is_reverse);
// Reverse the orientations
from_is_reverse = !from_is_reverse;
to_is_reverse = !to_is_reverse;
}

out << "L\t" << from_id << "\t" << (from_is_reverse ? '-' : '+')
<< "\t" << to_id << "\t" << (to_is_reverse ? '-' : '+') << "\t0M\n"; // Writing `std::endl` would flush the buffer.
return true;
}, false);
}

bool should_write_as_w_line(const PathHandleGraph* graph, path_handle_t path_handle) {
Expand Down
Loading