diff options
| author | Pjotr <wrk@bosa.lan> | 2026-10-08 13:37:57 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-08 13:37:57 +0000 |
| commit | 2edc685bb7c56d5f9f28da09378f300bfe81021d (patch) | |
| tree | 1120d7589a1143ef29a4f5d2e2a47437e8699552 /tests | |
| parent | 208eeac395079f46fcbe07b4185524e017c554ef (diff) | |
| download | genenetwork4-2edc685bb7c56d5f9f28da09378f300bfe81021d.tar.gz | |
* src/db.rs, src/routes: add mapping_method, tissue, /mapping-methods, /accessions.
Answers four more questions of aisearch's full_benchmark.csv from
tables the API did not expose.
* src/db.rs (Group, GroupDetail), src/routes/groups.rs: groups gain
`mapping_method`, the name of the MappingMethod row their
mapping_method_id points to (qtlreaper, Rqtl, ...), or null.
* src/db.rs (Dataset): datasets gain `tissue`, the Tissue their
ProbeFreeze points to (e.g. "Brain mRNA").
* src/routes/mapping_methods.rs: GET /mapping-methods lists the
MappingMethod table, including tools no group uses (PLINK, FastMap).
* src/routes/accessions.rs: GET /accessions/{accession} resolves a
GeneNetwork accession number (GN602, gn602 or 602) via InfoFiles to the
dataset's name, title, category (publish/probeset) and group.
* docs/genenetwork_datatypes.md: MappingMethodId is a key into the
MappingMethod table (the authoritative reading); GN2's code-based reading
is noted as superseded.
* tests/benchmark.rs, test/data/benchmark_search.json: add the 60 new
full-benchmark rows that pass (full rows 0..114; search rows run against
recorded production gn3, the rest need the database), and full rows 33
(mapping tools), 34 (Rqtl for outbred sets), 35 (GN602) and 44 (only
GTEx v8 has TPM datasets). The untested rows are listed in the file's
header comment with the reason for each.
* tests, test/python: tests for the new fields and endpoints; both
endpoints added to the OpenAPI and next-link crawl tests.
* README.md, RELEASE_NOTES.md: document the new fields and endpoints.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/accessions.rs | 80 | ||||
| -rw-r--r-- | tests/benchmark.rs | 400 | ||||
| -rw-r--r-- | tests/dataset_by_name.rs | 28 | ||||
| -rw-r--r-- | tests/envelope.rs | 3 | ||||
| -rw-r--r-- | tests/group_by_name.rs | 23 | ||||
| -rw-r--r-- | tests/groups.rs | 29 | ||||
| -rw-r--r-- | tests/mapping_methods.rs | 31 | ||||
| -rw-r--r-- | tests/openapi.rs | 2 |
8 files changed, 588 insertions, 8 deletions
diff --git a/tests/accessions.rs b/tests/accessions.rs new file mode 100644 index 0000000..a090e64 --- /dev/null +++ b/tests/accessions.rs @@ -0,0 +1,80 @@ +use axum::http::StatusCode; +use http_body_util::BodyExt; +use serde_json::Value; + +mod common; + +/// Needs a live MariaDB connection (SQL_URI) and a valid token; skips +/// rather than fails when either is missing, same as groups.rs. GN602 is +/// the BXD published phenotypes dataset; GN1 is Br_U_0803_M. +#[tokio::test] +async fn accession_resolves_to_its_dataset() { + if !common::db_available() { + eprintln!( + "skipping accession_resolves_to_its_dataset: no usable database (check SQL_URI credentials)" + ); + return; + } + let Some(token) = common::auth_token().await else { + eprintln!("skipping accession_resolves_to_its_dataset: no token (see docs/gn-auth.md)"); + return; + }; + + for uri in ["/accessions/GN602", "/accessions/gn602", "/accessions/602"] { + let response = common::get_with_token(&format!("GET {uri}"), uri, &token).await; + assert_eq!(response.status(), StatusCode::OK, "{uri}"); + let body = response.into_body().collect().await.unwrap().to_bytes(); + let found: Value = common::data(&body); + assert_eq!(found["accession"], 602, "{uri}"); + assert_eq!(found["name"], "BXDPublish"); + assert_eq!(found["title"], "BXD Published Phenotypes"); + assert_eq!(found["category"], "publish"); + assert_eq!(found["group"], "BXD"); + } + + // An expression dataset. + let response = common::get_with_token("GET /accessions/GN1", "/accessions/GN1", &token).await; + assert_eq!(response.status(), StatusCode::OK); + let body = response.into_body().collect().await.unwrap().to_bytes(); + let found: Value = common::data(&body); + assert_eq!(found["name"], "Br_U_0803_M"); + assert_eq!(found["category"], "probeset"); + assert_eq!(found["group"], "BXD"); +} + +#[tokio::test] +async fn accession_rejects_text_and_unknown_numbers() { + if !common::db_available() { + eprintln!( + "skipping accession_rejects_text_and_unknown_numbers: no usable database (check SQL_URI credentials)" + ); + return; + } + let Some(token) = common::auth_token().await else { + eprintln!("skipping accession_rejects_text_and_unknown_numbers: no token (see docs/gn-auth.md)"); + return; + }; + + let response = common::get_with_token( + "GET /accessions/BXDPublish", + "/accessions/BXDPublish", + &token, + ) + .await; + assert_eq!(response.status(), StatusCode::BAD_REQUEST); + let body = response.into_body().collect().await.unwrap().to_bytes(); + let error: Value = serde_json::from_slice(&body).unwrap(); + assert_eq!(error["code"], "invalid_parameter"); + assert_eq!(error["operation_id"], "accession"); + + let response = common::get_with_token( + "GET /accessions/GN99999999", + "/accessions/GN99999999", + &token, + ) + .await; + assert_eq!(response.status(), StatusCode::NOT_FOUND); + let body = response.into_body().collect().await.unwrap().to_bytes(); + let error: Value = serde_json::from_slice(&body).unwrap(); + assert_eq!(error["code"], "accession_not_found"); +} diff --git a/tests/benchmark.rs b/tests/benchmark.rs index 9bdeb9a..31c68ea 100644 --- a/tests/benchmark.rs +++ b/tests/benchmark.rs @@ -1,12 +1,22 @@ -//! The questions of aisearch/data/small_benchmark.csv that this API can -//! answer today, each checked against the benchmark's own answer. Row -//! numbers below are 0-based data rows of that file. +//! The questions of aisearch/data/small_benchmark.csv and +//! full_benchmark.csv that this API can answer today, each checked +//! against the benchmark's own answer. "Row N" is a 0-based data row of +//! the small file, "Full row N" of the full file (whose 115 rows include +//! 37 of the small file's, which are tested once, as small rows). //! -//! Not covered: rows 18 (the benchmark lists datasets our database does -//! not link to the group), 19 (no mammal/taxonomy class) and 38 (the -//! benchmark's answer is an arbitrary sample of many matching traits). -//! Rows 11, 16, 25, 30, 34 and 37 need trait short names (abbreviations), -//! the GeneNetwork trait URL and /search pagination. +//! Not covered, small file: rows 18 (the benchmark lists datasets our +//! database does not link to the group), 19 (no mammal/taxonomy class) +//! and 38 (an arbitrary sample of many matching traits). +//! Not covered, full file (the 14 new rows the API cannot answer, or +//! answers only in part): 1, 4, 5, 8, 32, 42, 43, 52, 55 (the tissue +//! reaches every benchmark dataset, but with 36 more), 61, 62, 63, 87 +//! (the benchmark's LOD belongs to the males' trait, though the +//! question says female) and 112 (several traits match). +//! Full rows 71, 78, 79, 80, 83, 84, 88, 101, 103 and 104 name traits by the +//! benchmark's sanitised short names (every non-alphanumeric character +//! turned into `_`), which the database stores unsanitised +//! (`AAP/Lys_CD`, `TAG(56:7)_2_CD`), so they are matched against the +//! group's full trait listing here. //! //! Search-based questions run against recorded production gn3 responses //! (test/data/benchmark_search.json, test/data/search_serotonin_midbrain_bxd.json; @@ -176,6 +186,376 @@ fn set_of(items: &[&str]) -> BTreeSet<String> { items.iter().map(|s| s.to_string()).collect() } +/// `text` lowercased with everything but letters and digits removed, to +/// compare descriptions and names across the benchmark's punctuation. +fn norm(text: &str) -> String { + text.chars() + .filter(|c| c.is_ascii_alphanumeric()) + .collect::<String>() + .to_lowercase() +} + +/// A set of names compared by `norm`. +fn nset<'a>(items: impl IntoIterator<Item = &'a str>) -> BTreeSet<String> { + items.into_iter().map(norm).collect() +} + +fn assert_close(actual: f64, expected: f64, what: &str) { + assert!( + (actual - expected).abs() <= 1e-9 * expected.abs().max(1.0), + "{what}: {actual} vs benchmark {expected}" + ); +} + +/// The trait of `listing` (`/groups/{g}/traits`) whose short name is the +/// benchmark's `sanitised` name, i.e. equal once every non-alphanumeric +/// character is `_`. +fn find_sanitised<'a>(listing: &'a [Value], sanitised: &str) -> &'a Value { + let sanitise = |s: &str| { + s.chars() + .map(|c| if c.is_ascii_alphanumeric() { c } else { '_' }) + .collect::<String>() + .trim_matches('_') + .to_string() + }; + let wanted = sanitise(sanitised); + let found: Vec<&Value> = listing + .iter() + .filter(|t| t["abbreviation"].as_str().is_some_and(|a| sanitise(a) == wanted)) + .collect(); + assert_eq!(found.len(), 1, "short name {sanitised}: {} matches", found.len()); + found[0] +} + +fn description(trait_info: &Value) -> &str { + trait_info["post_publication_description"] + .as_str() + .or_else(|| trait_info["description"].as_str()) + .unwrap() +} + + +/// Full-benchmark rows answered from `/search` (recorded gn3 responses). +async fn full_benchmark_search_rows(token: &str, db: bool) { + // Full rows 66-68: the trait for age at onset of working memory deficit + // in Alzheimer's BXD mice, its description and its PubMed id. + let hits = search("working AND memory AND onset AND group:BXD", token).await; + let aao = best( + &hits, + &["Age at onset of working memory deficit", "male and females average of AD-BXD cases positive for 5XFAD"], + &[], + ); + assert_lod(aao, 2.4026782929885950324); + assert!(norm(aao["description"].as_str().unwrap()).ends_with(&norm( + "Central nervous system, behavior, learning and memory: Age at onset of working memory deficit defined as first age at which performance dropped to chance 50%, male and females average of AD-BXD cases positive for 5XFAD transgene [months]" + ))); + assert_eq!(aao["pubmed_id"], 30595332); + if db { + assert_eq!(aao["locus"], "rsm10000005323"); + } + + // Full row 74: highest mapping score for 3NP neurodegeneration. + let nitro = search("nitropropionic", token).await; + let hit = best(&nitro, &["3-nitropropionic acid neurodegeneration"], &[]); + assert_lod(hit, 6.1340526876326206818); + if db { + assert_eq!(hit["locus"], "rsm10000005366"); + } + + // Full row 77: the PubMed study on THDOC in the olfactory bulb. + let olfactory = search("olfactory AND group:BXD", token).await; + let thdoc = best(&olfactory, &["THDOC", "olfactory bulb", "1 hour after saline"], &[]); + assert_eq!(thdoc["pubmed_id"], 21494628); + + // Full rows 85-86: the liver enzyme measured in 14-week old females. + let alt = search("alanine AND transaminase AND group:BXD", token).await; + let hit = best(&alt, &["Alanine transaminase", "14-week old females"], &[]); + assert_lod(hit, 2.1671810310648718101); + assert_eq!(hit["pubmed_id"], 22939713); + if db { + assert_eq!(hit["locus"], "rsm10000012410"); + } + + // Full row 91: additive effect of the acoustic startle response to + // 110 dB at 10 kHz (the trait without prepulse, not a PPI trait). + let startle = search("startle AND group:BXD", token).await; + let asr = best( + &startle, + &["Acoustic startle response to a 110 dB SPL, 10 kHz tone without prepul"], + &[], + ); + assert_close(asr["additive"].as_f64().unwrap(), -5.7583334166666668708, "ASR additive"); + + // Full row 94: the PubMed article on striatum volume. + let volume = search("striatum AND volume AND group:BXD", token).await; + let hit = best(&volume, &["dorsal striatum of young adults", "shrinkage corrected"], &[]); + assert_eq!(hit["pubmed_id"], 19191878); + + // Full rows 97-100: T cell populations estimated in the breast cancer + // tumors of BXD x C3-1TAg F1 females, found past the first 100 hits. + let mut timer = search_page("TIMER AND group:BXD", 1, token).await; + timer.extend(search_page("TIMER AND group:BXD", 2, token).await); + let ending = |tail: &str| -> &Value { + timer + .iter() + .find(|h| h["description"].as_str().unwrap().ends_with(tail)) + .unwrap_or_else(|| panic!("no TIMER trait ending {tail}")) + }; + ending("T.cell.gamma.delta_CIBERSORT"); // row 97 + ending("T.cell.CD4..naive_XCELL"); // row 98 ... + let cd8_naive = ending("T.cell.CD8..naive_XCELL"); // ... and 98-99 + assert_lod(cd8_naive, 2.6767753665261841967); + if db { + assert_eq!(cd8_naive["locus"], "rsm10000001634"); + } + let cd8 = ending("T.cell.CD8._TIMER"); // row 100: the model named in the description + let model = cd8["description"].as_str().unwrap(); + assert!(model.contains("C3 (1)-TAg") && model.contains("JAX Stock 013591")); + + // Full rows 106-107: serum TSH binding inhibition after 2 and 3 + // immunizations with TSHR A-subunit adenovirus, and its PubMed id. + let tsh = search("TSH AND binding AND group:BXD", token).await; + let two = best(&tsh, &["1 week after 2 immunizations"], &[]); + let three = best(&tsh, &["4 weeks after 3 immunizations"], &[]); + assert_lod(two, 7.8087209638496242192); + assert_lod(three, 11.292110851469207233); + assert_eq!(three["pubmed_id"], 25051451); + if db { + assert_eq!(two["locus"], "rs3672987"); + assert_eq!(three["locus"], "rs3672987"); + } + + // Full row 114: mean of 3-MT in male BXD striatum after saline. + let mptp = search("MPTP AND group:BXD", token).await; + let saline = best( + &mptp, + &["3-methoxytyramine", "2-4 month-old males 48 h after saline injection"], + &[], + ); + assert_close(saline["mean"].as_f64().unwrap(), 0.39399999976158139869, "3-MT mean"); +} + +/// Full-benchmark rows answered from the database-backed endpoints. +async fn full_benchmark_database_rows(token: &str) { + // Full row 0: three taxonomic families. + let species = get_json("/species", token).await; + let families: BTreeSet<&str> = species + .as_array() + .unwrap() + .iter() + .map(|s| s["family"].as_str().unwrap()) + .collect(); + assert_eq!(families, ["Other Metazoa", "Plants", "Vertebrates"].into_iter().collect()); + // Full row 3: Drosophila's reference assembly. + let fly = get_json("/species/drosophila", token).await; + assert!(fly["menu_name"].as_str().unwrap().contains("dm6")); + + // Group questions: the list (family, species, genetic type) plus every + // group's detail (description, set code). + let list = get_json("/groups", token).await; + let list = list.as_array().unwrap(); + let bxd = list.iter().find(|g| g["name"] == "BXD").unwrap(); + assert_eq!(bxd["genetic_type"], "riset"); // full row 12 + let mut details = Vec::new(); + for g in list { + details.push(get_json(&format!("/groups/{}", g["name"].as_str().unwrap()), token).await); + } + let detail = |name: &str| details.iter().find(|d| d["name"] == name).unwrap(); + // Full rows 10, 13, 15: genotypes, the full name of DOL, a category. + assert_eq!(detail("HIV-1Tg")["family"], "Groups Without Genotypes"); // no genotypes + assert!(detail("DOL")["full_name"].as_str().unwrap().contains("Boon Lung Infection")); + assert_eq!(detail("B6D2F2")["family"], "Crosses, AIL, HS"); + // Full row 11: eight population categories. + let categories: BTreeSet<&str> = details.iter().filter_map(|d| d["family"].as_str()).collect(); + assert_eq!(categories.len(), 8, "{categories:?}"); + // Full row 20: the reference-population RI panel from BALB/cBy and C57BL/6By. + let panel: Vec<&str> = details + .iter() + .filter(|d| d["family"].as_str().is_some_and(|f| f.starts_with("Reference"))) + .filter(|d| d["description"].as_str().unwrap_or_default().contains("BALB/cBy")) + .map(|d| d["name"].as_str().unwrap()) + .collect(); + assert_eq!(panel, ["CXB"]); + // Full row 21: the HS rat is outbred. + assert!(detail("HSNIH-Palmer")["description"].as_str().unwrap().to_lowercase().contains("outbred")); + // Full row 23: the set coded RHV. + let coded: Vec<&str> = details + .iter() + .filter(|d| d["group_code"] == "RHV") + .map(|d| d["name"].as_str().unwrap()) + .collect(); + assert_eq!(coded, ["HIV-1Tg"]); + // Full row 24: the human set on brain connectivity. + let human = group_names("species=human", token).await; + let connectivity: Vec<&str> = details + .iter() + .filter(|d| human.contains(d["name"].as_str().unwrap())) + .filter(|d| { + let text = format!("{} {}", d["full_name"], d["description"]).to_lowercase(); + text.contains("connectom") || text.contains("connectivity") + }) + .map(|d| d["name"].as_str().unwrap()) + .collect(); + assert_eq!(connectivity, ["HCP"]); + + // Group lookups by family, species or text. + let hrdp = group_names("family=HRDP", token).await; + assert_eq!(nset(hrdp.iter().map(String::as_str)), nset(["HRDP_HXB_BXH_BP", "HRDP_HXB_BXH_Metb"])); // 7 + assert_eq!(group_names("q=gulf", token).await, set_of(&["DOD-BXD-GWI"])); // 17 + assert_eq!(group_names("q=B6MRLF2", token).await, set_of(&["B6MRLF2-D2MRLF2"])); // 18 + assert_eq!(group_names("q=lens", token).await, set_of(&["B6-Lens"])); // 19 + assert!(group_names("q=UCI", token).await.contains("Aging-Brain-UCI")); // 25 + assert_eq!(group_names("q=islet", token).await, set_of(&["Islets-Gerling"])); // 26 + assert_eq!(group_names("species=human&q=child", token).await, set_of(&["CANDLE"])); // 28 + assert_eq!(group_names("q=CEPH", token).await, set_of(&["CEPH-2004", "CEPH-2009"])); // 29 + assert_eq!(group_names("species=medaka", token).await, set_of(&["MIKK"])); // 31 + assert_eq!(group_names("q=EBV", token).await, set_of(&["EBV_T_Cells_PERKINS"])); // 49 + // Full row 41: the human sets (no genotype field: all of them). + assert_eq!( + nset(human.iter().map(String::as_str)), + nset([ + "GTEx", "GTEx_v5", "GTEx_v8", "HCP", "EBV_T_Cells_PERKINS", "HB", "HLC", "HLT", "HSB", + "TIGEM_Retina_RNA_Seq", "Islets_Gerling", "Brain_Normal_NIH_Gibbs", "Aging_Brain_UCI", + "AD_cases_controls", "AD_cases_controls_Myers", "CANDLE", "CEPH_2004", "CEPH_2009", + ]) + ); + // Full row 48: CANDLE's species. + let candle = list.iter().find(|g| g["name"] == "CANDLE").unwrap(); + let candle_species = get_json(&format!("/species/{}", candle["species"].as_str().unwrap()), token).await; + assert!(candle_species["full_name"].as_str().unwrap().contains("Homo sapiens")); + // Full row 50: the human transcriptome resource with the most datasets. + let mut counts = Vec::new(); + for name in &human { + let datasets = get_json(&format!("/groups/{name}/datasets"), token).await; + counts.push((datasets.as_array().unwrap().len(), name.clone())); + } + counts.sort(); + assert!(counts.last().unwrap().1.starts_with("GTEx"), "{counts:?}"); + // Full row 44: the human dataset with both log2-transformed and + // TPM-normalised expression across tissues: only GTEx v8 has TPM + // datasets, and they are all on the log2 scale. + let mut tpm_groups = BTreeSet::new(); + for name in &human { + let datasets = get_json(&format!("/groups/{name}/datasets"), token).await; + for dataset in datasets.as_array().unwrap() { + if dataset["full_name"].as_str().unwrap().contains("TPM") { + tpm_groups.insert(name.clone()); + assert_eq!(dataset["data_scale"], "log2", "{}", dataset["name"]); + } + } + } + assert_eq!(tpm_groups, set_of(&["GTEx_v8"])); + + // Full row 33: the mapping tools in use, including those no group uses. + let methods = get_json("/mapping-methods", token).await; + let tools: BTreeSet<&str> = methods + .as_array() + .unwrap() + .iter() + .map(|m| m["name"].as_str().unwrap()) + .collect(); + assert_eq!(tools, ["FastMap", "HappyR", "PLINK", "Rqtl", "qtlreaper"].into_iter().collect()); + // Full row 34: the preferred tool for heterogeneous stock and outbred + // populations is Rqtl (HSNIH-RGSMC maps with qtlreaper, so it is a + // majority, not a rule). + for name in ["HSNIH-Palmer", "DO", "CC"] { + let group = list.iter().find(|g| g["name"] == name).unwrap(); + assert_eq!(group["mapping_method"], "Rqtl", "{name}"); + } + // Full row 35: GN602 is the BXD phenotype dataset. + let gn602 = get_json("/accessions/GN602", token).await; + assert_eq!(gn602["category"], "publish"); + assert_eq!(gn602["group"], "BXD"); + assert_eq!(gn602["title"], "BXD Published Phenotypes"); + + // Full rows 56-58: BXD datasets by topic. + let datasets = get_json("/groups/BXD/datasets", token).await; + let named = |word: &str| -> BTreeSet<String> { + datasets + .as_array() + .unwrap() + .iter() + .map(|d| d["name"].as_str().unwrap()) + .filter(|n| n.to_lowercase().contains(word)) + .map(norm) + .collect() + }; + assert_eq!(named("gut"), nset(["UTHSC_GutExL_0414", "UTHSC_GutGL_0414"])); + assert_eq!(named("neut"), nset(["UTHSC_Neut_EL_1014", "UTHSC_Neut_1014"])); + assert_eq!( + named("germ"), + nset([ + "JAX_BXD_Germ_Cells_edgeR_0820", + "JAX_BXD_Germ_Cells_edgeR_log2_0820", + "JAX_BXD_Germ_Cells_edgeR_log2z_0820", + ]) + ); + + // Trait questions. Short names the database stores verbatim: + let by_abbreviation = |abbreviation: &'static str| { + let token = token.to_string(); + async move { + let traits = get_json(&format!("/groups/BXD/traits?abbreviation={abbreviation}"), &token).await; + let traits = traits.as_array().unwrap(); + assert_eq!(traits.len(), 1, "{abbreviation}"); + traits[0].clone() + } + }; + let otu = by_abbreviation("OTU_310_CD_norm_log10").await; + assert_eq!(otu["dataset"], "BXDPublish"); // full row 40: set BXD + assert!(description(&otu).contains("EPFL LISP3 Cohort")); // 105 + assert_close(otu["mean"].as_f64().unwrap(), 7.8246294298479632801, "OTU mean"); // 109 + let serotonin = by_abbreviation("5HT_MB_M").await; + assert_eq!( + serotonin["url"], + "https://genenetwork.org/show_trait?trait_id=17985&dataset=BXDPublish" + ); // 53 + assert!(description(&serotonin).to_lowercase().contains("serotonin")); // 54 + // BXD's full trait listing, for short names the database does not store + // verbatim (see the module comment). + let listing = get_json("/groups/BXD/traits", token).await; + let listing = listing.as_array().unwrap(); + let mptp = find_sanitised(listing, "5HT_CPU_Sal_MPTP_M"); + assert!(norm(description(mptp)).contains(&norm( + "MPTP 1-methyl-4-phenyl-1,2,3,6-tetrahydropyridine response 12.5 mg/kg ip, serotonin 5-HT concentration in caudate-putamen striatum in males 48 h after injection saline-MPTP group [ug/mg total protein]" + ))); // 71 + let amph = find_sanitised(listing, "AMPHLOC5mg"); + assert_close(amph["mean"].as_f64().unwrap(), 7220.8214285714284415, "AMPHLOC5mg mean"); + assert_lod(amph, 3.4041048067742516459); + assert_eq!(amph["locus"], "D4Mit178"); + assert!(norm(description(amph)).contains(&norm( + "Amphetamine response 5 mg/kg ip, locomotor activity from 0-60 min after injection [cm]" + ))); // 83-84 + let trait_23391 = get_json("/groups/BXD/traits/23391", token).await; + assert_eq!(trait_23391["abbreviation"], "OTU_310_CD_norm_log10"); // 110 + let trait_15959 = get_json("/groups/BXD/traits/15959", token).await; + assert_eq!( + trait_15959["url"], + "https://genenetwork.org/show_trait?trait_id=15959&dataset=BXDPublish" + ); // 111 + + // Short names the benchmark sanitises (see the module comment). + let ratio = find_sanitised(listing, "AAP_Lys_CD"); + assert_close(ratio["mean"].as_f64().unwrap(), 0.0045021891883398230949, "AAP/Lys mean"); // 78 + assert_eq!(ratio["pubmed_id"], 25215496); // 79 + let alcohol = find_sanitised(listing, "20__Alcohol_intake_W4D4_all_Females"); // 80 + assert!(norm(description(alcohol)).contains(&norm( + "Ethanol response, consumption of 20% v/v EtOH using the drinking in the dark DID method, 4 h access on day 4 week 4 normally housed 4-6 month old females 5 week baseline [g/kg]" + ))); + let alt = find_sanitised(listing, "ALT_d0__mean_F"); // 88 + assert!(description(alt).contains("Liver injury day 0 in adult females before carbon tetrachloride challenge")); + let strep = find_sanitised(listing, "Streptococcus_genus_CD_norm_log10"); // 101 + assert_lod(strep, 2.6777190182706016586); + assert_eq!(strep["locus"], "rsm10000014670"); + let chow = find_sanitised(listing, "TAG_56_7__2_CD"); // 103-104 + let high = find_sanitised(listing, "TAG_56_7__2_HFD"); + assert_lod(chow, 1.9755325276024489067); + assert_eq!(chow["locus"], "rs27728896"); + assert_lod(high, 3.5849473664517539362); + assert_eq!(high["locus"], "rsm10000014270"); + assert!(description(chow).contains("TG(16:0_18:1_22:6)")); +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn benchmark_questions() { let gn3 = spawn(Router::new().route("/api/search/", get(serve_gn3))).await; @@ -335,6 +715,8 @@ async fn benchmark_questions() { assert_eq!(cd8["locus"], "rs29338660"); } + full_benchmark_search_rows(token, db).await; + if !db { return; } @@ -531,4 +913,6 @@ async fn benchmark_questions() { colon, set_of(&["EPFL-LISP_BXD_Col-CD+HFD0917", "EPFL-LISP_BXD_Col-CD0917", "EPFL-LISP_BXD_Col-HFD0917"]) ); + + full_benchmark_database_rows(token).await; } diff --git a/tests/dataset_by_name.rs b/tests/dataset_by_name.rs index 7f2e182..6f7cde6 100644 --- a/tests/dataset_by_name.rs +++ b/tests/dataset_by_name.rs @@ -63,3 +63,31 @@ async fn dataset_by_name_unknown_dataset_returns_404() { assert_eq!(error["code"], "dataset_not_found"); assert_eq!(error["operation_id"], "dataset_by_name"); } + +/// A dataset says what it was measured in (the Tissue its ProbeFreeze +/// points to), here and in the group's dataset list. +#[tokio::test] +async fn datasets_report_their_tissue() { + if !common::db_available() { + eprintln!( + "skipping datasets_report_their_tissue: no usable database (check SQL_URI credentials)" + ); + return; + } + let Some(token) = common::auth_token().await else { + eprintln!("skipping datasets_report_their_tissue: no token (see docs/gn-auth.md)"); + return; + }; + + let response = common::get_with_token("GET /datasets/Br_U_0803_M", "/datasets/Br_U_0803_M", &token).await; + assert_eq!(response.status(), StatusCode::OK); + let body = response.into_body().collect().await.unwrap().to_bytes(); + let dataset: Value = common::data(&body); + assert_eq!(dataset["tissue"], "Brain mRNA"); + + let response = common::get_with_token("GET /groups/BXD/datasets", "/groups/BXD/datasets", &token).await; + let body = response.into_body().collect().await.unwrap().to_bytes(); + let datasets: Vec<Value> = common::data(&body); + let gut = datasets.iter().find(|d| d["name"] == "UTHSC_GutGL_0414").unwrap(); + assert_eq!(gut["tissue"], "Gastrointestinal mRNA"); +} diff --git a/tests/envelope.rs b/tests/envelope.rs index 8c5160c..4455406 100644 --- a/tests/envelope.rs +++ b/tests/envelope.rs @@ -94,6 +94,9 @@ async fn next_links_resolve() { "/groups/BXD/strains", "/groups/BXD/case-attributes", "/groups/BXD/datasets", + "/mapping-methods", + "/accessions/GN602", + "/accessions/GN1", "/groups/BXD/traits?abbreviation=5HT_MB_M", "/groups/BXD/traits/17985", "/groups/BXD/traits/17985/values", diff --git a/tests/group_by_name.rs b/tests/group_by_name.rs index 654bd51..5cdd42e 100644 --- a/tests/group_by_name.rs +++ b/tests/group_by_name.rs @@ -94,3 +94,26 @@ async fn group_by_name_unknown_group_returns_404() { assert_eq!(error["next"], "/groups"); assert_eq!(error["request_id"], request_id); } + +/// A group's record names its mapping tool next to the raw id. +#[tokio::test] +async fn group_by_name_names_the_mapping_tool() { + if !common::db_available() { + eprintln!( + "skipping group_by_name_names_the_mapping_tool: no usable database (check SQL_URI credentials)" + ); + return; + } + let Some(token) = common::auth_token().await else { + eprintln!("skipping group_by_name_names_the_mapping_tool: no token (see docs/gn-auth.md)"); + return; + }; + + let response = common::get_with_token("GET /groups/HSNIH-Palmer", "/groups/HSNIH-Palmer", &token).await; + assert_eq!(response.status(), StatusCode::OK); + let body = response.into_body().collect().await.unwrap().to_bytes(); + let group: Value = common::data(&body); + + assert_eq!(group["mapping_method_id"], "2"); + assert_eq!(group["mapping_method"], "Rqtl"); +} diff --git a/tests/groups.rs b/tests/groups.rs index bbed73c..7035217 100644 --- a/tests/groups.rs +++ b/tests/groups.rs @@ -92,3 +92,32 @@ async fn groups_filters_by_family_species_and_text() { assert!(rat_reference.contains(&"HXBBXH".to_string())); assert!(!rat_reference.contains(&"BXD".to_string())); } + +/// Each group reports the mapping tool offered for it (the MappingMethod +/// its mapping_method_id points to), or null when it has none. +#[tokio::test] +async fn groups_report_the_mapping_tool_offered_for_them() { + if !common::db_available() { + eprintln!( + "skipping groups_report_the_mapping_tool_offered_for_them: no usable database (check SQL_URI credentials)" + ); + return; + } + let Some(token) = common::auth_token().await else { + eprintln!("skipping groups_report_the_mapping_tool_offered_for_them: no token (see docs/gn-auth.md)"); + return; + }; + + let response = common::get_with_token("GET /groups", "/groups", &token).await; + assert_eq!(response.status(), StatusCode::OK); + let body = response.into_body().collect().await.unwrap().to_bytes(); + let groups: Vec<Value> = common::data(&body); + let tool = |name: &str| -> Value { + groups.iter().find(|g| g["name"] == name).unwrap()["mapping_method"].clone() + }; + + assert_eq!(tool("BXD"), "qtlreaper"); + assert_eq!(tool("HSNIH-Palmer"), "Rqtl"); + assert_eq!(tool("HSNIH-RGSMC"), "qtlreaper"); // not every outbred set maps with Rqtl + assert!(tool("Oregon-R_x_2b3").is_null()); +} diff --git a/tests/mapping_methods.rs b/tests/mapping_methods.rs new file mode 100644 index 0000000..8cd5043 --- /dev/null +++ b/tests/mapping_methods.rs @@ -0,0 +1,31 @@ +use axum::http::StatusCode; +use http_body_util::BodyExt; +use serde_json::Value; + +mod common; + +/// Needs a live MariaDB connection (SQL_URI) and a valid token; skips +/// rather than fails when either is missing, same as groups.rs. +#[tokio::test] +async fn mapping_methods_lists_the_tools() { + if !common::db_available() { + eprintln!( + "skipping mapping_methods_lists_the_tools: no usable database (check SQL_URI credentials)" + ); + return; + } + let Some(token) = common::auth_token().await else { + eprintln!("skipping mapping_methods_lists_the_tools: no token (see docs/gn-auth.md)"); + return; + }; + + let response = common::get_with_token("GET /mapping-methods", "/mapping-methods", &token).await; + assert_eq!(response.status(), StatusCode::OK); + let body = response.into_body().collect().await.unwrap().to_bytes(); + let methods: Vec<Value> = common::data(&body); + + // The MappingMethod table lists tools no group uses (PLINK, FastMap). + let names: Vec<&str> = methods.iter().map(|m| m["name"].as_str().unwrap()).collect(); + assert_eq!(names, ["qtlreaper", "Rqtl", "HappyR", "PLINK", "FastMap"]); + assert_eq!(methods[0]["id"], 1); +} diff --git a/tests/openapi.rs b/tests/openapi.rs index a4dd1ba..5341d0a 100644 --- a/tests/openapi.rs +++ b/tests/openapi.rs @@ -36,6 +36,8 @@ async fn openapi_json_describes_all_endpoints() { "/groups/{group}/traits/{trait_id}/values", "/groups/{group}/datasets", "/publications/{pubmed_id}/traits", + "/mapping-methods", + "/accessions/{accession}", "/datasets/{dataset}", "/datasets/{dataset}/probesets/{probeset}", "/datasets/{dataset}/probesets/{probeset}/values", |
