Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6ec27a9
feat(import): add native WSI study loader
raylim Aug 13, 2026
5cf3f40
fix WSI metadata validation and migration
raylim Aug 14, 2026
03901d8
docs: document WSI artifact publication prerequisites
raylim Aug 14, 2026
fffde21
Document WSI serving projection
raylim Aug 17, 2026
d5ca56a
fix ClickHouse backup restore fallback
raylim Aug 19, 2026
62a6a16
Merge remote-tracking branch 'origin/main' into agent/wsi-native-import
raylim Sep 2, 2026
e427b55
test: pin canonical ClickHouse schema and fix retries
raylim Sep 2, 2026
1e6ccfa
feat(import): complete native WSI loader changes
raylim Sep 2, 2026
88ad87a
fix(wsi): enforce date de-identification and complete patient counts
raylim Sep 2, 2026
44ffedf
fix(wsi): enforce deidentified import contract
raylim Sep 4, 2026
02557b6
fix: import Java runner exception type
raylim Sep 17, 2026
3a01638
fix: preserve importer failure details
raylim Sep 17, 2026
52d8b17
Verify derived tables before recording hydration
raylim Sep 17, 2026
d28e25e
fix(core): align importer schema with ClickHouse 3.2
raylim Sep 17, 2026
5fa2087
fix(clickhouse): avoid false staging deletion retries
raylim Sep 17, 2026
41cb209
feat(wsi): validate and import canonical timeline data
raylim Sep 18, 2026
26ce16b
fix(wsi): align importer tile metadata validation
raylim Sep 19, 2026
65d0fd7
test(wsi): keep importer fixture on the v3 timing schema
raylim Sep 19, 2026
03b4f1d
fix(wsi): make tile metadata validation type-parity safe
raylim Sep 19, 2026
f4bded2
test(wsi): reject malformed tile metadata fixture
raylim Sep 20, 2026
ee488a7
test(wsi): cover Java malformed metadata rejection
raylim Sep 20, 2026
c178bb7
fix(wsi): reject non-finite downsample metadata
raylim Sep 20, 2026
fd90d59
Generalize WSI artifact validation
raylim Sep 22, 2026
217e7bb
fix(wsi): preserve escaped literal percent in artifact URIs
raylim Sep 22, 2026
3bb22e5
fix(wsi): make lifecycle deletes projection-safe
raylim Sep 23, 2026
ebd163e
Keep generic importer behavior out of WSI core
raylim Sep 23, 2026
ef7a558
Pin core to repaired backend foundation
raylim Sep 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ This repository contains the Java code used for the cBioPortal importer + script
For documentation and usage instructions on the cBioPortal importer, please see here: https://docs.cbioportal.org/data-loading/

If you are a developer and want to help contribute to the cBioPortal importer codebase, please see here: https://docs.cbioportal.org/data-loading/data-loading-for-developers/

## WSI imports

The WSI importer is documented in [`docs/wsi-study-format.md`](docs/wsi-study-format.md).
cBioPortal core is the sole ClickHouse writer for WSI snapshots. Thumbnail
artifacts and the completed `meta_wsi.txt`/`data_wsi.txt` snapshot must be
prepared by an upstream artifact-generation/export pipeline before
`metaImport.py` runs. That pipeline is deployment-specific; it may use
Databricks or another implementation. Core does not generate thumbnails or
write the object store. Pathology procedure timing is imported separately as
standard `PATHOLOGY SLIDES` clinical timeline data.
134 changes: 134 additions & 0 deletions docs/wsi-study-format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# WSI study import

cBioPortal core is the sole database writer for whole-slide-image (WSI)
studies. An upstream artifact-generation/export pipeline produces a normal
study directory with `meta_wsi.txt` and `data_wsi.txt`; the tile server only
serves the source and thumbnail artifacts returned by cBioPortal. The upstream
pipeline is deployment-specific and may use Databricks, scripts, or another
service; Databricks is not required by cBioPortal core.

## Upstream artifact publication

Before the study files are imported, an upstream artifact-generation/export
pipeline must read or receive the eligible slide inventory and source rows,
generate the required master thumbnails and tile metadata, store the artifacts
where the deployment's tile-serving layer can access them, and materialize the
artifact fields below into `data_wsi.txt`. The pipeline must set
`CAN_SERVE_TILES` consistently with the availability of the required source,
tile-metadata, and thumbnail fields. An implementation may maintain a
registry, perform canonical-association queries, or use a completion watermark,
but those details are producer-specific and are not part of the cBioPortal core
contract.

