PyOVERCAST 1.0.13__tar.gz → 1.0.15__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyOVERCAST
3
- Version: 1.0.13
3
+ Version: 1.0.15
4
4
  Summary: A Python package for mining key transcription factors from transcriptome data.
5
5
  Author-email: Tinghua Huang <thua45@126.com>
6
6
  License-Expression: MIT
@@ -14,6 +14,7 @@ plt.rcParams['axes.unicode_minus'] = False # 解决负号显示问题
14
14
  import multiprocessing as mp
15
15
  import seaborn as sns
16
16
  from scipy import stats
17
+ from scipy.stats import false_discovery_control
17
18
  import random
18
19
 
19
20
  overcast_data_dir = './OVERCAST_data'
@@ -104,7 +105,7 @@ def Z_to_frame(Z):
104
105
  return df
105
106
 
106
107
  def compute_dtci_core(df, x_col='x', y_col='y', z_col='z',
107
- c=1.0, alpha=1.0, beta_w=0.5, gamma=1.0):
108
+ c=1.0, alpha=1.0, beta_w=0.5, gamma=1.0, m=2.0):
108
109
  """
109
110
  核心DTCI计算 —— 使用 statsmodels.OLS
110
111
 
@@ -127,6 +128,7 @@ def compute_dtci_core(df, x_col='x', y_col='y', z_col='z',
127
128
  # 使用 statsmodels.OLS(自动处理常数项、标准误和p值)
128
129
  X_design = sm.add_constant(pd.DataFrame({'x': x, 'y': y, 'xy': xy}))
129
130
  model = sm.OLS(z, X_design).fit()
131
+ rmse = np.sqrt(model.mse_resid)
130
132
 
131
133
  # 提取系数 [const, x, y, xy]
132
134
  beta_hat = model.params.values
@@ -143,7 +145,16 @@ def compute_dtci_core(df, x_col='x', y_col='y', z_col='z',
143
145
  z_std = np.std(z, ddof=1)
144
146
 
145
147
  # 子指标
146
- DI = np.abs(beta3) / (np.abs(beta3) + c * z_std)
148
+ # DI = np.abs(beta3) / (np.abs(beta3) + c * z_std)
149
+ # RI: 翘起深度指数 —— 修正版 v4.0
150
+ # 信噪比 = 超额高度 / 纯噪声(残差标准差)
151
+ # SNR = h_diff / rmse if rmse > 1e-10 else 0.0
152
+ SNR = np.abs(beta3) / rmse if rmse > 1e-10 else 0.0
153
+ # Sigmoid 映射:SNR=m 时 RI=0.5,SNR 越大 RI 越接近1
154
+ if SNR > 0:
155
+ DI = 1.0 / (1.0 + np.exp(m - SNR))
156
+ else:
157
+ DI = 0.0
147
158
  SI = min(1.0, -np.log10(max(p_values[3], 1e-10)) / 10.0)
148
159
  QI = max(0.0, R2_adj)
149
160
 
@@ -706,6 +717,8 @@ def olcr_bootstrap(set_names=None, list_file=None, win=30, thread_n=16, bs_n=200
706
717
  results.append(rline)
707
718
  col_names = ['TF_motif', 'Beta3', 'Beta3_Pvalue', 'DTCI', 'DTCI_Pvalue', 'Rank_Score', 'Rank / N']
708
719
  df = pd.DataFrame(results, columns=col_names)
720
+ fdr = false_discovery_control(df['DTCI_Pvalue'], method='bh')
721
+ df.insert(loc=5, column='DTCI_FDR', value=fdr)
709
722
 
710
723
  return df
711
724
 
@@ -899,11 +912,13 @@ def plot_contour_graph(rrho_df, out_file=None):
899
912
  ax.set_title('Contour Graph of RRLO Matrix')
900
913
  # ax.set_aspect('equal')
901
914
  plt.tight_layout()
902
- #plt.savefig('contour_graph_invF.png', dpi=150)
903
- plt.show()
915
+ if out_file != None:
916
+ plt.savefig(out_file, dpi=150)
917
+ else:
918
+ plt.show()
904
919
 
905
920
 
906
- def plot_contour_plot(df1, df2, win):
921
+ def plot_contour_plot(df1, df2, win, out_file=None):
907
922
  gene_col1 = df1.columns[0]
908
923
  score_col1 = df1.columns[1]
909
924
  df1 = df1.sort_values(score_col1, ascending=False)
@@ -930,9 +945,9 @@ def plot_contour_plot(df1, df2, win):
930
945
 
931
946
  #beta_xy, pval_xy = td_coor(rrho_df.to_numpy())
932
947
  # df = Z_to_frame(rrho_df.to_numpy())
933
- plot_contour_graph(rrho_df)
948
+ plot_contour_graph(rrho_df, out_file=out_file)
934
949
 
935
- def plot_contour(set_names=['human_hocomoco_CLink_wtcoor_1w_0.8'], list_file='input_deg-list.txt', tf='NFKB1_HUMAN.H11MO.1.B', win=30, data_dir=None):
950
+ def plot_contour(set_names=['human_hocomoco_CLink_wtcoor_1w_0.8'], list_file='input_deg-list.txt', tf='NFKB1_HUMAN.H11MO.1.B', win=30, data_dir=None, out_file=None):
936
951
  if data_dir == None:
937
952
  data_dir = overcast_data_dir
938
953
  if not (os.path.exists(data_dir) and os.path.isdir(data_dir)):
@@ -958,10 +973,10 @@ def plot_contour(set_names=['human_hocomoco_CLink_wtcoor_1w_0.8'], list_file='in
958
973
  epsilon = 1e-15 # 常用值
959
974
  for i in range(tf_n):
960
975
  if tfbs_array[i][0] == tf:
961
- plot_contour_plot(deg_list, tfbs_array[i][1], win)
976
+ plot_contour_plot(deg_list, tfbs_array[i][1], win, out_file=out_file)
962
977
  break
963
978
 
964
- def plot_contour_permutation(set_names=['human_hocomoco_CLink_wtcoor_1w_0.8'], list_file='input_deg-list.txt', tf='NFKB1_HUMAN.H11MO.1.B', win=30, data_dir=None):
979
+ def plot_contour_permutation(set_names=['human_hocomoco_CLink_wtcoor_1w_0.8'], list_file='input_deg-list.txt', tf='NFKB1_HUMAN.H11MO.1.B', win=30, data_dir=None, out_file=None):
965
980
  if data_dir == None:
966
981
  data_dir = overcast_data_dir
967
982
  if not (os.path.exists(data_dir) and os.path.isdir(data_dir)):
@@ -988,7 +1003,7 @@ def plot_contour_permutation(set_names=['human_hocomoco_CLink_wtcoor_1w_0.8'], l
988
1003
  for i in range(tf_n):
989
1004
  if tfbs_array[i][0] == tf:
990
1005
  gene_set_pt, gene_list_pt = permutation(tfbs_array[i][1], deg_list)
991
- plot_contour_plot(gene_list_pt, gene_set_pt, win)
1006
+ plot_contour_plot(gene_list_pt, gene_set_pt, win, out_file=out_file)
992
1007
  # plot_contour_plot(deg_list, tfbs_array[i][1], win)
993
1008
  break
994
1009
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyOVERCAST
3
- Version: 1.0.13
3
+ Version: 1.0.15
4
4
  Summary: A Python package for mining key transcription factors from transcriptome data.
5
5
  Author-email: Tinghua Huang <thua45@126.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PyOVERCAST"
7
- version = "1.0.13"
7
+ version = "1.0.15"
8
8
  license = "MIT" # SPDX expression
9
9
  description = "A Python package for mining key transcription factors from transcriptome data."
10
10
  readme = "README.md"
File without changes
File without changes
File without changes