Skip to content

Commit

Permalink
filter browseable files/dirs to h5ad, 10x h5, Xenium, loom, Seurat, T…
Browse files Browse the repository at this point in the history
…ileDB, or zarr formats
  • Loading branch information
danielquintao committed Oct 3, 2024
1 parent a13e0ad commit 5ad54f7
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions cirrocumulus/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,42 @@ def handle_server():
other=["Gallus gallus", "Macaca fascicularis", "Macaca mulatta", "Rattus norvegicus"],
)

# browse server-side data files to allow user to select the desired dataset instead of necessarily typing the URL
# browse server-side data files to allow user to select the desired dataset instead of necessarily typing the URL:
d["server_files"] = []
if CIRRO_SERVER_DATA_DIR in os.environ and os.environ[CIRRO_SERVER_DATA_DIR]:
VALID_EXTENSIONS = [
".h5ad",
".h5",
".zip",
".tar",
".tar.gz",
".loom",
".h5seurat",
".rds",
".zarr",
]
for root, dirs, files in os.walk(os.environ[CIRRO_SERVER_DATA_DIR]):
for file in dirs + files:
d["server_files"] += [os.path.join(root, file)]
if any([file.endswith(ext) for ext in VALID_EXTENSIONS]):
d["server_files"] += [os.path.join(root, file)]
# if this is a directory, e.g. .zarr "files", prevent further recursion:
if file in dirs:
dirs.remove(file)
elif (
file in dirs
): # check if `file` is a MEX formatted directory (we must look at the subfiles)
# https://www.10xgenomics.com/support/software/xenium-panel-designer/latest/tutorials/create-single-cell-reference
count_tsvgz = 0 # MEX directoris have two subfiles with .tsv.gz extension
count_mtxgz = 0 # MEX directories also have one subfile with .mtx.gz extension
for subfile in os.listdir(os.path.join(root, file)):
if subfile.endswith(".tsv.gz"):
count_tsvgz += 1
elif subfile.endswith(".mtx.gz"):
count_mtxgz += 1
if count_tsvgz == 2 and count_mtxgz == 1:
d["server_files"] += [os.path.join(root, file)]
dirs.remove(file)
break

# from https://www.ebi.ac.uk/ols/ontologies/efo/terms?iri=http%3A%2F%2Fwww.ebi.ac.uk%2Fefo%2FEFO_0010183&viewMode=All&siblings=false
d["library"] = load_json(CIRRO_LIBRARY) or [
Expand Down

0 comments on commit 5ad54f7

Please sign in to comment.