FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tskit-rust/python/test_json_metadata.py at main · tskit-dev/tskit-rust · GitHub
tskit-dev
/
tskit-rust
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
18
Code
Issues
5
Pull requests
7
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tskit-rust
/
python
/
test_json_metadata.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (59 loc) · 2.16 KB
Breadcrumbs
tskit-rust
/
python
/
test_json_metadata.py
Copy path
File metadata and controls
71 lines (59 loc) · 2.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import
tskit
import
numpy
as
np
def
setup_ts_without_schema
():
ts
=
tskit
.
TreeSequence
.
load
(
"with_json_metadata.trees"
)
return
ts
def
setup_ts_with_schema
():
ts
=
setup_ts_without_schema
()
tables
=
ts
.
tables
tables
.
individuals
.
metadata_schema
=
tskit
.
metadata
.
MetadataSchema
(
{
"codec"
:
"json"
,
"type"
:
"object"
,
"name"
:
"Individual metadata"
,
"properties"
: {
"name"
: {
"type"
:
"string"
},
"phenotypes"
: {
"type"
:
"array"
}},
"additionalProperties"
:
False
,
})
tables
.
mutations
.
metadata_schema
=
tskit
.
metadata
.
MetadataSchema
(
{
"codec"
:
"json"
,
"type"
:
"object"
,
"name"
:
"Individual metadata"
,
"properties"
: {
"effect_size"
: {
"type"
:
"number"
},
"dominance"
: {
"type"
:
"number"
}},
"additionalProperties"
:
False
,
})
return
tables
.
tree_sequence
()
def
test_individual_metadata
():
# NOTE: the assertions here rely on knowing
# what examples/json_metadata.rs put into the
# metadata!
ts
=
setup_ts_with_schema
()
md
=
ts
.
individual
(
0
).
metadata
assert
md
[
"name"
]
==
"Jerome"
assert
md
[
"phenotypes"
]
==
[
0
,
1
,
2
,
0
]
def
test_individual_metadata_without_schema
():
# NOTE: the assertions here rely on knowing
# what examples/json_metadata.rs put into the
# metadata!
ts
=
setup_ts_without_schema
()
md
=
eval
(
ts
.
individual
(
0
).
metadata
)
assert
md
[
"name"
]
==
"Jerome"
assert
md
[
"phenotypes"
]
==
[
0
,
1
,
2
,
0
]
def
test_mutation_metadata
():
# NOTE: the assertions here rely on knowing
# what examples/json_metadata.rs put into the
# metadata!
ts
=
setup_ts_with_schema
()
md
=
ts
.
mutation
(
0
).
metadata
assert
np
.
isclose
(
md
[
"effect_size"
],
-
1e-3
)
assert
np
.
isclose
(
md
[
"dominance"
],
0.1
)
def
test_mutation_metadata_without_schema
():
# NOTE: the assertions here rely on knowing
# what examples/json_metadata.rs put into the
# metadata!
ts
=
setup_ts_without_schema
()
md
=
eval
(
ts
.
mutation
(
0
).
metadata
)
assert
np
.
isclose
(
md
[
"effect_size"
],
-
1e-3
)
assert
np
.
isclose
(
md
[
"dominance"
],
0.1
)
Back
|
FazBrowse Home
|
New Git URL