diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2020-08-13 11:58:02 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2020-08-13 11:58:02 -0700 |
commit | b498a39385f08f1ffa374b03637e2317da718004 (patch) | |
tree | ce1a918cb7a2718f41cda726572175fa944c5b77 | |
parent | 9deb0978ba029fc59ee699e8280dd60fb47bee1b (diff) |
fix: deal with inverted cases for block lists
-rw-r--r-- | pangraph/graph.py | 33 | ||||
-rw-r--r-- | pangraph/sequence.py | 5 |
2 files changed, 29 insertions, 9 deletions
diff --git a/pangraph/graph.py b/pangraph/graph.py index fb46be9..2926d3f 100644 --- a/pangraph/graph.py +++ b/pangraph/graph.py @@ -467,8 +467,9 @@ class Graph(object): blk_list = set() first = True for tag in ref.muts.keys(): - beg = self.seqs[tag[0]].position_of(new_refs[0], tag[1]) - end = self.seqs[tag[0]].position_of(new_refs[-1], tag[1]) + # NOTE: this is a hack to deal with flipped orientations + pos = sorted([self.seqs[tag[0]].position_of(b, tag[1]) for b in new_refs], key=lambda x: x[0]) + beg, end = pos[0], pos[-1] blks = self.seqs[tag[0]][beg[0]-EXTEND:end[1]+EXTEND] if first: blk_list = set([b.id for b in blks]) @@ -477,13 +478,37 @@ class Graph(object): blk_list.intersection_update(set([b.id for b in blks])) for tag in qry.muts.keys(): - beg = self.seqs[tag[0]].position_of(new_qrys[0], tag[1]) - end = self.seqs[tag[0]].position_of(new_qrys[-1], tag[1]) + pos = sorted([self.seqs[tag[0]].position_of(b, tag[1]) for b in new_qrys], key=lambda x: x[0]) + 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])) print(f"LEN: {len(blk_list)-len(shared_blks)}") if len(blk_list) < len(shared_blks): + ref_list = set() + first = True + for tag in ref.muts.keys(): + beg = self.seqs[tag[0]].position_of(new_refs[0], tag[1]) + end = self.seqs[tag[0]].position_of(new_refs[-1], tag[1]) + blks = self.seqs[tag[0]][beg[0]-EXTEND:end[1]+EXTEND] + if first: + ref_list = set([b.id for b in blks]) + first = False + else: + ref_list.intersection_update(set([b.id for b in blks])) + + qry_list = set() + first = True + for tag in qry.muts.keys(): + beg = self.seqs[tag[0]].position_of(new_qrys[0], tag[1]) + end = self.seqs[tag[0]].position_of(new_qrys[-1], tag[1]) + blks = self.seqs[tag[0]][beg[0]-EXTEND:end[1]+EXTEND] + if first: + qry_list = set([b.id for b in blks]) + first = False + else: + qry_list.intersection_update(set([b.id for b in blks])) + breakpoint("inconsistent number of blocks") self.prune_blks() diff --git a/pangraph/sequence.py b/pangraph/sequence.py index 185dd38..dd9677b 100644 --- a/pangraph/sequence.py +++ b/pangraph/sequence.py @@ -156,11 +156,6 @@ class Path(object): def position_of(self, blk, num): index = [i for i, n in enumerate(self.nodes) if n.blk == blk] if len(index) <= num: - # print(f"NODES: {self.nodes}") - # print(f"BLOCK: {blk}") - # print(f"POSITION: {self.position}") - # print(f"INDEX: {index}") - # breakpoint("break") return None return (self.position[index[num]], self.position[index[num]+1]) |