microarray 0.1.0__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.
Files changed (44) hide show
  1. microarray/__init__.py +15 -0
  2. microarray/_version.py +3 -0
  3. microarray/datasets/__init__.py +3 -0
  4. microarray/datasets/_arrayexpress.py +1 -0
  5. microarray/datasets/_cdf_files.py +35 -0
  6. microarray/datasets/_geo.py +1 -0
  7. microarray/datasets/_utils.py +143 -0
  8. microarray/io/__init__.py +17 -0
  9. microarray/io/_anndata_converter.py +198 -0
  10. microarray/io/_cdf.py +575 -0
  11. microarray/io/_cel.py +591 -0
  12. microarray/io/_read.py +127 -0
  13. microarray/plotting/__init__.py +28 -0
  14. microarray/plotting/_base.py +253 -0
  15. microarray/plotting/_cel.py +75 -0
  16. microarray/plotting/_de_plots.py +239 -0
  17. microarray/plotting/_diagnostic_plots.py +268 -0
  18. microarray/plotting/_heatmap.py +279 -0
  19. microarray/plotting/_ma_plots.py +136 -0
  20. microarray/plotting/_pca.py +320 -0
  21. microarray/plotting/_qc_plots.py +335 -0
  22. microarray/plotting/_score.py +38 -0
  23. microarray/plotting/_top_table_heatmap.py +98 -0
  24. microarray/plotting/_utils.py +280 -0
  25. microarray/preprocessing/__init__.py +39 -0
  26. microarray/preprocessing/_background.py +862 -0
  27. microarray/preprocessing/_log2.py +77 -0
  28. microarray/preprocessing/_normalize.py +1292 -0
  29. microarray/preprocessing/_rma.py +243 -0
  30. microarray/preprocessing/_robust.py +170 -0
  31. microarray/preprocessing/_summarize.py +318 -0
  32. microarray/py.typed +0 -0
  33. microarray/tools/__init__.py +26 -0
  34. microarray/tools/_biomart.py +416 -0
  35. microarray/tools/_empirical_bayes.py +401 -0
  36. microarray/tools/_fdist.py +171 -0
  37. microarray/tools/_linear_models.py +387 -0
  38. microarray/tools/_mds.py +101 -0
  39. microarray/tools/_pca.py +88 -0
  40. microarray/tools/_score.py +86 -0
  41. microarray/tools/_toptable.py +360 -0
  42. microarray-0.1.0.dist-info/METADATA +75 -0
  43. microarray-0.1.0.dist-info/RECORD +44 -0
  44. microarray-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,77 @@
1
+ import warnings
2
+
3
+ import numpy as np
4
+ from anndata import AnnData
5
+
6
+
7
+ def log2(
8
+ adata: AnnData,
9
+ copy: bool = False,
10
+ layer: str | None = None,
11
+ key_added: str | None = None,
12
+ ) -> AnnData | None:
13
+ """Apply log2 transformation to the data.
14
+
15
+ Parameters
16
+ ----------
17
+ adata : AnnData
18
+ Input AnnData object containing microarray data.
19
+ copy : bool, optional
20
+ Whether to return a new AnnData object or modify in place.
21
+ layer : str, optional
22
+ If specified, apply log2 transformation to the data in this layer instead of `adata.X`.
23
+ key_added : str, optional
24
+ Key to store the log2-transformed data in `adata.layers`.
25
+ If None, the transformation is applied directly to `adata.X`.
26
+
27
+ Returns:
28
+ -------
29
+ AnnData | None
30
+ Log2-transformed AnnData if `copy=True`, otherwise None.
31
+
32
+ Notes:
33
+ -----
34
+ This function checks if the data appears to be already log-transformed (e.g., if max value < 100) and issues a warning if so.
35
+ """
36
+ if _is_log_transformed(adata):
37
+ warnings.warn(
38
+ "Data appears to be already log-transformed. Skipping log2 transformation.",
39
+ UserWarning,
40
+ stacklevel=2,
41
+ )
42
+ return adata.copy() if copy else None
43
+
44
+ if copy:
45
+ adata = adata.copy()
46
+
47
+ X_to_transform = adata.layers[layer] if layer is not None else adata.X
48
+
49
+ if key_added is not None:
50
+ if key_added in adata.layers:
51
+ warnings.warn(
52
+ f"Layer '{key_added}' already exists and will be overwritten with log2-transformed data.",
53
+ UserWarning,
54
+ stacklevel=2,
55
+ )
56
+ adata.layers[key_added] = np.log2(X_to_transform + 1)
57
+ else:
58
+ adata.X = np.log2(X_to_transform + 1)
59
+
60
+ return adata if copy else None
61
+
62
+
63
+ def _is_log_transformed(adata: AnnData) -> bool:
64
+ """Heuristic check if data is already log-transformed.
65
+
66
+ Log-transformed microarray data typically has values mostly in the range [0, 20].
67
+ Raw intensities are typically in the range [1, 100000].
68
+ """
69
+ X = adata.X
70
+ max_val = np.max(X)
71
+ mean_val = np.mean(X)
72
+
73
+ # If max is relatively small and mean is in expected log range, likely log-transformed
74
+ if max_val < 30 and 3 < mean_val < 15:
75
+ return True
76
+
77
+ return False