The artifact-generation process is outside cBioPortal core and outside the
frontend. The frontend is a read-only consumer. A tile-serving deployment may
provide optional development or controlled-remediation tooling, but those
tools are not required by core and must not be used as the production
publication mechanism. The export must wait until artifact generation and
metadata publication are complete, and any producer-side metadata needed for
serving must be finalized before the study is imported.

## Metadata

```text
cancer_study_identifier: <study stable id>
genetic_alteration_type: PATHOLOGY_SLIDES
datatype: WSI
data_filename: data_wsi.txt
format_version: 3
```

The importer rejects unsupported format versions. A study may contain one WSI
pair. The data file follows the normal cBioPortal five-row preamble: four
comment rows, followed by this exact header:

```text
PATIENT_ID REFERENCE_SAMPLE_ID SAMPLE_ID IMAGE_ID PART_KEY PART_NUMBER PART_DESIGNATOR PART_TYPE PART_DESCRIPTION SUBSPECIALTY PATH_DX_TITLE BLOCK_KEY BLOCK_NUMBER BLOCK_LABEL MATCH_LEVEL SPECIMEN_KEY STAIN_NAME STAIN_GROUP IS_HNE IS_IHC MAGNIFICATION FILE_SIZE_BYTES BARCODE SLIDE_TYPE CAN_SERVE_TILES SOURCE_URL TILE_METADATA_JSON THUMBNAIL_URL THUMBNAIL_WIDTH THUMBNAIL_HEIGHT THUMBNAIL_CONTENT_TYPE TIMELINE_START_DAYS TIMELINE_DATE_STATUS TIMELINE_DATE_KIND TIMELINE_DATE_SOURCE TIMELINE_DATE_REASON TIMELINE_COORDINATE_SYSTEM TIMEPOINT_SOURCE
```

Values are tab-delimited. Format v3 carries the de-identified relative timing
contract on every row. `TIMELINE_START_DAYS` is relative to the patient's first
tumor-sequencing sample; day zero is valid. `TIMELINE_DATE_KIND` is `RECORDED`,
`ESTIMATED`, or `UNDATED`, and `TIMELINE_DATE_SOURCE` and
`TIMELINE_DATE_REASON` preserve provenance. The coordinate system must be
`patient_first_tumor_sequencing_day_zero`. Missing procedure dates remain in the
WSI hierarchy and are represented by the adjacent undated UI section; they are
not converted into dated clinical events.
Required values are `PATIENT_ID`, `IMAGE_ID`,
`PART_KEY`, `BLOCK_KEY`, `MATCH_LEVEL`, `SPECIMEN_KEY`, `IS_HNE`, `IS_IHC`,
and `CAN_SERVE_TILES`. `MATCH_LEVEL` is `BLOCK`, `PART`, or `UNMATCHED`;
matched rows require `SAMPLE_ID`, while unmatched rows leave it blank.

`IMAGE_ID` is unique within a study. Repeated part and block keys must carry
the same descriptive values. Stable patient, sample, and reference-sample IDs
must resolve to the study, and a sample/reference sample must belong to the
row's patient. `TILE_METADATA_JSON` must be a JSON object when present. For
servable rows, it must contain positive `dimensions.width` and
`dimensions.height`, a positive `levels` count with one positive
`level_dimensions` entry per level, a nonnegative `max_zoom`, and a positive
`tile_size`; additional producer-defined fields are preserved. URLs
must be absolute and must not contain credentials, query strings, fragments, or
path traversal. When `CAN_SERVE_TILES=TRUE`, source URL, tile metadata,
thumbnail URL, positive dimensions, and an `image/*` thumbnail content type are
mandatory. Core does not require a particular URI scheme, source filename
extension, or thumbnail URI extension; those choices belong to the serving
layer. Deployments may restrict source and thumbnail roots with the
`WSI_ALLOWED_SOURCE_PREFIXES` and `WSI_ALLOWED_THUMBNAIL_PREFIXES` environment
variables.
Non-servable rows have those artifact columns stored as null. The importer
does not perform de-identification scanning; upstream publication pipelines are
responsible for removing protected health information and deployment-specific
identifiers before export. Production deployments should set both URI prefix
allowlists; development may explicitly include `file:///app/testdata/`.

The importer assumes these values were already materialized by the upstream
artifact-generation/export pipeline. It does not discover source slides,
generate thumbnails, read a producer-specific registry, or write the object
store.

## Import commands

Full study import:

```bash
metaImport.py -s /path/to/study
```

WSI snapshots are loaded as part of a full study import into the inactive
blue/green database. WSI is not supported by incremental (`metaImport.py -d`)
imports. WSI loading runs after clinical sample definitions and before a full
study is marked `AVAILABLE`.

