From 78c0197f400f3f53109535a7dc209b4c1f7ccdf9 Mon Sep 17 00:00:00 2001 From: adf-ncgr Date: Mon, 19 Jun 2023 09:08:41 -0600 Subject: [PATCH] templated replacement of info in linkout urls --- src/app/core/models/placeholders.model.ts | 9 +++++++-- src/app/gene/services/gene.service.ts | 13 +++++-------- src/app/gene/services/region.service.ts | 15 ++++++++++++--- src/config/config.json | 6 +++--- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/app/core/models/placeholders.model.ts b/src/app/core/models/placeholders.model.ts index c0380ce1..88e72e27 100644 --- a/src/app/core/models/placeholders.model.ts +++ b/src/app/core/models/placeholders.model.ts @@ -3,8 +3,13 @@ export enum OrganismPlaceholders { Species = 'SPECIES', Chromosome = 'CHROMOSOME', } + export enum GenePlaceholders { - GeneID = 'GENE_ID', - Species = 'SPECIES', + Gene = 'GENE', +} + +export enum RegionPlaceholders { Chromosome = 'CHROMOSOME', + Start = 'START', + Stop = 'STOP', } diff --git a/src/app/gene/services/gene.service.ts b/src/app/gene/services/gene.service.ts index db58e89d..3833c3c9 100644 --- a/src/app/gene/services/gene.service.ts +++ b/src/app/gene/services/gene.service.ts @@ -76,19 +76,16 @@ export class GeneService extends HttpService { } //fill in templated geneLinksURL - //TODO: should different servers be able to specify their own geneLinks? - export function geneToGeneLinksURL(gene) { - let name = AppConfig.geneLinks.url; + geneToGeneLinksURL(urlTemplate: string, gene: string): string { const placeholders = {}; - placeholders[GenePlaceholders.GeneID] = gene; - return placeholderReplace(name, placeholders); - }; + placeholders[GenePlaceholders.Gene] = gene; + return placeholderReplace(urlTemplate, placeholders); + } // fetches source specific details for the given gene getGeneDetails(gene: string, source: string): Observable { const request = this._appConfig.getServerRequest(source, 'geneLinks'); - //TODO: make this more configurable via template substitution - const makeUrl = (url: string) => geneToGeneLinksURL(gene); + const makeUrl = (url: string) => this.geneToGeneLinksURL(request.url, gene); return this._makeHttpRequest(request, {}, makeUrl); } diff --git a/src/app/gene/services/region.service.ts b/src/app/gene/services/region.service.ts index 692bceb2..8bfd8934 100644 --- a/src/app/gene/services/region.service.ts +++ b/src/app/gene/services/region.service.ts @@ -8,10 +8,11 @@ import { Store } from '@ngrx/store'; import * as regionActions from '@gcv/gene/store/actions/region.actions'; import * as fromRoot from '@gcv/store/reducers'; // app -import { AppConfig, ConfigError, GET, POST, GRPC } from '@gcv/core/models'; +import { AppConfig, RegionPlaceholders, ConfigError, GET, POST, GRPC } from '@gcv/core/models'; import { Region } from '@gcv/gene/models'; import { HttpService } from '@gcv/core/services/http.service'; import { grpcRegionToModel } from './shims'; +import { placeholderReplace } from '@gcv/core/utils'; // api import { ChromosomeRegionGetReply, ChromosomeRegionGetRequest, ChromosomeRegionPromiseClient, } from 'legumeinfo-microservices/dist/chromosomeregion_service/v1'; @@ -61,11 +62,19 @@ export class RegionService extends HttpService { this._store.dispatch(new regionActions.Get({chromosome, start, stop, source})); } + //fill in templated regionLinksURL + regionToRegionLinksURL(urlTemplate: string, chromosome: string, start: number, stop: number): string { + const placeholders = {}; + placeholders[RegionPlaceholders.Chromosome] = chromosome; + placeholders[RegionPlaceholders.Start] = start.toString(); + placeholders[RegionPlaceholders.Stop] = stop.toString(); + return placeholderReplace(urlTemplate, placeholders); + } + // fetches source specific details for the given region getRegionDetails(chromosome: string, start: number, end: number, source: string): Observable { const request = this._appConfig.getServerRequest(source, 'regionLinks'); - //TODO: make this more configurable via template-based substitution - const makeUrl = (url: string) => url + chromosome + ':' + start + '-' + end ; + const makeUrl = (url: string) => this.regionToRegionLinksURL(request.url, chromosome, start, end); return this._makeHttpRequest(request, {}, makeUrl); } diff --git a/src/config/config.json b/src/config/config.json index b1101fec..14b41f17 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -56,15 +56,15 @@ }, "geneLinks": { "type": "GET", - "url": "https://services.lis.ncgr.org/gene_linkouts?genes={GENE_ID}" + "url": "https://services.lis.ncgr.org/gene_linkouts?genes={GENE}" }, "regionLinks": { "type": "GET", - "url": "https://services.lis.ncgr.org/linkouts/genomic_region_linkouts?" + "url": "https://services.lis.ncgr.org/genomic_region_linkouts?genomic_regions={CHROMOSOME}:{START}-{STOP}" }, "familyTreeLink": { "type": "GET", - "url": "http://legumeinfo.org/chado_gene_phylotree_v2?family=" + "url": "https://funnotate.legumeinfo.org/?family=" }, "chromosome": { "type": "GRPC",