diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2020-08-11 12:42:40 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2020-08-11 12:42:40 -0700 |
commit | da096f986322037af9ff351ba475085bbb0fd6d8 (patch) | |
tree | f921cdfbb5c86d3e50dd5ef39214dfa1138ae2de | |
parent | 211b47294d8e4a0371448c4121a292357d8c7fda (diff) |
fix: slicing of sequence paths
-rw-r--r-- | pangraph/graph.py | 14 | ||||
-rw-r--r-- | pangraph/sequence.py | 10 |
2 files changed, 15 insertions, 9 deletions
diff --git a/pangraph/graph.py b/pangraph/graph.py index 4ae721d..24defa9 100644 --- a/pangraph/graph.py +++ b/pangraph/graph.py @@ -419,13 +419,13 @@ class Graph(object): ref = old_ref[hit['ref']['start']:hit['ref']['end']] qry = old_qry[hit['qry']['start']:hit['qry']['end']] - # print(ref.positions) - # print(qry.positions) - # # TODO: check for out of bounds accesses - # for tag, item in ref.positions.items(): - # blks = self.seqs[tag[0]][item-EXTEND:item+EXTEND] - # print(f"Isolate: {tag[0]} blocks: {blks}") - # breakpoint("test positions") + print(ref.positions) + print(qry.positions) + for tag, item in ref.positions.items(): + blks = self.seqs[tag[0]][item[0]-EXTEND:item[1]+EXTEND] + if len(blks) >= 3: + print(f"Isolate: {tag[0]} blocks: {','.join(b.id for b in blks)}") + breakpoint("test positions") if hit["orientation"] == Strand.Minus: qry = qry.rev_cmpl() diff --git a/pangraph/sequence.py b/pangraph/sequence.py index b2b5ce7..5414364 100644 --- a/pangraph/sequence.py +++ b/pangraph/sequence.py @@ -158,8 +158,14 @@ class Path(object): beg = index.start or 0 end = index.stop or self.position[-1] - i = np.searchsorted(self.position, beg, side='right') - j = np.searchsorted(self.position, end, side='right') + 1 + # TODO: circular slicing + beg = max(0, beg) + end = min(end, self.position[-1]) + # if index.start < 0 or end > self.position[-1]: + # breakpoint(f"{index}:: need to implement circular slicing") + + i = np.searchsorted(self.position, beg, side='right') - 1 + j = np.searchsorted(self.position, end, side='left') assert i < j, "sorted" return [n.blk for n in self.nodes[i:j]] elif isinstance(index, int): |