During the WSI load, the importer also writes sample-level clinical attributes
(`WSI_SAMPLE_SLIDE_COUNT`, `WSI_SAMPLE_PART_MATCHED_SLIDE_COUNT`, and
`WSI_SAMPLE_BLOCK_MATCHED_SLIDE_COUNT`) and authoritative patient-level
attributes (`WSI_PATIENT_SLIDE_COUNT`, `WSI_PATIENT_PART_MATCHED_SLIDE_COUNT`,
and `WSI_PATIENT_BLOCK_MATCHED_SLIDE_COUNT`). Study View uses the patient-level
values so pagination cannot produce partial totals, and falls back to summing
sample values for older studies. Existing count attributes are preserved when a
generated WSI count clinical file was loaded earlier in the same full import.

## ClickHouse snapshot

The importer resolves the stable identifiers to internal IDs and normalizes
the flat file into these tables:

- `wsi_patient`
- `wsi_part`
- `wsi_block`
- `wsi_slide`
- `wsi_slide_placement`
- `wsi_slide_timing`
The five tables are provisioned by the cBioPortal backend schema. Core does not
create or migrate production tables. Study deletion removes the snapshot rows.
The importer is insert-only and must run against a fresh inactive database;
discard and rebuild that database after a failed or repeated WSI import.

The backend schema also provisions the additive `wsi_slide_by_access`
ClickHouse projection. It is ordered by `(cancer_study_id, image_id)` for the
authenticated slide-access lookup. A production rebuild must materialize the
projection before the new database is promoted; the importer itself does not
perform live schema changes.

The former tile-server ClickHouse loader is not supported; all WSI loads must
use the standard cBioPortal importer.
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

<!-- THIS SHOULD BE KEPT IN SYNC WITH db.version IN cbioportal/pom.xml and
info.db_schema_version IN cbioportal/src/main/resources/db-scripts/clickhouse/init/schema.sql -->
<db.version>3.0.0</db.version>
<cbioportal.version>v6.4.1</cbioportal.version>
<db.version>3.4.0</db.version>
<!-- Pin this to the backend commit containing the matching schema before merging. -->
<cbioportal.version>19dc061b076e9d59c1fba12da278f39344785662</cbioportal.version>
<maf.version>1.0.0</maf.version>

