From 14686c44f58c409e439d3bb699497e829be1462b Mon Sep 17 00:00:00 2001 From: Adam Taranto Date: Wed, 7 Feb 2024 18:14:23 +1100 Subject: [PATCH] Add --noprune opt to retain small features in microsynteny plots. --- jcvi/graphics/synteny.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/jcvi/graphics/synteny.py b/jcvi/graphics/synteny.py index a6b49637..d88ae28e 100644 --- a/jcvi/graphics/synteny.py +++ b/jcvi/graphics/synteny.py @@ -446,6 +446,7 @@ def __init__( glyphstyle: str = "arrow", glyphcolor: BasePalette = OrientationPalette(), seed: Optional[int] = None, + prune_features=True, ): _, h = fig.get_figwidth(), fig.get_figheight() bed = Bed(bedfile) @@ -465,13 +466,15 @@ def __init__( start, end, _, _, chrom, _, span = ext start, end = start.start, end.end # start, end coordinates ef = list(extra_features.extract(chrom, start, end)) - + # Pruning removes minor features with < 0.1% of the region - ef_pruned = [x for x in ef if x.span >= span / 1000] - logger.info( - "Extracted %d features (%d after pruning)", len(ef), len(ef_pruned) - ) - extras.append(ef_pruned) + if prune_features: + ef_pruned = [x for x in ef if x.span >= span / 1000] + logger.info(f'Extracted {len(ef)} features ({len(ef_pruned)} after pruning)') + extras.append(ef_pruned) + else: + ef_all = [x for x in ef] + extras.append(ef_all) maxspan = max(exts, key=lambda x: x[-1])[-1] scale = maxspan / CANVAS_SIZE @@ -672,6 +675,12 @@ def main(): default="", help="Prefix for the output file", ) + p.add_option( + "--noprune", + default=True, + action="store_false", + help="If set, do not exclude small features from annotation track. ", + ) opts, args, iopts = p.set_image_options(figsize="8x7") if len(args) != 3: @@ -702,6 +711,7 @@ def main(): glyphstyle=opts.glyphstyle, glyphcolor=opts.glyphcolor, seed=iopts.seed, + prune_features=opts.noprune, ) root.set_xlim(0, 1)