Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
actionet-python/tests/test_plotting_static.py at main · KellisLab/actionet-python · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
KellisLab
/
actionet-python
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
main
Breadcrumbs
actionet-python
/
tests
/
test_plotting_static.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
160 lines (126 loc) · 4.56 KB
main
Breadcrumbs
actionet-python
/
tests
/
test_plotting_static.py
Copy path
Top
File metadata and controls
Code
Blame
160 lines (126 loc) · 4.56 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import
io
import
numpy
as
np
import
pandas
as
pd
import
pytest
from
anndata
import
AnnData
lets_plot
=
pytest
.
importorskip
(
"lets_plot"
)
matplotlib
=
pytest
.
importorskip
(
"matplotlib"
)
from
matplotlib
.
figure
import
Figure
from
actionet
.
visualization
import
plot_feature_expression_raster
,
plot_umap
,
plot_umap_raster
def
_shared_keys
(
plot
)
->
set
[
str
]:
if
hasattr
(
plot
,
"get_plot_shared_data"
):
shared
=
plot
.
get_plot_shared_data
()
if
shared
is
None
:
return
set
()
if
isinstance
(
shared
,
pd
.
DataFrame
):
return
set
(
shared
.
columns
)
return
set
(
shared
.
keys
())
return
set
(
plot
.
as_dict
().
get
(
"data"
, {}).
keys
())
def
_make_adata
()
->
AnnData
:
x
=
np
.
array
(
[
[
1.0
,
0.5
,
0.0
],
[
0.2
,
1.1
,
0.3
],
[
0.7
,
0.0
,
1.4
],
[
0.9
,
0.4
,
0.1
],
[
1.3
,
0.8
,
0.2
],
[
0.4
,
1.0
,
1.1
],
],
dtype
=
float
,
)
adata
=
AnnData
(
x
)
adata
.
var_names
=
pd
.
Index
([
"GeneA"
,
"GeneB"
,
"GeneC"
])
adata
.
obs
[
"cluster"
]
=
pd
.
Categorical
([
"a"
,
"a"
,
"b"
,
"b"
,
None
,
"c"
])
adata
.
obs
[
"score"
]
=
np
.
array
([
0.1
,
0.8
,
np
.
nan
,
0.3
,
0.9
,
0.5
],
dtype
=
float
)
adata
.
obs
[
"annot_conf"
]
=
np
.
array
([
0.2
,
0.5
,
0.7
,
0.1
,
0.8
,
0.4
],
dtype
=
float
)
adata
.
obsm
[
"umap_2d_actionet"
]
=
np
.
array
(
[
[
0.0
,
0.0
],
[
1.0
,
0.5
],
[
1.5
,
1.0
],
[
0.5
,
1.5
],
[
1.8
,
0.2
],
[
0.2
,
1.8
],
],
dtype
=
float
,
)
adata
.
obsm
[
"colors_actionet"
]
=
np
.
array
(
[
[
0.9
,
0.1
,
0.1
],
[
0.1
,
0.7
,
0.3
],
[
0.2
,
0.4
,
0.9
],
[
0.8
,
0.8
,
0.1
],
[
0.6
,
0.3
,
0.8
],
[
0.2
,
0.8
,
0.8
],
],
dtype
=
float
,
)
adata
.
layers
[
"logcounts"
]
=
x
.
copy
()
return
adata
def
test_plot_umap_default_spec_omits_redundant_columns
()
->
None
:
plot
=
plot_umap
(
_make_adata
(),
color
=
None
,
color_source
=
None
,
color_slot
=
None
,
legend
=
False
)
spec
=
plot
.
as_dict
()
assert
_shared_keys
(
plot
)
==
set
()
assert
set
(
spec
[
"layers"
][
0
][
"data"
].
keys
())
==
{
"x"
,
"y"
}
assert
spec
[
"layers"
][
0
][
"sampling"
]
==
"none"
assert
spec
[
"layers"
][
0
][
"tooltips"
]
==
"none"
assert
"alpha"
not
in
spec
[
"mapping"
]
def
test_plot_umap_vector_alpha_keeps_alpha_column
()
->
None
:
alpha
=
np
.
linspace
(
0.2
,
1.0
,
_make_adata
().
n_obs
)
plot
=
plot_umap
(
_make_adata
(),
color
=
"cluster"
,
alpha
=
alpha
)
assert
"alpha"
in
_shared_keys
(
plot
)
def
test_plot_umap_random_sampling_validation
()
->
None
:
adata
=
_make_adata
()
with
pytest
.
raises
(
ValueError
,
match
=
"sample_n must be provided"
):
plot_umap
(
adata
,
color
=
"cluster"
,
sampling
=
"random"
)
with
pytest
.
raises
(
ValueError
,
match
=
"positive integer"
):
plot_umap
(
adata
,
color
=
"cluster"
,
sampling
=
"random"
,
sample_n
=
0
)
def
test_plot_umap_random_sampling_serializes_sampling_spec
()
->
None
:
plot
=
plot_umap
(
_make_adata
(),
color
=
"cluster"
,
sampling
=
"random"
,
sample_n
=
3
,
tooltips
=
"default"
,
)
layer
=
plot
.
as_dict
()[
"layers"
][
0
]
assert
layer
[
"sampling"
]
!=
"none"
assert
"tooltips"
not
in
layer
or
layer
[
"tooltips"
]
!=
"none"
def
test_plot_umap_continuous_na_layer_has_minimal_data
()
->
None
:
plot
=
plot_umap
(
_make_adata
(),
color
=
"score"
,
color_source
=
"obs"
,
legend
=
False
)
spec
=
plot
.
as_dict
()
assert
len
(
spec
[
"layers"
])
==
2
assert
set
(
spec
[
"layers"
][
1
][
"data"
].
keys
())
==
{
"x"
,
"y"
}
def
test_plot_umap_to_png_smoke
()
->
None
:
lets_plot
.
LetsPlot
.
setup_html
(
no_js
=
True
)
plot
=
plot_umap
(
_make_adata
(),
color
=
"cluster"
)
buf
=
io
.
BytesIO
()
plot
.
to_png
(
buf
)
assert
buf
.
getbuffer
().
nbytes
>
0
def
test_plot_umap_raster_savefig_smoke
()
->
None
:
fig
=
plot_umap_raster
(
_make_adata
(),
color
=
"score"
,
color_source
=
"obs"
)
buf
=
io
.
BytesIO
()
fig
.
savefig
(
buf
,
format
=
"png"
)
assert
isinstance
(
fig
,
Figure
)
assert
buf
.
getbuffer
().
nbytes
>
0
def
test_plot_feature_expression_raster_returns_figure_for_single_feature
()
->
None
:
fig
=
plot_feature_expression_raster
(
_make_adata
(),
features
=
"GeneA"
,
alpha
=
0
,
layer
=
"logcounts"
,
)
assert
isinstance
(
fig
,
Figure
)
buf
=
io
.
BytesIO
()
fig
.
savefig
(
buf
,
format
=
"png"
)
assert
buf
.
getbuffer
().
nbytes
>
0
def
test_plot_feature_expression_raster_single_plot_grid
()
->
None
:
fig
=
plot_feature_expression_raster
(
_make_adata
(),
features
=
[
"GeneA"
,
"GeneB"
],
alpha
=
0
,
layer
=
"logcounts"
,
single_plot
=
True
,
)
assert
isinstance
(
fig
,
Figure
)
assert
len
(
fig
.
axes
)
>=
2
You can’t perform that action at this time.