<commons_lang3.version>3.13.0</commons_lang3.version>
Expand Down
15 changes: 15 additions & 0 deletions scripts/importer/cbioportalImporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def process_study_directory(jvm_args, study_directory, update_generic_assay_enti
gsva_pvalue_filepair = None
structural_variant_filepair = None
cna_long_filepair = None
wsi_filepair = None

# Determine meta filenames in study directory
meta_filenames = get_meta_filenames(study_directory)
Expand Down Expand Up @@ -388,6 +389,13 @@ def process_study_directory(jvm_args, study_directory, update_generic_assay_enti
elif meta_file_type == MetaFileTypes.CNA_DISCRETE_LONG:
cna_long_filepair = (
(meta_filename, os.path.join(study_directory, meta_dictionary['data_filename'])))
elif meta_file_type == MetaFileTypes.WSI:
if wsi_filepair is not None:
raise RuntimeError(
'Multiple WSI files found: {} and {}'.format(
wsi_filepair[0], meta_filename))
wsi_filepair = (
meta_filename, os.path.join(study_directory, meta_dictionary['data_filename']))
# Add all other types of data
else:
regular_filepairs.append(
Expand All @@ -412,6 +420,13 @@ def process_study_directory(jvm_args, study_directory, update_generic_assay_enti
meta_filename, data_filename = sample_attr_filepair
import_data(jvm_args, meta_filename, data_filename, update_generic_assay_entity, study_meta_dictionary[meta_filename])

# WSI rows reference the study's patient/sample definitions and must be
# published before any later data import can mark the study available.
if wsi_filepair is not None:
meta_filename, data_filename = wsi_filepair
import_data(jvm_args, meta_filename, data_filename,
update_generic_assay_entity, study_meta_dictionary[meta_filename])

# Next, we need to import resource definitions for resource data
if resource_definition_filepair is not None:
meta_filename, data_filename = resource_definition_filepair
Expand Down
28 changes: 27 additions & 1 deletion scripts/importer/cbioportal_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class MetaFileTypes(object):
PATIENT_RESOURCES = 'meta_resource_patient'
STUDY_RESOURCES = 'meta_resource_study'
RESOURCES_DEFINITION = 'meta_resource_definition'
WSI = 'meta_wsi'

# class to hold information about a failed java process execution
class JavaRunException(Exception):
Expand Down Expand Up @@ -368,6 +369,13 @@ def __init__(self, process_return_status, message):
'resource_type': True,
'data_filename': True
},
MetaFileTypes.WSI: {
'cancer_study_identifier': True,
'genetic_alteration_type': True,
'datatype': True,
'data_filename': True,
'format_version': True,
},
}

# order is important! This is the order in which they should be loaded:
Expand Down Expand Up @@ -422,6 +430,7 @@ def __init__(self, process_return_status, message):
MetaFileTypes.PATIENT_RESOURCES: "org.mskcc.cbio.portal.scripts.ImportResourceData",
MetaFileTypes.STUDY_RESOURCES: "org.mskcc.cbio.portal.scripts.ImportResourceData",
MetaFileTypes.RESOURCES_DEFINITION: "org.mskcc.cbio.portal.scripts.ImportResourceDefinition",
MetaFileTypes.WSI: "org.mskcc.cbio.portal.scripts.ImportWsiData",
}

IMPORTER_REQUIRES_METADATA = {
Expand All @@ -433,7 +442,8 @@ def __init__(self, process_return_status, message):
"org.mskcc.cbio.portal.scripts.ImportTimelineData" : True,
"org.mskcc.cbio.portal.scripts.ImportGenePanelProfileMap" : False,
"org.mskcc.cbio.portal.scripts.ImportResourceData" : True,
"org.mskcc.cbio.portal.scripts.ImportResourceDefinition" : True
"org.mskcc.cbio.portal.scripts.ImportResourceDefinition" : True,
"org.mskcc.cbio.portal.scripts.ImportWsiData" : True
}

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -656,6 +666,8 @@ def get_meta_file_type(meta_dictionary, logger, filename):
("CLINICAL", "PATIENT_ATTRIBUTES"): MetaFileTypes.PATIENT_ATTRIBUTES,
("CLINICAL", "SAMPLE_ATTRIBUTES"): MetaFileTypes.SAMPLE_ATTRIBUTES,
("CLINICAL", "TIMELINE"): MetaFileTypes.TIMELINE,
# whole-slide images
("PATHOLOGY_SLIDES", "WSI"): MetaFileTypes.WSI,
# rppa and mass spectrometry
("PROTEIN_LEVEL", "LOG2-VALUE"): MetaFileTypes.PROTEIN,
("PROTEIN_LEVEL", "Z-SCORE"): MetaFileTypes.PROTEIN,
Expand Down Expand Up @@ -977,6 +989,20 @@ def parse_metadata_file(filename,
'cause': meta_dictionary['reference_genome_id']})
meta_dictionary['meta_file_type'] = None

if meta_file_type == MetaFileTypes.WSI:
if meta_dictionary.get('genetic_alteration_type') != 'PATHOLOGY_SLIDES' or \
meta_dictionary.get('datatype') != 'WSI':
logger.error(
'WSI metadata must use genetic_alteration_type PATHOLOGY_SLIDES and datatype WSI',
extra={'filename_': filename})
meta_dictionary['meta_file_type'] = None
elif meta_dictionary.get('format_version') != '3':
logger.error(
"Unsupported WSI format_version; expected '3'",
extra={'filename_': filename,
'cause': meta_dictionary.get('format_version')})
meta_dictionary['meta_file_type'] = None

if meta_file_type in [MetaFileTypes.MUTATION, MetaFileTypes.MUTATION_UNCALLED]:
if ('swissprot_identifier' in meta_dictionary and
meta_dictionary['swissprot_identifier'] not in ('name',
Expand Down
10 changes: 10 additions & 0 deletions scripts/importer/rebuild_derived_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ def rebuild_derived_tables(derived_table_sql_filepath=None):
if not portal_home:
raise RuntimeError("PORTAL_HOME not set, could not locate derived table script")
derived_table_sql_filepath = os.path.join(portal_home, 'populate_derived_tables.sql')
if not os.path.isfile(derived_table_sql_filepath):
# The primary cBioPortal repository keeps ClickHouse scripts
# under db-scripts/clickhouse in both source and build
# resource trees. Accept that layout as well as the legacy
# flat PORTAL_HOME layout used by older deployments.
nested = os.path.join(
portal_home, 'db-scripts', 'clickhouse', 'populate_derived_tables.sql'
)
if os.path.isfile(nested):
derived_table_sql_filepath = nested
if not os.path.exists(derived_table_sql_filepath):
raise RuntimeError(f"Could not find derived table script at {derived_table_sql_filepath}")

Expand Down
Loading