Skip to content

Commit 722bb40

Browse files
Ticket 53293: PTM conditional formatting improvements (#1082)
1 parent 2c66fab commit 722bb40

4 files changed

Lines changed: 87 additions & 25 deletions

File tree

src/org/labkey/targetedms/parser/Peptide.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public static boolean modifiedSequencesMatch(String modSeq1, String modSeq2)
370370
}
371371

372372
/**
373-
* Adds to a list all of the modifications in a modifiedSequence, and returns the unmodified sequence.
373+
* Adds to a list all the modifications in a modifiedSequence, and returns the unmodified sequence.
374374
*/
375375
public static String stripModifications(String modifiedSequence, List<Pair<Integer, String>> modifications)
376376
{

src/org/labkey/targetedms/query/CDRConditionalFormattingDisplayColumnFactory.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import org.labkey.api.data.SimpleFilter;
1313
import org.labkey.api.query.FieldKey;
1414
import org.labkey.api.util.Pair;
15+
import org.labkey.targetedms.parser.Peptide;
1516
import org.labkey.targetedms.parser.Protein;
1617

18+
import java.util.ArrayList;
1719
import java.util.Map;
1820
import java.util.Set;
1921
import java.util.function.Function;
@@ -31,13 +33,28 @@ public CDRConditionalFormattingDisplayColumnFactory(Function<Long, Protein> prot
3133
_runId = runId;
3234
}
3335

34-
public static RiskLevel getRiskLevel(Number value, boolean inCDR, boolean stressed)
36+
public static RiskLevel getRiskLevel(Number value, boolean inCDR, boolean stressed, String modification, String modifiedSequence)
3537
{
3638
if (value == null)
3739
{
3840
return null;
3941
}
4042

43+
if ("Gln->pyro-Glu (N-term Q)".equalsIgnoreCase(modification))
44+
{
45+
return null;
46+
}
47+
48+
if (modifiedSequence != null)
49+
{
50+
String sequence = Peptide.stripModifications(modifiedSequence, new ArrayList<>());
51+
// Ticket 53293 - exempt low-risk IgG1 and IgG4 sequences from scoring
52+
if ("EEQYNSTYR".equalsIgnoreCase(sequence) || "EEQFNSTYR".equalsIgnoreCase(sequence))
53+
{
54+
return null;
55+
}
56+
}
57+
4158
// Apply different cutoffs when the peptide is part of the complementarity determining region (CDR)
4259
// for the antibody. If it's in the region we're significantly more stringent about how much
4360
// of a PTM we consider medium or high risk.
@@ -136,12 +153,17 @@ public void addQueryFieldKeys(Set<FieldKey> keys)
136153
keys.add(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "Location"));
137154
keys.add(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "Modification"));
138155
keys.add(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "RunId"));
156+
keys.add(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "Sequence"));
139157
}
140158

141-
@NotNull
142-
private ConditionalFormat createConditionalFormat(Number value, boolean inCDR, boolean stressed)
159+
@Nullable
160+
private ConditionalFormat createConditionalFormat(Number value, boolean inCDR, boolean stressed, String modification, String modifiedSequence)
143161
{
144-
RiskLevel level = getRiskLevel(value, inCDR, stressed);
162+
RiskLevel level = getRiskLevel(value, inCDR, stressed, modification, modifiedSequence);
163+
if (level == null)
164+
{
165+
return null;
166+
}
145167

146168
ConditionalFormat result = new ConditionalFormat()
147169
{
@@ -178,10 +200,7 @@ public void appendFilterText(StringBuilder sb, SimpleFilter.ColumnNameFormatter
178200
}
179201

180202
String modification = ctx.get(new FieldKey(getBoundColumn().getFieldKey().getParent(), "Modification"), String.class);
181-
if ("Gln->pyro-Glu (N-term Q)".equalsIgnoreCase(modification))
182-
{
183-
return null;
184-
}
203+
String modifiedSequence = ctx.get(new FieldKey(getBoundColumn().getFieldKey().getParent(), "Sequence"), String.class);
185204

186205
boolean inCDR = isInCDR(getBoundColumn().getFieldKey().getParent(), ctx, _proteinGetter);
187206

@@ -192,7 +211,7 @@ public void appendFilterText(StringBuilder sb, SimpleFilter.ColumnNameFormatter
192211
sampleName = sampleName.substring(0, sampleName.indexOf("::"));
193212
}
194213
Pair<Boolean, String> metadata = _stressedSamples.get(Pair.of(sampleName, _runId));
195-
return createConditionalFormat(value, inCDR, metadata != null && metadata.first.booleanValue());
214+
return createConditionalFormat(value, inCDR, metadata != null && metadata.first.booleanValue(), modification, modifiedSequence);
196215
}
197216
}
198217

