Skip to content

Commit

Permalink
working fasta_api, with proper error handling. #629
Browse files Browse the repository at this point in the history
  • Loading branch information
ctcncgr committed Nov 13, 2024
1 parent c7b81ca commit 00c3c12
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 37 deletions.
69 changes: 66 additions & 3 deletions fasta_api/fasta_api/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,157 +2,220 @@
import aiohttp_cors
from aiohttp import web

from fastapi import HTTPException, status


async def http_index(request):
return web.Response(text="Index")


async def http_help(request):
test = request.match_info.get('test')
print(test)
resources = [str(resource) for resource in request.app.router.resources()]
return web.json_response(resources)


async def http_fasta_range(request):
seqid = request.match_info.get('seqid')
start = request.match_info.get('start')
end = request.match_info.get('end')
url = request.match_info.get('url')
handler = request.app["handler"]
range = handler.fasta_range(url, seqid, start, end)
if "error" in range:
return web.json_response(range, status=range["status"])
return web.json_response(range)


async def http_fasta_references(request):
url = request.match_info.get('url')
handler = request.app["handler"]
references = handler.fasta_references(url)
if "error" in references:
return web.json_response(references, status=references["status"])
return web.json_response(references)


async def http_fasta_lengths(request):
url = request.match_info.get('url')
handler = request.app["handler"]
lengths = handler.fasta_lengths(url)
if "error" in lengths:
return web.json_response(lengths, status=lengths["status"])
return web.json_response(lengths)


async def http_fasta_nreferences(request):
url = request.match_info.get('url')
handler = request.app["handler"]
nreferences = handler.fasta_nreferences(url)
if "error" in nreferences:
return web.json_response(nreferences, status=nreferences["status"])
return web.json_response(nreferences)


async def http_gff_references(request):
url = request.match_info.get('url')
handler = request.app["handler"]
references = handler.gff_references(url)
if "error" in references:
return web.json_response(references, status=references["status"])
return web.json_response(references)


async def http_gff_features(request):
seqid = request.match_info.get('seqid')
start = request.match_info.get('start')
end = request.match_info.get('end')
url = request.match_info.get('url')
handler = request.app["handler"]
features = handler.gff_features(url, seqid, start, end)
if "error" in features:
return web.json_response(features, status=features["status"])
return web.json_response(features)


async def http_bed_features(request):
seqid = request.match_info.get('seqid')
start = request.match_info.get('start')
end = request.match_info.get('end')
url = request.match_info.get('url')
handler = request.app["handler"]
features = handler.bed_features(url, seqid, start, end)
if "error" in features:
return web.json_response(features, status=features["status"])
return web.json_response(features)


async def http_vcf_contigs(request):
url = request.match_info.get('url')
handler = request.app["handler"]
contigs = handler.vcf_contigs(url)
if "error" in contigs:
return web.json_response(contigs, status=contigs["status"])
return web.json_response(contigs)


async def http_vcf_features(request):
seqid = request.match_info.get('seqid')
start = request.match_info.get('start')
end = request.match_info.get('end')
url = request.match_info.get('url')
handler = request.app["handler"]
features = handler.vcf_features(url, seqid, start, end)
if "error" in features:
return web.json_response(features, status=features["status"])
return web.json_response(features)


async def http_alignment_references(request):
url = request.match_info.get('url')
handler = request.app["handler"]
references = handler.alignment_references(url)
if "error" in references:
return web.json_response(references, status=references["status"])
return web.json_response(references)


async def http_alignment_unmapped(request):
url = request.match_info.get('url')
handler = request.app["handler"]
unmapped = handler.alignment_unmapped(url)
if "error" in unmapped:
return web.json_response(unmapped, status=unmapped["status"])
return web.json_response(unmapped)


async def http_alignment_nreferences(request):
url = request.match_info.get('url')
handler = request.app["handler"]
nreferences = handler.alignment_nreferences(url)
if "error" in nreferences:
return web.json_response(nreferences, status=nreferences["status"])
return web.json_response(nreferences)


async def http_alignment_nocoordinate(request):
url = request.match_info.get('url')
handler = request.app["handler"]
nocoordinate = handler.alignment_nocoordinate(url)
if "error" in nocoordinate:
return web.json_response(nocoordinate, status=nocoordinate["status"])
return web.json_response(nocoordinate)


async def http_alignment_mapped(request):
url = request.match_info.get('url')
handler = request.app["handler"]
mapped = handler.alignment_mapped(url)
if "error" in mapped:
return web.json_response(mapped, status=mapped["status"])
return web.json_response(mapped)


async def http_alignment_lengths(request):
url = request.match_info.get('url')
handler = request.app["handler"]
lengths = handler.alignment_lengths(url)
if "error" in lengths:
return web.json_response(lengths, status=lengths["status"])
return web.json_response(lengths)


async def http_alignment_index_statistics(request):
url = request.match_info.get('url')
handler = request.app["handler"]
statistics = handler.alignment_index_statistics(url)
if "error" in statistics:
return web.json_response(statistics, status=statistics["status"])
return web.json_response(statistics)


async def http_alignment_count(request):
contig = request.match_info.get('contig')
start = request.match_info.get('start')
stop = request.match_info.get('stop')
url = request.match_info.get('url')
handler = request.app["handler"]
count = handler.alignment_count(url, contig, start, stop)
if "error" in count:
return web.json_response(count, status=count["status"])
return web.json_response(count)


async def http_alignment_count_coverage(request):
contig = request.match_info.get('contig')
start = request.match_info.get('start')
stop = request.match_info.get('stop')
url = request.match_info.get('url')
handler = request.app["handler"]
coverage = handler.alignment_count_coverage(url, contig, start, stop)
if "error" in coverage:
return web.json_response(coverage, status=coverage["status"])
return web.json_response(coverage)


async def http_alignment_fetch(request):
contig = request.match_info.get('contig')
start = request.match_info.get('start')
stop = request.match_info.get('stop')
url = request.match_info.get('url')
handler = request.app["handler"]
fetch = handler.alignment_fetch(url, contig, start, stop)
if "error" in fetch:
return web.json_response(fetch, status=fetch["status"])
return web.json_response(fetch)


async def http_alignment_reference_lengths(request):
reference = request.match_info.get('reference')
url = request.match_info.get('url')
handler = request.app["handler"]
lengths = handler.alignment_reference_lengths(url, reference)
if "error" in lengths:
return web.json_response(lengths, status=lengths["status"])
return web.json_response(lengths)


def run_http_server(host, port, handler):
# make the app
app = web.Application()
Expand All @@ -170,7 +233,7 @@ def run_http_server(host, port, handler):
)
route = app.router.add_get("/", http_index)
cors.add(route)
route = app.router.add_get("/help/{test}", http_help)
route = app.router.add_get("/help", http_help)
cors.add(route)
route = app.router.add_get("/fasta/fetch/{seqid}:{start}-{end}/{url}", http_fasta_range)
cors.add(route)
Expand Down
Loading

0 comments on commit 00c3c12

Please sign in to comment.