Upload config.py with huggingface_hub
Browse files
config.py
CHANGED
|
@@ -72,8 +72,8 @@ def database_for(node_ids: list) -> list:
|
|
| 72 |
return out
|
| 73 |
|
| 74 |
|
| 75 |
-
def
|
| 76 |
-
"""SQL
|
| 77 |
|
| 78 |
The released dataset ships data/nodes_expected_ge5.parquet, which holds the
|
| 79 |
property rows for exactly the nodes in edges_expected_ge5 — enough for every
|
|
@@ -82,15 +82,19 @@ def node_property_query(con, column: str = "species") -> str:
|
|
| 82 |
across nodes_ML (MTBLS ids) and nodes_MW (ST ids).
|
| 83 |
"""
|
| 84 |
if NODES_PARQUET.exists():
|
| 85 |
-
return f"SELECT
|
| 86 |
if pathlib.Path(NODE_DB_PATH).exists():
|
| 87 |
con.execute(f"ATTACH IF NOT EXISTS '{NODE_DB_PATH}' AS g (READ_ONLY)")
|
| 88 |
-
return
|
| 89 |
-
f"UNION ALL SELECT id, {column} FROM g.nodes_MW")
|
| 90 |
raise SystemExit(f"no node properties found: expected {NODES_PARQUET} "
|
| 91 |
f"or {NODE_DB_PATH}")
|
| 92 |
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
def species_for(con, node_ids: list) -> list:
|
| 95 |
"""species per node id, in node_ids order. Raises if any id is unknown."""
|
| 96 |
by_id = dict(con.execute(node_property_query(con, "species")).fetchall())
|
|
|
|
| 72 |
return out
|
| 73 |
|
| 74 |
|
| 75 |
+
def node_source(con) -> str:
|
| 76 |
+
"""A SQL relation with the full node property columns, from whatever exists.
|
| 77 |
|
| 78 |
The released dataset ships data/nodes_expected_ge5.parquet, which holds the
|
| 79 |
property rows for exactly the nodes in edges_expected_ge5 — enough for every
|
|
|
|
| 82 |
across nodes_ML (MTBLS ids) and nodes_MW (ST ids).
|
| 83 |
"""
|
| 84 |
if NODES_PARQUET.exists():
|
| 85 |
+
return f"(SELECT * FROM '{NODES_PARQUET}')"
|
| 86 |
if pathlib.Path(NODE_DB_PATH).exists():
|
| 87 |
con.execute(f"ATTACH IF NOT EXISTS '{NODE_DB_PATH}' AS g (READ_ONLY)")
|
| 88 |
+
return "(SELECT * FROM g.nodes_ML UNION ALL SELECT * FROM g.nodes_MW)"
|
|
|
|
| 89 |
raise SystemExit(f"no node properties found: expected {NODES_PARQUET} "
|
| 90 |
f"or {NODE_DB_PATH}")
|
| 91 |
|
| 92 |
|
| 93 |
+
def node_property_query(con, column: str = "species") -> str:
|
| 94 |
+
"""SQL returning (id, <column>) for every node."""
|
| 95 |
+
return f"SELECT id, {column} FROM {node_source(con)}"
|
| 96 |
+
|
| 97 |
+
|
| 98 |
def species_for(con, node_ids: list) -> list:
|
| 99 |
"""species per node id, in node_ids order. Raises if any id is unknown."""
|
| 100 |
by_id = dict(con.execute(node_property_query(con, "species")).fetchall())
|