Commit ·
200948a
1
Parent(s): 9498226
Keep the Space page URL on the current page; rename homo-oligomer to Same protein
Browse files- frontend/src/App.tsx +2 -0
- frontend/src/components/Partners.tsx +2 -2
- frontend/src/lib/api.ts +1 -1
- frontend/src/lib/hfSpace.ts +110 -15
- frontend/src/main.tsx +12 -4
- frontend/src/pages/ChainPage.tsx +1 -1
- frontend/src/pages/StatisticsPage.tsx +2 -2
frontend/src/App.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import { SequencePage } from './pages/SequencePage';
|
|
| 9 |
import { ChainPage } from './pages/ChainPage';
|
| 10 |
import { StatisticsPage } from './pages/StatisticsPage';
|
| 11 |
import { DocsPage } from './pages/DocsPage';
|
|
|
|
| 12 |
|
| 13 |
function ScrollToTop() {
|
| 14 |
const { pathname } = useLocation();
|
|
@@ -43,6 +44,7 @@ export default function App() {
|
|
| 43 |
<div className="app">
|
| 44 |
<DatasetJsonLd />
|
| 45 |
<ScrollToTop />
|
|
|
|
| 46 |
<Header />
|
| 47 |
<main id="main">
|
| 48 |
<Routes>
|
|
|
|
| 9 |
import { ChainPage } from './pages/ChainPage';
|
| 10 |
import { StatisticsPage } from './pages/StatisticsPage';
|
| 11 |
import { DocsPage } from './pages/DocsPage';
|
| 12 |
+
import { HfSpaceSync, inHfSpace } from './lib/hfSpace';
|
| 13 |
|
| 14 |
function ScrollToTop() {
|
| 15 |
const { pathname } = useLocation();
|
|
|
|
| 44 |
<div className="app">
|
| 45 |
<DatasetJsonLd />
|
| 46 |
<ScrollToTop />
|
| 47 |
+
{inHfSpace && <HfSpaceSync />}
|
| 48 |
<Header />
|
| 49 |
<main id="main">
|
| 50 |
<Routes>
|
frontend/src/components/Partners.tsx
CHANGED
|
@@ -12,7 +12,7 @@ const TYPE_LABEL: Record<string, string> = { protein: 'Protein', dna: 'DNA', rna
|
|
| 12 |
|
| 13 |
/** Display label for a partner key ('self', a UniProt accession, 'dna', 'protein:<description>'). */
|
| 14 |
export function partnerLabel(key: string, names?: Record<string, PartnerName>): string {
|
| 15 |
-
if (key === SELF) return '
|
| 16 |
if (key === NO_PARTNER) return 'No partner';
|
| 17 |
const n = names?.[key];
|
| 18 |
if (n?.description) return n.description;
|
|
@@ -92,7 +92,7 @@ export function PartnerChips({
|
|
| 92 |
function kindOf(p: BindingPartner): { label: string; tone: string; hint: string } {
|
| 93 |
if (p.biological)
|
| 94 |
return p.same_entity
|
| 95 |
-
? { label: '
|
| 96 |
: { label: 'Bound partner', tone: 'bio', hint: 'A different polymer, in contact within biological assembly 1' };
|
| 97 |
if (p.n_res_target < 5)
|
| 98 |
return { label: 'Marginal', tone: 'weak', hint: 'Fewer than 5 interface residues on this chain' };
|
|
|
|
| 12 |
|
| 13 |
/** Display label for a partner key ('self', a UniProt accession, 'dna', 'protein:<description>'). */
|
| 14 |
export function partnerLabel(key: string, names?: Record<string, PartnerName>): string {
|
| 15 |
+
if (key === SELF) return 'Same protein';
|
| 16 |
if (key === NO_PARTNER) return 'No partner';
|
| 17 |
const n = names?.[key];
|
| 18 |
if (n?.description) return n.description;
|
|
|
|
| 92 |
function kindOf(p: BindingPartner): { label: string; tone: string; hint: string } {
|
| 93 |
if (p.biological)
|
| 94 |
return p.same_entity
|
| 95 |
+
? { label: 'Same protein', tone: 'homo', hint: "Another copy of this chain's protein (same entity), in contact within biological assembly 1" }
|
| 96 |
: { label: 'Bound partner', tone: 'bio', hint: 'A different polymer, in contact within biological assembly 1' };
|
| 97 |
if (p.n_res_target < 5)
|
| 98 |
return { label: 'Marginal', tone: 'weak', hint: 'Fewer than 5 interface residues on this chain' };
|
frontend/src/lib/api.ts
CHANGED
|
@@ -117,7 +117,7 @@ export interface Member {
|
|
| 117 |
pfam_id: string | null;
|
| 118 |
ecod_id: string | null;
|
| 119 |
ecod_fid: string | null;
|
| 120 |
-
/** Biological binding-partner keys, largest interface first; 'self' =
|
| 121 |
partners: string[];
|
| 122 |
/** EM specimen label (cryo-EM, negative-stain EM, MicroED, ...) for EM entries. */
|
| 123 |
em_label?: string | null;
|
|
|
|
| 117 |
pfam_id: string | null;
|
| 118 |
ecod_id: string | null;
|
| 119 |
ecod_fid: string | null;
|
| 120 |
+
/** Biological binding-partner keys, largest interface first; 'self' = another copy of the same protein. */
|
| 121 |
partners: string[];
|
| 122 |
/** EM specimen label (cryo-EM, negative-stain EM, MicroED, ...) for EM entries. */
|
| 123 |
em_label?: string | null;
|
frontend/src/lib/hfSpace.ts
CHANGED
|
@@ -1,25 +1,120 @@
|
|
| 1 |
/**
|
| 2 |
-
*
|
| 3 |
*
|
| 4 |
* huggingface.co/spaces/omaib/MuSProt shows this app in an iframe that always
|
| 5 |
-
* loads at "/"
|
| 6 |
-
* the
|
| 7 |
-
*
|
| 8 |
-
*
|
| 9 |
*
|
| 10 |
-
*
|
| 11 |
-
*
|
| 12 |
-
*
|
| 13 |
-
*
|
| 14 |
-
*
|
| 15 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
*/
|
|
|
|
|
|
|
| 17 |
|
|
|
|
| 18 |
const PARAM = 'p';
|
| 19 |
|
| 20 |
-
/**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
export function openDeepLink(): void {
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
window.history.replaceState(null, '', target
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
|
|
|
| 1 |
/**
|
| 2 |
+
* Running inside the Hugging Face Space page.
|
| 3 |
*
|
| 4 |
* huggingface.co/spaces/omaib/MuSProt shows this app in an iframe that always
|
| 5 |
+
* loads at "/". To give each page its own Space URL (…/MuSProt#/chain/7ua3/I)
|
| 6 |
+
* the app works with the two hooks the Space page offers
|
| 7 |
+
* (https://huggingface.co/docs/hub/spaces-handle-url-parameters), whose
|
| 8 |
+
* behaviour was checked on the live page (2026-10-08):
|
| 9 |
*
|
| 10 |
+
* - postMessage({hash}) to the parent: HF pushes a new parent history entry
|
| 11 |
+
* with that hash, every time;
|
| 12 |
+
* - when the parent's hash changes by Back/Forward, HF writes it into the
|
| 13 |
+
* iframe src, which reaches the app as a `hashchange` but also pushes an
|
| 14 |
+
* extra iframe history entry.
|
| 15 |
+
*
|
| 16 |
+
* So inside the Space the app keeps no browser history of its own (memory
|
| 17 |
+
* router): every page change becomes exactly one parent entry. On a Back, the
|
| 18 |
+
* app follows the hash HF hands it and steps back over HF's extra iframe entry,
|
| 19 |
+
* so the next Back again reaches the parent's previous page. Forward cannot be
|
| 20 |
+
* supported this way (HF's extra entry discards it); opened directly at
|
| 21 |
+
* omaib-musprot.hf.space the app uses the normal browser history.
|
| 22 |
+
*
|
| 23 |
+
* Links: …/MuSProt#/chain/7ua3/I (current) and …/MuSProt?p=/chain/7ua3/I
|
| 24 |
+
* (older) both open the page; HF passes the Space page's query string and hash
|
| 25 |
+
* to the iframe on first load.
|
| 26 |
*/
|
| 27 |
+
import { useEffect, useRef } from 'react';
|
| 28 |
+
import { useLocation, useNavigate } from 'react-router-dom';
|
| 29 |
|
| 30 |
+
const HF_ORIGIN = 'https://huggingface.co';
|
| 31 |
const PARAM = 'p';
|
| 32 |
|
| 33 |
+
/** Inside the HF Space page (not merely some iframe). */
|
| 34 |
+
export const inHfSpace: boolean = (() => {
|
| 35 |
+
try {
|
| 36 |
+
if (window.parent === window) return false;
|
| 37 |
+
} catch {
|
| 38 |
+
/* cross-origin parent: still embedded */
|
| 39 |
+
}
|
| 40 |
+
const ancestors = (window.location as Location & { ancestorOrigins?: DOMStringList }).ancestorOrigins;
|
| 41 |
+
return (
|
| 42 |
+
(ancestors?.length ? ancestors[0] === HF_ORIGIN : false) ||
|
| 43 |
+
document.referrer.startsWith(`${HF_ORIGIN}/`) ||
|
| 44 |
+
new URLSearchParams(window.location.search).has('__theme') // added by HF to the iframe URL
|
| 45 |
+
);
|
| 46 |
+
})();
|
| 47 |
+
|
| 48 |
+
/** '#/chain/7ua3/I' -> '/chain/7ua3/I'; null when the hash is not an app path. */
|
| 49 |
+
function pathFromHash(hash: string): string | null {
|
| 50 |
+
if (!hash.startsWith('#/') || hash.startsWith('#//')) return null;
|
| 51 |
+
try {
|
| 52 |
+
return decodeURI(hash.slice(1));
|
| 53 |
+
} catch {
|
| 54 |
+
return hash.slice(1);
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
function pathFromQuery(): string | null {
|
| 59 |
+
const p = new URLSearchParams(window.location.search).get(PARAM);
|
| 60 |
+
return p && p.startsWith('/') && !p.startsWith('//') ? p : null;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/** Page to open first: the Space page's hash, then ?p=, else home. */
|
| 64 |
+
export function initialPath(): string {
|
| 65 |
+
return pathFromHash(window.location.hash) ?? pathFromQuery() ?? '/';
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/** Outside the Space: turn a ?p= / #/ link into a real path before the router starts. */
|
| 69 |
export function openDeepLink(): void {
|
| 70 |
+
if (inHfSpace || window.location.pathname !== '/') return;
|
| 71 |
+
const target = pathFromHash(window.location.hash) ?? pathFromQuery();
|
| 72 |
+
if (target) window.history.replaceState(null, '', target);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/** Keeps the Space page's URL on the current page and follows its Back button. */
|
| 76 |
+
export function HfSpaceSync() {
|
| 77 |
+
const { pathname, search } = useLocation();
|
| 78 |
+
const navigate = useNavigate();
|
| 79 |
+
const path = pathname + search;
|
| 80 |
+
const current = useRef(path);
|
| 81 |
+
const fromParent = useRef(false);
|
| 82 |
+
// the parent already shows this page when the app was opened from its hash
|
| 83 |
+
const skipFirst = useRef(pathFromHash(window.location.hash) === initialPath());
|
| 84 |
+
const revertUntil = useRef(0);
|
| 85 |
+
|
| 86 |
+
useEffect(() => {
|
| 87 |
+
current.current = path;
|
| 88 |
+
if (skipFirst.current) {
|
| 89 |
+
skipFirst.current = false;
|
| 90 |
+
return;
|
| 91 |
+
}
|
| 92 |
+
if (fromParent.current) {
|
| 93 |
+
fromParent.current = false;
|
| 94 |
+
return;
|
| 95 |
+
}
|
| 96 |
+
window.parent.postMessage({ hash: `#${encodeURI(path)}` }, HF_ORIGIN);
|
| 97 |
+
}, [path]);
|
| 98 |
+
|
| 99 |
+
useEffect(() => {
|
| 100 |
+
const onHashChange = () => {
|
| 101 |
+
// our own step back over HF's extra entry fires a hashchange too
|
| 102 |
+
if (Date.now() < revertUntil.current) {
|
| 103 |
+
revertUntil.current = 0;
|
| 104 |
+
return;
|
| 105 |
+
}
|
| 106 |
+
const target = pathFromHash(window.location.hash);
|
| 107 |
+
if (target == null) return;
|
| 108 |
+
revertUntil.current = Date.now() + 600;
|
| 109 |
+
window.history.back();
|
| 110 |
+
if (target !== current.current) {
|
| 111 |
+
fromParent.current = true;
|
| 112 |
+
navigate(target, { replace: true });
|
| 113 |
+
}
|
| 114 |
+
};
|
| 115 |
+
window.addEventListener('hashchange', onHashChange);
|
| 116 |
+
return () => window.removeEventListener('hashchange', onHashChange);
|
| 117 |
+
}, [navigate]);
|
| 118 |
+
|
| 119 |
+
return null;
|
| 120 |
}
|
frontend/src/main.tsx
CHANGED
|
@@ -1,19 +1,27 @@
|
|
| 1 |
import { createRoot } from 'react-dom/client';
|
| 2 |
-
import { BrowserRouter } from 'react-router-dom';
|
| 3 |
import { HelmetProvider } from 'react-helmet-async';
|
| 4 |
import App from './App';
|
| 5 |
import './styles/tokens.css';
|
| 6 |
import './styles/base.css';
|
| 7 |
import './styles/ui.css';
|
| 8 |
import './styles/pages.css';
|
| 9 |
-
import { openDeepLink } from './lib/hfSpace';
|
| 10 |
|
| 11 |
openDeepLink();
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
createRoot(document.getElementById('root')!).render(
|
| 14 |
<HelmetProvider>
|
| 15 |
-
<
|
| 16 |
<App />
|
| 17 |
-
</
|
| 18 |
</HelmetProvider>,
|
| 19 |
);
|
|
|
|
| 1 |
import { createRoot } from 'react-dom/client';
|
| 2 |
+
import { BrowserRouter, MemoryRouter } from 'react-router-dom';
|
| 3 |
import { HelmetProvider } from 'react-helmet-async';
|
| 4 |
import App from './App';
|
| 5 |
import './styles/tokens.css';
|
| 6 |
import './styles/base.css';
|
| 7 |
import './styles/ui.css';
|
| 8 |
import './styles/pages.css';
|
| 9 |
+
import { inHfSpace, initialPath, openDeepLink } from './lib/hfSpace';
|
| 10 |
|
| 11 |
openDeepLink();
|
| 12 |
|
| 13 |
+
// inside the HF Space page the parent page's URL is the history (see lib/hfSpace.ts)
|
| 14 |
+
const Router = ({ children }: { children: React.ReactNode }) =>
|
| 15 |
+
inHfSpace ? (
|
| 16 |
+
<MemoryRouter initialEntries={[initialPath()]}>{children}</MemoryRouter>
|
| 17 |
+
) : (
|
| 18 |
+
<BrowserRouter>{children}</BrowserRouter>
|
| 19 |
+
);
|
| 20 |
+
|
| 21 |
createRoot(document.getElementById('root')!).render(
|
| 22 |
<HelmetProvider>
|
| 23 |
+
<Router>
|
| 24 |
<App />
|
| 25 |
+
</Router>
|
| 26 |
</HelmetProvider>,
|
| 27 |
);
|
frontend/src/pages/ChainPage.tsx
CHANGED
|
@@ -90,7 +90,7 @@ function BindingSummary({ c }: { c: ChainDetail }) {
|
|
| 90 |
</small>
|
| 91 |
</div>
|
| 92 |
<div className="metric" title="Other copies of the same entity in contact, in biological assembly 1">
|
| 93 |
-
<span>
|
| 94 |
<b className="tabular">{homo.length}</b>
|
| 95 |
<small>copies of this entity</small>
|
| 96 |
</div>
|
|
|
|
| 90 |
</small>
|
| 91 |
</div>
|
| 92 |
<div className="metric" title="Other copies of the same entity in contact, in biological assembly 1">
|
| 93 |
+
<span>Same-protein contacts</span>
|
| 94 |
<b className="tabular">{homo.length}</b>
|
| 95 |
<small>copies of this entity</small>
|
| 96 |
</div>
|
frontend/src/pages/StatisticsPage.tsx
CHANGED
|
@@ -246,7 +246,7 @@ export function StatisticsPage() {
|
|
| 246 |
height={16}
|
| 247 |
parts={[
|
| 248 |
{ key: 'hetero', label: 'Bound to another polymer', value: o.partners.observations_with_hetero_partner, color: 'var(--accent)' },
|
| 249 |
-
{ key: 'homo', label: '
|
| 250 |
{
|
| 251 |
key: 'none',
|
| 252 |
label: 'No polymer partner',
|
|
@@ -267,7 +267,7 @@ export function StatisticsPage() {
|
|
| 267 |
</ChartCard>
|
| 268 |
<ChartCard
|
| 269 |
title="Most frequent protein partners"
|
| 270 |
-
kicker="Observations bound to each protein (by UniProt accession), excluding
|
| 271 |
>
|
| 272 |
<div className="barlist--wide">
|
| 273 |
<BarList
|
|
|
|
| 246 |
height={16}
|
| 247 |
parts={[
|
| 248 |
{ key: 'hetero', label: 'Bound to another polymer', value: o.partners.observations_with_hetero_partner, color: 'var(--accent)' },
|
| 249 |
+
{ key: 'homo', label: 'Same-protein contacts only', value: o.partners.observations_homo_only, color: 'var(--fid-identical)' },
|
| 250 |
{
|
| 251 |
key: 'none',
|
| 252 |
label: 'No polymer partner',
|
|
|
|
| 267 |
</ChartCard>
|
| 268 |
<ChartCard
|
| 269 |
title="Most frequent protein partners"
|
| 270 |
+
kicker="Observations bound to each protein (by UniProt accession), excluding contacts with copies of the same protein."
|
| 271 |
>
|
| 272 |
<div className="barlist--wide">
|
| 273 |
<BarList
|