import ecoMap from '../adapters/config/evidence'; import { escapeHtml, sanitizeUrl } from '../utils/security'; import { acetylate, methylate, phosphorylate, sumoylate, ubiquitinate, } from './ptm-tooltip'; // Original mapping in src/main/java/uk/ac/ebi/uniprot/tools/proteomics/reader/ptm/PtmXchangeTsvReader.java. // from the GitLab repository https://gitlab.ebi.ac.uk/uniprot/framework/unp.fw.tools/ const taxIdToPeptideAtlasBuildData = { '36329_phosphorylation': { build: '542', organism: 'Plasmodium' }, '39947_phosphorylation': { build: '539', organism: 'Rice' }, '10090_phosphorylation': { build: '577', organism: 'Mouse' }, '9606_phosphorylation': { build: '606', organism: 'Human' }, '559292_phosphorylation': { build: '586', organism: 'Yeast' }, '4577_phosphorylation': { build: '591', organism: 'Maize' }, '185431_phosphorylation': { build: '590', organism: 'T Brucei' }, '508771_phosphorylation': { build: '601', organism: 'T Gondii' }, '9606_sumoylation': { build: '596', organism: 'Human' }, '9606_ubiquitinylation': { build: '604', organism: 'Human' }, '9606_acetylation': { build: '0', organism: 'Human' }, // Needs update when the build with acetylation data is ready in PeptideAtlas '9606_methylation': { build: '612', organism: 'Human' }, }; // https://docs.google.com/spreadsheets/d/1V51z3G3MhC8S-pCNlivAUG4WoFKwR1EhAEYYsgUyw2U/edit?gid=0#gid=0 const unimodIdMapping = { 'glu->pyro-glu': 27, 'ammonia-loss': 385, nqtgg: 2084, formyl: 122, carbamidomethyl: 4, ubiquitination: 121, tmt6plex: 737, phospho: 21, itraq8plex: 730, deamidated: 7, 'pyro-qqtgg': 2083, qqtgg: 2082, glygly: 121, oxidation: 35, 'gln->pyro-glu': 28, dehydrated: 23, dvfqqqtgg: 2085, acetyl: 1, itraq4plex: 214, tmtpro: 2016, 'label: 13c(6)15n(4)': 267, }; type EvidenceSource = { name?: string; id?: string; url?: string; alternativeUrl?: string; }; type Evidence = { code: string; source?: EvidenceSource; }; type Xref = { name: string; id: string; url?: string; }; type PTMDbReference = { id: string; properties: Record; }; type PTMHighlight = { name: string; position: number; dbReferences: PTMDbReference[]; }; export type TooltipFeature = { type?: string; start?: string | number; end?: string | number; description?: string; ftId?: string; alternativeSequence?: string; peptide?: string; unique?: boolean; xrefs?: Xref[]; evidences?: Evidence[]; residuesToHighlight?: PTMHighlight[]; ligandPart?: { name: string }; ligand?: { name: string }; [key: string]: unknown; }; const formatSource = (source: EvidenceSource) => { if (source.name?.toLowerCase() === 'PubMed'.toLowerCase()) { return `${escapeHtml(source.id)} (${escapeHtml(source.name)} EuropePMC)`; } const sourceLink = ` ${escapeHtml(source.id)}`; if (source.name) { // Temporary until we get the expected value as 'PeptideAtlas' instead of 'HppPeptideAtlas' if (source.name.startsWith('Hpp')) { return `${sourceLink} (${escapeHtml(source.name.slice(3))})`; } return `${sourceLink} (${escapeHtml(source.name)})`; } return sourceLink; }; export const getEvidenceFromCodes = (evidenceList: Evidence[] | undefined) => { if (!evidenceList) return ``; return ` `; }; export const formatXrefs = (xrefs: Xref[]) => { return ``; }; const getPTMEvidence = ( ptms: PTMHighlight[] | undefined, taxId: string | undefined ) => { if (!ptms) return ``; const ids = ptms.flatMap(({ dbReferences }) => dbReferences.map((ref) => ref.id) ); const idToPeptideAtlasUrl = new Map( ptms.flatMap(({ dbReferences }) => dbReferences.map( (ref) => [ref.id, ref.properties['PeptideAtlas URL']] as const ) ) ); const idToModificationName = new Map( ptms.flatMap(({ name, dbReferences }) => dbReferences.map((ref) => [ref.id, name] as const) ) ); const uniqueIds = [...new Set(ids.flat())]; // For 'Glue project' dataset (PXD012174), publication reference is hardcoded. const proteomexchange = 'https://proteomecentral.proteomexchange.org/dataset/'; return ` `; }; const formatPTMPeptidoform = (peptide: string, ptms: PTMHighlight[]) => { if (!ptms) return ``; const modificationValues = ptms.map((ptm) => ({ name: ptm.name, position: ptm.position, })); let peptidoform = ''; let lastModPosition = 0; modificationValues.forEach((p) => { peptidoform = `${peptidoform}${peptide.slice( lastModPosition, p.position )}[${p.name}]`; lastModPosition = p.position; }); // Add last remaining part of the peptide if any peptidoform = `${peptidoform}${peptide.slice(lastModPosition)}`; return peptidoform; }; const formatProformaWithLink = (proforma = '') => { return proforma.replace(/\[([^\]]+)\]/g, (_, modification) => { const id = unimodIdMapping[ modification.toLowerCase() as keyof typeof unimodIdMapping ]; if (!id) { console.error('Unimod ID not found for modification:', modification); return `[${modification}]`; } return `[${modification}]`; }); }; const findModifiedResidueName = ( feature: TooltipFeature, ptm: PTMHighlight ) => { const { peptide, start: peptideStart } = feature; const proteinLocation = Number(peptideStart) + ptm.position - 1; const modifiedResidue = (peptide ?? '').charAt(ptm.position - 1); // CharAt index starts from 0 switch (ptm.name) { case 'Phosphorylation': return `${proteinLocation} ${phosphorylate(modifiedResidue)}`; case 'SUMOylation': return `${proteinLocation} ${sumoylate(modifiedResidue)}`; case 'Ubiquitinylation': return `${proteinLocation} ${ubiquitinate(modifiedResidue)}`; case 'Acetylation': return `${proteinLocation} ${acetylate(modifiedResidue)}`; case 'Methylation': return `${proteinLocation} ${methylate(modifiedResidue)}`; default: return ''; } }; const formatTooltip = (feature: TooltipFeature, taxId?: string) => { const evidenceHTML = feature.type === 'PROTEOMICS_PTM' ? getPTMEvidence(feature.residuesToHighlight, taxId) : getEvidenceFromCodes(feature.evidences); const ptms = feature.type === 'PROTEOMICS_PTM' && feature.residuesToHighlight?.map((ptm) => findModifiedResidueName(feature, ptm) ); const dataset = feature.type === 'PROTEOMICS_PTM' && feature.residuesToHighlight?.flatMap(({ dbReferences }) => dbReferences.map((ref) => ref.id) ); let { description } = feature; if (feature.type === 'BINDING' || feature.type === 'Binding site') { let bindingDescription = ''; if (feature.ligandPart) { bindingDescription += `${feature.ligandPart.name} of `; } if (feature.ligand) { bindingDescription += feature.ligand.name; } if (feature.description) { bindingDescription += `; ${feature.description}`; } description = bindingDescription; } try { return ` ${ feature.type && feature.start && feature.end ? `

