From 73bb6b25000fa1440a9220a63b5f19075bacbbb4 Mon Sep 17 00:00:00 2001 From: sureshhewa Date: Tue, 6 Feb 2024 21:19:36 +0000 Subject: [PATCH] add visualisation endpoint --- app/routes/xiview.py | 34 +++++++++++++++++++++++++++++++++- db_config_parser.py | 7 +++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/routes/xiview.py b/app/routes/xiview.py index dd0d8f9..573f332 100644 --- a/app/routes/xiview.py +++ b/app/routes/xiview.py @@ -3,12 +3,18 @@ import logging.config import struct +import fastapi import psycopg2 -from fastapi import APIRouter +from fastapi import APIRouter, Depends, Request from psycopg2 import sql from psycopg2.extras import RealDictCursor +from sqlalchemy.orm import session, Session +from app.models.projectdetail import ProjectDetail +from app.models.upload import Upload from app.routes.shared import get_db_connection, get_most_recent_upload_ids +from index import get_session +from db_config_parser import get_xiview_base_url xiview_data_router = APIRouter() @@ -36,6 +42,7 @@ async def get_xiview_data(project, file=None): return data_object + @xiview_data_router.get('/get_peaklist', tags=["xiVIEW"]) async def get_peaklist(id, sd_ref, upload_id): conn = None @@ -62,6 +69,29 @@ async def get_peaklist(id, sd_ref, upload_id): return data +@xiview_data_router.get('/visualisations/{project_id}', tags=["xiVIEW"]) +def visualisations(project_id: str, request: Request, session: Session = Depends(get_session)): + xiview_base_url = get_xiview_base_url() + project_detail = session.query(Upload) \ + .filter(Upload.project_id == project_id) \ + .all() + datasets = [] + processed_filenames = set() + for record in project_detail: + filename = record.identification_file_name + if filename not in processed_filenames: + datafile = { + "filename": filename, + "visualisation": "cross-linking", + "link": (xiview_base_url + "?project=" + project_id + "&file=" + + str(filename)) + } + datasets.append(datafile) + processed_filenames.add(filename) + + return datasets + + async def get_data_object(ids, pxid): """ Connect to the PostgreSQL database server """ conn = None @@ -89,6 +119,7 @@ async def get_data_object(ids, pxid): raise error return data + async def get_pride_api_info(cur, pxid): """ Get the PRIDE API info for the projects """ query = """SELECT p.id AS id, @@ -100,6 +131,7 @@ async def get_pride_api_info(cur, pxid): cur.execute(query, [pxid]) return cur.fetchall() + async def get_results_metadata(cur, ids): """ Get the metadata for the results """ metadata = {} diff --git a/db_config_parser.py b/db_config_parser.py index 59e152d..5397468 100644 --- a/db_config_parser.py +++ b/db_config_parser.py @@ -36,3 +36,10 @@ def security_API_key(): security_info = parse_info(config, 'security') apikey = security_info.get("apikey") return apikey + + +def get_xiview_base_url(): + config = os.environ.get('DB_CONFIG', 'database.ini') + security_info = parse_info(config, 'security') + xiviewbaseurl = security_info.get("xiviewbaseurl") + return xiviewbaseurl