Skip to content

Commit

Permalink
r200: DFS=>BFS on subgraph extraction
Browse files Browse the repository at this point in the history
resolves #15
  • Loading branch information
lh3 committed Dec 22, 2020
1 parent 8ee106e commit 53eca7a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ gfa-aug.o: gfa-priv.h gfa.h ksort.h
gfa-base.o: gfa-priv.h gfa.h kstring.h khash.h kalloc.h ksort.h
gfa-gt.o: gfa-priv.h gfa.h khash.h kalloc.h
gfa-io.o: kstring.h gfa-priv.h gfa.h kseq.h
gfa-sub.o: gfa-priv.h gfa.h kalloc.h kavl.h khash.h ksort.h
gfa-util.o: gfa-priv.h gfa.h kvec.h ksort.h
gfa-sub.o: gfa-priv.h gfa.h kalloc.h kavl.h khash.h ksort.h kvec.h
gfa-util.o: gfa-priv.h gfa.h kvec.h ksort.h kdq.h
kalloc.o: kalloc.h
main.o: ketopt.h gfa-priv.h gfa.h kseq.h
22 changes: 13 additions & 9 deletions gfa-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,31 @@
#include "gfa-priv.h"
#include "kvec.h"
#include "ksort.h"
#include "kdq.h"
KDQ_INIT(uint64_t)

void gfa_sub(gfa_t *g, int n, char *const* seg, int step)
{
int32_t i;
int8_t *flag;
kvec_t(uint64_t) stack = {0,0,0};
kdq_t(uint64_t) *q;
if (n == 0) return;
q = kdq_init(uint64_t);
GFA_CALLOC(flag, g->n_seg * 2);
for (i = 0; i < n; ++i) {
int32_t s;
s = gfa_name2id(g, seg[i]);
if (s >= 0) {
kv_push(uint64_t, stack, (uint64_t)(s<<1|0)<<32);
kv_push(uint64_t, stack, (uint64_t)(s<<1|1)<<32);
kdq_push(uint64_t, q, ((uint64_t)s<<1|0)<<32);
kdq_push(uint64_t, q, ((uint64_t)s<<1|1)<<32);
}
}
for (i = 0; i < g->n_seg; ++i) // mark all segments to be deleted
g->seg[i].del = 1;
while (stack.n) {
uint64_t x = kv_pop(stack);
uint32_t v = x>>32, r = (uint32_t)x;
while (kdq_size(q) > 0) {
uint64_t x = *kdq_shift(uint64_t, q);
uint32_t v = x>>32;
int r = (int32_t)x;
if (flag[v]) continue; // already visited
flag[v] = 1;
g->seg[v>>1].del = 0;
Expand All @@ -32,13 +36,13 @@ void gfa_sub(gfa_t *g, int n, char *const* seg, int step)
gfa_arc_t *av = gfa_arc_a(g, v);
for (i = 0; i < nv; ++i) {
if (flag[av[i].w] == 0)
kv_push(uint64_t, stack, (uint64_t)av[i].w<<32 | (r + 1));
kdq_push(uint64_t, q, (uint64_t)av[i].w<<32 | (r + 1));
if (flag[av[i].w^1] == 0)
kv_push(uint64_t, stack, (uint64_t)(av[i].w^1)<<32 | (r + 1));
kdq_push(uint64_t, q, (uint64_t)(av[i].w^1)<<32 | (r + 1));
}
}
}
free(stack.a);
kdq_destroy(uint64_t, q);
free(flag);
gfa_arc_rm(g);
}
Expand Down
2 changes: 1 addition & 1 deletion gfa.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdint.h>

#define GFA_VERSION "0.4-r199-dirty"
#define GFA_VERSION "0.4-r200-dirty"

#define GFA_O_OV_EXT 0x1
#define GFA_O_NO_SEQ 0x2
Expand Down

0 comments on commit 53eca7a

Please sign in to comment.