diff options
| author | Pjotr <wrk@bosa.lan> | 2026-10-15 12:09:18 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-15 12:09:18 +0000 |
| commit | a7d69da70e98bf8cef1e6ec11000714831dd6853 (patch) | |
| tree | 7f664555eedd61881cd1a582c636e9eaed8e0acc /src | |
| parent | acdcb3a7ddfdfadf91531599f87190c451fd8624 (diff) | |
| download | genenetwork4-a7d69da70e98bf8cef1e6ec11000714831dd6853.tar.gz | |
response: add meta.num_rows/num_cols alongside meta.columns
So a caller of /compute/gemma(/ravanan) or /compute/rqtl doesn't need to count data's rows or columns.len() itself. with_columns now takes the row count too and derives num_cols from the column list. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/response.rs | 17 | ||||
| -rw-r--r-- | src/routes/gemma.rs | 6 | ||||
| -rw-r--r-- | src/routes/rqtl.rs | 3 |
3 files changed, 21 insertions, 5 deletions
diff --git a/src/response.rs b/src/response.rs index bff1767..e85362a 100644 --- a/src/response.rs +++ b/src/response.rs @@ -45,6 +45,14 @@ pub struct Meta { /// is already keyed or isn't tabular. #[serde(skip_serializing_if = "Option::is_none")] pub columns: Option<Vec<String>>, + /// How many rows `data` carries, alongside `columns` (same + /// condition for being present). + #[serde(skip_serializing_if = "Option::is_none")] + pub num_rows: Option<usize>, + /// `columns.len()`, alongside `columns`, so a caller doesn't need + /// to count it itself. + #[serde(skip_serializing_if = "Option::is_none")] + pub num_cols: Option<usize>, } /// A success response: the payload, facts about the response, notes on @@ -82,10 +90,13 @@ impl<T: Serialize + utoipa::ToSchema> Envelope<T> { self } - /// Sets `meta.columns` for a `data` of positional rows (see + /// Sets `meta.columns`/`meta.num_cols`/`meta.num_rows` for a `data` + /// of `num_rows` positional rows, each `columns.len()` long (see /// `Meta::columns`). - pub fn with_columns(mut self, columns: Vec<String>) -> Self { + pub fn with_columns(mut self, columns: Vec<String>, num_rows: usize) -> Self { + self.meta.num_cols = Some(columns.len()); self.meta.columns = Some(columns); + self.meta.num_rows = Some(num_rows); self } @@ -163,6 +174,8 @@ impl Ctx { took_ms: self.info.took_ms(), request_id: self.info.id(), columns: None, + num_rows: None, + num_cols: None, }, notes: Vec::new(), next: Vec::new(), diff --git a/src/routes/gemma.rs b/src/routes/gemma.rs index 83ec902..05d2d15 100644 --- a/src/routes/gemma.rs +++ b/src/routes/gemma.rs @@ -122,9 +122,10 @@ pub async fn compute_gemma( ) .await .map(|output| { + let num_rows = output.rows.as_array().map(Vec::len).unwrap_or(0); let mut envelope = ctx .envelope(output.rows) - .with_columns(output.columns) + .with_columns(output.columns, num_rows) .with_note( "Rows come from GEMMA's own .assoc.txt output, positional (see meta.columns for names); column names depend on the lmm value used.", ); @@ -213,9 +214,10 @@ pub async fn compute_gemma_ravanan( ) .await .map(|output| { + let num_rows = output.rows.as_array().map(Vec::len).unwrap_or(0); let mut envelope = ctx .envelope(output.rows) - .with_columns(output.columns) + .with_columns(output.columns, num_rows) .with_note( "Rows come from GEMMA's own .assoc.txt output, positional (see meta.columns for names); column names depend on the lmm value used.", ); diff --git a/src/routes/rqtl.rs b/src/routes/rqtl.rs index 638557c..ab44225 100644 --- a/src/routes/rqtl.rs +++ b/src/routes/rqtl.rs @@ -122,9 +122,10 @@ pub async fn compute_rqtl( .await .map(|output| { let notes = output.notes.clone(); + let num_rows = output.markers.len(); let mut envelope = ctx .envelope(rqtl::to_json(output)) - .with_columns(rqtl::MARKER_COLUMNS.iter().map(|s| s.to_string()).collect()) + .with_columns(rqtl::MARKER_COLUMNS.iter().map(|s| s.to_string()).collect(), num_rows) .with_note( "markers come from R/qtl's scanone output, positional (see meta.columns for names); permutation is null unless nperm > 0 was requested.", ); |
