Skip to content

Rapid help and blast url redirect and api schema changes #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ The resolver service generates new Ensembl website urls for different features b
`$ mv sample-env .env`

`$ docker-compose -f docker-compose.yml up`

### Deploy the app and run docker-compose:
Some urls that are available after deployment on your local machine:

http://localhost:8001/id/ENSG00000127720

http://localhost:8001/id/ENSG00000127720.3

### Run unit tests:
```
cd app
python -m unittest tests.test_rapid
```
3 changes: 3 additions & 0 deletions app/api/models/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ class MetadataResult(BaseModel):

class ResolvedPayload(MetadataResult):
resolved_url: str

class ResolvedURLResponse(BaseModel):
resolved_url: str
27 changes: 23 additions & 4 deletions app/api/resources/rapid_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from fastapi import APIRouter, Request, HTTPException, Query
from fastapi.responses import RedirectResponse
import logging
from api.models.resolver import ResolvedURLResponse
from core.logging import InterceptHandler
from core.config import ENSEMBL_URL
from api.utils.metadata import get_genome_id_from_assembly_accession_id
Expand All @@ -12,12 +13,24 @@
router = APIRouter()


@router.get("/info/{subpath:path}", name="Resolve rapid help page")
async def resolve_rapid_help(request: Request, subpath: str = ""):
help_page_url = f"{ENSEMBL_URL}/help"
return resolved_response(help_page_url, request)


@router.get("/Blast", name="Resolve rapid blast page")
async def resolve_rapid_blast(request: Request):
blast_page_url = f"{ENSEMBL_URL}/blast"
return resolved_response(blast_page_url, request)


# Resolve rapid urls
@router.get("/{species_url_name}/", name="Rapid Species Resources")
@router.get("/{species_url_name}", name="Rapid Species Resources")
@router.get("/{species_url_name}/{subpath:path}", name="Rapid Species Resources")
async def resolve_species(
request: Request, species_url_name: str, subpath: str = "", r: str = Query(None)
) -> RedirectResponse:
):
assembly_accession_id = format_assembly_accession(species_url_name)

if assembly_accession_id is None:
Expand All @@ -35,7 +48,7 @@ async def resolve_species(
query_params = parse_qs(query_string, separator=";")

url = construct_url(genome_id, subpath, query_params)
return RedirectResponse(url)
return resolved_response(url, request)
else:
raise HTTPException(status_code=404, detail="Genome not found")

Expand All @@ -52,4 +65,10 @@ async def resolve_species(

@router.get("/", name="Rapid Home")
async def resolve_home(request: Request):
return RedirectResponse(ENSEMBL_URL)
return resolved_response(ENSEMBL_URL, request)


def resolved_response(url: str, request: Request):
if "application/json" in request.headers.get("accept"):
return ResolvedURLResponse(resolved_url=url)
return RedirectResponse(url=url, status_code=301)
235 changes: 233 additions & 2 deletions app/static/APISpecification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ info:
servers:
- url: https://resolver.ensembl.org
tags:
- name: resolver
- name: Resolver
description: Resolver API resolves external urls to Ensembl
- name: Rapid Resolver
description: Resolver API to resolve rapid site urls to Ensembl
paths:
/id/{stable_id}:
get:
tags:
- resolver
- Resolver
summary: Resolve stable ID with optional query params
description: Resolves to a beta url when a stable id wih optional query params provided
parameters:
Expand Down Expand Up @@ -100,6 +102,235 @@ paths:
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
/rapid:
get:
summary: Resolve rapid site url
description: Resolves to Ensembl site url (home page).
tags:
- Rapid Resolver
responses:
'301':
description: Redirect to resolved URL
headers:
Location:
schema:
type: string
description: Ensembl URL
content: {}
'200':
description: OK
headers:
Location:
schema:
type: string
description: Ensembl URL
content:
application/json:
schema:
type: object
properties:
resolved_url:
type: string
description: Resolved url to Ensembl site
'400':
$ref: '#/components/responses/400'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
/rapid/Blast:
get:
summary: Resolve rapid site blast url
description: Resolves to Ensembl site blast url.
tags:
- Rapid Resolver
responses:
'301':
description: Redirect to Ensembl blast page
headers:
Location:
schema:
type: string
description: Ensembl blast URL
content: {}
'200':
description: OK
headers:
Location:
schema:
type: string
description: Ensembl blast URL
content:
application/json:
schema:
type: object
properties:
resolved_url:
type: string
description: Resolved url to Ensembl site help page
'400':
$ref: '#/components/responses/400'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
/rapid/{species_url_name}:
get:
summary: Resolve rapid site url with species url name (with assembly accession)
description: Resolves to Ensembl site url with the species url name provided.
tags:
- Rapid Resolver
parameters:
- name: species_url_name
in: path
description: Species name with assembly accession
required: true
schema:
type: string
example: Camarhynchus_parvulus_GCA_902806625.1
responses:
'301':
description: Redirect to resolved URL
headers:
Location:
schema:
type: string
description: Ensembl URL
content: {}
'200':
description: OK
headers:
Location:
schema:
type: string
description: Ensembl URL
content:
application/json:
schema:
type: object
properties:
resolved_url:
type: string
description: Resolved url to Ensembl site
'422':
description: Unprocessable Content
content:
application/json:
schema:
example: '{"status_code": 422, "detail": "Unable to process input accession ID"}'
'400':
$ref: '#/components/responses/400'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
/rapid/{species_url_name}/{subpath}:
get:
summary: Resolve rapid site url with species url name and subpath
description: Resolves to Ensembl site url with the species url name and subpath provided.
tags:
- Rapid Resolver
parameters:
- name: species_url_name
in: path
description: Species name with assembly accession
required: true
schema:
type: string
example: Camarhynchus_parvulus_GCA_902806625.1
- name: subpath
in: path
description: Additional path under species_url_name
required: true
schema:
type: string
example: Location/View
- name: r
in: query
required: false
description: Region string
schema:
type: string
example: 2:361680-384534
responses:
'301':
description: Redirect to resolved URL
headers:
Location:
schema:
type: string
description: Ensembl URL
content: {}
'200':
description: OK
headers:
Location:
schema:
type: string
description: Ensembl URL
content:
application/json:
schema:
type: object
properties:
resolved_url:
type: string
description: Resolved url to Ensembl site
'422':
description: Unprocessable Content
content:
application/json:
schema:
example: '{"status_code": 422, "detail": "Unable to process input accession ID"}'
'400':
$ref: '#/components/responses/400'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
/rapid/info/{subpath}:
get:
summary: Resolve rapid site help and docs url
description: Resolves to Ensembl site help page url.
tags:
- Rapid Resolver
parameters:
- name: subpath
in: path
required: true
schema:
type: string
example: index.html
responses:
'301':
description: Redirect to Ensembl help page
headers:
Location:
schema:
type: string
description: Ensembl help page URL
content: {}
'200':
description: OK
headers:
Location:
schema:
type: string
description: Ensembl help page URL
content:
application/json:
schema:
type: object
properties:
resolved_url:
type: string
description: Resolved url to Ensembl site help page
'400':
$ref: '#/components/responses/400'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
components:
responses:
400:
Expand Down
Loading