Skip to content

Commit

Permalink
Emit GFA header:
Browse files Browse the repository at this point in the history
 - GFA version
 - Version of producer
  • Loading branch information
asl committed May 14, 2024
1 parent fb78220 commit c6d938f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ void GFAPathWriter::WritePaths12(const std::vector<EdgeId> &edges,
os_ << '\n';
}

void GFAPathWriter::WriteHeader() {
os_ << "H\t"
<< "VN:Z:" << (version_ == Version::GFAv11 ? "1.1" : "1.2") << '\t'
<< "sp:Z:" << version::flavour() << '-' << version::package() << '\t'
<< "sg:Z:" << version::gitrev() << '\t'
<< "sr:Z:" << version::refspec() << '\n';
}


void GFAPathWriter::WritePaths(const std::vector<EdgeId> &edges,
const std::string &name,
const std::string &flags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class GFAPathWriter : public gfa::GFAWriter {
using JumpLinks = std::unordered_set<std::pair<EdgeId, EdgeId>>;
void WriteJumpLinks(const JumpLinks &links);

protected:
void WriteHeader() override;

public:
enum class Version {
GFAv11, // Split gapped paths into segments
Expand Down
7 changes: 7 additions & 0 deletions src/common/io/graph/gfa_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void GFAWriter::WriteLinks(const Component &gc) {
}

void GFAWriter::WriteSegmentsAndLinks(const Component &gc) {
WriteHeader();
WriteSegments(gc);
WriteLinks(gc);
}
Expand Down Expand Up @@ -109,3 +110,9 @@ void GFAWriter::WriteVertexLinks(const VertexId &vertex, const Component &gc) {
}
}

void GFAWriter::WriteHeader() {
os_ << "H\t"
<< "sp:Z:" << version::flavour() << '-' << version::package() << '\t'
<< "sg:Z:" << version::gitrev() << '\t'
<< "sr:Z:" << version::refspec() << '\n';
}
14 changes: 7 additions & 7 deletions src/common/io/graph/gfa_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
#include "assembly_graph/components/graph_component.hpp"
#include "assembly_graph/core/graph.hpp"
#include "io/utils/edge_namer.hpp"
#include "io/utils/id_mapper.hpp"

#include <memory>
#include <string>
#include <ostream>

namespace omnigraph {

template <class Graph>
class GraphComponent;

}

namespace gfa {
Expand All @@ -36,15 +32,20 @@ class GFAWriter {
io::EdgeNamingF<Graph> naming_f = io::IdNamingF<Graph>())
: graph_(graph),
edge_namer_(graph_, naming_f),
os_(os) {
}
os_(os) {}

virtual ~GFAWriter() = default;

void WriteSegmentsAndLinks() {
WriteHeader();
WriteSegments();
WriteLinks();
}
void WriteSegmentsAndLinks(const Component &gc);

protected:
virtual void WriteHeader();

private:
void WriteSegments();
void WriteLinks();
Expand All @@ -62,4 +63,3 @@ class GFAWriter {
};

}

5 changes: 5 additions & 0 deletions src/include/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
//***************************************************************************

namespace version {
const char *major();
const char *minor();
const char *patch();
const char *package();
const char *flavour();
const char *refspec();
const char *gitrev();
};
Expand Down

0 comments on commit c6d938f

Please sign in to comment.