Spaces:
Sleeping
Sleeping
File size: 1,359 Bytes
7aa8120 5d94482 | 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 | import streamlit as st
import anndata as ad
import pandas as pd
from pathlib import Path
import io
# Page config
st.set_page_config(page_title="AnnData Explorer", layout="wide")
st.title("AnnData Explorer – X, obs, var")
# Sidebar: file upload
uploaded = st.sidebar.file_uploader("Upload .h5ad", type=["h5ad"])
@st.cache_data
def load_adata(path_or_bytes):
if isinstance(path_or_bytes, (str, Path)):
return ad.read_h5ad(path_or_bytes)
# UploadedFile
return ad.read_h5ad(io.BytesIO(path_or_bytes.read()))
if uploaded is None:
st.info("Please upload an .h5ad file from the sidebar.")
st.stop()
adata = load_adata(uploaded)
# Sidebar: dimension info
st.sidebar.write("### Dataset info")
st.sidebar.write(f"Cells: {adata.n_obs}")
st.sidebar.write(f"Features: {adata.n_vars}")
# Main area: three tables
tab1, tab2, tab3 = st.tabs(["X", "obs", "var"])
with tab1:
st.subheader("AnnData.X")
st.dataframe(
pd.DataFrame(
adata.X.todense() if hasattr(adata.X, "todense") else adata.X,
index=adata.obs_names,
columns=adata.var_names,
),
use_container_width=True,
)
with tab2:
st.subheader("AnnData.obs")
st.dataframe(adata.obs, use_container_width=True)
with tab3:
st.subheader("AnnData.var")
st.dataframe(adata.var, use_container_width=True) |