diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-04 14:52:57 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-04 14:52:57 +0000 |
| commit | ea3633cf3e00047ca3906406c270d9f04acd2241 (patch) | |
| tree | c2aeb365ee43dd9eb1de2fab201c01921420a833 /src | |
| parent | 5e7870834fc29e707bc7332d83e4c68f05b9b8f7 (diff) | |
| download | genenetwork4-ea3633cf3e00047ca3906406c270d9f04acd2241.tar.gz | |
Add GET /species/{species}/datasets
Lists the expression (ProbeSet) datasets belonging to a species, across
all of its groups -- the species-scoped equivalent of
/groups/{group}/datasets (db::get_species_datasets joins ProbeSetFreeze
through ProbeFreeze and InbredSet to InbredSet.SpeciesId, reusing the
existing Dataset struct). GeneNetwork2's own species-scoped variant of
wqflask.api.router.get_datasets_for_group still requires a group name
(species only disambiguates it); this doesn't.
Not gated on gn-auth, matching its /groups/{group}/datasets sibling:
this returns dataset metadata (names, public/confidentiality flags),
not trait data, unlike the /datasets/{dataset}/probesets family.
tests/species_datasets.rs and its Python mirror cover the mouse-group
and unknown-species cases.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
Diffstat (limited to 'src')
| -rw-r--r-- | src/db.rs | 47 | ||||
| -rw-r--r-- | src/lib.rs | 1 | ||||
| -rw-r--r-- | src/routes/species.rs | 54 |
3 files changed, 102 insertions, 0 deletions
diff --git a/src/db.rs b/src/db.rs index 903f2d6..6a5d122 100644 --- a/src/db.rs +++ b/src/db.rs @@ -465,6 +465,53 @@ pub fn get_group_datasets(group_id: u16) -> Result<Vec<Dataset>, mysql::Error> { ) } +/// Fetch the expression datasets belonging to a species (across all of +/// its groups), the species-scoped equivalent of get_group_datasets. +/// GeneNetwork2's own species-scoped variant of +/// wqflask.api.router.get_datasets_for_group still requires a group +/// name (species only disambiguates it); this doesn't need one. +pub fn get_species_datasets(species_id: u16) -> Result<Vec<Dataset>, mysql::Error> { + let pool = pool()?; + let mut conn = pool.get_conn()?; + conn.exec_map( + "SELECT ProbeSetFreeze.Id, ProbeSetFreeze.ProbeFreezeId, ProbeSetFreeze.Name, \ + ProbeSetFreeze.Name2, ProbeSetFreeze.FullName, ProbeSetFreeze.ShortName, \ + CAST(ProbeSetFreeze.CreateTime AS CHAR), ProbeSetFreeze.public, \ + ProbeSetFreeze.confidentiality, ProbeSetFreeze.DataScale \ + FROM ProbeSetFreeze \ + JOIN ProbeFreeze ON ProbeFreeze.ProbeFreezeId = ProbeSetFreeze.ProbeFreezeId \ + JOIN InbredSet ON InbredSet.Id = ProbeFreeze.InbredSetId \ + WHERE InbredSet.SpeciesId = :species_id \ + ORDER BY ProbeSetFreeze.Name", + mysql::params! { "species_id" => species_id }, + |( + id, + probe_freeze_id, + name, + name2, + full_name, + short_name, + create_time, + public, + confidentiality, + data_scale, + )| { + Dataset { + id, + probe_freeze_id, + name, + name2, + full_name, + short_name, + create_time, + public, + confidentiality, + data_scale, + } + }, + ) +} + /// Fetch one dataset by Name, Name2, FullName, ShortName or numeric /// Id, matching GeneNetwork2's wqflask.api.router.get_dataset_info's /// matching logic for its ProbeSet (mRNA expression) branch. diff --git a/src/lib.rs b/src/lib.rs index 4454e3b..cac59d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,6 +54,7 @@ pub fn app() -> Router { .routes(routes!(version)) .routes(routes!(routes::species::species)) .routes(routes!(routes::species::species_by_name)) + .routes(routes!(routes::species::species_datasets)) .routes(routes!(routes::groups::groups)) .routes(routes!(routes::groups::group_by_name)) .routes(routes!(routes::groups::group_strains)) diff --git a/src/routes/species.rs b/src/routes/species.rs index ef775f4..bb8794e 100644 --- a/src/routes/species.rs +++ b/src/routes/species.rs @@ -92,3 +92,57 @@ pub async fn species_by_name( .with_next("/species") }) } + +#[utoipa::path(get, path = "/species/{species}/datasets", summary = "List the expression (ProbeSet) datasets belonging to a species", params( + ("species" = String, Path, description = "Species Name, FullName or SpeciesName") +), responses( + (status = 200, description = "The expression (ProbeSet) datasets belonging to the species", body = Vec<db::Dataset>), + (status = 404, description = "No matching species", body = ApiError), + (status = 500, description = "Database error", body = ApiError) +))] +pub async fn species_datasets( + Extension(request_id): Extension<RequestId>, + Path(species): Path<String>, +) -> Result<Json<Vec<db::Dataset>>, ApiError> { + let rid = request_id_string(&request_id); + let not_found_name = species.clone(); + tokio::task::spawn_blocking(move || { + db::get_species_by_name(&species).and_then(|species| match species { + Some(species) => db::get_species_datasets(species.id).map(Some), + None => Ok(None), + }) + }) + .await + .map_err(|e| { + ApiError::new( + StatusCode::INTERNAL_SERVER_ERROR, + "internal_error", + "Internal error", + e.to_string(), + "species_datasets", + ) + .with_request_id(rid.clone()) + })? + .map_err(|e| { + ApiError::new( + StatusCode::INTERNAL_SERVER_ERROR, + "database_error", + "Database error", + e.to_string(), + "species_datasets", + ) + .with_request_id(rid.clone()) + })? + .map(Json) + .ok_or_else(|| { + ApiError::new( + StatusCode::NOT_FOUND, + "species_not_found", + "Species not found", + format!("No species matching '{not_found_name}'."), + "species_datasets", + ) + .with_request_id(rid) + .with_next("/species") + }) +} |