${escapeHtml(feature.type)} ${escapeHtml(feature.start)}-${escapeHtml(feature.end)}


` : '' } ${description ? `
Description

${escapeHtml(description)}

` : ``} ${feature.ftId ? `
Feature ID

${escapeHtml(feature.ftId)}

` : ``} ${ feature.alternativeSequence ? `
Alternative sequence

${escapeHtml(feature.alternativeSequence)}

` : `` } ${ ptms ? `
PTMs
` : '' } ${ feature.peptide && feature.type === 'PROTEOMICS_PTM' ? `
Peptidoform

${escapeHtml( formatPTMPeptidoform( feature.peptide, feature.residuesToHighlight ?? [] ) )}

` : `` } ${ feature.peptide && feature.type !== 'PROTEOMICS_PTM' ? `
Peptide

${escapeHtml(feature.peptide)}

` : `` } ${ feature.unique ? `
Unique

${feature.unique ? 'Yes' : 'No'}

` : `` } ${ feature.xrefs ? `
Cross-references
${formatXrefs(feature.xrefs)}` : `` } ${evidenceHTML ? `
Evidence
${evidenceHTML}` : ``} ${ feature.residuesToHighlight && dataset && !dataset.includes('PXD012174') // Exclude 'Glue project' dataset as it is from PRIDE and it doesn't have PTM statistical attributes ? `
PTM statistical attributes
` : '' } `; } catch (error) { console.error(error); return ''; } }; export default formatTooltip;