Skip to content

Commit

Permalink
move filter_blocks outside print_to_file
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Jul 22, 2024
1 parent 9136d94 commit 6932b08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions jcvi/compara/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def make_ranges(self, order, clip=10):
return ranges, block_pairs

def filter_blocks(self, accepted: Dict[Tuple[str, str], str]):
"""
Filter the blocks based on the accepted pairs. This is used to update
the anchors so that they match the info in the LAST file.
"""
new_blocks = []
nremoved = 0
ncorrected = 0
Expand All @@ -76,12 +80,14 @@ def filter_blocks(self, accepted: Dict[Tuple[str, str], str]):
if nblocks_removed:
logger.debug("Removed %d empty blocks", nblocks_removed)
logger.debug("Corrected scores for %d anchors", ncorrected)
return new_blocks
self.blocks = new_blocks

def print_to_file(self, filename="stdout", accepted=None):
def print_to_file(self, filename="stdout"):
"""
Print the anchors to a file, optionally filtering them based on the
accepted pairs.
"""
fw = must_open(filename, "w")
if accepted:
self.blocks = self.filter_blocks(accepted)
for block in self.blocks:
print("###", file=fw)
for line in block:
Expand Down
4 changes: 3 additions & 1 deletion jcvi/compara/synteny.py
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,9 @@ def liftover(args):

logger.debug("%d new pairs found (dist=%d).", lifted, dist)
newanchorfile = anchor_file.rsplit(".", 1)[0] + ".lifted.anchors"
ac.print_to_file(filename=newanchorfile, accepted=accepted)
if accepted:
ac.filter_blocks(accepted)
ac.print_to_file(filename=newanchorfile)
summary([newanchorfile])

return newanchorfile
Expand Down

0 comments on commit 6932b08

Please sign in to comment.