py2ls 0.2.4.1__py3-none-any.whl → 0.2.4.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py2ls/plot.py CHANGED
@@ -10,13 +10,15 @@ from cycler import cycler
10
10
  import logging
11
11
  import os
12
12
  import re
13
- from typing import List, Optional, Union
14
- from .ips import fsave, fload, mkdir, listdir, figsave, strcmp, unique, get_os, ssplit
13
+ from typing import Union
14
+ from .ips import fsave, fload, mkdir, listdir, figsave, strcmp, unique, get_os, ssplit,plt_font
15
15
  from .stats import *
16
16
  from .netfinder import get_soup, fetch
17
17
 
18
18
  # Suppress INFO messages from fontTools
19
- logging.getLogger("fontTools").setLevel(logging.WARNING)
19
+ logging.getLogger("fontTools").setLevel(logging.ERROR)
20
+ logging.getLogger('matplotlib').setLevel(logging.ERROR)
21
+
20
22
 
21
23
 
22
24
  def add_text(ax=None, height_offset=0.5, fmt=".1f", **kwargs):
@@ -1862,8 +1864,10 @@ def figsets(*args, **kwargs):
1862
1864
  matplotlib.rc("text", usetex=False)
1863
1865
 
1864
1866
  fig = plt.gcf()
1865
- fontsize = 11
1866
- fontname = "Arial"
1867
+ fontsize = kwargs.get("fontsize",11)
1868
+ plt.rcParams["font.size"]=fontsize
1869
+ fontname = kwargs.pop("fontname","Arial")
1870
+ fontname=plt_font(fontname) # 显示中文
1867
1871
  sns_themes = ["white", "whitegrid", "dark", "darkgrid", "ticks"]
1868
1872
  sns_contexts = ["notebook", "talk", "poster"] # now available "paper"
1869
1873
  scienceplots_styles = [
@@ -1889,6 +1893,7 @@ def figsets(*args, **kwargs):
1889
1893
  ]
1890
1894
 
1891
1895
  def set_step_1(ax, key, value):
1896
+ nonlocal fontsize, fontname
1892
1897
  if ("fo" in key) and (("size" in key) or ("sz" in key)):
1893
1898
  fontsize = value
1894
1899
  plt.rcParams.update({"font.size": fontsize})
@@ -1931,15 +1936,15 @@ def figsets(*args, **kwargs):
1931
1936
  if ("x" in key.lower()) and (
1932
1937
  "tic" not in key.lower() and "tk" not in key.lower()
1933
1938
  ):
1934
- ax.set_xlabel(value, fontname=fontname)
1939
+ ax.set_xlabel(value, fontname=fontname,fontsize=fontsize)
1935
1940
  if ("y" in key.lower()) and (
1936
1941
  "tic" not in key.lower() and "tk" not in key.lower()
1937
1942
  ):
1938
- ax.set_ylabel(value, fontname=fontname)
1943
+ ax.set_ylabel(value, fontname=fontname,fontsize=fontsize)
1939
1944
  if ("z" in key.lower()) and (
1940
1945
  "tic" not in key.lower() and "tk" not in key.lower()
1941
1946
  ):
1942
- ax.set_zlabel(value, fontname=fontname)
1947
+ ax.set_zlabel(value, fontname=fontname,fontsize=fontsize)
1943
1948
  if key == "xlabel" and isinstance(value, dict):
1944
1949
  ax.set_xlabel(**value)
1945
1950
  if key == "ylabel" and isinstance(value, dict):
@@ -2142,6 +2147,7 @@ def figsets(*args, **kwargs):
2142
2147
  plt.set_cmap(value)
2143
2148
 
2144
2149
  def set_step_2(ax, key, value):
2150
+ nonlocal fontsize, fontname
2145
2151
  if key == "figsize":
2146
2152
  pass
2147
2153
  if "xlim" in key.lower():
@@ -2181,9 +2187,9 @@ def figsets(*args, **kwargs):
2181
2187
  ax.grid(visible=False)
2182
2188
  if "tit" in key.lower():
2183
2189
  if "sup" in key.lower():
2184
- plt.suptitle(value)
2190
+ plt.suptitle(value,fontname=fontname,fontsize=fontsize)
2185
2191
  else:
