diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2020-08-13 12:52:20 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2020-08-13 12:52:20 -0700 |
commit | b1af35822273ebe52f6fa089cfb5bc5f8ef542a3 (patch) | |
tree | e0fa2f2ddbc87fa5d1392e1d41c3a06cf2b25647 | |
parent | b498a39385f08f1ffa374b03637e2317da718004 (diff) |
fix: bug associated to position of using index absolutely instead of relative to true dictionary key
-rw-r--r-- | pangraph/graph.py | 5 | ||||
-rw-r--r-- | pangraph/sequence.py | 12 |
2 files changed, 8 insertions, 9 deletions
diff --git a/pangraph/graph.py b/pangraph/graph.py index 2926d3f..afff779 100644 --- a/pangraph/graph.py +++ b/pangraph/graph.py @@ -478,7 +478,10 @@ class Graph(object): blk_list.intersection_update(set([b.id for b in blks])) for tag in qry.muts.keys(): - pos = sorted([self.seqs[tag[0]].position_of(b, tag[1]) for b in new_qrys], key=lambda x: x[0]) + try: + pos = sorted([self.seqs[tag[0]].position_of(b, tag[1]) for b in new_qrys], key=lambda x: x[0]) + except: + breakpoint("bad find") beg, end = pos[0], pos[-1] blks = self.seqs[tag[0]][beg[0]-EXTEND:end[1]+EXTEND] blk_list.intersection_update(set([b.id for b in blks])) diff --git a/pangraph/sequence.py b/pangraph/sequence.py index dd9677b..6b9baba 100644 --- a/pangraph/sequence.py +++ b/pangraph/sequence.py @@ -88,12 +88,6 @@ class Path(object): return seq - # def position_of(self, blk): - # for i, n in enumerate(self.nodes): - # if n.blk == blk: - # return i, n.num - # raise ValueError("block not found in path") - def rm_nil_blks(self): good, popped = [], set() for i, n in enumerate(self.nodes): @@ -121,6 +115,8 @@ class Path(object): try: i, j = ids.index(start[0]), ids.index(stop[0]) + if N > 0: + breakpoint("HIT") if self.nodes[i].strand == start[1]: beg, end, s = i, j, Strand.Plus else: @@ -154,8 +150,8 @@ class Path(object): self.position = np.cumsum([0] + [n.length(self.name) for n in self.nodes]) def position_of(self, blk, num): - index = [i for i, n in enumerate(self.nodes) if n.blk == blk] - if len(index) <= num: + index = { n.num:i for i, n in enumerate(self.nodes) if n.blk == blk } + if not num in index: return None return (self.position[index[num]], self.position[index[num]+1]) |