Skip to content

WSI annotation authoring in the viewer package - #19

Open
raylim wants to merge 83 commits into
masterfrom
codex/wsi-rd-annotations
Open

raylim wants to merge 83 commits into
masterfrom
codex/wsi-rd-annotations

Conversation

@raylim

@raylim raylim commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Fork follow-up stacked on codex/wsi-viewer-package (cBioPortal#5732). It adds slide annotation authoring to the viewer, saved to a separate annotation service.

Behavior

  • When an annotation service is configured, the viewer sidebar gets Layers and Annotations sections.
  • Drawing tools: rectangle, ellipse, circle, line and polygon (Esc cancels).
  • Named layers: add, delete, choose the active layer, show or hide.
  • A named color palette with custom colors.
  • Each annotation can be relabeled, recolored or deleted.
  • Annotations are W3C Web Annotations stored by the service. slide_id carries the slide's opaque slide key.
  • Without a configured service, the viewer is unchanged.

Service calls and auth

The annotation service sits behind a proxy that authenticates each request by calling the portal with the browser's session cookie, then forwards the user and study to the service. The browser holds no token.

Request Use
GET {url}/annotations?slide_id=…&study_id=…&studyId=… List a slide's annotations
POST {url}/annotations?studyId=… Create; the body names slide_id and study_id
PUT {url}/annotations/{id}?studyId=… Update, with the annotation's version
DELETE {url}/annotations/{id}?studyId=… Delete

Every request (wsiServiceRequest.ts):

  • is sent with credentials: 'include' and no Authorization header;
  • carries studyId exactly once in the query string. The proxy authorizes that study;
  • if it is a write (POST, PUT, PATCH, DELETE), sends X-Requested-With: XMLHttpRequest, and Content-Type: application/json when it has a body.

Errors:

  • 401 (signed out): the toolbar shows "Sign in to view and edit annotations." and the editing controls are hidden.
  • 403 (no access to the study): annotations are read-only, with a message saying so.
  • Neither is retried. A refused create is dropped, and a refused edit or delete puts the saved shape back. Opening another slide or study tries again.

Anyone who can read the study may write annotations; there is no separate write permission.

Config

  • wsi_annotation_api_url (default '') fills WsiViewerConfig.annotations.apiUrl, e.g. /wsi on the portal host.

Backend dependencies

Bundling

  • @annotorious/openseadragon loads lazily in its own async chunk on first use.
  • An rspack split-chunks group keeps a single OpenSeadragon copy (wsi-openseadragon) shared by the viewer and Annotorious.
  • scripts/assert_wsi_osd_bundle.js fails on a duplicated OpenSeadragon or on Annotorious in an initial bundle.

Tests

  • wsiServiceRequest.spec.ts: credentials, the CSRF header on writes only, JSON content type, studyId, 401/403 mapping.
  • wsiAnnotationController.spec.ts: list, create, update and delete each send studyId once, the cookie and no Authorization; the CSRF header only on writes; a 401 turns editing off; a 403 on a write makes the slide read-only with no retry.

🤖 Generated with Claude Code

@raylim
raylim force-pushed the codex/wsi-rd-annotations branch from f0a6fe8 to 531063c Compare September 30, 2026 19:05
@raylim
raylim force-pushed the codex/wsi-rd-annotations branch 2 times, most recently from e10c5fa to fcecd6f Compare September 30, 2026 20:22
raylim added a commit that referenced this pull request Oct 8, 2026
Rebuilt on codex/wsi-viewer-package (slide timing out, clinical section,
patient tab URL scoping) with the updated children: study #17, molecular
#18, agent #20 (with annotations #19) and study slides #23. #21 is closed:
its patient-tab URL scoping is now in the base and its slide timeline moved
to #28, so the timeline files, timing fields and mock routes it brought in
are left out. The previous head is kept as a parent so the update is a
fast-forward; this commit keeps the rebuilt tree.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
raylim added a commit that referenced this pull request Oct 9, 2026
…d-agent

Brings in #19 merged with the simplified cBioPortal#5732 and re-expresses the
research assistant on it:
- selection outcomes are settled from the base's resetMount (cancelled)
  and failMount (failed, with the short per-outcome details the agent
  reported before); the trimmed init-load trace is not reintroduced
- selectSlide keeps the base contract (resolves once mounted);
  selectSlideAndWait resolves with the outcome for the agent's
  select_slide and set_filters actions. The base, molecular and controller
  specs no longer need the child's "cancel the pending mount" helpers
- firstSlideForCurrentFilters is shared by the user's filter reselect and
  the agent's set_filters; agent filter checks use preferredSlideKeys and
  matchesMatchFilter
- the agent token getter relies on the now-required studyId and authScope
- the live-stack wsi-foundation-route.spec.ts stays deleted (its mocked
  fallback duplicated wsi-foundation-mocked.spec.ts); the agent's mocked
  spec drops the WSI_CHILD_CONTRACT guard and the mocks drop
  msk_wsi_authentication_enabled
- the foundation specs use the base's shared fixtures

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
raylim added a commit that referenced this pull request Oct 12, 2026
raylim added a commit that referenced this pull request Oct 13, 2026
… simplifications

- The viewer entry derives its props from WSIViewer's, leaving out the
  runtime-provided annotation service and agent flag.
- The agent's filter action no longer reports to the removed
  onStainFilterChange/onMatchFilterChange host callbacks.
- The controller keeps the agent's selection waiters beside the new
  cancel-handle schedules.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
raylim added a commit that referenced this pull request Oct 13, 2026
Molecular (#18) and annotations/agent (#19/#20) both add to the viewer,
controller host, sidebar, runtime config and light entry; keep both, as
the previous integration did.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
raylim added a commit that referenced this pull request Oct 13, 2026
Merges the updated children: #17 b56bec1, #18 ff6ea53, #20 64712b9
(with #19 0b5a959) and #23 35c00aa (with #27 46d3dcb), all on
cBioPortal#5732 e90d380. The tree is the children merged onto each other (second
parent); the previous integration head stays the first parent so the
push fast-forwards.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@raylim
raylim added this pull request to stack #31 October 14, 2026 17:09
Adds the cbioportal-wsi-viewer package (OpenSeadragon slide viewer with the slide list, details sidebar, panel chrome, scale bar and shareable view state) and the patient view Pathology Slides tab that serves whole-slide images from resource data. Slide resources and, when the viewer is configured, the legacy H&E resources are left out of Files & Links and the resource tabs (ResourcePolicy.isHiddenFromResourceViews, applied through ResourceTableStore's hideResource option).

Squashed onto master after resource table v2 (cBioPortal#5629); the previous history is on branch backup/codex-wsi-viewer-package-20261015.
raylim and others added 3 commits October 15, 2026 16:33
The tab count and the patient ResourcesTab table came from cBioPortal#5629's
server-driven code, which lists every resource; slides have their own
Pathology Slides tab.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… page links, study resource tabs

- Cancel a queued slide click when the hierarchy reloads, so a patient
  switch can't open the previous patient's slide.
- Request slide access with `credentials: 'include'`, like the hierarchy
  request, so an API on another origin gets its login cookie.
- Build the sidebar's patient/sample links through a new optional
  `buildPageUrl` runtime hook; the portal passes buildCBioPortalPageUrl so
  links keep the deployment context path (e.g. /beta).
- Study view: give the page's resource store the hiding policy and use its
  visibleTabs for the tabs, hasNewResourceTabs and the Files & Links
  redirect, so a hidden H&E resource is never the redirect target.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Squash of #19 onto the rebased cBioPortal#5732 after resource table v2 merged upstream.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@raylim
raylim force-pushed the codex/wsi-rd-annotations branch from 94a271f to 15baa33 Compare October 15, 2026 21:06
raylim added a commit that referenced this pull request Oct 15, 2026
Squash of #20 onto the rebased #19 after resource table v2 merged upstream.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
raylim added a commit that referenced this pull request Oct 15, 2026
…rge target)

Rebuilt from the rebased cBioPortal#5732 (44b68b8) by merging #17 (30456c9),
#18 (643d044), #20 (d81dab9, includes #19) and #23 (008ce69).

Squash of #22 onto the rebased cBioPortal#5732 after resource table v2 merged upstream.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
raylim and others added 3 commits October 15, 2026 17:32
Follows the backend rename of msk.wsi.tile_server.url to
wsi.tile_server.url: the setting isn't MSK-specific.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…e_server_url rename)

# Conflicts:
#	src/config/IAppConfig.ts
#	src/config/serverConfigDefaults.ts
raylim added a commit that referenced this pull request Oct 15, 2026
…ration

#17 5304083, #18 704a81c, #20 be9a529 (with #19), #23 8f4a2bb.
The integration tree already matched them; this records the parents.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The opaque slide key is now the first 12 hex characters of the old
32-hex key. Update the slide-key doc comments, the mocked backend's
access validation, and the test fixtures to 12-hex keys.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
raylim and others added 14 commits October 27, 2026 20:29
…i_url

The backend property is now wsi.annotation_api.url (raylim/cbioportal#9),
like the tile server's wsi.tile_server.url.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The filter reset showed whenever the page passed a sample or an initial
stain, even when clicking it did nothing: after a link scope had been
released (the preferred sample only picks the first slide), for a link
scope that hides no slide, or once the initial stain was cleared. It now
shows only while a stain or match filter is set, or while a link scope
the viewer may release hides some of the patient's viewable slides.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The sample chip's clear button had the same no-op case as the filter
reset: for a link sample scope that hides no viewable slide (all of the
patient's viewable slides are in that sample), clearing it changed
nothing. The list is narrowed to, and the chip names, a link's sample only
while the scope hides slides; a host-owned sample is unchanged. Tests also
cover unmatched slides hidden by a sample scope, a link that matches no
slide, a match-level link and slides the viewer cannot open.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Access control moves to the ingress: an nginx auth subrequest checks the
portal session cookie against GET /api/studies/{studyId}, and the tile
server no longer takes a JWT. The viewer therefore stops requesting
GET /api/resources/{studyId}/{resourceId}/access and sends no
Authorization header.

- Tiles: {tileServerUrl}/tiles/zxy/{z}/{x}/{y}?studyId=&key=&enc=
- Thumbnails: {tileServerUrl}/thumbnails?studyId=&key=&enc=&tw=&th=&width=&height=
  (key = serving.key, enc = serving.sealed_source, tw/th = the stored
  thumbnail size; all URL-encoded; same-origin, so the session cookie
  goes along)
- The slide registry (wsiAuth.ts) now keeps each published slide's
  serving key, sealed source, thumbnail size and tile metadata;
  getWsiSlideSource replaces the async access request. The Slide model
  carries sealed_source/thumbnail_width/thumbnail_height from the row;
  none of them is rendered.
- Removed token caching, refresh/expiry timers, OpenSeadragon ajax
  headers and the metadata prefetch that only warmed access requests.
  Tiles are still loaded with XHR so a refused tile's status is visible.
- A 401/403 from a tile or the thumbnail preview fails the slide at once
  with a "reload the page or sign in again" message in the existing
  error state.
- The hidden prop keeps pausing panel shortcuts and OpenSeadragon
  auto-resize; only the token refresh part is gone.
- Jest specs, the mocked Playwright WSI suite and the README portal
  contract follow the new contract (studyId/key/enc, tw/th, no
  Authorization header, no /access request, no image id).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…tal#5732: tile requests by key and sealed source, no token)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The tile server sizes thumbnails itself and ignores tw/th, so thumbnail
URLs carry only studyId, key, enc, width and height. The viewer no longer
reads the stored thumbnail size from a slide's row; nothing laid out by it.

The Playwright mock now models the ingress (401/403 on session refusal)
separately from the tile server, which answers 404 for a key/enc mismatch
and never 401/403.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A preview error, 401/403 included, now just drops the preview. Tiles
decide whether the slide fails: a tile answered 401/403 still shows the
session-expired error at once. Before, a refused preview failed the mount
while tiles kept loading, so the error flashed and then cleared.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
fetchWsiPatientHierarchy registered a hierarchy's slides whenever the
shared cache promise resolved, even after the caller aborted or after
clearWsiSlideSources (e.g. for a change of user), bringing back slides the
clear had removed. The registry now has a generation that every
clearWsiSlideSources bumps; a call captures it before its request and
skips registration if it changed or if the caller aborted. Registering a
hierarchy does not bump it, so concurrent loads of other patients are
unaffected.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…erver

Tile and thumbnail URLs are now built the same way: the tile-server base is
normalized to exactly one trailing slash and the path and query are
appended, so `/wsi` and `/wsi/` give the same URLs and a relative base
stays relative.

The ingress authorizes tile and thumbnail requests with the portal session
cookie, so the tile server must be same-origin with the portal. The README
says so, and the viewer logs a console.error once per cross-origin tile
server it is configured with.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…tal#5732: thumbnails without tw/th, ingress-only 401/403, registry generation)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@raylim raylim added the enhancement New feature or request label Nov 3, 2026
raylim and others added 6 commits November 5, 2026 11:47
…rged as 8052359)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* Keep enrichment rows whose group mean is 0

getFilteredData read each group's value as
`meanExpression || alteredPercentage`. A mean of exactly 0 is falsy, so
expression and generic assay rows fell back to an undefined altered
percentage, every comparison failed, and the row was dropped from the
enrichment table and its download while still showing in the volcano
plot.

Fall back to the altered percentage only when the group has no mean.

Fixes cBioPortal/cbioportal#12417

* Update mRNA enrichment e2e expectations for zero-mean rows

Rows with a group mean of 0 are now listed, which changes two remote
e2e results:

- group-comparison-mrna-enrichments-several: the table now has 19287
  rows instead of 17742, with OR6B2 (p = 5.0e-13, means 0/0/0/0.74)
  on top. The reference is the actual image from CircleCI.
- excluding-unprofiled comparison mrna: genes with an Unaltered mean of
  0 now rank first, so the expected top hit is AQP7 instead of KRT17P5.

* Update excluding-unprofiled mRNA e2e reference for zero-mean rows

The expected top gene is now AQP7 (Unaltered mean 0, p = 9.3e-12), so the reference shows its box plot and a table led by genes whose Unaltered-group mean is 0. The reference is the actual image from CircleCI, identical on the first run and the retry.
Cover the Generic Assay entity selectors in Study View Add Chart,
Oncoprint Add Tracks and the Plots tab on the remote lane, using
ccle_broad_2019, whose treatment profiles have more entities than the
100 options the selector lists at once. The tests search for, select
and restore from the URL a treatment outside the first 100, and check
that methylation probes of the queried gene are listed first.

In the local treatment spec, wait for option and chip counts with
toHaveCount, and add tests that a selection is kept after clearing a
search and after switching to a profile that has the same treatment.

Co-authored-by: dippindots <dippindots@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…rtal#5790)

* Format StructureVisualizer3D.ts with Prettier

No code changes. The file was not Prettier-formatted on master, and the CI prettier check runs on every changed file.

* Color AlphaFold models by pLDDT band to match the legend

The pLDDT coloring passed the four AlphaFold colors to 3Dmol as a linear
gradient over 0-100. 3Dmol spreads gradient colors in equal steps of 25,
so the drawn colors didn't match the legend's bands (<50, 50-70, 70-90,
>90): pLDDT 45 was drawn light blue instead of orange, and 72-88 dark
blue instead of light blue, so low-confidence regions looked confident.

Color each atom with a colorfunc that returns the band color from
ALPHAFOLD_PLDDT_LEGEND, so the structure and the legend share one
definition of the bands.

Fixes cBioPortal/cbioportal#12439
…ions

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
raylim added a commit that referenced this pull request Nov 12, 2026
…end master) into codex/wsi-rd-agent

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@raylim
raylim removed this pull request from stack #31 November 12, 2026 18:21
@raylim
raylim changed the base branch from codex/wsi-viewer-package to master November 12, 2026 18:21
@raylim
raylim added this pull request to stack #37 November 12, 2026 18:22
The annotation service now sits behind a proxy that authorizes each request
with the portal session cookie for the study named in the query, so the
viewer no longer fetches or sends study tokens.

- wsiServiceRequest.ts: every request sends credentials: 'include' and
  exactly one studyId in the query; writes (POST/PUT/PATCH/DELETE) add
  X-Requested-With: XMLHttpRequest, and a body is sent as application/json.
- wsiAnnotationController: list, create, update and delete all carry
  studyId (update and delete sent none before). A 401 asks the user to sign
  in and a 403 makes annotations read-only; neither is retried, and the
  toolbar and panel hide the editing controls.
- wsiAuth.ts: the purpose-token cache and its tests are removed.
- README: documents the annotation service contract.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
raylim added a commit that referenced this pull request Nov 12, 2026
…service) into codex/wsi-rd-agent

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The annotation service now scopes GET /annotations to the studyId the
proxy authorized and ignores a study_id query parameter, so the list call
no longer sends one. POST bodies keep study_id, which the service still
requires.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
raylim added a commit that referenced this pull request Nov 12, 2026
)

This merge takes its tree entirely from deploy/wsi-rd-children-20261112
(dd19c06), the second parent:
- codex/wsi-study-slide-facets-ui (#29, 7e493f7; stacked on #23 and #27)
- codex/wsi-rd-study (#17, 0c999a1)
- codex/wsi-rd-molecular (#18, ce690cf)
- codex/wsi-summary-timeline (#28, 406f52b)

The annotation (#19) and research assistant (#20) branches merged earlier
are not part of the result. The first parent keeps the branch's earlier
history, so the push is a fast-forward.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants