eyck 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.
- eyck/__init__.py +31 -0
- eyck/encoder.py +61 -0
- eyck/flow/__init__.py +19 -0
- eyck/flow/flow.py +244 -0
- eyck/flow/flow_template.jinja2 +40 -0
- eyck/flow/linked.py +85 -0
- eyck/flow/memorymap.py +673 -0
- eyck/flow/objects.py +510 -0
- eyck/flow/tipyte.py +452 -0
- eyck/modalities/__init__.py +15 -0
- eyck/modalities/clustering/__init__.py +1 -0
- eyck/modalities/clustering/clustering.py +85 -0
- eyck/modalities/folds/__init__.py +1 -0
- eyck/modalities/folds/folds.py +77 -0
- eyck/modalities/fragments/__init__.py +2 -0
- eyck/modalities/fragments/fragments.py +967 -0
- eyck/modalities/fragments/loaders/__init__.py +1 -0
- eyck/modalities/fragments/loaders/helpers.c +31052 -0
- eyck/modalities/fragments/loaders/helpers.pyx +109 -0
- eyck/modalities/fragments/loaders/loaders.py +408 -0
- eyck/modalities/fragments/view.py +464 -0
- eyck/modalities/gradient/__init__.py +1 -0
- eyck/modalities/gradient/gradient.py +48 -0
- eyck/modalities/regions/__init__.py +233 -0
- eyck/modalities/transcriptome/__init__.py +15 -0
- eyck/modalities/transcriptome/data.py +279 -0
- eyck/modalities/transcriptome/diffexp.py +81 -0
- eyck/modalities/transcriptome/plot.py +1239 -0
- eyck/modalities/transcriptome/timetranscriptome.py +40 -0
- eyck/modalities/transcriptome/tools.py +124 -0
- eyck/processes/__init__.py +1 -0
- eyck/processes/cellcycle/__init__.py +41 -0
- eyck/targets.py +83 -0
- eyck/utils/__init__.py +73 -0
- eyck/utils/files.py +31 -0
- eyck-0.1.0.dist-info/METADATA +35 -0
- eyck-0.1.0.dist-info/RECORD +41 -0
- eyck-0.1.0.dist-info/WHEEL +5 -0
- eyck-0.1.0.dist-info/scm_file_list.json +43 -0
- eyck-0.1.0.dist-info/scm_version.json +8 -0
- eyck-0.1.0.dist-info/top_level.txt +1 -0
eyck/__init__.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from .utils import (
|
|
2
|
+
get_git_root,
|
|
3
|
+
get_output,
|
|
4
|
+
get_code,
|
|
5
|
+
get_results,
|
|
6
|
+
save,
|
|
7
|
+
Unpickler,
|
|
8
|
+
load,
|
|
9
|
+
)
|
|
10
|
+
from . import utils
|
|
11
|
+
from . import flow
|
|
12
|
+
from . import modalities
|
|
13
|
+
m = modalities
|
|
14
|
+
|
|
15
|
+
# from . import encoder
|
|
16
|
+
from . import processes
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"get_git_root",
|
|
20
|
+
"get_output",
|
|
21
|
+
"get_code",
|
|
22
|
+
"get_results",
|
|
23
|
+
"save",
|
|
24
|
+
"Unpickler",
|
|
25
|
+
"load",
|
|
26
|
+
"utils",
|
|
27
|
+
"flow",
|
|
28
|
+
"modalities",
|
|
29
|
+
"processes",
|
|
30
|
+
"m"
|
|
31
|
+
]
|
eyck/encoder.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import latenta as la
|
|
2
|
+
|
|
3
|
+
def transfer_amortization_input(amortization_input, transcriptome, loader = None, verbose = True):
|
|
4
|
+
if loader is None:
|
|
5
|
+
loader = transcriptome.create_loader()
|
|
6
|
+
|
|
7
|
+
transcriptome_definition = transcriptome.create_definition()
|
|
8
|
+
|
|
9
|
+
print(f"""
|
|
10
|
+
coords equal: {transcriptome_definition["gene"].coords == amortization_input["gene"].coords}
|
|
11
|
+
length new : {len(transcriptome_definition["gene"].coords)}
|
|
12
|
+
length amort: {len(amortization_input["gene"].coords)}
|
|
13
|
+
overlap : {len(set(transcriptome_definition["gene"].coords) & set(amortization_input["gene"].coords))}
|
|
14
|
+
""")
|
|
15
|
+
|
|
16
|
+
coords_equal = transcriptome_definition["gene"].coords == amortization_input["gene"].coords
|
|
17
|
+
|
|
18
|
+
amortization_input_raw = la.Fixed(loader, definition = transcriptome_definition, label = "amortization_input", transforms = [la.transforms.Log1p()], invert_value = False)
|
|
19
|
+
|
|
20
|
+
if not coords_equal:
|
|
21
|
+
amortization_input = la.operations.SelectAndImpute(x = amortization_input_raw, filtering = dict(gene = amortization_input.coords))
|
|
22
|
+
else:
|
|
23
|
+
amortization_input = amortization_input_raw
|
|
24
|
+
|
|
25
|
+
return amortization_input
|
|
26
|
+
|
|
27
|
+
def transfer_encoder(latent, transcriptome, loader = None, verbose = True):
|
|
28
|
+
latent = latent.clone()
|
|
29
|
+
if loader is None:
|
|
30
|
+
loader = transcriptome.create_loader()
|
|
31
|
+
|
|
32
|
+
transcriptome_definition = transcriptome.create_definition()
|
|
33
|
+
|
|
34
|
+
print(f"""
|
|
35
|
+
coords equal: {transcriptome_definition["gene"].coords == latent.find("amortization_input")["gene"].coords}
|
|
36
|
+
length new : {len(transcriptome_definition["gene"].coords)}
|
|
37
|
+
length amort: {len(latent.find("amortization_input")["gene"].coords)}
|
|
38
|
+
overlap : {len(set(transcriptome_definition["gene"].coords) & set(latent.find("amortization_input")["gene"].coords))}
|
|
39
|
+
""")
|
|
40
|
+
|
|
41
|
+
coords_equal = transcriptome_definition["gene"].coords == latent.find("amortization_input")["gene"].coords
|
|
42
|
+
|
|
43
|
+
amortization_input_raw = la.Fixed(loader, definition = transcriptome_definition, label = "amortization_input_raw", transforms = [la.transforms.Log1p()], invert_value = False)
|
|
44
|
+
|
|
45
|
+
if not coords_equal:
|
|
46
|
+
amortization_input = la.operations.SelectAndImpute(x = amortization_input_raw, filtering = dict(gene = latent.find("amortization_input")["gene"].coords))
|
|
47
|
+
else:
|
|
48
|
+
amortization_input = amortization_input_raw
|
|
49
|
+
|
|
50
|
+
latent.replace(latent.find("amortization_input"), amortization_input)
|
|
51
|
+
|
|
52
|
+
loc = la.Fixed(latent.q.loc.prior_pd())
|
|
53
|
+
scale = la.Fixed(latent.q.scale.prior_pd())
|
|
54
|
+
|
|
55
|
+
latent = la.variables.Latent(
|
|
56
|
+
q = la.distributions.Normal(loc, scale, transforms = latent.q.transforms),
|
|
57
|
+
p = latent.p,
|
|
58
|
+
label = latent.label,
|
|
59
|
+
symbol = latent.symbol,
|
|
60
|
+
)
|
|
61
|
+
return latent
|
eyck/flow/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from .objects import (
|
|
2
|
+
Linked,
|
|
3
|
+
Stored,
|
|
4
|
+
StoredDataFrame,
|
|
5
|
+
StoredNumpyInt64,
|
|
6
|
+
CompressedNumpy,
|
|
7
|
+
CompressedNumpyFloat64,
|
|
8
|
+
CompressedNumpyInt64,
|
|
9
|
+
TSV,
|
|
10
|
+
StoredDict,
|
|
11
|
+
DataArray,
|
|
12
|
+
Dataset,
|
|
13
|
+
)
|
|
14
|
+
from .flow import (
|
|
15
|
+
Flow,
|
|
16
|
+
PathLike,
|
|
17
|
+
)
|
|
18
|
+
from . import memorymap
|
|
19
|
+
from .linked import LinkedDict
|
eyck/flow/flow.py
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import gzip
|
|
2
|
+
import importlib
|
|
3
|
+
import json
|
|
4
|
+
import pathlib
|
|
5
|
+
import pickle
|
|
6
|
+
import shutil
|
|
7
|
+
from typing import Union
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
import weakref
|
|
11
|
+
|
|
12
|
+
from .objects import is_instance, is_obj
|
|
13
|
+
|
|
14
|
+
PathLike = Union[str, pathlib.Path]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
_cache = weakref.WeakValueDictionary()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def nearest_common_parent(path1, path2):
|
|
21
|
+
# Get parent directories for each path
|
|
22
|
+
parents1 = set(path1.parents)
|
|
23
|
+
parents2 = set(path2.parents)
|
|
24
|
+
|
|
25
|
+
# Find the common parents
|
|
26
|
+
common_parents = parents1.intersection(parents2)
|
|
27
|
+
|
|
28
|
+
# If there are no common parents, return None
|
|
29
|
+
if not common_parents:
|
|
30
|
+
return None
|
|
31
|
+
|
|
32
|
+
# Return the closest common parent
|
|
33
|
+
return max(common_parents, key=lambda p: len(p.parts))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def relative_to_nearest_parent(path1, path2):
|
|
37
|
+
parent = nearest_common_parent(path1, path2)
|
|
38
|
+
if parent is None:
|
|
39
|
+
return path1
|
|
40
|
+
|
|
41
|
+
return path1.relative_to(parent)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Flowable(type):
|
|
45
|
+
def __init__(cls, name, bases, attrs):
|
|
46
|
+
super().__init__(name, bases, attrs)
|
|
47
|
+
|
|
48
|
+
parent = None
|
|
49
|
+
if len(bases) > 0:
|
|
50
|
+
parent = bases[0]
|
|
51
|
+
if hasattr(parent, "_obj_map"):
|
|
52
|
+
cls._obj_map = parent._obj_map.copy()
|
|
53
|
+
else:
|
|
54
|
+
cls._obj_map = {}
|
|
55
|
+
else:
|
|
56
|
+
cls._obj_map = {}
|
|
57
|
+
|
|
58
|
+
# compile objects
|
|
59
|
+
for attr_id, attr in cls.__dict__.items():
|
|
60
|
+
if is_obj(attr):
|
|
61
|
+
assert isinstance(attr_id, str)
|
|
62
|
+
attr.name = attr_id
|
|
63
|
+
cls._obj_map[attr_id] = attr
|
|
64
|
+
|
|
65
|
+
def __setattr__(cls, key, value):
|
|
66
|
+
super().__setattr__(key, value)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class FlowObjects:
|
|
70
|
+
def __init__(self, flow):
|
|
71
|
+
self.flow = flow
|
|
72
|
+
|
|
73
|
+
def __getattr__(self, key):
|
|
74
|
+
if key != "flow":
|
|
75
|
+
return self.flow.get(key)
|
|
76
|
+
else:
|
|
77
|
+
return super().__getattr__(key)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Flow(metaclass=Flowable):
|
|
81
|
+
"""
|
|
82
|
+
A folder on disk that can contain other folders or objects
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
path: pathlib.Path
|
|
86
|
+
default_name = None
|
|
87
|
+
|
|
88
|
+
def __init__(self, path=None, folder=None, name=None, reset=False, **kwargs):
|
|
89
|
+
if isinstance(path, str):
|
|
90
|
+
path = pathlib.Path(path)
|
|
91
|
+
elif isinstance(path, Flow):
|
|
92
|
+
path = path.path
|
|
93
|
+
if path is None:
|
|
94
|
+
if folder is None:
|
|
95
|
+
# make temporary
|
|
96
|
+
try:
|
|
97
|
+
import pathlibfs
|
|
98
|
+
except ImportError:
|
|
99
|
+
raise ImportError("To create a temporary flow, install pathlibfs")
|
|
100
|
+
from uuid import uuid4
|
|
101
|
+
|
|
102
|
+
name = str(uuid4())
|
|
103
|
+
folder = pathlibfs.Path("memory://")
|
|
104
|
+
elif name is None:
|
|
105
|
+
if self.default_name is None:
|
|
106
|
+
raise ValueError(
|
|
107
|
+
"Cannot create Flow without name, and no default_name specified"
|
|
108
|
+
)
|
|
109
|
+
name = self.default_name
|
|
110
|
+
|
|
111
|
+
path = folder / name
|
|
112
|
+
|
|
113
|
+
self.path = path
|
|
114
|
+
global _cache
|
|
115
|
+
_cache[str(self.path.resolve())] = self
|
|
116
|
+
if not path.exists():
|
|
117
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
118
|
+
|
|
119
|
+
if reset:
|
|
120
|
+
self.reset()
|
|
121
|
+
|
|
122
|
+
if not self._get_info_path().exists():
|
|
123
|
+
self._store_info()
|
|
124
|
+
|
|
125
|
+
self._obj_instances = {}
|
|
126
|
+
|
|
127
|
+
for key, value in kwargs.items():
|
|
128
|
+
setattr(self, key, value)
|
|
129
|
+
|
|
130
|
+
def __copy__(self):
|
|
131
|
+
return self.__class__(path=None)
|
|
132
|
+
|
|
133
|
+
def __deepcopy__(self, memo):
|
|
134
|
+
return self.__class__(path=None)
|
|
135
|
+
|
|
136
|
+
@classmethod
|
|
137
|
+
def create(cls, path=None, reset=False, **kwargs):
|
|
138
|
+
if isinstance(path, str):
|
|
139
|
+
path = pathlib.Path(path)
|
|
140
|
+
self = cls(path=path, reset=reset)
|
|
141
|
+
|
|
142
|
+
for key, value in kwargs.items():
|
|
143
|
+
setattr(self, key, value)
|
|
144
|
+
return self
|
|
145
|
+
|
|
146
|
+
def _store_info(self):
|
|
147
|
+
info = {"module": self.__class__.__module__, "class": self.__class__.__name__}
|
|
148
|
+
|
|
149
|
+
json.dump(info, self._get_info_path().open("w"))
|
|
150
|
+
|
|
151
|
+
def _get_info_path(self):
|
|
152
|
+
return self.path / ".flow"
|
|
153
|
+
|
|
154
|
+
def __repr__(self):
|
|
155
|
+
return f'{self.__class__.__name__}("{self.path}")'
|
|
156
|
+
|
|
157
|
+
@classmethod
|
|
158
|
+
def from_path(cls, path):
|
|
159
|
+
"""
|
|
160
|
+
Load a previously created flow from disk
|
|
161
|
+
"""
|
|
162
|
+
if str(path) in _cache:
|
|
163
|
+
return _cache[str(path.resolve())]
|
|
164
|
+
info = json.load(open(path.resolve() / ".flow"))
|
|
165
|
+
|
|
166
|
+
# load class
|
|
167
|
+
module = importlib.import_module(info["module"])
|
|
168
|
+
cls = getattr(module, info["class"])
|
|
169
|
+
|
|
170
|
+
return cls(path=path)
|
|
171
|
+
|
|
172
|
+
def reset(self):
|
|
173
|
+
"""
|
|
174
|
+
Remove all files in this flow
|
|
175
|
+
"""
|
|
176
|
+
if self.path.exists():
|
|
177
|
+
if not str(self.path).startswith("memory"):
|
|
178
|
+
shutil.rmtree(self.path)
|
|
179
|
+
self.path.mkdir(parents=True, exist_ok=True)
|
|
180
|
+
|
|
181
|
+
def __getstate__(self):
|
|
182
|
+
raise TypeError("This class cannot be pickled.")
|
|
183
|
+
|
|
184
|
+
def get(self, k):
|
|
185
|
+
if k in self._obj_instances:
|
|
186
|
+
return self._obj_instances[k]
|
|
187
|
+
return self._obj_map[k]
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def o(self):
|
|
191
|
+
return FlowObjects(self)
|
|
192
|
+
|
|
193
|
+
def _repr_html_(self):
|
|
194
|
+
import json
|
|
195
|
+
|
|
196
|
+
from . import tipyte
|
|
197
|
+
import pkg_resources
|
|
198
|
+
from IPython.display import HTML, display
|
|
199
|
+
import random
|
|
200
|
+
|
|
201
|
+
lines = []
|
|
202
|
+
lines.append(
|
|
203
|
+
"""
|
|
204
|
+
"""
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
cls = f"<span class='soft'>({self.__class__.__module__}.{self.__class__.__name__})</span>"
|
|
208
|
+
if not str(self.path).startswith("memory"):
|
|
209
|
+
path = f"<span class='soft' style='font-size:0.8em'>{relative_to_nearest_parent(self.path.parent, pathlib.Path.cwd())}/</span>"
|
|
210
|
+
else:
|
|
211
|
+
path = ""
|
|
212
|
+
lines += [
|
|
213
|
+
"<div class='la-flow'>",
|
|
214
|
+
path + "<strong>" + str(self.path.name) + "</strong>" + " " + cls,
|
|
215
|
+
]
|
|
216
|
+
lines += ["<ul class='instances'>"]
|
|
217
|
+
for obj_id, obj in self._obj_map.items():
|
|
218
|
+
if obj_id in self._obj_instances:
|
|
219
|
+
instance = self._obj_instances[obj_id]
|
|
220
|
+
if instance.exists():
|
|
221
|
+
html_repr = instance._repr_html_()
|
|
222
|
+
lines.append(f"<li>{html_repr}</li>")
|
|
223
|
+
elif is_obj(obj):
|
|
224
|
+
if obj.exists(self):
|
|
225
|
+
html_repr = obj._repr_html_(self)
|
|
226
|
+
lines.append(f"<li>{html_repr}</li>")
|
|
227
|
+
lines += ["</ul>"]
|
|
228
|
+
|
|
229
|
+
# create template
|
|
230
|
+
template = tipyte.template_to_function(
|
|
231
|
+
pkg_resources.resource_filename("eyck", "flow/flow_template.jinja2"),
|
|
232
|
+
escaper=lambda x: x,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
parameters = {"div_id": random.randint(0, 50000), "html": "".join(lines)}
|
|
236
|
+
html = template(**parameters)
|
|
237
|
+
|
|
238
|
+
return html
|
|
239
|
+
|
|
240
|
+
def __truediv__(self, other):
|
|
241
|
+
if isinstance(other, str):
|
|
242
|
+
return Flow(self.path / other)
|
|
243
|
+
else:
|
|
244
|
+
raise ValueError("Can only divide by string")
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.js" integrity="sha512-vRqhAr2wsn+/cSsyz80psBbCcqzz2GTuhGk3bq3dAyytz4J/8XwFqMjiAGFBj+WM95lHBJ9cDf87T3P8yMrY7A==" crossorigin="anonymous" referrerpolicy="no-referrer" id="script{{div_id}}" onload="loaded{{ div_id }}"></script>
|
|
2
|
+
<style>
|
|
3
|
+
.la-flow {
|
|
4
|
+
font-size:15px;
|
|
5
|
+
}
|
|
6
|
+
.la-flow>ul {
|
|
7
|
+
margin-top:0;
|
|
8
|
+
list-style: none;
|
|
9
|
+
padding: 0;
|
|
10
|
+
padding-left: 0;
|
|
11
|
+
margin-left:0;
|
|
12
|
+
margin-bottom:0;
|
|
13
|
+
|
|
14
|
+
display: flex !important;
|
|
15
|
+
flex-wrap: wrap;
|
|
16
|
+
gap: 10px; /* Gap between each card */
|
|
17
|
+
list-style-type: none; /* Remove bullet points from <li> */
|
|
18
|
+
padding-left: 0; /* Remove default padding from <ul> */
|
|
19
|
+
justify-content: flex-start; /* Align items to the start */
|
|
20
|
+
}
|
|
21
|
+
.la-flow>ul.instances>li {
|
|
22
|
+
flex: 0 0 auto; /* Allow items to grow and shrink */
|
|
23
|
+
min-width: 10px; /* Minimum width of each card. Adjust as needed. */
|
|
24
|
+
background-color: #f9f9f9; /* Sample background color */
|
|
25
|
+
padding: 5px;
|
|
26
|
+
border: 1px dashed #ccc;
|
|
27
|
+
border-radius: 2px;
|
|
28
|
+
margin-bottom:0;
|
|
29
|
+
margin-left:0;
|
|
30
|
+
}
|
|
31
|
+
.la-flow .soft {
|
|
32
|
+
opacity:0.5;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
</style>
|
|
37
|
+
|
|
38
|
+
<script src="//code.iconify.design/1/1.0.6/iconify.min.js"></script>
|
|
39
|
+
|
|
40
|
+
{{ html }}
|
eyck/flow/linked.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from .objects import Obj, Instance, Linked
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class LinkedDict(Obj):
|
|
5
|
+
def __init__(self, cls=Linked, name=None, kwargs=None):
|
|
6
|
+
super().__init__(name=name)
|
|
7
|
+
if kwargs is None:
|
|
8
|
+
kwargs = {}
|
|
9
|
+
self.kwargs = kwargs
|
|
10
|
+
self.cls = cls
|
|
11
|
+
|
|
12
|
+
def get_path(self, folder):
|
|
13
|
+
return folder / self.name
|
|
14
|
+
|
|
15
|
+
def __get__(self, obj, type=None):
|
|
16
|
+
if obj is not None:
|
|
17
|
+
name = "_" + str(self.name)
|
|
18
|
+
if not hasattr(obj, name):
|
|
19
|
+
x = LinkedDictInstance(self.name, self.get_path(obj.path), self.cls, obj, self.kwargs)
|
|
20
|
+
setattr(obj, name, x)
|
|
21
|
+
return getattr(obj, name)
|
|
22
|
+
|
|
23
|
+
def __set__(self, obj, value, folder=None):
|
|
24
|
+
instance = self.__get__(obj)
|
|
25
|
+
instance.__set__(obj, value)
|
|
26
|
+
|
|
27
|
+
def _repr_html_(self, obj=None):
|
|
28
|
+
instance = self.__get__(obj)
|
|
29
|
+
return instance._repr_html_()
|
|
30
|
+
|
|
31
|
+
def exists(self, obj):
|
|
32
|
+
return True
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class LinkedDictInstance(Instance):
|
|
36
|
+
def __init__(self, name, path, cls, obj, kwargs):
|
|
37
|
+
super().__init__(name=name, path=path, obj=obj)
|
|
38
|
+
self.dict = {}
|
|
39
|
+
self.cls = cls
|
|
40
|
+
self.obj = obj
|
|
41
|
+
self.name = name
|
|
42
|
+
self.path = path
|
|
43
|
+
self.kwargs = kwargs
|
|
44
|
+
if not self.path.exists():
|
|
45
|
+
self.path.mkdir(parents=True)
|
|
46
|
+
for file in self.path.iterdir():
|
|
47
|
+
key = file.name
|
|
48
|
+
self.dict[key] = self.cls(name=key, **self.kwargs)
|
|
49
|
+
|
|
50
|
+
def __getitem__(self, key):
|
|
51
|
+
return self.dict[key].__get__(self)
|
|
52
|
+
|
|
53
|
+
def __setitem__(self, key, value):
|
|
54
|
+
if key not in self.dict:
|
|
55
|
+
self.dict[key] = self.cls(name=key, **self.kwargs)
|
|
56
|
+
self.dict[key].__set__(self, value)
|
|
57
|
+
|
|
58
|
+
def __set__(self, obj, value, folder=None):
|
|
59
|
+
for k, v in value.items():
|
|
60
|
+
self[k] = v
|
|
61
|
+
|
|
62
|
+
def __contains__(self, key):
|
|
63
|
+
return key in self.dict
|
|
64
|
+
|
|
65
|
+
def __len__(self):
|
|
66
|
+
return len(self.dict)
|
|
67
|
+
|
|
68
|
+
def items(self):
|
|
69
|
+
for k in self.dict:
|
|
70
|
+
yield k, self[k]
|
|
71
|
+
|
|
72
|
+
def keys(self):
|
|
73
|
+
return self.dict.keys()
|
|
74
|
+
|
|
75
|
+
def exists(self):
|
|
76
|
+
return True
|
|
77
|
+
|
|
78
|
+
def _repr_html_(self):
|
|
79
|
+
# return f"<span class='iconify' data-icon='mdi-layers'></span> <b>{self.name}</b> ({', '.join([getattr(self.obj, k)._repr_html_() for k in self.keys()])})"
|
|
80
|
+
items = []
|
|
81
|
+
for i, k in zip(range(3), self.keys()):
|
|
82
|
+
items.append(self.dict[k]._repr_html_(self))
|
|
83
|
+
if len(self.keys()) > 3:
|
|
84
|
+
items.append("...")
|
|
85
|
+
return f"<span class='iconify' data-icon='mdi-layers'></span> <b>{self.name}</b> ({', '.join(items)})"
|