xener 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xener/__init__.py +5 -0
- xener/config.py +59 -0
- xener/core.py +929 -0
- xener/utils/__init__.py +219 -0
- xener/utils/blast/__init__.py +5 -0
- xener/utils/blast/blastp.py +56 -0
- xener/utils/blast/get_blastdb.py +29 -0
- xener/utils/blast/makeblastdb.py +70 -0
- xener/utils/h5ad/__init__.py +6 -0
- xener/utils/h5ad/preprocess.py +62 -0
- xener/utils/kg/__init__.py +5 -0
- xener/utils/kg/base.py +45 -0
- xener/utils/kg/bolt_backend.py +258 -0
- xener/utils/kg/client.py +99 -0
- xener/utils/kg/http_backend.py +106 -0
- xener/utils/logger.py +185 -0
- xener/utils/seq.py +86 -0
- xener-0.1.0.dist-info/METADATA +120 -0
- xener-0.1.0.dist-info/RECORD +23 -0
- xener-0.1.0.dist-info/WHEEL +5 -0
- xener-0.1.0.dist-info/entry_points.txt +2 -0
- xener-0.1.0.dist-info/licenses/LICENSE +21 -0
- xener-0.1.0.dist-info/top_level.txt +1 -0
xener/__init__.py
ADDED
xener/config.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
_DATA_URL = {
|
|
4
|
+
"blastdb.zip":"https://xenor.dcs.cloud/api/public/download?file=blastdb.zip",
|
|
5
|
+
"default_run_conf.yaml":"https://xenor.dcs.cloud/api/public/download?file=default_run_conf.yaml"}
|
|
6
|
+
_XENER_DATA_DIR = Path.home() / ".xener" / "data"
|
|
7
|
+
|
|
8
|
+
def _ensure_data(DATA_KEY:str=None, force_update:bool=False):
|
|
9
|
+
assert DATA_KEY is None or DATA_KEY in _DATA_URL.keys(), "Invalid data key"
|
|
10
|
+
|
|
11
|
+
if DATA_KEY is None:
|
|
12
|
+
if _XENER_DATA_DIR.exists() and any(_XENER_DATA_DIR.iterdir()):
|
|
13
|
+
return
|
|
14
|
+
_XENER_DATA_DIR.mkdir(parents=True, exist_ok=True)
|
|
15
|
+
print(f"[xener] Dependence on missing data, currently downloading dependent data...")
|
|
16
|
+
for name, url in _DATA_URL.items():
|
|
17
|
+
data_path = _XENER_DATA_DIR / name
|
|
18
|
+
__download_data(name, data_path, url)
|
|
19
|
+
else:
|
|
20
|
+
name, url = DATA_KEY, _DATA_URL[DATA_KEY]
|
|
21
|
+
data_path = _XENER_DATA_DIR / name
|
|
22
|
+
if data_path.exists() and not force_update: return
|
|
23
|
+
__download_data(name, data_path, url)
|
|
24
|
+
def __download_data(name:str, data_path:Path, url:str):
|
|
25
|
+
try:
|
|
26
|
+
import requests
|
|
27
|
+
|
|
28
|
+
resp = requests.get(url, stream=True, timeout=60)
|
|
29
|
+
resp.raise_for_status()
|
|
30
|
+
total = int(resp.headers.get("content-length", 0))
|
|
31
|
+
downloaded = 0
|
|
32
|
+
with open(data_path, "wb") as f:
|
|
33
|
+
for chunk in resp.iter_content(chunk_size=8192):
|
|
34
|
+
if chunk:
|
|
35
|
+
f.write(chunk)
|
|
36
|
+
downloaded += len(chunk)
|
|
37
|
+
if total:
|
|
38
|
+
percent = min(downloaded * 100 // total, 100)
|
|
39
|
+
print(f"\r[xener] Download {name} progress: {percent}%", end="", flush=True)
|
|
40
|
+
if total == 0:
|
|
41
|
+
print(f"\r[xener] Download {name} progress: 100%", end="")
|
|
42
|
+
print()
|
|
43
|
+
except Exception as e:
|
|
44
|
+
if data_path.exists():
|
|
45
|
+
data_path.unlink()
|
|
46
|
+
raise RuntimeError(f"[xener] Data download {name} failed: {e}") from e
|
|
47
|
+
|
|
48
|
+
if name.endswith(".zip"):
|
|
49
|
+
try:
|
|
50
|
+
import zipfile
|
|
51
|
+
|
|
52
|
+
with zipfile.ZipFile(data_path, "r") as z:
|
|
53
|
+
z.extractall(_XENER_DATA_DIR)
|
|
54
|
+
data_path.unlink()
|
|
55
|
+
print(f"[xener] The data dependency has been configured in {_XENER_DATA_DIR}")
|
|
56
|
+
except Exception as e:
|
|
57
|
+
if data_path.exists():
|
|
58
|
+
data_path.unlink()
|
|
59
|
+
raise RuntimeError(f"[xener] Data decompression failed: {e}") from e
|