aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-08-11 14:12:24 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-08-11 14:12:24 -0700
commite5c6778ca74ac0e8eb5bc09d6e7ddc54e460e951 (patch)
treee961a962d70fe39f00bd2675aadd11fec3abab19
parentda096f986322037af9ff351ba475085bbb0fd6d8 (diff)
fix: circular slicing check for singleton paths
-rw-r--r--pangraph/graph.py4
-rw-r--r--pangraph/sequence.py19
2 files changed, 13 insertions, 10 deletions
diff --git a/pangraph/graph.py b/pangraph/graph.py
index 24defa9..6b29b1e 100644
--- a/pangraph/graph.py
+++ b/pangraph/graph.py
@@ -419,11 +419,11 @@ 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)
for tag, item in ref.positions.items():
blks = self.seqs[tag[0]][item[0]-EXTEND:item[1]+EXTEND]
if len(blks) >= 3:
+ print(ref.positions)
+ print(qry.positions)
print(f"Isolate: {tag[0]} blocks: {','.join(b.id for b in blks)}")
breakpoint("test positions")
diff --git a/pangraph/sequence.py b/pangraph/sequence.py
index 5414364..baff6a2 100644
--- a/pangraph/sequence.py
+++ b/pangraph/sequence.py
@@ -157,19 +157,22 @@ class Path(object):
if isinstance(index, slice):
beg = index.start or 0
end = index.stop or self.position[-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")
+ l, r = [], []
+ if beg < 0:
+ if len(self.nodes) > 1:
+ l = self[self.position[-1] + beg:self.position[-1]]
+ beg = 0
+ if end > self.position[-1]:
+ if len(self.nodes) > 1:
+ r = self[0:end-self.position[-1]]
+ end = self.position[-1]
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]]
+ return l + [n.blk for n in self.nodes[i:j]] + r
elif isinstance(index, int):
- i = np.searchsorted(self.position, index, side='left')
+ i = np.searchsorted(self.position, index, side='right') - 1
return self.nodes[i].blk
else:
raise ValueError(f"type '{type(index)}' not supported as index")