From a280f7fc2ab92fdebe51e78d6030bffd94d6e893 Mon Sep 17 00:00:00 2001 From: Tong-Chen Date: Wed, 27 Sep 2023 09:55:46 +0800 Subject: [PATCH 1/6] add ignore zero anchor parameter for skip no matches in batch search --- jcvi/compara/catalog.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/jcvi/compara/catalog.py b/jcvi/compara/catalog.py index 80488cc2..eb8e4749 100644 --- a/jcvi/compara/catalog.py +++ b/jcvi/compara/catalog.py @@ -666,6 +666,12 @@ def ortholog(args): dotplot_group.add_option( "--no_dotplot", default=False, action="store_true", help="Do not make dotplot" ) + p.add_option( + "--ignore_zero_anchor", + default=False, + action="store_true", + help="Ignore this pair of ortholog identification instead of throwing an error when performing many pairs of cataloging." + ) opts, args = p.parse_args(args) @@ -674,6 +680,7 @@ def ortholog(args): a, b = args dbtype = opts.dbtype + ignore_zero_anchor = opts.ignore_zero_anchor suffix = ".cds" if dbtype == "nucl" else ".pep" abed, afasta = a + ".bed", a + suffix bbed, bfasta = b + ".bed", b + suffix @@ -727,7 +734,15 @@ def ortholog(args): dargs += ["--no_strip_names"] if opts.liftover_dist: dargs += ["--liftover_dist={}".format(opts.liftover_dist)] - scan(dargs) + try: + scan(dargs) + except ValueError as e: + if ignore_zero_anchor: + logging.debug(f"{e}") + logging.debug("Ignoring this error and continuing...") + return + else: + raise ValueError(e) if quota: quota_main([lifted_anchors, "--quota={0}".format(quota), "--screen"]) if need_update(anchors, pdf, warn=True) and not opts.no_dotplot: From 1e1fbd21b61d92f4e811440daed3d455817ff27b Mon Sep 17 00:00:00 2001 From: Tong-Chen Date: Sat, 18 Nov 2023 22:18:43 +0800 Subject: [PATCH 2/6] ignore blank line in bed --- jcvi/formats/bed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jcvi/formats/bed.py b/jcvi/formats/bed.py index df791837..c80ee54c 100755 --- a/jcvi/formats/bed.py +++ b/jcvi/formats/bed.py @@ -151,7 +151,7 @@ def __init__(self, filename=None, key=None, sorted=True, juncs=False, include=No return for line in must_open(filename): - if line[0] == "#" or (juncs and line.startswith("track name")): + if line[0] == "#" or (juncs and line.startswith("track name")) or line.strip()=="": continue b = BedLine(line) if include and b.accn not in include: From be4ea21e4e6b7392f289927bf422f746037b2f52 Mon Sep 17 00:00:00 2001 From: Tong-Chen Date: Wed, 22 Nov 2023 10:00:05 +0800 Subject: [PATCH 3/6] set label/chr size in layout file --- jcvi/graphics/synteny.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/jcvi/graphics/synteny.py b/jcvi/graphics/synteny.py index 5df591af..065bdc40 100644 --- a/jcvi/graphics/synteny.py +++ b/jcvi/graphics/synteny.py @@ -79,7 +79,10 @@ def __init__(self, row, delimiter=","): self.label = args[7].strip() else: self.label = None - + if len(args) > 8: + self.label_fontsize = float(args[8]) + else: + self.label_fontsize = 10 class Layout(AbstractLayout): def __init__(self, filename, delimiter=",", seed: Optional[int] = None): @@ -352,13 +355,13 @@ def __init__( loc_label = label if loc_label else None if chr_label: if loc_label: - ax.text(lx, ly + vpad, chr_label, color=layout.color, **kwargs) + ax.text(lx, ly + vpad, chr_label, size=layout.label_fontsize, color=layout.color, **kwargs) ax.text( lx, ly - vpad, loc_label, color="lightslategrey", - size=10, + size=layout.label_fontsize, **kwargs, ) else: From eef86469aef56b925ef5168330d9db8121e2ec67 Mon Sep 17 00:00:00 2001 From: Tong-Chen Date: Wed, 22 Nov 2023 11:08:34 +0800 Subject: [PATCH 4/6] add genelabel rotation (customize x and y for rotation with angle 0) --- jcvi/graphics/synteny.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jcvi/graphics/synteny.py b/jcvi/graphics/synteny.py index 065bdc40..bb209cdc 100644 --- a/jcvi/graphics/synteny.py +++ b/jcvi/graphics/synteny.py @@ -196,6 +196,7 @@ def __init__( loc_label=True, gene_labels: Optional[set] = None, genelabelsize=0, + genelabelrotation=25, pad=0.05, vpad=0.015, extra_features=None, @@ -280,7 +281,7 @@ def __init__( y + height / 2 + genelabelsize * vpad / 3, markup(gene_name), size=genelabelsize, - rotation=25, + rotation=genelabelrotation, ha="left", va="center", color="lightslategray", @@ -602,6 +603,13 @@ def main(): + "However, plot may appear visually crowded. " + "Reasonably good values are 2 to 6 [Default: disabled]", ) + p.add_option( + "--genelabelrotation", + default=25, + type="int", + help="Rotate gene labels at this angle (anti-clockwise), useful for debugging. " + + "[Default: 25]", + ) p.add_option( "--scalebar", default=False, @@ -650,6 +658,7 @@ def main(): extra_features=opts.extra, gene_labels=gene_labels, genelabelsize=opts.genelabelsize, + genelabelrotation=opts.genelabelrotation, scalebar=opts.scalebar, shadestyle=opts.shadestyle, glyphstyle=opts.glyphstyle, From e8f9f0a75022e6eca5911e25c8c25c35f08470e5 Mon Sep 17 00:00:00 2001 From: Tong-Chen Date: Thu, 30 Nov 2023 14:59:57 +0800 Subject: [PATCH 5/6] add customize x y for genelabelrotation 0; add --outputprefix for customized output --- jcvi/graphics/synteny.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/jcvi/graphics/synteny.py b/jcvi/graphics/synteny.py index bb209cdc..841f26ba 100644 --- a/jcvi/graphics/synteny.py +++ b/jcvi/graphics/synteny.py @@ -276,9 +276,15 @@ def __init__( ) gp.set_transform(tr) if genelabelsize and (not gene_labels or gene_name in gene_labels): + if genelabelrotation == 0: + text_x = x1 if x1>x2 else x2 + text_y = y + else: + text_x = (x1 + x2) / 2 + text_y = y + height / 2 + genelabelsize * vpad / 3 ax.text( - (x1 + x2) / 2, - y + height / 2 + genelabelsize * vpad / 3, + text_x, + text_y, markup(gene_name), size=genelabelsize, rotation=genelabelrotation, @@ -406,6 +412,7 @@ def __init__( loc_label=True, gene_labels: Optional[set] = None, genelabelsize=0, + genelabelrotation=25, pad=0.05, vpad=0.015, scalebar=False, @@ -465,6 +472,7 @@ def __init__( switch, gene_labels=gene_labels, genelabelsize=genelabelsize, + genelabelrotation=genelabelrotation, chr_label=chr_label, loc_label=loc_label, vpad=vpad, @@ -634,6 +642,11 @@ def main(): choices=Shade.Styles, help="Style of syntenic wedges", ) + p.add_option( + "--outputprefix", + default="", + help="Prefix for the output file.", + ) opts, args, iopts = p.set_image_options(figsize="8x7") if len(args) != 3: @@ -670,6 +683,9 @@ def main(): root.set_ylim(0, 1) root.set_axis_off() + outputprefix=opts.outputprefix + if outputprefix: + pf = outputprefix image_name = pf + "." + iopts.format savefig(image_name, dpi=iopts.dpi, iopts=iopts) From 824a6009a6fd2c87ee47bbcd6b880e8ae0bcbf70 Mon Sep 17 00:00:00 2001 From: Haibao Tang Date: Thu, 30 Nov 2023 02:22:32 -0800 Subject: [PATCH 6/6] Reverting some changes when I messed up the "Resolving Conflicts" step --- jcvi/graphics/synteny.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jcvi/graphics/synteny.py b/jcvi/graphics/synteny.py index d76969b5..a6b49637 100644 --- a/jcvi/graphics/synteny.py +++ b/jcvi/graphics/synteny.py @@ -91,7 +91,6 @@ def __init__(self, row, delimiter=","): self.label_fontsize = 10 - class Layout(AbstractLayout): """ Parse the layout file. @@ -297,8 +296,8 @@ def __init__( gp.set_transform(tr) if genelabelsize and (not gene_labels or gene_name in gene_labels): if genelabelrotation == 0: - text_x = x1 if x1>x2 else x2 - text_y = y + text_x = x1 if x1 > x2 else x2 + text_y = y else: text_x = (x1 + x2) / 2 text_y = y + height / 2 + genelabelsize * vpad / 3 @@ -374,6 +373,7 @@ def __init__( chr_label = markup(chrom) if chr_label else None loc_label = label if loc_label else None if chr_label: + if loc_label: ax.text( lx, ly + vpad, @@ -670,7 +670,7 @@ def main(): p.add_option( "--outputprefix", default="", - help="Prefix for the output file.", + help="Prefix for the output file", ) opts, args, iopts = p.set_image_options(figsize="8x7") @@ -708,7 +708,7 @@ def main(): root.set_ylim(0, 1) root.set_axis_off() - outputprefix=opts.outputprefix + outputprefix = opts.outputprefix if outputprefix: pf = outputprefix image_name = pf + "." + iopts.format