Skip to content

Commit e0dd713

Browse files
author
zhangrengang
committed
fix bug: black when Ks values are unified
1 parent 169b187 commit e0dd713

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

soi/OrthoFinder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,10 @@ def get_blast(self, sps=None):
932932
if sps is None:
933933
spIds = list(d_sp.values())
934934
else:
935-
spIds = [d_sp[sp] for sp in sps]
935+
nofound = [sp for sp in sps if sp not in d_sp]
936+
if nofound:
937+
print('{} is not found'.format(nofound), file=sys.stderr)
938+
spIds = [d_sp.get(sp) for sp in sps if sp in d_sp]
936939
spIds = sorted(spIds)
937940
for sp1, sp2 in itertools.product(spIds, spIds):
938941
blast = '{}/Blast{}_{}.txt.gz'.format(

soi/dot_plotter.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
mpl.use("Agg")
1515
mpl.rcParams['pdf.fonttype'] = 42
16+
#mpl.rcParams['image.antialiased'] = False
1617

1718
from .RunCmdsMP import logger
1819
from .WGDI import AK
@@ -99,7 +100,7 @@ def dotplot_args(parser):
99100
help="basic font size of labels [default=%(default)s]")
100101
group_dot.add_argument('--cfont_scale', metavar='NUM', type=float, default=0.8,
101102
help="scaling factor for font size of chromosome labels [default=%(default)s]")
102-
group_dot.add_argument('--dotsize', metavar='NUM', type=float, default=1, dest='point_size',
103+
group_dot.add_argument('--dotsize', metavar='NUM', type=float, default=5, dest='point_size',
103104
help="dot size [default=%(default)s]")
104105

105106
group_orth = parser.add_argument_group('Orthology Index filter/color',
@@ -346,6 +347,7 @@ def plot_blocks(blocks, outplots, ks=None, max_ks=None, ks_hist=False, ks_cmap=N
346347
ymin, ymax = 0, ylim
347348
xmin, xmax = 0, xlim
348349

350+
349351
if ks is not None:
350352
try:
351353
min_ks = min([v for v in Ks if v >= 0])
@@ -361,7 +363,9 @@ def plot_blocks(blocks, outplots, ks=None, max_ks=None, ks_hist=False, ks_cmap=N
361363
kXs += [None, None] # points not plot
362364
kYs += [None, None]
363365
Ks += [0, max_ks] # unify the scale
364-
plt.scatter(kXs, kYs, marker=',', s=point_size, c=Ks, cmap=cmap, rasterized=True,)
366+
plt.scatter(kXs, kYs, marker=',', s=point_size, c=Ks, cmap=cmap,
367+
rasterized=True, edgecolors='none',linewidths=0,
368+
)
365369
if same_sp:
366370
plt.plot((xmin, xmax), (ymin, ymax), ls='--',
367371
color="grey", linewidth=0.8)
@@ -504,7 +508,7 @@ def plot_blocks(blocks, outplots, ks=None, max_ks=None, ks_hist=False, ks_cmap=N
504508
logger.info('Output figures: {}'.format(outplots))
505509
logging.disable()
506510
for outplot in outplots:
507-
plt.savefig(outplot, bbox_inches='tight', dpi=400) # transparent=True
511+
plt.savefig(outplot, bbox_inches='tight', dpi=400, transparent=True) # transparent=True
508512

509513
# x/y ~ Ks
510514
if plot_bin:

soi/mcscan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def identify_orthologous_blocks(collinearities=None, orthologs=None, fout=sys.st
640640
divide(self.retained_oi, self.post_ng)]
641641
tp, fp = self.retained_oi, self.removed_oi,
642642
tn, fn = self.pre_ng-self.post_ng, self.post_ng - self.retained_oi
643-
recall = tp/(tp+fn)
644-
precision = tp/(tp+fp)
643+
recall = tp/(tp+fn) if tp+fn > 0 else None
644+
precision = tp/(tp+fp) if tp+fp > 0 else None
645645
line += [precision, recall]
646646
print('\t'.join(map(str, line)), file=out_stats)
647647
out_stats.close()

soi/ploidy_plotter.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,17 @@ def plot_fold(collinearity, gff, ref, qry, **kargs):
116116
**kargs)
117117
data += [np.array(sorted(d_fold.items()))]
118118
#print(sp, sorted(d_fold.items()))
119-
return plot_bars(data, **kargs)
119+
return plot_bars(data, ref=ref, **kargs)
120120

121121

122122
def plot_bars(data, titles, ax=None, outfigs=None, nrow=1, ncol=1, fontsize=10,
123123
suptitle=None, max_ploidy=10, color='white', edgecolor='black',
124124
ylabel='Number of windows', xlabel='Synteny depth',
125-
output_depth=None, mode='w',
125+
output_depth=None, mode='w', ref=None,
126126
**kargs):
127127
if output_depth:
128-
save_depth_table(data, titles, output_depth=output_depth, mode=mode, max_ploidy=max_ploidy)
128+
save_depth_table(data, titles, output_depth=output_depth,
129+
mode=mode, max_ploidy=max_ploidy, ref=ref)
129130
if ax is None:
130131
if nrow*ncol == 1:
131132
ax = plt.subplot(111)
@@ -161,12 +162,12 @@ def plot_bars(data, titles, ax=None, outfigs=None, nrow=1, ncol=1, fontsize=10,
161162
plt.savefig(outfig)
162163
else:
163164
return ax
164-
def save_depth_table(data, titles, output_depth=None, mode='w', max_ploidy=10):
165+
def save_depth_table(data, titles, ref=None, output_depth=None, mode='w', max_ploidy=10):
165166
"""
166167
每行一个物种,列为不同深度 (1 to max_ploidy)
167168
"""
168169
# 1. 构建表头: Species, 1, 2, 3, ..., 10+
169-
header = ["Species"] + [str(i) for i in range(1, max_ploidy)] + [f"{max_ploidy}+"]
170+
header = ['Reference', "Query"] + [str(i) for i in range(1, max_ploidy)] + [f"{max_ploidy}+"]
170171

171172
rows = [header]
172173

@@ -183,14 +184,14 @@ def save_depth_table(data, titles, output_depth=None, mode='w', max_ploidy=10):
183184
counts[depth] += count
184185

185186
# 构造当前行:物种名 + 各深度的计数
186-
row = [species] + [str(counts[p]) for p in range(1, max_ploidy + 1)]
187+
row = [str(ref), species] + [str(counts[p]) for p in range(1, max_ploidy + 1)]
187188
rows.append(row)
188189

189190
# 3. 拼接为 TSV 文本
190191
output_text = "\n".join(["\t".join(row) for row in rows]) + "\n"
191192

192193
# 4. 输出
193-
if output_depth:
194+
if output_depth and output_depth != 'stdout':
194195
with open(output_depth, mode=mode, encoding='utf-8') as f:
195196
f.write(output_text)
196197
else:

0 commit comments

Comments
 (0)