2186
- ax.set_title(value)
2192
+ ax.set_title(value,fontname=fontname,fontsize=fontsize)
2187
2193
  if key.lower() in ["spine", "adjust", "ad", "sp", "spi", "adj", "spines"]:
2188
2194
  if isinstance(value, bool) or (value in ["go", "do", "ja", "yes"]):
2189
2195
  if value:
@@ -2919,7 +2925,7 @@ def plot_xy(
2919
2925
  x=None,
2920
2926
  y=None,
2921
2927
  ax=None,
2922
- kind: Union(str, list) = None, # Specify the kind of plot
2928
+ kind: Union[str, list] = None, # Specify the kind of plot
2923
2929
  verbose=False,
2924
2930
  **kwargs,
2925
2931
  ):
@@ -2933,7 +2939,7 @@ def plotxy(
2933
2939
  x=None,
2934
2940
  y=None,
2935
2941
  ax=None,
2936
- kind: Union(str, list) = None, # Specify the kind of plot
2942
+ kind: Union[str, list] = None, # Specify the kind of plot
2937
2943
  verbose=False,
2938
2944
  **kwargs,
2939
2945
  ):
@@ -3111,6 +3117,8 @@ def plotxy(
3111
3117
  ax = sns.barplot(data=data, x=x, y=y, ax=ax, **kws_bar)
3112
3118
  elif k == "countplot":
3113
3119
  kws_count = kwargs.pop("kws_count", kwargs)
3120
+ if not kws_count.get("hue",None):
3121
+ kws_count.pop("palette",None)
3114
3122
  ax = sns.countplot(data=data, x=x, ax=ax, **kws_count)
3115
3123
  elif k == "regplot":
3116
3124
  kws_reg = kwargs.pop("kws_reg", kwargs)
@@ -3123,6 +3131,7 @@ def plotxy(
3123
3131
  ax = sns.lineplot(ax=ax, data=data, x=x, y=y, **kws_line)
3124
3132
 
3125
3133
  figsets(ax=ax, **kws_figsets)
3134
+ print(kws_add_text)
3126
3135
  add_text(ax=ax, **kws_add_text) if kws_add_text else None
3127
3136
  print(k, " ⤵ ")
3128
3137
  print(default_settings[k])
@@ -3138,14 +3147,14 @@ def plotxy(
3138
3147
 
3139
3148
 
3140
3149
  def volcano(
3141
- data,
3142
- x,
3143
- y,
3150
+ data:pd.DataFrame,
3151
+ x:str,
3152
+ y:str,
3144
3153
  gene_col=None,
3145
- top_genes=5,
3154
+ top_genes=[5, 5], # [down-regulated, up-regulated]
3146
3155
  thr_x=np.log2(1.5),
3147
3156
  thr_y=-np.log10(0.05),
3148
- colors=("#e70b0b", "#0d26e3", "#b8bbbe"),
3157
+ colors=("#00BFFF", "#9d9a9a", "#FF3030"),
3149
3158
  s=20,
3150
3159
  fill=True, # plot filled scatter
3151
3160
  facecolor="none",
@@ -3155,8 +3164,12 @@ def volcano(
3155
3164
  legend=False,
3156
3165
  ax=None,
3157
3166
  verbose=False,
3158
- kws_arrow=None,
3159
- kws_text=None,
3167
+ kws_text=dict(fontsize=10, color="k"),
3168
+ kws_bbox=dict(facecolor='none',
3169
+ alpha=0.5,
3170
+ edgecolor='black',
3171
+ boxstyle='round,pad=0.3'),# '{}' to hide
3172
+ kws_arrow={},
3160
3173
  **kwargs,
3161
3174
  ):
3162
3175
  """
@@ -3172,7 +3185,7 @@ def volcano(
3172
3185
  Column name for y-axis values (e.g., -log10(FDR)).
3173
3186
  gene_col : str, optional
3174
3187
  Column name for gene names. If provided, gene names will be displayed. Default is None.
3175
- top_genes : int, optional
3188
+ top_genes : int, list, optional
3176
3189
  Number of top genes to label based on y-axis values. Default is 5.
3177
3190
  thr_x : float, optional
3178
3191
  Threshold for x-axis values. Default is 0.585.
@@ -3232,14 +3245,22 @@ def volcano(
3232
3245
  colors[2],
3233
3246
  np.where((data[x] < -thr_x) & (data[y] > thr_y), colors[0], colors[1]),
3234
3247
  )
3248
+ top_genes=[top_genes, top_genes] if isinstance(top_genes,int) else top_genes
3249
+
3250
+ down_reg_genes = data[
3251
+ (data["color"] == colors[0]) &
3252
+ (data[x].abs() > thr_x) &
3253
+ (data[y] > thr_y)
3254
+ ].sort_values(by=[y, x], ascending=[False, True]).head(top_genes[0])
3255
+
3256
+ # Selecting top upregulated genes based on both p-value and fold change
3257
+ up_reg_genes = data[
3258
+ (data["color"] == colors[2]) &
3259
+ (data[x].abs() > thr_x) &
3260
+ (data[y] > thr_y)
3261
+ ].sort_values(by=[y, x], ascending=[False, False]).head(top_genes[1])
3262
+ sele_gene = pd.concat([down_reg_genes, up_reg_genes])
3235
3263
 
3236
- # Selecting top significant points for labeling
3237
- sele_gene = (
3238
- data.query("color != @colors[2]") # Exclude gray points
3239
- .groupby("color", axis=0)
3240
- .apply(lambda x: x.sort_values(y, ascending=False).head(top_genes))
3241
- .droplevel(level=0)
3242
- )
3243
3264
  palette = {colors[0]: colors[0], colors[1]: colors[1], colors[2]: colors[2]}
3244
3265
  # Plot setup
3245
3266
  if ax is None:
@@ -3270,9 +3291,9 @@ def volcano(
3270
3291
  )
3271
3292
 
3272
3293
  # Add threshold lines for x and y axes
3273
- plt.axhline(y=thr_y, color="black", linestyle="--")
3274
- plt.axvline(x=-thr_x, color="black", linestyle="--")
3275
- plt.axvline(x=thr_x, color="black", linestyle="--")
3294
+ ax.axhline(y=thr_y, color="black", linestyle="--",lw=1)
3295
+ ax.axvline(x=-thr_x, color="black", linestyle="--",lw=1)
3296
+ ax.axvline(x=thr_x, color="black", linestyle="--",lw=1)
3276
3297
 
3277
3298
  # Add gene labels for selected significant points
3278
3299
  if gene_col:
@@ -3281,56 +3302,62 @@ def volcano(
3281
3302
  fontname = kws_text.pop("fontname", "Arial")
3282
3303
  textcolor = kws_text.pop("color", "k")
3283
3304
  fontsize = kws_text.pop("fontsize", 10)
3284
- for i in range(sele_gene.shape[0]):
3285
- if isinstance(textcolor, list): # be consistant with dots's color
3286
- textcolor = colors[0] if sele_gene[x].iloc[i] > 0 else colors[1]
3287
- texts.append(
3288
- plt.text(
3289
- x=sele_gene[x].iloc[i],
3290
- y=sele_gene[y].iloc[i],
3291
- s=sele_gene[gene_col].iloc[i],
3292
- fontdict={
3293
- "fontsize": fontsize,
3294
- "color": textcolor,
3295
- "fontname": fontname,
3296
- },
3305
+ arrowstyles = [
3306
+ "->","<-","<->","<|-","-|>","<|-|>",
3307
+ "-","-[","-[",
3308
+ "fancy","simple","wedge",
3309
+ ]
3310
+ arrowstyle = kws_arrow.pop("style", "<|-")
3311
+ arrowstyle = strcmp(arrowstyle, arrowstyles,scorer='strict')[0]
3312
+ expand=kws_arrow.pop("expand",(1.05,1.1))
3313
+ arrowcolor = kws_arrow.pop("color", "0.4")
3314
+ arrowlinewidth = kws_arrow.pop("lw", 0.75)
3315
+ shrinkA = kws_arrow.pop("shrinkA", 0)
3316
+ shrinkB = kws_arrow.pop("shrinkB", 0)
3317
+ mutation_scale = kws_arrow.pop("head", 10)
3318
+ arrow_fill=kws_arrow.pop("fill", False)
3319
+ for i in range(sele_gene.shape[0]):
3320
+ if isinstance(textcolor, list): # be consistant with dots's color
3321
+ textcolor = colors[0] if sele_gene[x].iloc[i] > 0 else colors[1]
3322
+ texts.append(
3323
+ ax.text(
3324
+ x=sele_gene[x].iloc[i],
3325
+ y=sele_gene[y].iloc[i],
3326
+ s=sele_gene[gene_col].iloc[i],
3327
+ bbox=kws_bbox if kws_bbox else None,
3328
+ fontdict={
3329
+ "fontsize": fontsize,
3330
+ "color": textcolor,
3331
+ "fontname": fontname,
3332
+ },
3333
+ )
3334
+ )
3335
+ print(arrowstyle)
3336
+ adjust_text(
3337
+ texts,
3338
+ expand=expand,
3339
+ min_arrow_len=5,
3340
+ # force_explode=(0.1, 0.5),
3341
+ # force_text=(0.1, 0.5),
3342
+ # force_points=(0.1, 0.5),
3343
+ # explode_radius=10,
3344
+ # expand_text=(1, 1),
3345
+ # expand_points=(1, 1),
3346
+ # ha='center',
3347
+ # va='top',
3348
+ ax=ax,
3349
+ arrowprops=dict(
3350
+ arrowstyle=arrowstyle,
3351
+ fill=arrow_fill,
3352
+ color=arrowcolor,
3353
+ lw=arrowlinewidth,
3354
+ shrinkA=shrinkA,
3355
+ shrinkB=shrinkB,
3356
+ mutation_scale=mutation_scale,
3357
+ **kws_arrow,
3297
3358
  )
3298
3359
  )
3299
3360
 
3300
- arrowstyles = [
3301
- "-",
3302
- "->",
3303
- "-[",
3304
- "|->",
3305
- "<-",
3306
- "<->",
3307
- "<|-",
3308
- "<|-|>",
3309
- "-|>",
3310
- "-[ ",
3311
- "fancy",
3312
- "simple",
3313
- "wedge",
3314
- ]
3315
- arrowstyle = kws_arrow.pop("style", "-")
3316
- arrowcolor = kws_arrow.pop("color", "0.5")
3317
- arrowlinewidth = kws_arrow.pop("lw", 0.5)
3318
- shrinkA = kws_arrow.pop("shrinkA", 5)
3319
- shrinkB = kws_arrow.pop("shrinkB", 5)
3320
- arrowstyle = strcmp(arrowstyle, arrowstyles)[0]
3321
- adjust_text(
3322
- texts,
3323
- expand_text=(1.05, 1.2),
3324
- arrowprops=dict(
3325
- arrowstyle=arrowstyle,
3326
- color=arrowcolor,
3327
- lw=arrowlinewidth,
3328
- shrinkA=shrinkA,
3329
- shrinkB=shrinkB,
3330
- **kws_arrow,
3331
- ),
3332
- )
3333
-
3334
3361
  figsets(**kws_figsets)
3335
3362
 
3336
3363
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.2.4.1
3
+ Version: 0.2.4.3
4
4
  Summary: py(thon)2(too)ls
5
5
  Author: Jianfeng
6
6
  Author-email: Jianfeng.Liu0413@gmail.com
@@ -173,6 +173,7 @@ py2ls/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
173
173
  py2ls/README.md,sha256=CwvJWAnSXnCnrVHlnEbrxxi6MbjbE_MT6DH2D53S818,11572
174
174
  py2ls/__init__.py,sha256=Nn8jTIvySX7t7DMJ8VNRVctTStgXGjHldOIdZ35PdW8,165
175
175
  py2ls/batman.py,sha256=E7gYofbDzN7S5oCmO_dd5Z1bxxhoYMJSD6s-VaF388E,11398
176
+ py2ls/bio.py,sha256=FnEf4RV4LBUQfLefWIpIFszVRYeXjnRlc5261DINIdg,18835
176
177
  py2ls/brain_atlas.py,sha256=w1o5EelRjq89zuFJUNSz4Da8HnTCwAwDAZ4NU4a-bAY,5486
177
178
  py2ls/chat.py,sha256=Yr22GoIvoWhpV3m4fdwV_I0Mn77La346_ymSinR-ORA,3793
178
179
  py2ls/correlators.py,sha256=RbOaJIPLCHJtUm5SFi_4dCJ7VFUPWR0PErfK3K26ad4,18243
@@ -203,23 +204,24 @@ py2ls/data/styles/style6.json,sha256=tu-MYOT9x5Rorc-2IK6sy-J-frmz0RNdm65XAsDQKX4
203
204
  py2ls/data/styles/style7.json,sha256=StdUFwIVrS7T_6CDrADHMorzc0WZFWBM7IyYdO1TPHg,4447
204
205
  py2ls/data/styles/style8.json,sha256=8XUgkZtew8ebvjbAHlDHCSWUqNra3ktDvMCO4vNh-CM,4456
205
206
  py2ls/data/styles/style9.json,sha256=PLxvntbH_kfzZlnCTtCEAUVBGi5m6Lngb9C01rArQog,4769
206
- py2ls/data/usages_pd.json,sha256=A76y7lr28BUBdggFN_50r-4My3Q51M_3y0ZcQ4LHSco,15077
207
+ py2ls/data/usages_pd copy.json,sha256=cS2fYSKvSC274uAw1l6eMPGzLMvZt184dfbcuUiErmw,197313
208
+ py2ls/data/usages_pd.json,sha256=4DgbPahF4G5Hd6G0TQurb6dBRVey67lpKdgK6A01Tww,266818
207
209
  py2ls/data/usages_sns.json,sha256=3OTu6T7n9HbQaFkz-UPMJ_9-Ug6Xjf7q5aDIvZ_6cHk,9246
208
210
  py2ls/db2ls.py,sha256=MMfFX47aIPIyu7fU9aPvX9lbPRPYOpJ_VXwlnWk-8qo,13615
209
211
  py2ls/doc.py,sha256=xN3g1OWfoaGUhikbJ0NqbN5eKy1VZVvWwRlhHMgyVEc,4243
210
212
  py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,2325
211
- py2ls/fetch_update.py,sha256=jh2MQHREpCqzYhDmEnMpuIvQVf4_wD9pDdIziXoFE3E,4055
213
+ py2ls/fetch_update.py,sha256=9LXj661GpCEFII2wx_99aINYctDiHni6DOruDs_fdt8,4752
212
214
  py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
213
215
  py2ls/ich2ls.py,sha256=3E9R8oVpyYZXH5PiIQgT3CN5NxLe4Dwtm2LwaeacE6I,21381
214
- py2ls/ips.py,sha256=fBBco8wQFc6u4KxJ32xwrMh1SZeNz4o8ohiUB5WMKOs,199755
216
+ py2ls/ips.py,sha256=yYSpbHIGDfLK2SXtTX4f--H5oa885pggXePEbhiNRsw,220887
215
217
  py2ls/netfinder.py,sha256=LwBkGITB_4BTNtY6RlKdEZVFW6epzMWlnqy2g03KtyU,56117
216
218
  py2ls/ocr.py,sha256=5lhUbJufIKRSOL6wAWVLEo8TqMYSjoI_Q-IO-_4u3DE,31419
217
- py2ls/plot.py,sha256=m8SxFSS1ogwRNQ-O9l-BJWqjGPmjGbsegU56kXG0krw,135132
219
+ py2ls/plot.py,sha256=B_npRfO2rZJJjcYSQ7YMZt2LZTG0mU08JCDnM6zAVx4,136956
218
220
  py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
219
221
  py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
220
222
  py2ls/stats.py,sha256=DMoJd8Z5YV9T1wB-4P52F5K5scfVK55DT8UP4Twcebo,38627
221
223
  py2ls/translator.py,sha256=zBeq4pYZeroqw3DT-5g7uHfVqKd-EQptT6LJ-Adi8JY,34244
222
224
  py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
223
- py2ls-0.2.4.1.dist-info/METADATA,sha256=xxXfqGzklXZ1eGESjgYcm1ptiKIRl_Nk0AlfUIyYSIU,20038
224
- py2ls-0.2.4.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
225
- py2ls-0.2.4.1.dist-info/RECORD,,
225
+ py2ls-0.2.4.3.dist-info/METADATA,sha256=S4Il5phQ0Vx8U7VrlEUopkX-hfwcKKQi-qkfD2EYI1g,20038
226
+ py2ls-0.2.4.3.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
227
+ py2ls-0.2.4.3.dist-info/RECORD,,