dspin 1.3.4__tar.gz → 1.3.5__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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: dspin
3
- Version: 1.3.4
3
+ Version: 1.3.5
4
4
  Summary: Regulatory network models from single-cell perturbation profiling
5
5
  Home-page: https://github.com/JialongJiang/DSPIN
6
6
  Author: Jialong Jiang
@@ -25,6 +25,18 @@ Requires-Dist: scanpy
25
25
  Requires-Dist: tqdm
26
26
  Requires-Dist: igraph
27
27
  Requires-Dist: leidenalg
28
+ Dynamic: author
29
+ Dynamic: author-email
30
+ Dynamic: classifier
31
+ Dynamic: description
32
+ Dynamic: description-content-type
33
+ Dynamic: home-page
34
+ Dynamic: keywords
35
+ Dynamic: license
36
+ Dynamic: license-file
37
+ Dynamic: requires-dist
38
+ Dynamic: requires-python
39
+ Dynamic: summary
28
40
 
29
41
  # D-SPIN: Constructing regulatory network models from scRNA-seq perturbation profiling
30
42
 
@@ -609,9 +609,9 @@ class ProgramDSPIN(AbstractDSPIN):
609
609
  Parameters for discretization of the oNMF representation. Default is an empty dictionary.
610
610
  """
611
611
 
612
- if mode not in ['compute_summary', 'compute_only', 'summary_only']:
612
+ if mode not in ['compute_summary', 'compute_only', 'summary_only', 'precomputed']:
613
613
  raise ValueError(
614
- 'Mode must be one of compute_summary, compute_only, or summary_only')
614
+ 'Mode must be one of compute_summary, compute_only, summary_only, or precomputed.')
615
615
 
616
616
  adata = self.adata
617
617
  num_spin = self.num_spin
@@ -631,7 +631,7 @@ class ProgramDSPIN(AbstractDSPIN):
631
631
 
632
632
  if onmf_parameters['num_subsample_large'] is None:
633
633
  onmf_parameters['num_subsample_large'] = min(onmf_parameters['num_subsample'] * 5, adata.shape[0])
634
- print(onmf_parameters['num_subsample_large'])
634
+ # print(onmf_parameters['num_subsample_large'])
635
635
 
636
636
  if onmf_parameters['balance_method'] not in ['equal', 'proportional', 'squareroot', None]:
637
637
  raise ValueError('balance_method must be one of equal, proportional, squareroot, or None')
@@ -681,7 +681,7 @@ class ProgramDSPIN(AbstractDSPIN):
681
681
 
682
682
  compute_onmf_decomposition(sub_gene_matrix_normed, num_onmf_components, seed=cur_seed, params=onmf_parameters, save_path=self.save_path + f'onmf/onmf_components_{num_onmf_components}_repeat_{cur_seed}.npy')
683
683
 
684
- if mode == 'compute_summary' or mode == 'summary_only':
684
+ if mode == 'compute_summary' or mode == 'summary_only' or mode == 'precomputed':
685
685
 
686
686
  cluster_label_raw = adata.obs[cluster_key].values
687
687
  cluster_label = pd.factorize(cluster_label_raw)[0]
@@ -689,18 +689,28 @@ class ProgramDSPIN(AbstractDSPIN):
689
689
  # Perform subsampling and standard deviation clipping on the matrix
690
690
  std_clipped, sub_large_gene_matrix_normed = subsample_normalize_gene_matrix(adata.X, cluster_label, num_subsample=onmf_parameters['num_subsample_large'], seed=seed, params=onmf_parameters)
691
691
  self.matrix_std = std_clipped
692
-
693
- # Summarize the oNMF decompositions
694
- if num_onmf_components > 0:
695
- onmf_summary = self.summarize_onmf_result(sub_large_gene_matrix_normed, num_onmf_components, num_repeat)
692
+
693
+ if mode != 'precomputed':
694
+ # Summarize the oNMF decompositions
695
+ if num_onmf_components > 0:
696
+ onmf_summary = self.summarize_onmf_result(sub_large_gene_matrix_normed, num_onmf_components, num_repeat)
697
+ else:
698
+ onmf_summary = self.compute_onmf_expression(sub_large_gene_matrix_normed, prior_program_ind)
699
+
700
+ onmf_save_path = self.save_path + f'onmf/onmf_summary_total_{num_spin}_onmf_{num_onmf_components}_prior_{len(prior_program_ind)}.npy'
701
+ np.save(onmf_save_path, onmf_summary)
702
+ print(f"Consensus oNMF results saved to {onmf_save_path}")
696
703
  else:
697
- onmf_summary = self.compute_onmf_expression(sub_large_gene_matrix_normed, prior_program_ind)
704
+ assert 'precomputed_onmf_path' in params.keys(), "For precomputed mode, 'precomputed_onmf_path' must be provided in params."
705
+ onmf_summary = np.load(params['precomputed_onmf_path'], allow_pickle=True).item()
698
706
 
699
707
  self._onmf_summary = onmf_summary
700
708
 
701
709
  # Save the gene programs to a CSV file
702
710
  file_path = onmf_to_csv(onmf_summary.components_, adata.var_names, self.save_path + f'gene_programs_total_{num_spin}_onmf_{num_onmf_components}_prior_{len(prior_program_ind)}.csv', thres=0.01)
703
- print('Gene programs saved to {}'.format(file_path))
711
+ print('Gene program information saved to {}'.format(file_path))
712
+ file_wpath = onmf_to_csv(onmf_summary.components_, adata.var_names, self.save_path + f'gene_programs_total_{num_spin}_onmf_{num_onmf_components}_prior_{len(prior_program_ind)}_weights.csv', thres=0.01, if_write_weights=True)
713
+ # print('Gene programs saved to {}'.format(file_path))
704
714
  self.gene_program_csv = file_path
705
715
 
706
716
  gene_matrix = self.adata.X
@@ -21,7 +21,7 @@ from scipy import optimize
21
21
  from scipy.spatial.distance import pdist
22
22
 
23
23
 
24
- def onmf_to_csv(features, gene_name, file_path, thres=0.01):
24
+ def onmf_to_csv(features, gene_name, file_path, thres=0.01, if_write_weights=False):
25
25
  """
