Skip to content

Commit

Permalink
Merge pull request #907 from hubmapconsortium/john-conroy/-addl-soft-…
Browse files Browse the repository at this point in the history
…assay-fields

John conroy/ addl soft assay fields
  • Loading branch information
yuanzhou authored Nov 7, 2024
2 parents 507b107 + abbad8c commit 7398c2d
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,38 @@ def _get_descendants(doc, transformation_resources):
raise


def _add_pipeline(doc, assay_details):
if pipeline := assay_details.get('pipeline-shorthand'):
doc['pipeline'] = pipeline
# pipeline-shorthand is not returned for EPICs.
elif doc.get('processing_type') == 'external':
doc['pipeline'] = assay_details.get('description')
# pipeline-shorthand is not returned for Image Pyramids.
elif set(['pyramid', 'is_image']).issubset(set(assay_details.get('vitessce-hints'))):
doc['pipeline'] = 'Image Pyramid'
# Fallback to get pipeline in the dataset_type's brackets.
elif pipeline := re.search("(?<=\\[)[^][]*(?=])", doc.get('dataset_type', '')):
doc['pipeline'] = pipeline.group()


def add_assay_details(doc, transformation_resources):
if 'dataset_type' in doc:
assay_details = _get_assay_details(doc, transformation_resources)

doc['raw_dataset_type'] = re.sub(
"\\[(.*?)\\]", '', doc.get('dataset_type', '')).rstrip()

if pipeline := re.search("(?<=\\[)[^][]*(?=])", doc.get('dataset_type', '')):
doc['pipeline'] = pipeline.group()
_add_dataset_categories(doc, assay_details)
_add_pipeline(doc, assay_details)

if soft_assaytype := assay_details.get('assaytype'):
doc['soft_assaytype'] = soft_assaytype
# Preserve the previous shape of mapped_data_types.
doc['assay_display_name'] = [assay_details.get('description')]
# Remove once the portal-ui has transitioned to use assay_display_name.
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def test_raw_dataset_type(mocker):
'entity_type': 'Dataset',
'assay_modality': 'single',
'creation_action': 'Create Dataset Activity',
'processing': 'raw'
'processing': 'raw',
'soft_assaytype': 'sciRNAseq'
}
add_assay_details(input_raw_doc, transformation_resources)
assert input_raw_doc == expected_raw_output_doc
Expand All @@ -74,6 +75,7 @@ def mock_processed_soft_assay(uuid=None, headers=None):
return mock_response({
"assaytype": "salmon_rnaseq_sciseq",
"contains-pii": True,
"pipeline-shorthand": "Salmon",
"description": "sciRNA-seq [Salmon]",
"primary": False,
"vitessce-hints": [
Expand Down Expand Up @@ -106,6 +108,7 @@ def test_processed_dataset_type(mocker):
'processing': 'processed',
'processing_type': 'hubmap',
'uuid': '22684b9011fc5aea5cb3f89670a461e8',
'soft_assaytype': 'salmon_rnaseq_sciseq',
'vitessce-hints': [
"is_sc",
"rna"
Expand Down Expand Up @@ -203,7 +206,7 @@ def mock_image_pyramid_support(uuid=None, headers=None):
})


def test_transform_image_pyramid(mocker):
def test_transform_image_pyramid_parent(mocker):
mocker.patch('requests.get', side_effect=[
# initial request to has_visualization with parent entity
mock_image_pyramid_parent(),
Expand Down Expand Up @@ -233,13 +236,104 @@ def test_transform_image_pyramid(mocker):
'uuid': '69c70762689b20308bb049ac49653342',
'vitessce-hints': [],
'visualization': True,
"soft_assaytype": "PAS",
'entity_type': 'Dataset',
}

add_assay_details(image_pyramid_input_doc, transformation_resources)
assert image_pyramid_input_doc == image_pyramid_output_doc


def test_transform_image_pyramid_support(mocker):
mocker.patch('requests.get', side_effect=[
mock_image_pyramid_support(),
mock_empty_descendants(),
])
image_pyramid_input_doc = {
'uuid': '0bf9cb40adebcfb261dfbe9244607508',
'dataset_type': 'Histology [Image Pyramid]',
'entity_type': 'Dataset',
'creation_action': 'Central Process'
}

image_pyramid_output_doc = {
'assay_display_name': ['Image Pyramid'],
'assay_modality': 'single',
'creation_action': 'Central Process',
'dataset_type': 'Histology [Image Pyramid]',
'mapped_data_types': ['Image Pyramid'],
"processing": "processed",
'raw_dataset_type': 'Histology',
'uuid': '0bf9cb40adebcfb261dfbe9244607508',
'pipeline': 'Image Pyramid',
'processing_type': 'hubmap',
'vitessce-hints': [
"is_image",
"is_support",
"pyramid",

],
'visualization': False,
"soft_assaytype": "image_pyramid",
'entity_type': 'Dataset',
}

add_assay_details(image_pyramid_input_doc, transformation_resources)
assert image_pyramid_input_doc == image_pyramid_output_doc


def mock_epic(uuid=None, headers=None):
return mock_response({
"assaytype": None,
"description": "Segmentation Mask",
"is-multi-assay": False,
"pipeline-shorthand": "",
"primary": False,
"vitessce-hints": [
"segmentation_mask",
"is_image",
"pyramid"
]
})


def test_transform_epic(mocker):
mocker.patch('requests.get', side_effect=[
mock_epic(),
mock_empty_descendants(),
])
epic_input_doc = {
'uuid': 'abc123',
'dataset_type': 'Segmentation Mask',
'entity_type': 'Dataset',
'creation_action': 'External Process'
}

epic_output_doc = {
'assay_display_name': ['Segmentation Mask'],
'assay_modality': 'single',
'creation_action': 'External Process',
'dataset_type': 'Segmentation Mask',
'mapped_data_types': ['Segmentation Mask'],
"processing": "processed",
'raw_dataset_type': 'Segmentation Mask',
'uuid': 'abc123',
'pipeline': 'Segmentation Mask',
'processing_type': 'external',
'vitessce-hints': [
"segmentation_mask",
"is_image",
"pyramid",

],
'visualization': False,
'entity_type': 'Dataset',
}

add_assay_details(epic_input_doc, transformation_resources)
assert epic_input_doc == epic_output_doc


def test_hubmap_processing():
hubmap_processed_input_doc = {
'creation_action': 'Central Process',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
'["http://purl.obolibrary.org/obo/UBERON_0001157"]}',
'status': 'New',
'uuid': '69c70762689b20308bb049ac49653342',
'soft_assaytype': 'salmon_rnaseq_10x',
'vitessce-hints': ['is_sc', 'rna'],
'visualization': True,
}
Expand All @@ -137,6 +138,7 @@ def raise_for_status(self):
def mock_soft_assay(uuid=None, headers=None):
return mock_response({'assaytype': 'salmon_rnaseq_10x',
'contains-pii': False,
'pipeline-shorthand': 'Salmon',
'description': 'scRNA-seq (10x Genomics) [Salmon]',
'primary': False,
'vitessce-hints': ['is_sc', 'rna']})
Expand Down

0 comments on commit 7398c2d

Please sign in to comment.