diff --git a/src/schema/provenance_schema.yaml b/src/schema/provenance_schema.yaml index b72bf3a1..7e43d41a 100644 --- a/src/schema/provenance_schema.yaml +++ b/src/schema/provenance_schema.yaml @@ -897,33 +897,6 @@ ENTITIES: - validate_sample_category before_property_update_validators: - validate_sample_category - - # No logner required on create, specimen_type -> sample_category 12/15/2022 - specimen_type: - type: string - #required_on_create: true # Only required for create via POST, not update via PUT - description: "A code representing the type of specimen. Must be one of the codes specified in: [tissue sample types](https://github.com/hubmapconsortium/search-api/blob/main/src/search-schema/data/definitions/enums/tissue_sample_types.yaml)" - # Validate the given value against the definitions: https://github.com/hubmapconsortium/search-api/blob/main/src/search-schema/data/definitions/enums/tissue_sample_types.yaml - # Disabled validation 12/15/2022 - # before_property_create_validators: - # - validate_specimen_type - # before_property_update_validators: - # - validate_specimen_type - specimen_type_other: - type: string - description: "The user provided sample type if the 'other' sample_type is chosen." - - - # specimen_type no logner required on create, will remove this field when removing specimen_type - # Simply always set to 'Unknown' and no need to update 12/15/2022 - tissue_type: - type: string - generated: true # Can not be updated via the PUT - #auto_update: true # Will always update automatically if the entity gets updated - description: 'The type of the tissue based on the mapping between type (Block/Section/Suspension) and the specimen_type, default is Unknown' - before_create_trigger: set_tissue_type - #before_update_trigger: set_tissue_type - portal_metadata_upload_files: type: json_string description: "A list of relative paths to metadata files" @@ -949,7 +922,6 @@ ENTITIES: immutable: true description: "The displayname of globus group which the user who created this entity is a member of" before_create_trigger: set_group_name - # Should be required on create only when specimen_type==organ organ: type: string description: "Organ code specifier, only set if sample_type == organ. Valid values found in: [organ types](https://github.com/hubmapconsortium/search-api/blob/main/src/search-schema/data/definitions/enums/organ_types.yaml)" diff --git a/src/schema/schema_constants.py b/src/schema/schema_constants.py index b426827c..e34bd10a 100644 --- a/src/schema/schema_constants.py +++ b/src/schema/schema_constants.py @@ -2,13 +2,11 @@ class SchemaConstants(object): MEMCACHED_TTL = 7200 - # Constants used by validators INGEST_API_APP = 'ingest-api' INGEST_PIPELINE_APP = 'ingest-pipeline' HUBMAP_APP_HEADER = 'X-Hubmap-Application' DATASET_STATUS_PUBLISHED = 'published' - # Used by triggers, all lowercase for easy comparision ACCESS_LEVEL_PUBLIC = 'public' ACCESS_LEVEL_CONSORTIUM = 'consortium' ACCESS_LEVEL_PROTECTED = 'protected' @@ -19,9 +17,6 @@ class SchemaConstants(object): ONTOLOGY_API_ASSAY_TYPES_ENDPOINT = '/assaytype?application_context=HuBMAP' ONTOLOGY_API_ORGAN_TYPES_ENDPOINT = '/organs?application_context=HuBMAP' - # For generating Sample.tissue_type - TISSUE_TYPES_YAML = 'https://raw.githubusercontent.com/hubmapconsortium/search-api/main/src/search-schema/data/definitions/enums/tissue_sample_types.yaml' - DOI_BASE_URL = 'https://doi.org/' # Define an enumeration to classify an entity's visibility, which can be combined with diff --git a/src/schema/schema_triggers.py b/src/schema/schema_triggers.py index d831670a..093ed3a6 100644 --- a/src/schema/schema_triggers.py +++ b/src/schema/schema_triggers.py @@ -1562,105 +1562,6 @@ def get_sample_direct_ancestor(property_key, normalized_type, user_token, existi return property_key, schema_manager.normalize_entity_result_for_response(direct_ancestor_dict) -""" -Trigger event method of generating the type of the tissue based on the mapping between type (Block/Section/Suspension) and the specimen_type -This method applies to both the create and update triggers - -Rererence: - - https://docs.google.com/spreadsheets/d/1OODo8QK852txSNSmfIe0ua4A7nPFSgKq6h46grmrpto/edit#gid=0 - - https://github.com/hubmapconsortium/search-api/blob/main/src/search-schema/data/definitions/enums/tissue_sample_types.yaml - -Parameters ----------- -property_key : str - The target property key of the value to be generated -normalized_type : str - One of the types defined in the schema yaml: Sample -user_token: str - The user's globus nexus token -existing_data_dict : dict - A dictionary that contains all existing entity properties -new_data_dict : dict - A merged dictionary that contains all possible input data to be used - -Returns -------- -str: The target property key -str: The type of the tissue -""" -def set_tissue_type(property_key, normalized_type, user_token, existing_data_dict, new_data_dict): - # specimen_type is no logner required on create 12/15/2022, set to Unknown - # Default to use 'Unknown' - tissue_type = 'Unknown' - - # # The `specimen_type` field is required on entity creation via POST - # # thus should be available on existing entity update via PUT - # # We do a double check here just in case - # if ('specimen_type' not in new_data_dict) and ('specimen_type' not in existing_data_dict): - # raise KeyError("Missing 'specimen_type' key in both 'new_data_dict' and 'existing_data_dict' during calling 'set_tissue_type()' trigger method.") - - # # Always calculate the tissue_type value no matter new creation or update existing - # # The `specimen_type` field can be used in a PUT - # # But if it's not in the request JSON of a PUT, it must be in the existing data - # if 'specimen_type' in new_data_dict: - # # The `specimen_type` value validation is handled in the `schema_validators.validate_specimen_type()` - # # and that gets called before this trigger method - # specimen_type = new_data_dict['specimen_type'].lower() - # else: - # # Use lowercase in case someone manually updated the neo4j filed with incorrect case - # specimen_type = existing_data_dict['specimen_type'].lower() - - # # Categories: Block, Section, Suspension - # block_category = [ - # 'pbmc', - # 'biopsy', - # 'segment', - # 'ffpe_block', - # 'organ_piece', - # 'fresh_tissue', - # 'clarity_hydrogel', - # 'fixed_tissue_piece', - # 'fresh_frozen_tissue', - # 'fresh_frozen_oct_block', - # 'formalin_fixed_oct_block', - # 'pfa_fixed_frozen_oct_block', - # 'flash_frozen_liquid_nitrogen', - # 'frozen_cell_pellet_buffy_coat' - # ] - - # section_category = [ - # 'ffpe_slide', - # 'fixed_frozen_section_slide', - # 'fresh_frozen_section_slide', - # 'fresh_frozen_tissue_section', - # 'cryosections_curls_rnalater', - # 'cryosections_curls_from_fresh_frozen_oct' - # ] - - # suspension_category = [ - # 'gdna', - # 'serum', - # 'plasma', - # 'nuclei', - # 'protein', - # 'rna_total', - # 'cell_lysate', - # 'tissue_lysate', - # 'sequence_library', - # 'ran_poly_a_enriched', - # 'single_cell_cryopreserved' - # ] - - # # Capitalized type, default is 'Unknown' if no match - # if specimen_type in block_category: - # tissue_type = 'Block' - # elif specimen_type in section_category: - # tissue_type = 'Section' - # elif specimen_type in suspension_category: - # tissue_type = 'Suspension' - - return property_key, tissue_type - #################################################################################################### ## Trigger methods specific to Publication - DO NOT RENAME diff --git a/src/schema/schema_validators.py b/src/schema/schema_validators.py index 8c1269a5..cedd2d53 100644 --- a/src/schema/schema_validators.py +++ b/src/schema/schema_validators.py @@ -430,33 +430,6 @@ def validate_upload_status_value(property_key, normalized_entity_type, request, raise ValueError(f"Invalid status value: {new_status}") -""" -NOTE: TO BE REMOVED when we remove specimen_type field - -Validate the provided value of Sample.specimen_type on create via POST and update via PUT - -Parameters ----------- -property_key : str - The target property key -normalized_type : str - Submission -request: Flask request object - The instance of Flask request passed in from application request -existing_data_dict : dict - A dictionary that contains all existing entity properties -new_data_dict : dict - The json data in request body, already after the regular validations -""" -def validate_specimen_type(property_key, normalized_entity_type, request, existing_data_dict, new_data_dict): - # Use lowercase for comparison - defined_tissue_types = _get_tissue_types() - specimen_type = new_data_dict[property_key].lower() - - if specimen_type not in defined_tissue_types: - raise ValueError(f"Invalid specimen_type value: {specimen_type}") - - """ Validate the provided value of Sample.sample_category on create via POST and update via PUT @@ -562,47 +535,3 @@ def _validate_application_header(applications_allowed, request_headers): msg = f"Unable to proceed due to invalid {SchemaConstants.HUBMAP_APP_HEADER} header value: {app_header}" raise schema_errors.InvalidApplicationHeaderException(msg) - -""" -Get the complete list of defined tissue types - -Returns -------- -list: The list of defined tissue types -""" -def _get_tissue_types(): - yaml_file_url = SchemaConstants.TISSUE_TYPES_YAML - - # Use Memcached to improve performance - response = schema_manager.make_request_get(yaml_file_url) - - if response.status_code == 200: - yaml_file = response.text - - try: - tissue_types_dict = yaml.safe_load(response.text) - - # We don't need the description here, just a list of tissue types - # Note: dict.keys() returns a dict, need to typecast to list - tissue_types_list = list(tissue_types_dict.keys()) - - # Add the 'other' - tissue_types_list.append('other') - - return tissue_types_list - except yaml.YAMLError as e: - raise yaml.YAMLError(e) - else: - msg = f"Unable to fetch the: {yaml_file_url}" - # Log the full stack trace, prepend a line with our message - logger.exception(msg) - - logger.debug("======_get_tissue_types() status code======") - logger.debug(response.status_code) - - logger.debug("======_get_tissue_types() response text======") - logger.debug(response.text) - - # Also bubble up the error message - raise requests.exceptions.RequestException(response.text) -