Skip to content

Commit

Permalink
add visualisation endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshhewabi committed Feb 6, 2024
1 parent 8520723 commit 73bb6b2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
34 changes: 33 additions & 1 deletion app/routes/xiview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 = {}
Expand Down
7 changes: 7 additions & 0 deletions db_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 73bb6b2

Please sign in to comment.