src/org/labkey/targetedms/query/PTMRiskDisplayColumnFactory.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ public Object getValue(RenderContext ctx)
4848
Object result = super.getValue(ctx);
4949
if (result == null)
5050
{
51-
Number modified = ctx.get(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "PercentModified"), Number.class);
52-
String sampleName = ctx.get(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "SampleName"), String.class);
51+
Number percentModified = ctx.get(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "PercentModified"), Number.class);
52+
String replicateName = ctx.get(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "ReplicateName"), String.class);
5353
Long runId = ctx.get(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "RunId"), Long.class);
54-
if (modified == null || sampleName == null || runId == null)
54+
String modification = ctx.get(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "Modification"), String.class);
55+
String modifiedSequence = ctx.get(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "Sequence"), String.class);
56+
if (percentModified == null || replicateName == null || runId == null)
5557
{
5658
return null;
5759
}
@@ -62,10 +64,10 @@ public Object getValue(RenderContext ctx)
6264
}
6365

6466
boolean cdr = CDRConditionalFormattingDisplayColumnFactory.isInCDR(getBoundColumn().getFieldKey().getParent(), ctx, _proteinGetter);
65-
Pair<Boolean, String> metadata = _stressedSamples.get(Pair.of(sampleName, runId));
67+
Pair<Boolean, String> metadata = _stressedSamples.get(Pair.of(replicateName, runId));
6668
boolean stressed = metadata != null && metadata.first.booleanValue();
6769

68-
result = CDRConditionalFormattingDisplayColumnFactory.getRiskLevel(modified, cdr, stressed);
70+
result = CDRConditionalFormattingDisplayColumnFactory.getRiskLevel(percentModified, cdr, stressed, modification, modifiedSequence);
6971
}
7072
return result;
7173
}
@@ -81,7 +83,7 @@ public void addQueryFieldKeys(Set<FieldKey> keys)
8183
{
8284
super.addQueryFieldKeys(keys);
8385
keys.add(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "PercentModified"));
84-
keys.add(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "SampleName"));
86+
keys.add(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "ReplicateName"));
8587
keys.add(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "PeptideGroupId"));
8688
keys.add(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "Location"));
8789
keys.add(FieldKey.fromString(getBoundColumn().getFieldKey().getParent(), "RunId"));

test/src/org/labkey/test/tests/targetedms/TargetedMSEarlyStagePTMReportTest.java

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import org.labkey.test.util.DataRegionTable;
99

1010
import java.util.Arrays;
11+
import java.util.List;
12+
13+
import static org.junit.Assert.assertEquals;
1114

1215
@Category({})
1316
public class TargetedMSEarlyStagePTMReportTest extends TargetedMSTest
@@ -33,6 +36,38 @@ private void doInit()
3336
importData(IMPORT_FILE);
3437
}
3538