26
26
  Extract gene names in ONMF to CSV.
27
27
 
@@ -30,6 +30,7 @@ def onmf_to_csv(features, gene_name, file_path, thres=0.01):
30
30
  gene_name (List[str]): Names of the genes corresponding to feature indices.
31
31
  file_path (str): Path of the file where the CSV will be written.
32
32
  thres (float): Threshold value for filtering features.
33
+ if_write_weights (bool): If True, writes weights to the CSV file.
33
34
 
34
35
  Returns:
35
36
  str: Path of the created CSV file.
@@ -51,6 +52,11 @@ def onmf_to_csv(features, gene_name, file_path, thres=0.01):
51
52
  cur_line.insert(0, spin)
52
53
  write.writerow(cur_line) # Write the current line to the CSV file
53
54
 
55
+ if if_write_weights:
56
+ cur_line = [features[spin, ind].round(6) for ind in gene_ind]
57
+ cur_line.insert(0, f'Weights_{spin}')
58
+ write.writerow(cur_line)
59
+
54
60
  # Read the created CSV, transpose it and save it again
55
61
  pd_csv = pd.read_csv(file_path, names=range(rec_max_gene + 1))
56
62
  pd_csv = pd_csv.transpose()
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: dspin
3
- Version: 1.3.4
3
+ Version: 1.3.5
4
4
  Summary: Regulatory network models from single-cell perturbation profiling
5
5
  Home-page: https://github.com/JialongJiang/DSPIN
6
6
  Author: Jialong Jiang
@@ -25,6 +25,18 @@ Requires-Dist: scanpy
25
25
  Requires-Dist: tqdm
26
26
  Requires-Dist: igraph
27
27
  Requires-Dist: leidenalg
28
+ Dynamic: author
29
+ Dynamic: author-email
30
+ Dynamic: classifier
31
+ Dynamic: description
32
+ Dynamic: description-content-type
33
+ Dynamic: home-page
34
+ Dynamic: keywords
35
+ Dynamic: license
36
+ Dynamic: license-file
37
+ Dynamic: requires-dist
38
+ Dynamic: requires-python
39
+ Dynamic: summary
28
40
 
29
41
  # D-SPIN: Constructing regulatory network models from scRNA-seq perturbation profiling
30
42
 
@@ -21,7 +21,7 @@ install_requires = [
21
21
  # ]
22
22
 
23
23
  # Managing your version (adjust accordingly)
24
- version = "1.3.4" # You can manage versioning in a more sophisticated way if needed
24
+ version = "1.3.5" # You can manage versioning in a more sophisticated way if needed
25
25
 
26
26
  # Long description (usually a README file)
27
27
  readme = open("README_PyPI.md").read() # Adjust the file name if necessary
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes