Skip to content

Commit

Permalink
templated replacement of info in linkout urls
Browse files Browse the repository at this point in the history
  • Loading branch information
adf-ncgr committed Jun 19, 2023
1 parent 4dc2cba commit 78c0197
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
9 changes: 7 additions & 2 deletions src/app/core/models/placeholders.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
13 changes: 5 additions & 8 deletions src/app/gene/services/gene.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
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<any>(request, {}, makeUrl);
}

Expand Down
15 changes: 12 additions & 3 deletions src/app/gene/services/region.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<any> {
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<any>(request, {}, makeUrl);
}

Expand Down
6 changes: 3 additions & 3 deletions src/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 78c0197

Please sign in to comment.