From 02d45654203678f031187981a6085f1865aa3641 Mon Sep 17 00:00:00 2001 From: hunterckx <118154470+hunterckx@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:31:58 -0700 Subject: [PATCH] refactor: prepare `getWorkflowLandingUrl` for alternative genome keys (#137) --- .../brc-analytics-catalog/common/constants.ts | 7 +++--- .../brc-analytics-catalog/common/entities.ts | 4 ++++ app/utils/galaxy-api.ts | 24 +++++++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/apis/catalog/brc-analytics-catalog/common/constants.ts b/app/apis/catalog/brc-analytics-catalog/common/constants.ts index 37cbeef..6beab74 100644 --- a/app/apis/catalog/brc-analytics-catalog/common/constants.ts +++ b/app/apis/catalog/brc-analytics-catalog/common/constants.ts @@ -1,8 +1,7 @@ -import { ANALYSIS_METHOD } from "./entities"; +import { ANALYSIS_METHOD, WORKFLOW_ID } from "./entities"; export const WORKFLOW_IDS_BY_ANALYSIS_METHOD: Partial< - Record + Record > = { - [ANALYSIS_METHOD.REGULATION]: - "https://dockstore.org/api/ga4gh/trs/v2/tools/#workflow/github.com/iwc-workflows/chipseq-pe/main/versions/v0.12", + [ANALYSIS_METHOD.REGULATION]: WORKFLOW_ID.REGULATION, }; diff --git a/app/apis/catalog/brc-analytics-catalog/common/entities.ts b/app/apis/catalog/brc-analytics-catalog/common/entities.ts index eaf085e..496055c 100644 --- a/app/apis/catalog/brc-analytics-catalog/common/entities.ts +++ b/app/apis/catalog/brc-analytics-catalog/common/entities.ts @@ -34,3 +34,7 @@ export interface EntitiesResponsePagination { size: number; total: number; } + +export enum WORKFLOW_ID { + REGULATION = "https://dockstore.org/api/ga4gh/trs/v2/tools/#workflow/github.com/iwc-workflows/chipseq-pe/main/versions/v0.12", +} diff --git a/app/utils/galaxy-api.ts b/app/utils/galaxy-api.ts index fe42b42..75f79e1 100644 --- a/app/utils/galaxy-api.ts +++ b/app/utils/galaxy-api.ts @@ -1,11 +1,14 @@ import ky from "ky"; +import { WORKFLOW_ID } from "../apis/catalog/brc-analytics-catalog/common/entities"; interface WorkflowLandingsBody { - request_state: { reference_genome: string }; + request_state: WorkflowLandingsBodyRequestState; workflow_id: string; workflow_target_type: "trs_url"; } +type WorkflowLandingsBodyRequestState = { reference_genome: string }; + interface WorkflowLanding { uuid: string; } @@ -23,13 +26,11 @@ const WORKFLOW_LANDING_URL_PREFIX = * @returns workflow landing URL. */ export async function getWorkflowLandingUrl( - workflowId: string, + workflowId: WORKFLOW_ID, referenceGenome: string ): Promise { const body: WorkflowLandingsBody = { - request_state: { - reference_genome: referenceGenome, - }, + request_state: getWorkflowLandingsRequestState(workflowId, referenceGenome), workflow_id: workflowId, workflow_target_type: "trs_url", }; @@ -42,3 +43,16 @@ export async function getWorkflowLandingUrl( const id = (await res.json()).uuid; return WORKFLOW_LANDING_URL_PREFIX + encodeURIComponent(id); } + +/** + * Get the appropriate `request_state` object for the given workflow ID and reference genome. + * @param workflowId - Workflow ID. + * @param referenceGenome - Reference genome. + * @returns `request_state` value for the workflow landings request body. + */ +function getWorkflowLandingsRequestState( + workflowId: WORKFLOW_ID, + referenceGenome: string +): WorkflowLandingsBodyRequestState { + return { reference_genome: referenceGenome }; +}