Skip to content

Commit

Permalink
Merge pull request #254 from sennetconsortium/tjmadonna/add-vitessce-…
Browse files Browse the repository at this point in the history
…config

Adding basic validation and error handling to Vitessce config endpoint
  • Loading branch information
maxsibilla authored Jan 10, 2024
2 parents 6821136 + 62949ca commit 1bd983e
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 4 deletions.
129 changes: 129 additions & 0 deletions ingest-api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,44 @@ components:

file_uuid:
type: string

File:
type: object
properties:
description:
type: string
description: Free text description of the file
edam_term:
type: string
description: The EDAM ontology term for the file type
is_qa_qc:
type: boolean
description: True if the file is a QA file
rel_path:
type: string
description: The path on the local file system, relative to the base data directory.
size:
type: integer
description: The size of the file in bytes
type:
type: string
description: The file type

DagProvenanceItem:
type: object
properties:
hash:
type: string
description: The 7 character hash of the commit
example: 1994f0f
name:
type: string
description: The name of the cwl file
example: anndata-to-ui.cwl
origin:
type: string
description: The git origin of the cwl file
example: https://github.com/hubmapconsortium/portal-containers

Sources:
type: object
Expand Down Expand Up @@ -761,3 +799,94 @@ paths:
description: User's token is not valid
"500":
description: An unexpected error occured
/vitessce/config:
post:
tags:
- vitessce
summary: Return a Vitessce configuration for a given Dataset
requestBody:
content:
application/json:
schema:
type: object
properties:
uuid:
type: string
description: The SenNet unique identifier, intended for internal software use only. This is a 32 digit hexadecimal UUID e.g. 461bbfdc353a2673e381f632510b0f17
example: 461bbfdc353a2673e381f632510b0f17
status:
type: string
enum:
- New
- Processing
- QA
- Published
- Error
- Hold
- Invalid
description: 'One of: New|Processing|QA|Published|Error|Hold|Invalid'
entity_type:
type: string
enum:
- Dataset
description: 'Dataset entity type'
data_types:
type: array
items:
type: string
enum:
- 10x-multiome
- bulk-RNA
- CITE-Seq
- CODEX
- codex_cytokit
- codex_cytokit_v1
- CosMX (RNA)
- DBiT-seq
- FACS - Fluorescence-activated Cell Sorting
- GeoMX (RNA)
- image_pyramid
- LC-MS
- Lightsheet
- MIBI
- mibi_deepcell
- Mint-ChIP
- publication
- publication_ancillary
- salmon_rnaseq_10x
- salmon_rnaseq_bulk
- salmon_sn_rnaseq_10x
- SASP
- scRNA-seq
- sn_atac_seq
- snATAC-seq
- snRNA-seq
- snRNAseq-10xGenomics-v3
- Stained Slides
- Visium
description: The data or assay types contained in this dataset as a json array of strings. Each is an assay code from [assay types](https://ontology.api.hubmapconsortium.org/datasets?application_context=Sennet).
files:
type: array
items:
$ref: '#/components/schemas/File'
description: The files associated with this Dataset
metadata:
type: object
description: The metadata associated with this Dataset
properties:
dag_provenance_list:
type: array
items:
$ref: '#/components/schemas/DagProvenanceItem'
description: The list of dag provenance items associated with this Dataset
responses:
"200":
description: The [Vitessce JSON configuration](http://vitessce.io/docs/view-config-json) for the given Dataset
"400":
description: Request body schema was invalid or was for an invalid Dataset
"401":
description: The user's token has expired or the user did not have authorization
"404":
description: The Vitesce configuration for the given Dataset could not be found
"500":
description: Internal error
48 changes: 44 additions & 4 deletions src/routes/vitessce/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from uuid import UUID

from flask import Blueprint, Response, current_app, jsonify, request
from flask import Blueprint, current_app, jsonify, request
from hubmap_commons.hm_auth import AuthHelper
from portal_visualization.builder_factory import get_view_config_builder

Expand All @@ -14,6 +15,9 @@
@vitessce_blueprint.route("/vitessce/config", methods=["POST"])
@require_json(param="entity")
def vitessce_config(entity: dict):
if errors := validate_vitessce_entity(entity) :
return jsonify({"error": errors}), 400

def get_assaytype(entity):
if "metadata" in entity.get("metadata", {}):
metadata = entity["metadata"]["metadata"]
Expand All @@ -38,7 +42,43 @@ def get_assaytype(entity):
entity, groups_token, current_app.config["ASSETS_WEBSERVICE_URL"]
)
vitessce_conf = builder.get_conf_cells(marker=None)
return jsonify(vitessce_conf[0] or {}), 200
if len(vitessce_conf) < 1 or not vitessce_conf[0]:
raise ValueError("empty vitessce config")
return jsonify(vitessce_conf[0]), 200
except Exception as e:
logger.error(e)
return Response("Unexpected error while retrieving Vitessce config", 500)
logger.error(f"Error while retrieving Vitessce config for uuid {entity['uuid']}:", e)
return jsonify({"error": "404 Not Found: Entity or filepath not found"}), 404


def validate_vitessce_entity(entity):
"""Add basic validation for vitessce config request body
Args:
entity (dict): vitessce config request body
Returns:
list: list of errors
"""
errors = []
try:
UUID(entity.get("uuid"))
except Exception:
errors.append("uuid must be a valid UUID")

if not entity.get("status") or not isinstance(entity["status"], str):
errors.append("'status' string is required")

if not entity.get("data_types") or not isinstance(entity["data_types"], list):
errors.append("'data_types' array is required")

if not entity.get("files") or not isinstance(entity["files"], list):
errors.append("'files' array is required")

if entity.get("entity_type") != "Dataset":
errors.append("'entity_type' 'Dataset' is required")

prov_list = entity.get("metadata", {}).get("dag_provenance_list")
if not prov_list or not isinstance(prov_list, list):
errors.append("'metadata.dag_provenance_list' array is required")

return errors

0 comments on commit 1bd983e

Please sign in to comment.