Skip to content

Commit

Permalink
feat: barcode support to the string graph
Browse files Browse the repository at this point in the history
  • Loading branch information
chungongyu committed Nov 9, 2020
1 parent 418d727 commit 766dec1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Assembler : public Runner {
// Trimming
size_t trimRound = 0, numTrimRounds = options.get<size_t>("cut-terminal", 10);
while (trimRound < numTrimRounds) {
LOG4CXX_INFO(logger, boost::format("[Trim] Trim round: %d") % (trimRound + 1))
LOG4CXX_INFO(logger, boost::format("[Trim] Trim round: %d") % (trimRound + 1));
bool modified = false;

LOG4CXX_INFO(logger, "Trimming tips");
Expand All @@ -118,7 +118,7 @@ class Assembler : public Runner {
// Trimming
size_t trimRound = 0, numTrimRounds = options.get<size_t>("cut-terminal", 10);
while (trimRound < numTrimRounds) {
LOG4CXX_INFO(logger, boost::format("[Trim] Trim round: %d") % (trimRound + 1))
LOG4CXX_INFO(logger, boost::format("[Trim] Trim round: %d") % (trimRound + 1));
bool modified = false;

LOG4CXX_INFO(logger, "Removing loops");
Expand Down
6 changes: 3 additions & 3 deletions src/bigraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void Edge::validate() const {
LOG4CXX_ERROR(logger, "Error, matching strings are not the same length");
LOG4CXX_ERROR(logger, boost::format("V1M: %s,%s") % start()->id() % m1);
LOG4CXX_ERROR(logger, boost::format("V2M: %s,%s") % end()->id() % m2);
LOG4CXX_ERROR(logger, boost::format("V1: %s") % v1)
LOG4CXX_ERROR(logger, boost::format("V2: %s") % v2)
LOG4CXX_ERROR(logger, boost::format("V1: %s") % v1);
LOG4CXX_ERROR(logger, boost::format("V2: %s") % v2);
assert(false);
}
}
Expand Down Expand Up @@ -503,7 +503,7 @@ bool Bigraph::load(std::istream& stream, size_t minOverlap, bool allowContainmen
LOG4CXX_ERROR(logger, boost::format("Error: Unexpected vertex record found at line %s") % line);
return false;
}
Vertex* vertex = new Vertex(record.id, record.seq, record.substring ? (int)record.substring : false);
Vertex* vertex = new Vertex(record.id, record.seq, record.substring ? (int)record.substring : false, record.barcode ? (std::string)record.barcode : "");
if (!g->addVertex(vertex)) {
LOG4CXX_ERROR(logger, boost::format("Error: Attempted to insert vertex into graph with a duplicate id: %s") % vertex->id());
LOG4CXX_ERROR(logger, "All reads must have a unique identifier");
Expand Down
6 changes: 5 additions & 1 deletion src/bigraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Vertex {
public:
typedef std::string Id;

Vertex(const Id& id, const std::string& seq, bool contained = false) : _id(id), _seq(seq), _contained(contained), _color(GC_NONE), _coverage(1) {
Vertex(const Id& id, const std::string& seq, bool contained=false, const std::string& index="") : _id(id), _seq(seq), _contained(contained), _index(index), _color(GC_NONE), _coverage(1) {
}
~Vertex();

Expand All @@ -121,6 +121,9 @@ class Vertex {
const std::string& seq() const {
return _seq;
}
const std::string& index() const {
return _index;
}
size_t coverage() const {
return _coverage;
}
Expand Down Expand Up @@ -173,6 +176,7 @@ class Vertex {
Id _id;
GraphColor _color;
std::string _seq;
std::string _index;
size_t _coverage; // Number of vertices that have been merged into this one
bool _contained;

Expand Down
2 changes: 1 addition & 1 deletion src/subgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SubgraphExtractor {
void addVertex(const Vertex* vertex, Bigraph* sub) {
// Make sure the vertex hasn't been added yet
if (sub->getVertex(vertex->id()) == NULL) {
sub->addVertex(new Vertex(vertex->id(), vertex->seq(), vertex->contained()));
sub->addVertex(new Vertex(vertex->id(), vertex->seq(), vertex->contained(), vertex->index()));
}
}

Expand Down
35 changes: 35 additions & 0 deletions test/index_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,39 @@ BOOST_AUTO_TEST_CASE(RLUnit_test) {
}
}

BOOST_AUTO_TEST_CASE(RLString_test) {
DNASeq read("test", "AAACGGGTA");

RLString runs;

RLUnit run;
for (const auto& c : read.seq) {
if (run.initialized()) {
if (run == c && !run.full()) {
++run;
} else {
runs.push_back(run);
run = RLUnit(c);
}
} else {
run = RLUnit(c);
}
}
if (run.initialized()) {
runs.push_back(run);
}

BOOST_CHECK_EQUAL(runs.size(), 5);
BOOST_CHECK_EQUAL(runs[0], 'A');
BOOST_CHECK_EQUAL(runs[0].count(), 3);
BOOST_CHECK_EQUAL(runs[1], 'C');
BOOST_CHECK_EQUAL(runs[1].count(), 1);
BOOST_CHECK_EQUAL(runs[2], 'G');
BOOST_CHECK_EQUAL(runs[2].count(), 3);
BOOST_CHECK_EQUAL(runs[3], 'T');
BOOST_CHECK_EQUAL(runs[3].count(), 1);
BOOST_CHECK_EQUAL(runs[4], 'A');
BOOST_CHECK_EQUAL(runs[4].count(), 1);
}

BOOST_AUTO_TEST_SUITE_END();

0 comments on commit 766dec1

Please sign in to comment.