39+
@Test
40+
public void testEarlyStagePrepivot()
41+
{
42+
goToProjectHome();
43+
goToSchemaBrowser();
44+
DataRegionTable table = viewQueryData("targetedms", "PTMPercentsGroupedPrepivot");
45+
46+
// Test special-cased peptide
47+
table.setFilter("PeptideModifiedSequence", "Starts With", "EEQ");
48+
table = new DataRegionTable("query", this);
49+
assertEquals(List.of("false", "false", "false", "false", "false", "false"), table.getColumnDataAsText("IsCdr"));
50+
assertEquals(List.of(" ", " ", " ", " ", " ", " "), table.getColumnDataAsText("Risk"));
51+
52+
// Test "normal" peptide
53+
table.setFilter("PeptideModifiedSequence", "Starts With", "WQQ");
54+
table = new DataRegionTable("query", this);
55+
assertEquals(List.of("false", "false"), table.getColumnDataAsText("IsCdr"));
56+
assertEquals(List.of("Low", "Medium"), table.getColumnDataAsText("Risk"));
57+
58+
// Test CDR peptide
59+
table.setFilter("PeptideModifiedSequence", "Starts With", "VTN");
60+
table = new DataRegionTable("query", this);
61+
assertEquals(List.of("true", "true"), table.getColumnDataAsText("IsCdr"));
62+
assertEquals(List.of("High", "Medium"), table.getColumnDataAsText("Risk"));
63+
64+
// Test special-cased N-Term Modification, present on QVTL peptide (Q is modified, so don't use it in the filter)
65+
table.setFilter("PeptideModifiedSequence", "Contains", "VTL");
66+
table = new DataRegionTable("query", this);
67+
assertEquals(List.of("false", "false"), table.getColumnDataAsText("IsCdr"));
68+
assertEquals(List.of(" ", " "), table.getColumnDataAsText("Risk"));
69+
}
70+
3671
@Test
3772
public void testEarlyStagePTMReport()
3873
{
@@ -42,28 +77,34 @@ public void testEarlyStagePTMReport()
4277
DataRegionTable reportTable = new DataRegionTable.DataRegionFinder(getDriver()).withName("earlyStagePtmReport").waitFor();
4378

4479
log("Verifying the table headers");
45-
Assert.assertEquals("Incorrect column headers", Arrays.asList("Chain", "Site Location", "Sequence", "Modification", "Max Percent Modified",
80+
assertEquals("Incorrect column headers", Arrays.asList("Chain", "Site Location", "Sequence", "Modification", "Max Percent Modified",
4681
"Percent Modified", "Total Percent Modified", "Percent Modified", "Total Percent Modified"), reportTable.getColumnLabels());
47-
Assert.assertEquals("Incorrect Sample Names displayed as headers", "Sample1 QE_2",
82+
assertEquals("Incorrect Sample Names displayed as headers", "Sample1 QE_2",
4883
Locator.xpath("//table/thead[2]/tr").findElement(reportTable).getText());
4984

85+
int qvtRowIndex = 0; // Special-cased modification: Gln->pyro-Glu (N-term Q)
5086
int vtnRowIndex = 1;
87+
int eeqRowIndex = 3; // Special-cased peptide: EEQYNSTYR(V)
5188
int wqqRowIndex = 7;
5289

5390
log("Verifying the modified percentage for sequence with CDR Range and stressed or not stressed updates");
54-
Assert.assertEquals("Incorrect percentages for (K)VTNMDPADTATYYCAR(D) sequence", Arrays.asList("(K)VTNMDPADTATYYCAR(D)", "11.3%", "11.3%", "11.1%", "11.1%"),
91+
assertEquals("Incorrect percentages for (K)VTNMDPADTATYYCAR(D) sequence", Arrays.asList("(K)VTNMDPADTATYYCAR(D)", "11.3%", "11.3%", "11.1%", "11.1%"),
5592
reportTable.getRowDataAsText(vtnRowIndex, "Sequence", "QE_1::PercentModified", "QE_1::TotalPercentModified",
5693
"QE_2::PercentModified", "QE_2::TotalPercentModified"));
57-
Assert.assertEquals("Incorrect percentages for (R)WQQGNVFSCSVMHEALHNHYTQK(S) sequence", Arrays.asList("(R)WQQGNVFSCSVMHEALHNHYTQK(S)", "22.1%", "22.1%", "24.1%", "24.1%"),
94+
assertEquals("Incorrect percentages for (R)WQQGNVFSCSVMHEALHNHYTQK(S) sequence", Arrays.asList("(R)WQQGNVFSCSVMHEALHNHYTQK(S)", "22.1%", "22.1%", "24.1%", "24.1%"),
5895
reportTable.getRowDataAsText(wqqRowIndex, "Sequence", "QE_1::PercentModified", "QE_1::TotalPercentModified",
5996
"QE_2::PercentModified", "QE_2::TotalPercentModified"));
6097

61-
log("Verifying the cell colors:Green, Yellow and Red");
62-
Assert.assertEquals("Incorrect risk category color for - Green", "rgb(137, 202, 83)",
63-
Locator.xpath("//table/tbody/tr[" + (wqqRowIndex + 1) + "]/td[6]").findElement(reportTable).getCssValue("background-color"));
64-
Assert.assertEquals("Incorrect risk category color for - Yellow", "rgb(254, 255, 63)",
98+
log("Verifying the cell colors: Gray, Green, Yellow and Red");
99+
assertEquals("Incorrect risk category color for QVT/Sample1 - Green", "rgb(246, 246, 246)",
100+
Locator.xpath("//table/tbody/tr[" + (qvtRowIndex + 1) + "]/td[6]").findElement(reportTable).getCssValue("background-color"));
101+
assertEquals("Incorrect risk category color for VTN/Sample1 - Yellow", "rgb(254, 255, 63)",
65102
Locator.xpath("//table/tbody/tr[" + (vtnRowIndex + 1) + "]/td[6]").findElement(reportTable).getCssValue("background-color"));
66-
Assert.assertEquals("Incorrect risk category color for - Red", "rgb(250, 8, 26)",
103+
assertEquals("Incorrect risk category color for VTN/QE_2 - Red", "rgb(250, 8, 26)",
67104
Locator.xpath("//table/tbody/tr[" + (vtnRowIndex + 1) + "]/td[8]").findElement(reportTable).getCssValue("background-color"));
105+
assertEquals("Incorrect risk category color for EEQ/Sample1 - Green", "rgb(246, 246, 246)",
106+
Locator.xpath("//table/tbody/tr[" + (eeqRowIndex + 1) + "]/td[6]").findElement(reportTable).getCssValue("background-color"));
107+
assertEquals("Incorrect risk category color for WQQ/Sample1 - Green", "rgb(137, 202, 83)",
108+
Locator.xpath("//table/tbody/tr[" + (wqqRowIndex + 1) + "]/td[6]").findElement(reportTable).getCssValue("background-color"));
68109
}
69110
}

0 commit comments

Comments
 (0)