gsMap3D 0.1.0a1__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.
- gsMap/__init__.py +13 -0
- gsMap/__main__.py +4 -0
- gsMap/cauchy_combination_test.py +342 -0
- gsMap/cli.py +355 -0
- gsMap/config/__init__.py +72 -0
- gsMap/config/base.py +296 -0
- gsMap/config/cauchy_config.py +79 -0
- gsMap/config/dataclasses.py +235 -0
- gsMap/config/decorators.py +302 -0
- gsMap/config/find_latent_config.py +276 -0
- gsMap/config/format_sumstats_config.py +54 -0
- gsMap/config/latent2gene_config.py +461 -0
- gsMap/config/ldscore_config.py +261 -0
- gsMap/config/quick_mode_config.py +242 -0
- gsMap/config/report_config.py +81 -0
- gsMap/config/spatial_ldsc_config.py +334 -0
- gsMap/config/utils.py +286 -0
- gsMap/find_latent/__init__.py +3 -0
- gsMap/find_latent/find_latent_representation.py +312 -0
- gsMap/find_latent/gnn/distribution.py +498 -0
- gsMap/find_latent/gnn/encoder_decoder.py +186 -0
- gsMap/find_latent/gnn/gcn.py +85 -0
- gsMap/find_latent/gnn/gene_former.py +164 -0
- gsMap/find_latent/gnn/loss.py +18 -0
- gsMap/find_latent/gnn/st_model.py +125 -0
- gsMap/find_latent/gnn/train_step.py +177 -0
- gsMap/find_latent/st_process.py +781 -0
- gsMap/format_sumstats.py +446 -0
- gsMap/generate_ldscore.py +1018 -0
- gsMap/latent2gene/__init__.py +18 -0
- gsMap/latent2gene/connectivity.py +781 -0
- gsMap/latent2gene/entry_point.py +141 -0
- gsMap/latent2gene/marker_scores.py +1265 -0
- gsMap/latent2gene/memmap_io.py +766 -0
- gsMap/latent2gene/rank_calculator.py +590 -0
- gsMap/latent2gene/row_ordering.py +182 -0
- gsMap/latent2gene/row_ordering_jax.py +159 -0
- gsMap/ldscore/__init__.py +1 -0
- gsMap/ldscore/batch_construction.py +163 -0
- gsMap/ldscore/compute.py +126 -0
- gsMap/ldscore/constants.py +70 -0
- gsMap/ldscore/io.py +262 -0
- gsMap/ldscore/mapping.py +262 -0
- gsMap/ldscore/pipeline.py +615 -0
- gsMap/pipeline/quick_mode.py +134 -0
- gsMap/report/__init__.py +2 -0
- gsMap/report/diagnosis.py +375 -0
- gsMap/report/report.py +100 -0
- gsMap/report/report_data.py +1832 -0
- gsMap/report/static/js_lib/alpine.min.js +5 -0
- gsMap/report/static/js_lib/tailwindcss.js +83 -0
- gsMap/report/static/template.html +2242 -0
- gsMap/report/three_d_combine.py +312 -0
- gsMap/report/three_d_plot/three_d_plot_decorate.py +246 -0
- gsMap/report/three_d_plot/three_d_plot_prepare.py +202 -0
- gsMap/report/three_d_plot/three_d_plots.py +425 -0
- gsMap/report/visualize.py +1409 -0
- gsMap/setup.py +5 -0
- gsMap/spatial_ldsc/__init__.py +0 -0
- gsMap/spatial_ldsc/io.py +656 -0
- gsMap/spatial_ldsc/ldscore_quick_mode.py +912 -0
- gsMap/spatial_ldsc/spatial_ldsc_jax.py +382 -0
- gsMap/spatial_ldsc/spatial_ldsc_multiple_sumstats.py +439 -0
- gsMap/utils/__init__.py +0 -0
- gsMap/utils/generate_r2_matrix.py +610 -0
- gsMap/utils/jackknife.py +518 -0
- gsMap/utils/manhattan_plot.py +643 -0
- gsMap/utils/regression_read.py +177 -0
- gsMap/utils/torch_utils.py +23 -0
- gsmap3d-0.1.0a1.dist-info/METADATA +168 -0
- gsmap3d-0.1.0a1.dist-info/RECORD +74 -0
- gsmap3d-0.1.0a1.dist-info/WHEEL +4 -0
- gsmap3d-0.1.0a1.dist-info/entry_points.txt +2 -0
- gsmap3d-0.1.0a1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Main entry point for the latent2gene subpackage
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import yaml
|
|
10
|
+
from rich.console import Console
|
|
11
|
+
from rich.panel import Panel
|
|
12
|
+
|
|
13
|
+
from gsMap.config import LatentToGeneConfig
|
|
14
|
+
|
|
15
|
+
from .marker_scores import MarkerScoreCalculator
|
|
16
|
+
from .memmap_io import MemMapDense
|
|
17
|
+
from .rank_calculator import RankCalculator
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
console = Console()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def run_latent_to_gene(config: LatentToGeneConfig) -> dict[str, Any]:
|
|
24
|
+
"""
|
|
25
|
+
Main entry point for latent to gene conversion
|
|
26
|
+
|
|
27
|
+
This function orchestrates the complete pipeline:
|
|
28
|
+
1. Calculate ranks and concatenate latent representations
|
|
29
|
+
2. Calculate marker scores for each cell type
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
config: LatentToGeneConfig object with all necessary parameters
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Dictionary with paths to all outputs:
|
|
36
|
+
- concatenated_latent_adata: Path to concatenated latent representations
|
|
37
|
+
- rank_memmap: Path to rank memory map file
|
|
38
|
+
- mean_frac: Path to mean expression fraction
|
|
39
|
+
- marker_scores: Path to marker scores memory map
|
|
40
|
+
- metadata: Path to metadata YAML file
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
# Setup output directory using config paths
|
|
44
|
+
output_dir = Path(config.latent2gene_dir)
|
|
45
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
46
|
+
|
|
47
|
+
# Check if all outputs already exist using config paths
|
|
48
|
+
expected_outputs = {
|
|
49
|
+
"concatenated_latent_adata": Path(config.concatenated_latent_adata_path),
|
|
50
|
+
"rank_memmap": Path(config.rank_memmap_path),
|
|
51
|
+
"mean_frac": Path(config.mean_frac_path),
|
|
52
|
+
"marker_scores": Path(config.marker_scores_memmap_path),
|
|
53
|
+
"metadata": Path(config.latent2gene_metadata_path),
|
|
54
|
+
"rank_meta": Path(config.rank_memmap_path).with_suffix('.meta.json'),
|
|
55
|
+
"marker_scores_meta": Path(config.marker_scores_memmap_path).with_suffix('.meta.json')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if all(Path(p).exists() for p in expected_outputs.values()):
|
|
59
|
+
logger.info("All outputs already exist. Checking completion status...")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# Check rank memmap completion using the new class method
|
|
63
|
+
rank_memmap_complete, rank_meta = MemMapDense.check_complete(expected_outputs["rank_memmap"])
|
|
64
|
+
if not rank_memmap_complete:
|
|
65
|
+
if rank_meta:
|
|
66
|
+
logger.warning("Rank memmap exists but is not marked as complete")
|
|
67
|
+
else:
|
|
68
|
+
logger.warning("Could not read rank memmap metadata")
|
|
69
|
+
|
|
70
|
+
# Check marker scores memmap completion using the new class method
|
|
71
|
+
marker_scores_complete, marker_meta = MemMapDense.check_complete(expected_outputs["marker_scores"])
|
|
72
|
+
if not marker_scores_complete:
|
|
73
|
+
if marker_meta:
|
|
74
|
+
logger.warning("Marker scores memmap exists but is not marked as complete")
|
|
75
|
+
else:
|
|
76
|
+
logger.warning("Could not read marker scores memmap metadata")
|
|
77
|
+
|
|
78
|
+
if rank_memmap_complete and marker_scores_complete:
|
|
79
|
+
logger.info("All memory maps are properly completed. Loading metadata...")
|
|
80
|
+
with open(expected_outputs["metadata"]) as f:
|
|
81
|
+
existing_metadata = yaml.unsafe_load(f)
|
|
82
|
+
logger.info(f"Found existing complete results for {existing_metadata.get('n_cells', 'unknown')} cells "
|
|
83
|
+
f"and {existing_metadata.get('n_genes', 'unknown')} genes")
|
|
84
|
+
return {k: str(v) for k, v in expected_outputs.items()}
|
|
85
|
+
else:
|
|
86
|
+
logger.warning("Memory maps exist but are not properly completed. Re-running pipeline...")
|
|
87
|
+
|
|
88
|
+
# Step 1: Calculate ranks and concatenate
|
|
89
|
+
console.print(Panel(
|
|
90
|
+
"[bold cyan]Step 1: Rank calculation and concatenation[/bold cyan]",
|
|
91
|
+
border_style="cyan"
|
|
92
|
+
))
|
|
93
|
+
|
|
94
|
+
rank_calculator = RankCalculator(config)
|
|
95
|
+
|
|
96
|
+
# Use sample_h5ad_dict from config (already validated in config.__post_init__)
|
|
97
|
+
logger.info(f"Found {len(config.sample_h5ad_dict)} samples to process")
|
|
98
|
+
|
|
99
|
+
rank_outputs = rank_calculator.calculate_ranks_and_concatenate(
|
|
100
|
+
sample_h5ad_dict=config.sample_h5ad_dict,
|
|
101
|
+
annotation_key=config.annotation,
|
|
102
|
+
data_layer=config.data_layer,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# Step 2: Calculate marker scores
|
|
106
|
+
console.print(Panel(
|
|
107
|
+
"[bold cyan]Step 2: Marker score calculation[/bold cyan]",
|
|
108
|
+
border_style="cyan"
|
|
109
|
+
))
|
|
110
|
+
|
|
111
|
+
marker_calculator = MarkerScoreCalculator(config)
|
|
112
|
+
|
|
113
|
+
marker_scores_path = marker_calculator.calculate_marker_scores(
|
|
114
|
+
adata_path=rank_outputs["concatenated_latent_adata"],
|
|
115
|
+
rank_memmap_path=rank_outputs["rank_memmap"],
|
|
116
|
+
mean_frac_path=rank_outputs["mean_frac"],
|
|
117
|
+
output_path=expected_outputs["marker_scores"]
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Convert config to dict with all Path objects as strings
|
|
121
|
+
config_dict = config.to_dict_with_paths_as_strings()
|
|
122
|
+
|
|
123
|
+
# Create overall metadata
|
|
124
|
+
metadata = {
|
|
125
|
+
"config": config_dict,
|
|
126
|
+
"outputs": {
|
|
127
|
+
"concatenated_latent_adata": str(rank_outputs["concatenated_latent_adata"]),
|
|
128
|
+
"rank_memmap": str(rank_outputs["rank_memmap"]),
|
|
129
|
+
"mean_frac": str(rank_outputs["mean_frac"]),
|
|
130
|
+
"marker_scores": str(marker_scores_path)
|
|
131
|
+
},
|
|
132
|
+
"n_sections": len(config.sample_h5ad_dict)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
# Save overall metadata in YAML format
|
|
136
|
+
with open(expected_outputs["metadata"], 'w') as f:
|
|
137
|
+
yaml.dump(metadata, f, default_flow_style=False, sort_keys=False)
|
|
138
|
+
|
|
139
|
+
logger.info(f"All outputs saved to: {output_dir}")
|
|
140
|
+
|
|
141
|
+
return metadata["outputs"]
|