Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- app/.source-revision +1 -1
- app/main.py +2 -14
- app/rnaseq/geo_counts.py +1 -20
- app/routers/rnaseq_expression.py +1 -4
- app/services/auth.py +2 -12
app/.source-revision
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
403db3c67a9c050af9b29600e8c5481f379494ce
|
app/main.py
CHANGED
|
@@ -253,22 +253,10 @@ async def _startup_services():
|
|
| 253 |
logger.info("In-process durable worker started")
|
| 254 |
else:
|
| 255 |
logger.info("In-process durable worker disabled")
|
| 256 |
-
|
| 257 |
-
# The expression queue is durable in Supabase when credentials are present.
|
| 258 |
-
# Start its lease-based worker by default in that deployment; an explicit
|
| 259 |
-
# false remains available for split API/worker deployments. Multiple API
|
| 260 |
-
# replicas are safe because the Postgres claim RPC provides exclusive leases.
|
| 261 |
-
run_expression_worker = (
|
| 262 |
-
expression_worker_setting.strip().lower() in ('1', 'true', 'yes')
|
| 263 |
-
if expression_worker_setting is not None
|
| 264 |
-
else bool(settings.SUPABASE_URL and settings.SUPABASE_SERVICE_ROLE_KEY)
|
| 265 |
-
)
|
| 266 |
-
if run_expression_worker:
|
| 267 |
from app.rnaseq.durable import start_expression_worker
|
| 268 |
app.state.expression_worker = start_expression_worker()
|
| 269 |
-
logger.info('
|
| 270 |
-
else:
|
| 271 |
-
logger.info('RNA-seq expression worker disabled: durable Supabase configuration absent or explicitly disabled')
|
| 272 |
|
| 273 |
|
| 274 |
@app.get("/health")
|
|
|
|
| 253 |
logger.info("In-process durable worker started")
|
| 254 |
else:
|
| 255 |
logger.info("In-process durable worker disabled")
|
| 256 |
+
if os.environ.get('RUN_EXPRESSION_WORKER', 'false').strip().lower() in ('1','true','yes'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
from app.rnaseq.durable import start_expression_worker
|
| 258 |
app.state.expression_worker = start_expression_worker()
|
| 259 |
+
logger.info('Expression queue worker explicitly enabled')
|
|
|
|
|
|
|
| 260 |
|
| 261 |
|
| 262 |
@app.get("/health")
|
app/rnaseq/geo_counts.py
CHANGED
|
@@ -116,26 +116,7 @@ async def fetch_series(client: httpx.AsyncClient, accession: str) -> dict:
|
|
| 116 |
base = {"acc": accession, "form": "text", "view": "quick"}
|
| 117 |
series_text = (await _get_limited(client, GEO_URL, params={**base, "targ": "self"})).decode("utf-8-sig")
|
| 118 |
if f"^SERIES = {accession}" not in series_text:
|
| 119 |
-
|
| 120 |
-
# return a challenge page during anti-bot throttling). Confirm the
|
| 121 |
-
# accession through E-utilities before classifying it as not found.
|
| 122 |
-
if "<html" in series_text[:1000].lower() or "<!doctype" in series_text[:1000].lower():
|
| 123 |
-
import xml.etree.ElementTree as ET
|
| 124 |
-
try:
|
| 125 |
-
async with httpx.AsyncClient(timeout=15) as verify_client:
|
| 126 |
-
response = await verify_client.get(
|
| 127 |
-
"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi",
|
| 128 |
-
params={"db": "gds", "term": f"{accession}[Accession]", "retmode": "xml", "retmax": 1},
|
| 129 |
-
)
|
| 130 |
-
response.raise_for_status()
|
| 131 |
-
count = ET.fromstring(response.text).findtext("Count", default="0")
|
| 132 |
-
if count == "0":
|
| 133 |
-
raise GeoCountsError(f"GEO Series {accession} was not found in NCBI GEO. Check the accession or use the reviewed count-matrix upload workflow.")
|
| 134 |
-
except GeoCountsError:
|
| 135 |
-
raise
|
| 136 |
-
except Exception as exc:
|
| 137 |
-
raise GeoCountsError("NCBI GEO returned an HTML challenge instead of a Series record; retry later or use the reviewed count-matrix upload workflow.") from exc
|
| 138 |
-
raise GeoCountsError("NCBI GEO did not return a valid SOFT Series record for this accession.")
|
| 139 |
sample_text = (await _get_limited(client, GEO_URL, params={**base, "targ": "gsm"}, limit=5 * 1024 * 1024)).decode("utf-8-sig")
|
| 140 |
organisms = sorted(set(_soft_lines(sample_text, "Sample_organism_ch1")))
|
| 141 |
samples: list[GeoSample] = []
|
|
|
|
| 116 |
base = {"acc": accession, "form": "text", "view": "quick"}
|
| 117 |
series_text = (await _get_limited(client, GEO_URL, params={**base, "targ": "self"})).decode("utf-8-sig")
|
| 118 |
if f"^SERIES = {accession}" not in series_text:
|
| 119 |
+
raise GeoCountsError("GEO did not return the requested Series record.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
sample_text = (await _get_limited(client, GEO_URL, params={**base, "targ": "gsm"}, limit=5 * 1024 * 1024)).decode("utf-8-sig")
|
| 121 |
organisms = sorted(set(_soft_lines(sample_text, "Sample_organism_ch1")))
|
| 122 |
samples: list[GeoSample] = []
|
app/routers/rnaseq_expression.py
CHANGED
|
@@ -66,10 +66,7 @@ async def _save_upload(upload: UploadFile, target: Path, max_bytes: int) -> None
|
|
| 66 |
|
| 67 |
@router.get("/capabilities")
|
| 68 |
def expression_capabilities():
|
| 69 |
-
|
| 70 |
-
# The real upload route requires durable private storage and a live worker.
|
| 71 |
-
from app.rnaseq import durable
|
| 72 |
-
readiness = durable.readiness()
|
| 73 |
rscript = readiness["rscript_available"]
|
| 74 |
return {
|
| 75 |
**readiness,
|
|
|
|
| 66 |
|
| 67 |
@router.get("/capabilities")
|
| 68 |
def expression_capabilities():
|
| 69 |
+
readiness = expression_readiness()
|
|
|
|
|
|
|
|
|
|
| 70 |
rscript = readiness["rscript_available"]
|
| 71 |
return {
|
| 72 |
**readiness,
|
app/services/auth.py
CHANGED
|
@@ -108,18 +108,8 @@ async def get_user_id(
|
|
| 108 |
if not _looks_like_jwt(token):
|
| 109 |
return None
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
# SUPABASE_JWT_SECRET must not force every live asymmetric session through
|
| 114 |
-
# an HS256-only verifier. Inspect only the untrusted header to choose the
|
| 115 |
-
# verification route; identity is returned exclusively by a signature
|
| 116 |
-
# check or Supabase Auth's authoritative /user endpoint.
|
| 117 |
-
local_identity = _verify_locally(token) if _jwt_secret() else None
|
| 118 |
-
if local_identity:
|
| 119 |
-
return local_identity
|
| 120 |
-
# If local HS256 verification fails, ask Supabase Auth to validate the
|
| 121 |
-
# bearer token. This also handles rotated legacy secrets and asymmetric
|
| 122 |
-
# signing keys without ever trusting the decoded JWT payload.
|
| 123 |
return await _verify_via_supabase(token)
|
| 124 |
|
| 125 |
|
|
|
|
| 108 |
if not _looks_like_jwt(token):
|
| 109 |
return None
|
| 110 |
|
| 111 |
+
if _jwt_secret():
|
| 112 |
+
return _verify_locally(token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
return await _verify_via_supabase(token)
|
| 114 |
|
| 115 |
|