From 288b05d2770dab8b6c2d59aff35ca68e481f4a8d Mon Sep 17 00:00:00 2001 From: zhangrengang Date: Thu, 24 Oct 2024 13:53:47 +0800 Subject: [PATCH] fix bug; support Proteinortho6 --- README.md | 1 + soi/colors.py | 18 +++++++++++++----- soi/evaluator.py | 2 +- soi/mcscan.py | 4 +++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 15affaa..3ed0dfe 100644 --- a/README.md +++ b/README.md @@ -396,6 +396,7 @@ Tetracendron_sinense|Tesin01G0062600 Trochodendron_aralioides|evm.TU.group9.7 #### Orthology format #### The outputs from [OrthoFinder2](https://github.com/davidemms/OrthoFinder), OrthoMCL, +[Proteinortho6](https://gitlab.com/paulklemm_PHD/proteinortho), [Broccoli](https://github.com/rderelle/Broccoli), [SonicParanoid2](https://gitlab.com/salvo981/sonicparanoid2) are supported: ``` # OrthoFinder2 output directory like: diff --git a/soi/colors.py b/soi/colors.py index 5133e9d..bbd79c6 100644 --- a/soi/colors.py +++ b/soi/colors.py @@ -2,6 +2,7 @@ #from reportlab.lib import colors import numpy as np from matplotlib import cm +from matplotlib import colors import matplotlib COLORS_HEX = ['#f9c00c', '#00b9f1', '#7200da', '#f9320c', '#00b8a9', "#F4A460", '#009999', '#00C02E', @@ -20,8 +21,9 @@ def __init__(self, colors_hex=None): self.colors_hex = colors_hex @property def colors_rgb(self): - colors_lst = [colors.HexColor(v) for v in self.colors_hex] - return [','.join(map(str, v.bitmap_rgb())) for v in colors_lst] +# colors_lst = [colors.HexColor(v) for v in self.colors_hex] +# return [','.join(map(str, v.bitmap_rgb())) for v in colors_lst] + return [hex2rgb(v) for v in self.colors_hex] @property def colors_r(self): return 'c({})'.format(','.join(map(repr, self.colors_hex))) @@ -30,6 +32,11 @@ def __str__(self): def __repr__(self): return str(self.colors_hex) +def hex2rgb(Hex): + rgb = colors.to_rgb(Hex) + rgb255 = ','.join(map(str, [int(v*255) for v in rgb])) + return rgb255 + class Colors: def __init__(self, n): self.n = n @@ -48,9 +55,10 @@ def to_hex(self): colors_hex = [matplotlib.colors.to_hex(c) for c in self.colors] return colors_hex def to_rgb(self): - colors_hex = self.to_hex() - colors_lst = [colors.HexColor(v) for v in colors_hex] - colors_rgb = [','.join(map(str, v.bitmap_rgb())) for v in colors_lst] +# colors_hex = self.to_hex() +# colors_lst = [colors.HexColor(v) for v in colors_hex] +# colors_rgb = [','.join(map(str, v.bitmap_rgb())) for v in colors_lst] + colors_rgb = [hex2rgb(v) for v in self.colors] return colors_rgb diff --git a/soi/evaluator.py b/soi/evaluator.py index c351507..1a297c3 100644 --- a/soi/evaluator.py +++ b/soi/evaluator.py @@ -106,7 +106,7 @@ def plot_eval(d_rcs, outfig, legend_fontsize=9): ncols = n // 30 + 1 ax0.set_xlim(0,1) ax0.set_ylim(0,1) - ax0.legend(loc=(-1.5, 0),fancybox=False, frameon=False, ncols=ncols) + ax0.legend(loc=(-1.5, 0),fancybox=False, frameon=False, ncols=ncols) # ax0.xaxis.set_tick_params(length=0) ax0.spines['right'].set_color('none') ax0.spines['top'].set_color('none') diff --git a/soi/mcscan.py b/soi/mcscan.py index b4426ff..cb9740f 100644 --- a/soi/mcscan.py +++ b/soi/mcscan.py @@ -1127,7 +1127,7 @@ def slim_tandem(tandem, pairs, outPairs): pair.write(outPairs) def split_pair(line, sep=None, parser=None): - pair = tuple(line.rstrip().split(sep, 1)) + pair = tuple(line.rstrip().split(sep)) # 1 return parser(*pair) class CommonPair(object): @@ -1186,6 +1186,8 @@ def __iter__(self): def _parse(self): for line in open(self.pairs): line = lazy_decode(line) + if line.startswith('#'): # comments + continue yield split_pair(line, self.sep, self.parser) def graph(self): G = nx.Graph()