|
1 | 1 | """Generate figures for the RISE tutorial documentation.""" |
| 2 | + |
2 | 3 | import matplotlib |
3 | | -matplotlib.use('Agg') # Non-interactive backend |
| 4 | + |
| 5 | +matplotlib.use("Agg") # Non-interactive backend |
4 | 6 | import matplotlib.pyplot as plt |
5 | 7 | from pathlib import Path |
6 | 8 |
|
|
13 | 15 | from RISE.figures.commonFuncs.plotGeneral import plot_r2x |
14 | 16 | from RISE.figures.figureS4 import plot_fms_diff_ranks |
15 | 17 | from RISE.factorization import pf2 |
16 | | -from RISE.figures.commonFuncs.plotFactors import plot_condition_factors, plot_eigenstate_factors, plot_gene_factors |
17 | | -from RISE.figures.commonFuncs.plotPaCMAP import plot_labels_pacmap, plot_gene_pacmap, plot_wp_pacmap |
| 18 | +from RISE.figures.commonFuncs.plotFactors import ( |
| 19 | + plot_condition_factors, |
| 20 | + plot_eigenstate_factors, |
| 21 | + plot_gene_factors, |
| 22 | +) |
| 23 | +from RISE.figures.commonFuncs.plotPaCMAP import ( |
| 24 | + plot_labels_pacmap, |
| 25 | + plot_gene_pacmap, |
| 26 | + plot_wp_pacmap, |
| 27 | +) |
18 | 28 |
|
19 | 29 | print("Loading dataset...") |
20 | 30 | X = import_thomson() |
|
25 | 35 | fig, ax = plt.subplots(figsize=(5, 5)) |
26 | 36 | plot_r2x(X, ranks, ax) |
27 | 37 | plt.tight_layout() |
28 | | -plt.savefig(output_dir / "step2_r2x.png", dpi=150, bbox_inches='tight') |
| 38 | +plt.savefig(output_dir / "step2_r2x.png", dpi=150, bbox_inches="tight") |
29 | 39 | plt.close() |
30 | 40 |
|
31 | 41 | # Figure 2: Factor Match Score |
32 | 42 | print("Generating Figure 2: FMS plot...") |
33 | 43 | fig, ax = plt.subplots(figsize=(5, 5)) |
34 | 44 | plot_fms_diff_ranks(X, ax, ranksList=list(ranks), runs=3) |
35 | 45 | plt.tight_layout() |
36 | | -plt.savefig(output_dir / "step3_fms.png", dpi=150, bbox_inches='tight') |
| 46 | +plt.savefig(output_dir / "step3_fms.png", dpi=150, bbox_inches="tight") |
37 | 47 | plt.close() |
38 | 48 |
|
39 | 49 | # Perform RISE factorization |
|
46 | 56 | fig, ax = plt.subplots(figsize=(8, 8)) |
47 | 57 | plot_condition_factors(X, ax=ax, cond="Condition", log_transform=True) |
48 | 58 | plt.tight_layout() |
49 | | -plt.savefig(output_dir / "step5_condition_factors.png", dpi=150, bbox_inches='tight') |
| 59 | +plt.savefig(output_dir / "step5_condition_factors.png", dpi=150, bbox_inches="tight") |
50 | 60 | plt.close() |
51 | 61 |
|
52 | 62 | # Figure 4: Cell Embedding |
53 | 63 | print("Generating Figure 4: Cell embedding...") |
54 | 64 | fig, ax = plt.subplots(figsize=(8, 8)) |
55 | 65 | plot_labels_pacmap(X, labelType="Cell Type", ax=ax) |
56 | 66 | plt.tight_layout() |
57 | | -plt.savefig(output_dir / "step6_cell_embedding.png", dpi=150, bbox_inches='tight') |
| 67 | +plt.savefig(output_dir / "step6_cell_embedding.png", dpi=150, bbox_inches="tight") |
58 | 68 | plt.close() |
59 | 69 |
|
60 | 70 | # Figure 5: Eigen-state Factors |
|
63 | 73 | plot_eigenstate_factors(X, ax=ax) |
64 | 74 | plt.ylabel("Eigen-state") |
65 | 75 | plt.tight_layout() |
66 | | -plt.savefig(output_dir / "step7_eigenstate_factors.png", dpi=150, bbox_inches='tight') |
| 76 | +plt.savefig(output_dir / "step7_eigenstate_factors.png", dpi=150, bbox_inches="tight") |
67 | 77 | plt.close() |
68 | 78 |
|
69 | 79 | # Figure 6: Gene Factors |
70 | 80 | print("Generating Figure 6: Gene factors...") |
71 | 81 | fig, ax = plt.subplots(figsize=(7, 8)) |
72 | 82 | plot_gene_factors(X, ax=ax, weight=0.2, trim=True) |
73 | 83 | plt.tight_layout() |
74 | | -plt.savefig(output_dir / "step8_gene_factors.png", dpi=150, bbox_inches='tight') |
| 84 | +plt.savefig(output_dir / "step8_gene_factors.png", dpi=150, bbox_inches="tight") |
75 | 85 | plt.close() |
76 | 86 |
|
77 | 87 | # Figure 7: Gene Expression on PaCMAP |
|
80 | 90 | gene = "MS4A1" |
81 | 91 | plot_gene_pacmap(gene, X, ax=ax, clip_outliers=0.9995) |
82 | 92 | plt.tight_layout() |
83 | | -plt.savefig(output_dir / "step9_gene_expression.png", dpi=150, bbox_inches='tight') |
| 93 | +plt.savefig(output_dir / "step9_gene_expression.png", dpi=150, bbox_inches="tight") |
84 | 94 | plt.close() |
85 | 95 |
|
86 | 96 | # Figure 8: Weighted Projections |
87 | 97 | print("Generating Figure 8: Weighted projections...") |
88 | 98 | fig, ax = plt.subplots(figsize=(8, 8)) |
89 | 99 | plot_wp_pacmap(X, cmp=10, ax=ax, cbarMax=0.9) |
90 | 100 | plt.tight_layout() |
91 | | -plt.savefig(output_dir / "step10_weighted_projections.png", dpi=150, bbox_inches='tight') |
| 101 | +plt.savefig( |
| 102 | + output_dir / "step10_weighted_projections.png", dpi=150, bbox_inches="tight" |
| 103 | +) |
92 | 104 | plt.close() |
93 | 105 |
|
94 | 106 | print(f"\nAll figures saved to {output_dir}") |
|
0 commit comments