Skip to content

Commit

Permalink
update path storage to linked lists
Browse files Browse the repository at this point in the history
Resolves #30
  • Loading branch information
ekg committed Apr 22, 2015
1 parent 3b22c51 commit ada72b6
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
@@ -1,6 +1,6 @@
[submodule "pb2json"]
path = pb2json
url = https://github.com/shafreeck/pb2json.git
url = https://github.com/ekg/pb2json.git
[submodule "vcflib"]
path = vcflib
url = https://github.com/ekg/vcflib.git
Expand Down
7 changes: 4 additions & 3 deletions index.cpp
Expand Up @@ -536,7 +536,7 @@ void Index::load_graph(VG& graph) {

void Index::load_paths(VG& graph) {
graph.destroy_progress();
graph.create_progress("indexing paths of " + graph.name, graph.paths._paths->size());
graph.create_progress("indexing paths of " + graph.name, graph.paths._paths.size());
store_paths(graph);
graph.destroy_progress();
}
Expand Down Expand Up @@ -608,9 +608,10 @@ int64_t Index::get_path_id(const string& name) {
}

void Index::store_paths(VG& graph) {
for (auto& path : *graph.paths._paths) {
function<void(Path&)> lambda = [this, &graph](Path& path) {
store_path(graph, path);
}
};
graph.paths.for_each(lambda);
}

void Index::store_path(VG& graph, Path& path) {
Expand Down
40 changes: 36 additions & 4 deletions main.cpp
Expand Up @@ -332,8 +332,10 @@ void help_mod(char** argv) {
<< "Modifies graph, outputs modified on stdout." << endl
<< endl
<< "options:" << endl
<< " -k, --keep-path NAME keep only nodes and edges in the path" << endl
<< " -o, --remove-orphans remove orphan edges from graph (edge specified but node missing)" << endl;
<< " -i, --include-aln FILE include the paths implied by alignments in the graph" << endl
<< " -c, --compact-ids should we sort and compact the id space? (default false)" << endl
<< " -k, --keep-path NAME keep only nodes and edges in the path" << endl
<< " -o, --remove-orphans remove orphan edges from graph (edge specified but node missing)" << endl;
}

int main_mod(int argc, char** argv) {
Expand All @@ -345,20 +347,24 @@ int main_mod(int argc, char** argv) {

string path_name;
bool remove_orphans = false;
string aln_file;
bool compact_ids = false;

int c;
optind = 2; // force optind past command positional argument
while (true) {
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
{"include-aln", required_argument, 0, 'i'},
{"compact-ids", no_argument, 0, 'c'},
{"keep-path", required_argument, 0, 'k'},
{"remove-orphans", no_argument, 0, 'o'},
{0, 0, 0, 0}
};

int option_index = 0;
c = getopt_long (argc, argv, "hk:o",
c = getopt_long (argc, argv, "hk:oi:c",
long_options, &option_index);

// Detect the end of the options.
Expand All @@ -368,6 +374,14 @@ int main_mod(int argc, char** argv) {
switch (c)
{

case 'i':
aln_file = optarg;
break;

case 'c':
compact_ids = true;
break;

case 'k':
path_name = optarg;
break;
Expand Down Expand Up @@ -405,6 +419,24 @@ int main_mod(int argc, char** argv) {
graph->remove_orphan_edges();
}

if (!aln_file.empty()) {
function<void(Alignment&)> lambda = [&graph](Alignment& aln) {
const Path& path = aln.path();
graph->include(path);
};
if (aln_file == "-") {
stream::for_each(std::cin, lambda);
} else {
ifstream in;
in.open(aln_file.c_str());
stream::for_each(in, lambda);
}
if (compact_ids) {
graph->sort();
graph->compact_ids();
}
}

graph->serialize_to_ostream(std::cout);

delete graph;
Expand Down Expand Up @@ -2554,7 +2586,7 @@ void vg_help(char** argv) {
<< " -- concat concatenate graphs tail-to-head" << endl
<< " -- kmers enumerate kmers of the graph" << endl
<< " -- sim simulate reads from the graph" << endl
<< " -- mod filter and transform the graph" << endl
<< " -- mod filter, transform, and edit the graph" << endl
<< " -- surject map alignments onto specific paths" << endl;
}

Expand Down

0 comments on commit ada72b6

Please sign in to comment.