spatialproteomics 0.4.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.
- spatialproteomics/__init__.py +95 -0
- spatialproteomics/base_logger.py +4 -0
- spatialproteomics/constants.py +178 -0
- spatialproteomics/container.py +71 -0
- spatialproteomics/ext/__init__.py +5 -0
- spatialproteomics/ext/external.py +445 -0
- spatialproteomics/la/__init__.py +5 -0
- spatialproteomics/la/label.py +626 -0
- spatialproteomics/la/utils.py +16 -0
- spatialproteomics/pl/__init__.py +10 -0
- spatialproteomics/pl/plot.py +1030 -0
- spatialproteomics/pl/spectra.py +192 -0
- spatialproteomics/pl/utils.py +127 -0
- spatialproteomics/pp/__init__.py +25 -0
- spatialproteomics/pp/intensity.py +201 -0
- spatialproteomics/pp/preprocessing.py +1062 -0
- spatialproteomics/pp/utils.py +261 -0
- spatialproteomics/tl/__init__.py +5 -0
- spatialproteomics/tl/gaussian.py +181 -0
- spatialproteomics-0.4.0.dist-info/LICENSE +21 -0
- spatialproteomics-0.4.0.dist-info/METADATA +22 -0
- spatialproteomics-0.4.0.dist-info/RECORD +23 -0
- spatialproteomics-0.4.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from .constants import (
|
|
2
|
+
Apricot,
|
|
3
|
+
Beige,
|
|
4
|
+
Black,
|
|
5
|
+
Blue,
|
|
6
|
+
Brown,
|
|
7
|
+
Cyan,
|
|
8
|
+
Dims,
|
|
9
|
+
Features,
|
|
10
|
+
Green,
|
|
11
|
+
Grey,
|
|
12
|
+
Lavender,
|
|
13
|
+
Layers,
|
|
14
|
+
Lime,
|
|
15
|
+
Magenta,
|
|
16
|
+
Maroon,
|
|
17
|
+
Mint,
|
|
18
|
+
Navy,
|
|
19
|
+
Olive,
|
|
20
|
+
Orange,
|
|
21
|
+
Pink,
|
|
22
|
+
Props,
|
|
23
|
+
Purple,
|
|
24
|
+
Red,
|
|
25
|
+
Teal,
|
|
26
|
+
White,
|
|
27
|
+
Yellow,
|
|
28
|
+
)
|
|
29
|
+
from .container import load_image_data
|
|
30
|
+
from .ext import ExternalAccessor
|
|
31
|
+
from .la import LabelAccessor
|
|
32
|
+
from .pl import PlotAccessor
|
|
33
|
+
from .pp import (
|
|
34
|
+
PreprocessingAccessor,
|
|
35
|
+
arcsinh_mean_intensity,
|
|
36
|
+
arcsinh_median_intensity,
|
|
37
|
+
arcsinh_sum_intensity,
|
|
38
|
+
arcsinh_var_intensity,
|
|
39
|
+
detect_peaks_num,
|
|
40
|
+
is_positive,
|
|
41
|
+
mean_intensity,
|
|
42
|
+
percentage_positive,
|
|
43
|
+
sum_intensity,
|
|
44
|
+
)
|
|
45
|
+
from .tl import TwoComponentGaussianMixture
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
"load_image_data",
|
|
49
|
+
"PreprocessingAccessor",
|
|
50
|
+
"LabelAccessor",
|
|
51
|
+
"PlotAccessor",
|
|
52
|
+
"SegmentationAccessor",
|
|
53
|
+
"ExternalAccessor",
|
|
54
|
+
"Layers",
|
|
55
|
+
"Dims",
|
|
56
|
+
"Features",
|
|
57
|
+
"Props",
|
|
58
|
+
"sum_intensity",
|
|
59
|
+
"mean_intensity",
|
|
60
|
+
"arcsinh_sum_intensity",
|
|
61
|
+
"arcsinh_mean_intensity",
|
|
62
|
+
"arcsinh_var_intensity",
|
|
63
|
+
"arcsinh_median_intensity",
|
|
64
|
+
"merge_segmentation",
|
|
65
|
+
"detect_peaks_num",
|
|
66
|
+
"percentage_positive",
|
|
67
|
+
"is_positive",
|
|
68
|
+
"TwoComponentGaussianMixture",
|
|
69
|
+
"Apricot",
|
|
70
|
+
"Beige",
|
|
71
|
+
"Black",
|
|
72
|
+
"Blue",
|
|
73
|
+
"Brown",
|
|
74
|
+
"Cyan",
|
|
75
|
+
"Dims",
|
|
76
|
+
"Features",
|
|
77
|
+
"Green",
|
|
78
|
+
"Grey",
|
|
79
|
+
"Lavender",
|
|
80
|
+
"Layers",
|
|
81
|
+
"Lime",
|
|
82
|
+
"Magenta",
|
|
83
|
+
"Maroon",
|
|
84
|
+
"Mint",
|
|
85
|
+
"Navy",
|
|
86
|
+
"Olive",
|
|
87
|
+
"Orange",
|
|
88
|
+
"Pink",
|
|
89
|
+
"Props",
|
|
90
|
+
"Purple",
|
|
91
|
+
"Red",
|
|
92
|
+
"Teal",
|
|
93
|
+
"White",
|
|
94
|
+
"Yellow",
|
|
95
|
+
]
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Red = "#e6194B"
|
|
2
|
+
Green = "#3cb44b"
|
|
3
|
+
Yellow = "#ffe119"
|
|
4
|
+
Blue = "#4363d8"
|
|
5
|
+
Orange = "#f58231"
|
|
6
|
+
Purple = "#911eb4"
|
|
7
|
+
Cyan = "#42d4f4"
|
|
8
|
+
Magenta = "#f032e6"
|
|
9
|
+
Lime = "#bfef45"
|
|
10
|
+
Pink = "#fabed4"
|
|
11
|
+
Teal = "#469990"
|
|
12
|
+
Lavender = "#dcbeff"
|
|
13
|
+
Brown = "#9A6324"
|
|
14
|
+
Beige = "#fffac8"
|
|
15
|
+
Maroon = "#800000"
|
|
16
|
+
Mint = "#aaffc3"
|
|
17
|
+
Olive = "#808000"
|
|
18
|
+
Apricot = "#ffd8b1"
|
|
19
|
+
Navy = "#000075"
|
|
20
|
+
Grey = "#a9a9a9"
|
|
21
|
+
White = "#ffffff"
|
|
22
|
+
Black = "#000000"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Layers(object):
|
|
26
|
+
IMAGE = "_image"
|
|
27
|
+
SEGMENTATION = "_segmentation"
|
|
28
|
+
COORDINATES = "_coordinates"
|
|
29
|
+
LABELS = "_labels"
|
|
30
|
+
DATA = "_data"
|
|
31
|
+
PLOT = "_plot"
|
|
32
|
+
OBS = "_obs"
|
|
33
|
+
NEIGHBORS = "_neighbors"
|
|
34
|
+
INTENSITY = "_intensity"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Dims(object):
|
|
38
|
+
CHANNELS = "channels"
|
|
39
|
+
X = "x"
|
|
40
|
+
Y = "y"
|
|
41
|
+
RGBA = "rgba"
|
|
42
|
+
CELLS = "cells"
|
|
43
|
+
COORDINATES = "coordinates"
|
|
44
|
+
LABELS = "labels"
|
|
45
|
+
FEATURES = "features"
|
|
46
|
+
PROPS = "props"
|
|
47
|
+
NEIGHBORS = "neighbors"
|
|
48
|
+
IMAGE = ["channels", "x", "y"]
|
|
49
|
+
COLORED_IMAGE = ["channels", "x", "y", "rgba"]
|
|
50
|
+
SEGMENTATION = ["x", "y"]
|
|
51
|
+
DATA = ["cell_idx", "channels"]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class Attrs(object):
|
|
55
|
+
IMAGE_COLORS = "image_colors"
|
|
56
|
+
LABEL_COLORS = "label_colors"
|
|
57
|
+
LABEL_NAMES = "label_names"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Props(object):
|
|
61
|
+
COLOR = "_color"
|
|
62
|
+
NAME = "_name"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class Features(object):
|
|
66
|
+
LABELS = "_labels"
|
|
67
|
+
X = "centroid-1"
|
|
68
|
+
Y = "centroid-0"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Labels(object):
|
|
72
|
+
UNLABELED = "Unlabeled"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
COLORS = [
|
|
76
|
+
"#FFFF00",
|
|
77
|
+
"#1CE6FF",
|
|
78
|
+
"#FF34FF",
|
|
79
|
+
"#FF4A46",
|
|
80
|
+
"#008941",
|
|
81
|
+
"#006FA6",
|
|
82
|
+
"#A30059",
|
|
83
|
+
"#FFDBE5",
|
|
84
|
+
"#7A4900",
|
|
85
|
+
"#0000A6",
|
|
86
|
+
"#63FFAC",
|
|
87
|
+
"#B79762",
|
|
88
|
+
"#004D43",
|
|
89
|
+
"#8FB0FF",
|
|
90
|
+
"#997D87",
|
|
91
|
+
"#5A0007",
|
|
92
|
+
"#809693",
|
|
93
|
+
"#6A3A4C",
|
|
94
|
+
"#1B4400",
|
|
95
|
+
"#4FC601",
|
|
96
|
+
"#3B5DFF",
|
|
97
|
+
"#4A3B53",
|
|
98
|
+
"#FF2F80",
|
|
99
|
+
"#61615A",
|
|
100
|
+
"#BA0900",
|
|
101
|
+
"#6B7900",
|
|
102
|
+
"#00C2A0",
|
|
103
|
+
"#FFAA92",
|
|
104
|
+
"#FF90C9",
|
|
105
|
+
"#B903AA",
|
|
106
|
+
"#D16100",
|
|
107
|
+
"#DDEFFF",
|
|
108
|
+
"#000035",
|
|
109
|
+
"#7B4F4B",
|
|
110
|
+
"#A1C299",
|
|
111
|
+
"#0AA6D8",
|
|
112
|
+
"#013349",
|
|
113
|
+
"#00846F",
|
|
114
|
+
"#372101",
|
|
115
|
+
"#FFB500",
|
|
116
|
+
"#C2FFED",
|
|
117
|
+
"#A079BF",
|
|
118
|
+
"#CC0744",
|
|
119
|
+
"#C0B9B2",
|
|
120
|
+
"#C2FF99",
|
|
121
|
+
"#00489C",
|
|
122
|
+
"#6F0062",
|
|
123
|
+
"#0CBD66",
|
|
124
|
+
"#EEC3FF",
|
|
125
|
+
"#456D75",
|
|
126
|
+
"#B77B68",
|
|
127
|
+
"#7A87A1",
|
|
128
|
+
"#788D66",
|
|
129
|
+
"#885578",
|
|
130
|
+
"#FAD09F",
|
|
131
|
+
"#FF8A9A",
|
|
132
|
+
"#D157A0",
|
|
133
|
+
"#BEC459",
|
|
134
|
+
"#456648",
|
|
135
|
+
"#0086ED",
|
|
136
|
+
"#886F4C",
|
|
137
|
+
"#34362D",
|
|
138
|
+
"#B4A8BD",
|
|
139
|
+
"#00A6AA",
|
|
140
|
+
"#452C2C",
|
|
141
|
+
"#636375",
|
|
142
|
+
"#A3C8C9",
|
|
143
|
+
"#FF913F",
|
|
144
|
+
"#938A81",
|
|
145
|
+
"#575329",
|
|
146
|
+
"#00FECF",
|
|
147
|
+
"#B05B6F",
|
|
148
|
+
"#8CD0FF",
|
|
149
|
+
"#3B9700",
|
|
150
|
+
"#04F757",
|
|
151
|
+
"#C8A1A1",
|
|
152
|
+
"#1E6E00",
|
|
153
|
+
"#7900D7",
|
|
154
|
+
"#A77500",
|
|
155
|
+
"#6367A9",
|
|
156
|
+
"#A05837",
|
|
157
|
+
"#6B002C",
|
|
158
|
+
"#772600",
|
|
159
|
+
"#D790FF",
|
|
160
|
+
"#9B9700",
|
|
161
|
+
"#549E79",
|
|
162
|
+
"#FFF69F",
|
|
163
|
+
"#72418F",
|
|
164
|
+
"#BC23FF",
|
|
165
|
+
"#99ADC0",
|
|
166
|
+
"#3A2465",
|
|
167
|
+
"#922329",
|
|
168
|
+
"#5B4534",
|
|
169
|
+
"#FDE8DC",
|
|
170
|
+
"#404E55",
|
|
171
|
+
"#0089A3",
|
|
172
|
+
"#CB7E98",
|
|
173
|
+
"#A4E804",
|
|
174
|
+
"#324E72",
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
PROPS_DICT = {"centroid-1": Features.X, "centroid-0": Features.Y}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from typing import List, Union
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import xarray as xr
|
|
6
|
+
|
|
7
|
+
from .constants import Dims, Layers
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def load_image_data(
|
|
11
|
+
image: np.ndarray,
|
|
12
|
+
channel_coords: Union[str, List[str]],
|
|
13
|
+
segmentation: Union[None, np.ndarray] = None,
|
|
14
|
+
labels: Union[None, pd.DataFrame] = None,
|
|
15
|
+
cell_col: str = "cell",
|
|
16
|
+
label_col: str = "label",
|
|
17
|
+
copy_segmentation: bool = False,
|
|
18
|
+
copy_image: bool = False,
|
|
19
|
+
):
|
|
20
|
+
"""Creates a image container.
|
|
21
|
+
|
|
22
|
+
Creates an Xarray dataset with images, segmentation, and
|
|
23
|
+
coordinate fields.
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
image : np.ndarray
|
|
28
|
+
np.ndarray with image.shape = (n, x, y)
|
|
29
|
+
channel_coords: str | List[str]
|
|
30
|
+
list with the names for each channel
|
|
31
|
+
|
|
32
|
+
Returns
|
|
33
|
+
-------
|
|
34
|
+
xr.Dataset
|
|
35
|
+
An X-array dataset with all fields.
|
|
36
|
+
"""
|
|
37
|
+
if copy_image:
|
|
38
|
+
image = image.copy()
|
|
39
|
+
|
|
40
|
+
if type(channel_coords) is str:
|
|
41
|
+
channel_coords = [channel_coords]
|
|
42
|
+
|
|
43
|
+
if image.ndim == 2:
|
|
44
|
+
image = np.expand_dims(image, 0)
|
|
45
|
+
|
|
46
|
+
channel_dim, y_dim, x_dim = image.shape
|
|
47
|
+
|
|
48
|
+
assert len(channel_coords) == channel_dim, "Length of channel_coords must match image.shape[0]."
|
|
49
|
+
|
|
50
|
+
if labels is not None:
|
|
51
|
+
assert segmentation is not None, "Labels may only be provided in conjunction with a segmentation."
|
|
52
|
+
|
|
53
|
+
im = xr.DataArray(
|
|
54
|
+
image,
|
|
55
|
+
coords=[channel_coords, range(y_dim), range(x_dim)],
|
|
56
|
+
dims=[Dims.CHANNELS, Dims.Y, Dims.X],
|
|
57
|
+
name=Layers.IMAGE,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
dataset = xr.Dataset(data_vars={Layers.IMAGE: im})
|
|
61
|
+
|
|
62
|
+
if segmentation is not None:
|
|
63
|
+
dataset = dataset.pp.add_segmentation(segmentation, copy=copy_segmentation)
|
|
64
|
+
|
|
65
|
+
if labels is not None:
|
|
66
|
+
dataset = dataset.pp.add_labels(labels, cell_col=cell_col, label_col=label_col)
|
|
67
|
+
|
|
68
|
+
else:
|
|
69
|
+
dataset = xr.Dataset(data_vars={Layers.IMAGE: im})
|
|
70
|
+
|
|
71
|
+
return dataset
|