mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-08 16:58:12 +08:00
#22 blackened code
This commit is contained in:
@@ -9,7 +9,12 @@
|
||||
|
||||
import os
|
||||
from cellxgene_gateway import env
|
||||
from cellxgene_gateway.dir_util import make_h5ad, make_annotations, annotations_suffix
|
||||
from cellxgene_gateway.dir_util import (
|
||||
make_h5ad,
|
||||
make_annotations,
|
||||
annotations_suffix,
|
||||
)
|
||||
|
||||
|
||||
def recurse_dir(path):
|
||||
if not os.path.exists(path):
|
||||
@@ -18,21 +23,42 @@ def recurse_dir(path):
|
||||
)
|
||||
|
||||
all_entries = sorted(os.listdir(path))
|
||||
|
||||
def is_h5ad(el):
|
||||
return el.endswith('.h5ad') and os.path.isfile(os.path.join(path, el))
|
||||
return el.endswith(".h5ad") and os.path.isfile(os.path.join(path, el))
|
||||
|
||||
h5ad_entries = [x for x in all_entries if is_h5ad(x)]
|
||||
annotation_dir_entries = [x for x in all_entries if x.endswith(annotations_suffix) and make_h5ad(x) in h5ad_entries]
|
||||
annotation_dir_entries = [
|
||||
x
|
||||
for x in all_entries
|
||||
if x.endswith(annotations_suffix) and make_h5ad(x) in h5ad_entries
|
||||
]
|
||||
|
||||
def list_annotations(el):
|
||||
full_path = os.path.join(path, el)
|
||||
if not os.path.isdir(full_path):
|
||||
entries = []
|
||||
else:
|
||||
entries = [{
|
||||
"name": x[:-13] if (len(x) > 13 and x[-13] in ['-','_']) else (
|
||||
x[:-4] if x.endswith('.csv') else x),
|
||||
"path": os.path.join(full_path, x).replace(env.cellxgene_data, ""),
|
||||
} for x in sorted(os.listdir(full_path)) if x.endswith('.csv') and os.path.isfile(os.path.join(full_path, x))]
|
||||
return [{"name":'new', "class":'new', "path":full_path.replace(env.cellxgene_data, "")}] + entries
|
||||
entries = [
|
||||
{
|
||||
"name": x[:-13]
|
||||
if (len(x) > 13 and x[-13] in ["-", "_"])
|
||||
else (x[:-4] if x.endswith(".csv") else x),
|
||||
"path": os.path.join(full_path, x).replace(
|
||||
env.cellxgene_data, ""
|
||||
),
|
||||
}
|
||||
for x in sorted(os.listdir(full_path))
|
||||
if x.endswith(".csv")
|
||||
and os.path.isfile(os.path.join(full_path, x))
|
||||
]
|
||||
return [
|
||||
{
|
||||
"name": "new",
|
||||
"class": "new",
|
||||
"path": full_path.replace(env.cellxgene_data, ""),
|
||||
}
|
||||
] + entries
|
||||
|
||||
def make_entry(el):
|
||||
full_path = os.path.join(path, el)
|
||||
@@ -63,16 +89,26 @@ def recurse_dir(path):
|
||||
def render_entries(entries):
|
||||
return "<ul>" + "\n".join([render_entry(e) for e in entries]) + "</ul>"
|
||||
|
||||
|
||||
def get_url(entry):
|
||||
return f"/view/{ entry['path'].lstrip('/') }"
|
||||
|
||||
|
||||
def get_class(entry):
|
||||
return f" class='{entry['class']}'" if 'class' in entry else ''
|
||||
return f" class='{entry['class']}'" if "class" in entry else ""
|
||||
|
||||
|
||||
def render_annotations(entry):
|
||||
if len(entry['annotations']) > 0:
|
||||
return ' | annotations: ' + ", ".join([f"<a href='{get_url(a)}'{get_class(a)}>{a['name']}</a>" for a in entry['annotations']])
|
||||
if len(entry["annotations"]) > 0:
|
||||
return " | annotations: " + ", ".join(
|
||||
[
|
||||
f"<a href='{get_url(a)}'{get_class(a)}>{a['name']}</a>"
|
||||
for a in entry["annotations"]
|
||||
]
|
||||
)
|
||||
else:
|
||||
return ''
|
||||
return ""
|
||||
|
||||
|
||||
def render_entry(entry):
|
||||
if entry["type"] == "file":
|
||||
|
||||
Reference in New Issue
Block a user