Skip to content

Commit

Permalink
Merge pull request #750 from hubmapconsortium/lchoy/CAT-573-is-multi-…
Browse files Browse the repository at this point in the history
…assay-refactor

Lchoy/cat 573 is multi assay refactor
  • Loading branch information
yuanzhou authored Mar 1, 2024
2 parents 35447da + 6b5ee01 commit 8894027
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 214 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ docker/search-api/BUILD

# Portal cache
src/hubmap_translation/addl_index_transformations/portal/cache/*.jsonld


# python virtual environments
**/.venv
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
add_assay_details
)

from hubmap_translation.addl_index_transformations.portal.add_dataset_categories import (
add_dataset_categories
)

from hubmap_translation.addl_index_transformations.portal.lift_dataset_metadata_fields import (
lift_dataset_metadata_fields
)
Expand Down Expand Up @@ -72,7 +68,6 @@ def transform(doc, transformation_resources, batch_id='unspecified'):
doc_copy['transformation_errors'] = []
try:
add_assay_details(doc_copy, transformation_resources)
add_dataset_categories(doc_copy)
lift_dataset_metadata_fields(doc_copy)
translate(doc_copy)
except TranslationException as e:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
import logging
import re
from enum import Enum

from portal_visualization.builder_factory import has_visualization

Expand All @@ -13,6 +14,20 @@
logger = logging.getLogger(__name__)


class CreationAction(str, Enum):
CREATE_DATASET = 'Create Dataset Activity'
MULTI_ASSAY_SPLIT = 'Multi-Assay Split'
CENTRAL_PROCESS = 'Central Process'
LAB_PROCESS = 'Lab Process'
CREATE_PUBLICATION = 'Create Publication Activity'


processing_type_map = {
CreationAction.CENTRAL_PROCESS: 'hubmap',
CreationAction.LAB_PROCESS: 'lab',
}


def _get_assay_details(doc, transformation_resources):
soft_assay_url = transformation_resources.get('ingest_api_soft_assay_url')
token = transformation_resources.get('token')
Expand All @@ -33,6 +48,56 @@ def _get_assay_details(doc, transformation_resources):
raise


def _add_dataset_processing_fields(doc):
if processing_type := processing_type_map.get(doc['creation_action']):
doc['processing'] = 'processed'
doc['processing_type'] = processing_type
else:
doc['processing'] = 'raw'


def _is_component_dataset(doc):
if 'creation_action' in doc and doc['creation_action'] == CreationAction.MULTI_ASSAY_SPLIT:
return True
return False


def _add_multi_assay_fields(doc, assay_details):
if _is_component_dataset(doc):
doc['assay_modality'] = 'multiple'
doc['is_component'] = True
return

if assay_details.get('is-multi-assay', False):
doc['assay_modality'] = 'multiple'
creation_action = doc.get('creation_action', None)
if creation_action in [CreationAction.CREATE_DATASET, CreationAction.CENTRAL_PROCESS]:
doc['is_component'] = False
else:
error_msg = f"Unexpected creation_action={creation_action}. is_component will not be set."
_log_transformation_error(doc, error_msg)
return

doc['assay_modality'] = 'single'


def _add_dataset_categories(doc, assay_details):
if doc['entity_type'] == 'Dataset':
creation_action = doc.get('creation_action')
if not creation_action:
error_msg = "Creation action undefined."
_log_transformation_error(doc, error_msg)
return

if creation_action not in {enum.value for enum in CreationAction}:
error_msg = f"Unrecognized creation action, {creation_action}."
_log_transformation_error(doc, error_msg)
return

_add_dataset_processing_fields(doc)
_add_multi_assay_fields(doc, assay_details)


def add_assay_details(doc, transformation_resources):
if 'dataset_type' in doc:
assay_details = _get_assay_details(doc, transformation_resources)
Expand All @@ -48,6 +113,8 @@ def add_assay_details(doc, transformation_resources):
doc['mapped_data_types'] = [assay_details.get('description')]
doc['vitessce-hints'] = assay_details.get('vitessce-hints')

_add_dataset_categories(doc, assay_details)

error_msg = assay_details.get('error')
if error_msg:
_log_transformation_error(doc, error_msg)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ end portal/doctests

start portal/pytest
cd ../../../
PYTHONPATH="src:$PYTHONPATH" pytest --verbose --log-cli-level WARN
PYTHONPATH="src:$PYTHONPATH" pytest -vv --log-cli-level WARN
cd -
end portal/pytest

This file was deleted.

Loading

0 comments on commit 8894027

Please sign in to comment.