From 55eb03d4f4bc52ba6eb4059eec5cb1f026c4fd92 Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Sun, 24 May 2026 15:00:28 +0530 Subject: [PATCH] fix: only relabel whitelisted 5'Flank mutations as "Promoter" with custom filters MutationFilter.acceptMutation() handled the "Promoter" protein-change relabeling inconsistently depending on whether a custom filtered-mutations list was used: - Default filter (no custom list): a 5'Flank mutation is relabeled "Promoter" only when its gene is on the promoter whitelist (currently TERT); for any other gene the mutation is rejected. - Custom filter: every accepted 5'Flank mutation was relabeled "Promoter", regardless of the gene. As a result, the same 5'Flank mutation on a non-whitelisted gene could be labeled "Promoter" or not purely depending on the filter configuration, which misrepresents the mutation (the "Promoter" convention is specific to whitelisted promoter genes such as TERT). Gate the relabeling in the custom-filter branch by the promoter whitelist, so it matches the default-filter branch. The accept/reject behavior of custom filters is unchanged: a 5'Flank type that is not in the custom list is still accepted; it is simply no longer relabeled as a promoter mutation unless the gene is whitelisted. Adds TestMutationFilterPromoter covering both filter modes for whitelisted and non-whitelisted genes. Fixes #65 --- .../cbio/portal/scripts/MutationFilter.java | 7 +- .../scripts/TestMutationFilterPromoter.java | 102 ++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/mskcc/cbio/portal/scripts/TestMutationFilterPromoter.java diff --git a/src/main/java/org/mskcc/cbio/portal/scripts/MutationFilter.java b/src/main/java/org/mskcc/cbio/portal/scripts/MutationFilter.java index cfc3a197..9d5a24a8 100644 --- a/src/main/java/org/mskcc/cbio/portal/scripts/MutationFilter.java +++ b/src/main/java/org/mskcc/cbio/portal/scripts/MutationFilter.java @@ -125,7 +125,12 @@ public boolean acceptMutation(ExtendedMutation mutation, Set filteredMut addRejectedVariant(rejectionMap, mutation.getMutationType()); return false; } else { - if( safeStringTest( mutation.getMutationType(), "5'Flank" ) ) { + // Only relabel 5'Flank mutations as "Promoter" for whitelisted genes + // (e.g. TERT), consistent with the default-filter branch below. A + // custom filtered-mutations list controls which types are excluded; + // it must not turn every 5'Flank mutation into a promoter mutation. + if( safeStringTest( mutation.getMutationType(), "5'Flank" ) + && whiteListGenesForPromoterMutations.contains(mutation.getEntrezGeneId()) ) { mutation.setProteinChange("Promoter"); } return true; diff --git a/src/test/java/org/mskcc/cbio/portal/scripts/TestMutationFilterPromoter.java b/src/test/java/org/mskcc/cbio/portal/scripts/TestMutationFilterPromoter.java new file mode 100644 index 00000000..9a9448d8 --- /dev/null +++ b/src/test/java/org/mskcc/cbio/portal/scripts/TestMutationFilterPromoter.java @@ -0,0 +1,102 @@ +/* + * This file is part of cBioPortal. + * + * cBioPortal is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +*/ + +package org.mskcc.cbio.portal.scripts; + +import org.junit.Test; +import org.mskcc.cbio.portal.model.CanonicalGene; +import org.mskcc.cbio.portal.model.ExtendedMutation; + +import java.util.Collections; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +/** + * Unit tests covering the handling of {@code 5'Flank} (promoter) mutations by + * {@link MutationFilter}, both with the default filter and with a custom list of + * filtered mutation types. + * + *

The "Promoter" protein-change relabeling is reserved for genes on the + * promoter whitelist (currently only TERT, Entrez 7015). This must hold + * regardless of whether a custom filtered-mutations list is supplied. + */ +public class TestMutationFilterPromoter { + + private static final long TERT_ENTREZ_ID = 7015L; + private static final long NON_WHITELISTED_ENTREZ_ID = 207L; // AKT1 + + private ExtendedMutation fivePrimeFlankMutation(long entrezGeneId) { + CanonicalGene gene = new CanonicalGene(entrezGeneId, "GENE" + entrezGeneId); + return new ExtendedMutation(gene, "Valid", "Somatic", "5'Flank"); + } + + @Test + public void defaultFilterLabelsWhitelistedFlankMutationAsPromoter() { + MutationFilter filter = new MutationFilter(); + ExtendedMutation mutation = fivePrimeFlankMutation(TERT_ENTREZ_ID); + + assertTrue(filter.acceptMutation(mutation, null)); + assertEquals("Promoter", mutation.getProteinChange()); + } + + @Test + public void defaultFilterRejectsNonWhitelistedFlankMutation() { + MutationFilter filter = new MutationFilter(); + ExtendedMutation mutation = fivePrimeFlankMutation(NON_WHITELISTED_ENTREZ_ID); + + assertFalse(filter.acceptMutation(mutation, null)); + } + + @Test + public void customFilterLabelsWhitelistedFlankMutationAsPromoter() { + MutationFilter filter = new MutationFilter(); + Set filteredMutations = Collections.singleton("Silent"); + ExtendedMutation mutation = fivePrimeFlankMutation(TERT_ENTREZ_ID); + + assertTrue(filter.acceptMutation(mutation, filteredMutations)); + assertEquals("Promoter", mutation.getProteinChange()); + } + + @Test + public void customFilterKeepsNonWhitelistedFlankMutationWithoutPromoterLabel() { + MutationFilter filter = new MutationFilter(); + Set filteredMutations = Collections.singleton("Silent"); + ExtendedMutation mutation = fivePrimeFlankMutation(NON_WHITELISTED_ENTREZ_ID); + mutation.setProteinChange("p.E17K"); + + // A custom filtered-mutations list only excludes the listed types, so a + // 5'Flank mutation that is not listed must still be accepted ... + assertTrue(filter.acceptMutation(mutation, filteredMutations)); + // ... but it must not be relabeled as a promoter mutation, since the + // gene is not on the promoter whitelist. + assertNotEquals("Promoter", mutation.getProteinChange()); + assertEquals("p.E17K", mutation.getProteinChange()); + } + + @Test + public void customFilterRejectsListedMutationType() { + MutationFilter filter = new MutationFilter(); + Set filteredMutations = Collections.singleton("5'Flank"); + ExtendedMutation mutation = fivePrimeFlankMutation(TERT_ENTREZ_ID); + + assertFalse(filter.acceptMutation(mutation, filteredMutations)); + } +}