This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-9040-0e9c48b4a8e2dfb1ac317ae22b7f12f1d1792139 in repository https://gitbox.apache.org/repos/asf/texera.git
commit 713834a553dc2214b597caa5ce6c4b31ec60dd01 Author: Eugene Gu <[email protected]> AuthorDate: Mon Nov 16 02:46:36 2026 +0000 feat(workflow-operator): volcano plot labels follow columns (#9040) ### What changes were proposed in this PR? Root cause: `VolcanoPlotOpDesc.generatePythonCode` hard-codes the y column as the literal `"-log10(pvalue)"` and plots it under that name, so the y axis always says `-log10(pvalue)` even when the selected column is `padj`. The title is the literal `"Volcano Plot"` and the x axis and color bar show the raw effect column name. None of this can be changed from the property panel. ``` Before: P-Value Column = padj -> y column "-log10(pvalue)" -> y axis "-log10(pvalue)" After: P-Value Column = padj -> y column "-log10(padj)" -> y axis "-log10(padj)", or the Y Label the user typed ``` The y column is now named after the selected p-value column, so the axis and the hover text say which column was transformed. Three optional label properties are added, empty by default: | Property | Empty | Set | |---|---|---| | Title | `Volcano Plot` | the text typed | | X Label | effect column name | the text typed | | Y Label | `-log10(<p-value column>)` | the text typed | The color bar has no label of its own: the points are colored by the effect column, the same column that is on the x axis, so the color bar carries the X Label text (or the effect column name when X Label is empty). If a later change lets the color encode a different column, a label for it would come with that change. The labels go through `fig.update_layout(xaxis_title, yaxis_title, coloraxis_colorbar_title_text)`, same as Line Chart's X Label / Y Label. Each label is an `EncodableString`, so quotes and non-ASCII text are fine. A whitespace-only field counts as empty. The hover box still shows raw column names (plotly behaviour, same as Line Chart). Behavior change for saved workflows: a workflow with `padj` as the p-value column now renders `-log10(padj)` instead of `-log10(pvalue)`. That is the fix. Since #8504 merged, the operator also has an export path, `generateStandaloneCode()`, which writes the same figure as a standalone script. It carried the same hard-coded `"-log10(pvalue)"` and `title="Volcano Plot"`, so this PR applies the same change there: the y column is named after the selected p-value column and the three labels go through `fig.update_layout` as escaped Python literals (the export has no decoder, so `pyStringLiteral` escapes quotes and backslashes). The engine template and the exported script now label the figure the same way. Rebase note: `coloraxis_colorbar_title_text` is emitted unconditionally, in both templates. Once the PR for the significance coloring (#9039) lands, the categorical mode has no `coloraxis`, so whichever branch rebases second needs to make that entry conditional. Figures below are the operator's generated Python from `main` and from this branch, run on the 430-gene example workflow from the issue; the third one has the title and both axis labels filled in. | Before | After (defaults) | After (labels set) | |---|---|---| | <img width="1398" height="849" alt="before-main" src="https://github.com/user-attachments/assets/0c0dd5ef-3675-44e2-98f6-236b54bd631b" /> | <img width="1398" height="849" alt="labels-after-default" src="https://github.com/user-attachments/assets/ee8dc430-2142-47ac-947f-59c535c2b308" /> | <img width="1398" height="849" alt="labels-after-custom" src="https://github.com/user-attachments/assets/8299992d-d84d-48fe-9556-e66a8579e859" /> | ### Any related issues, documentation, discussions? Closes #9037 PR #8504 (merged) added the `generateStandaloneCode()` export path with the same hard-coded `"-log10(pvalue)"`; the mirroring described above is the follow-up it needed. ### How was this PR tested? New tests in `VolcanoPlotOpDescSpec`, written before the source change: - y column and axis are named after the selected p-value column; the old literal is gone - every label falls back to its default when empty or whitespace-only - a set label replaces its default and reaches the code only as a decode site (sentinels with quotes, backslash, non-ASCII) - the color bar title follows X Label when it is set and the effect column name otherwise - one set label leaves the other two at their defaults - a workflow JSON saved before this change (only the two column keys) generates byte-for-byte the same code as a default-constructed operator - `generateStandaloneCode`: the y column and axis are named after the p-value column (including a name with a quote, `p"adj`), the labels fall back to the column-derived defaults, a set label is emitted as an escaped literal and the default title is gone, the color bar carries the X Label text, and whitespace-only keeps the default ``` sbt -Dsbt.server.forcestart=true "WorkflowOperator/testOnly *VolcanoPlotOpDescSpec" # Tests: succeeded 15, failed 0, canceled 0, ignored 0, pending 1 (the pending one is pre-existing) sbt -Dsbt.server.forcestart=true "WorkflowOperator/scalafmtAll" "WorkflowOperator/Test/scalafmtAll" sbt -Dsbt.server.forcestart=true "WorkflowOperator/scalafixAll --check" # success ``` Smoke run: the generated code was executed outside Texera (pytexera stubbed, pandas + plotly 5.24.1) on the 430-gene mock table. Defaults give title `Volcano Plot`, x `lfc_shrunk`, y `-log10(padj)`, color bar `lfc_shrunk`; with the labels set the figure shows the typed text; whitespace-only title and y label fall back to the defaults. The exported script for the default and the all-labels configuration parses with `ast.parse`. ### Was this PR authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Code (claude-fable-5-1). Co-authored with Claude; the author reviewed the change before submission. --- .../volcanoPlot/VolcanoPlotOpDesc.scala | 52 +++++++- .../volcanoPlot/VolcanoPlotOpDescSpec.scala | 147 ++++++++++++++++++++- 2 files changed, 191 insertions(+), 8 deletions(-) diff --git a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDesc.scala b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDesc.scala index 8e6d6dc660..c433e198bc 100644 --- a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDesc.scala +++ b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDesc.scala @@ -67,6 +67,23 @@ class VolcanoPlotOpDesc extends PythonVisualizationOpDesc with PlotlyStandaloneC @NotNull(message = "P-Value Column cannot be empty") var pvalueColumn: EncodableString = "" + @JsonProperty(required = false) + @JsonSchemaTitle("Title") + @JsonPropertyDescription("The figure title; leave empty for Volcano Plot") + var title: EncodableString = "" + + @JsonProperty(required = false) + @JsonSchemaTitle("X Label") + @JsonPropertyDescription( + "The label for the x axis and the color bar; leave empty for the effect size column name" + ) + var xLabel: EncodableString = "" + + @JsonProperty(required = false) + @JsonSchemaTitle("Y Label") + @JsonPropertyDescription("The label for the y axis; leave empty for -log10(<p-value column>)") + var yLabel: EncodableString = "" + override def operatorInfo: OperatorInfo = OperatorInfo.forVisualization( userFriendlyName = "Volcano Plot", @@ -74,6 +91,16 @@ class VolcanoPlotOpDesc extends PythonVisualizationOpDesc with PlotlyStandaloneC operatorGroupName = OperatorGroupConstants.VISUALIZATION_SCIENTIFIC_GROUP ) + /** The y column is named after the selected p-value column, so a figure drawn + * from an adjusted column says so instead of always reading "-log10(pvalue)". + */ + private def yColumn: EncodableString = s"-log10($pvalueColumn)" + + // An empty or blank label keeps the text the figure derives from the selected columns. + private def titleText: EncodableString = if (title.trim.nonEmpty) title else "Volcano Plot" + private def xAxisTitle: EncodableString = if (xLabel.trim.nonEmpty) xLabel else effectColumn + private def yAxisTitle: EncodableString = if (yLabel.trim.nonEmpty) yLabel else yColumn + override def generatePythonCode(): String = { pyb""" |from pytexera import * @@ -102,16 +129,21 @@ class VolcanoPlotOpDesc extends PythonVisualizationOpDesc with PlotlyStandaloneC | yield {"html-content": self.render_error("No rows with valid p-values.")} | return | - | table["-log10(pvalue)"] = -np.log10(table[$pvalueColumn]) + | table[$yColumn] = -np.log10(table[$pvalueColumn]) | | fig = px.scatter( | table, | x=$effectColumn, - | y="-log10(pvalue)", + | y=$yColumn, | hover_name=table.columns[0], | color=$effectColumn, | color_continuous_scale="RdBu", - | title="Volcano Plot" + | title=$titleText + | ) + | fig.update_layout( + | xaxis_title=$xAxisTitle, + | yaxis_title=$yAxisTitle, + | coloraxis_colorbar_title_text=$xAxisTitle | ) | | html = plotly.io.to_html(fig, include_plotlyjs='cdn', auto_play=False) @@ -119,9 +151,12 @@ class VolcanoPlotOpDesc extends PythonVisualizationOpDesc with PlotlyStandaloneC |""".encode } + // The exported script draws the same figure as the engine, so it labels it the same + // way; the only difference is that the text is a Python literal rather than decoded. override def generateStandaloneCode(): String = { val pvalueLit = pyStringLiteral(pvalueColumn) val effectLit = pyStringLiteral(effectColumn) + val yLit = pyStringLiteral(yColumn) s"""import numpy as np | |def render_error(msg): @@ -139,15 +174,20 @@ class VolcanoPlotOpDesc extends PythonVisualizationOpDesc with PlotlyStandaloneC | with open(outputHtml, "w", encoding="utf-8") as output: | output.write(render_error("No rows with valid p-values.")) | else: - | table["-log10(pvalue)"] = -np.log10(table[$pvalueLit]) + | table[$yLit] = -np.log10(table[$pvalueLit]) | fig = px.scatter( | table, | x=$effectLit, - | y="-log10(pvalue)", + | y=$yLit, | hover_name=table.columns[0], | color=$effectLit, | color_continuous_scale="RdBu", - | title="Volcano Plot" + | title=${pyStringLiteral(titleText)} + | ) + | fig.update_layout( + | xaxis_title=${pyStringLiteral(xAxisTitle)}, + | yaxis_title=${pyStringLiteral(yAxisTitle)}, + | coloraxis_colorbar_title_text=${pyStringLiteral(xAxisTitle)} | ) | fig.write_json(outputJson) | fig.write_html(outputHtml) diff --git a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDescSpec.scala b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDescSpec.scala index e85ed589ef..79faa0e4ed 100644 --- a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDescSpec.scala +++ b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDescSpec.scala @@ -20,10 +20,15 @@ package org.apache.texera.amber.operator.visualization.volcanoPlot import org.apache.texera.amber.core.tuple.AttributeType +import org.apache.texera.amber.operator.LogicalOp import org.apache.texera.amber.operator.metadata.OperatorGroupConstants +import org.apache.texera.amber.util.JSONUtils.objectMapper import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers +import java.nio.charset.StandardCharsets +import java.util.Base64 + class VolcanoPlotOpDescSpec extends AnyFlatSpec with Matchers { private def configured: VolcanoPlotOpDesc = { @@ -33,6 +38,14 @@ class VolcanoPlotOpDescSpec extends AnyFlatSpec with Matchers { op } + private def b64(s: String): String = + Base64.getEncoder.encodeToString(s.getBytes(StandardCharsets.UTF_8)) + + // Every UI-provided string reaches the generated code as this runtime + // decode expression, never as a literal. + private def decoded(s: String): String = + s"self.decode_python_template('${b64(s)}')" + "VolcanoPlotOpDesc.operatorInfo" should "advertise the user-friendly name and Scientific group" in { val info = (new VolcanoPlotOpDesc).operatorInfo info.userFriendlyName shouldBe "Volcano Plot" @@ -63,12 +76,142 @@ class VolcanoPlotOpDescSpec extends AnyFlatSpec with Matchers { val code = configured.generatePythonCode() code should include("class ProcessTableOperator(UDFTableOperator)") code should include("plotly.express") - code should include("-log10(pvalue)") val decodeOccurrences = "decode_python_template".r.findAllIn(code).length decodeOccurrences should be >= 2 } - it should "currently render code even when required fields are empty (no assert guard)" in { + it should "name the y column and its axis after the selected p-value column" in { + // The y axis used to read "-log10(pvalue)" whatever column was chosen; a + // figure drawn from an adjusted column must say so. + val op = configured + op.pvalueColumn = "padj" + val code = op.generatePythonCode() + code should include(s"table[${decoded("-log10(padj)")}] = -np.log10(") + code should include(s"y=${decoded("-log10(padj)")}") + code should include(s"yaxis_title=${decoded("-log10(padj)")}") + code should not include "-log10(pvalue)" + code should not include b64("-log10(pvalue)") + } + + it should "fall back to the column-derived labels when no label is set" in { + val code = configured.generatePythonCode() + code should include(s"title=${decoded("Volcano Plot")}") + code should include(s"xaxis_title=${decoded("log2fc")}") + code should include(s"yaxis_title=${decoded("-log10(pvalue)")}") + code should include(s"coloraxis_colorbar_title_text=${decoded("log2fc")}") + } + + it should "route every configured label through the decoder instead of the default" in { + // Sentinels with quotes, a backslash and non-ASCII text: as decode sites + // they cannot break the Python source, and the raw text must never + // appear in it. + val op = configured + op.title = "TITLE_SENT \"quoted\" 火山" + op.xLabel = "X_LBL_SENT log₂ fold change" + op.yLabel = "Y_LBL_SENT -log₁₀(BH-adjusted p) \\ back\\slash" + val code = op.generatePythonCode() + code should include(s"title=${decoded(op.title)}") + code should include(s"xaxis_title=${decoded(op.xLabel)}") + code should include(s"yaxis_title=${decoded(op.yLabel)}") + // The color bar follows the x label, since both show the effect column. + code should include(s"coloraxis_colorbar_title_text=${decoded(op.xLabel)}") + Seq(op.title, op.xLabel, op.yLabel).foreach { sentinel => + code should not include sentinel + } + // A set label replaces the default rather than being emitted next to it. + code should not include b64("Volcano Plot") + code should not include s"xaxis_title=${decoded("log2fc")}" + code should not include s"yaxis_title=${decoded("-log10(pvalue)")}" + code should not include s"coloraxis_colorbar_title_text=${decoded("log2fc")}" + // The y column itself keeps the derived name: a label is text on the axis, + // not a column rename. + code should include(s"y=${decoded("-log10(pvalue)")}") + } + + it should "treat a whitespace-only label as empty and keep the default" in { + val op = configured + op.title = " " + op.xLabel = "\t" + op.yLabel = " \n " + op.generatePythonCode() shouldBe configured.generatePythonCode() + } + + it should "treat each label independently so one set label leaves the others at their default" in { + val op = configured + op.yLabel = "Y_ONLY_SENT" + val code = op.generatePythonCode() + code should include(s"yaxis_title=${decoded("Y_ONLY_SENT")}") + code should include(s"title=${decoded("Volcano Plot")}") + code should include(s"xaxis_title=${decoded("log2fc")}") + code should include(s"coloraxis_colorbar_title_text=${decoded("log2fc")}") + } + + it should "render a workflow saved before this change exactly as a default-constructed operator" in { + val saved = objectMapper + .readValue( + """{"operatorType":"VolcanoPlot","effectColumn":"log2fc","pvalueColumn":"pvalue"}""", + classOf[LogicalOp] + ) + .asInstanceOf[VolcanoPlotOpDesc] + saved.generatePythonCode() shouldBe configured.generatePythonCode() + } + + "VolcanoPlotOpDesc.generateStandaloneCode" should "name the y column and its axis after the selected p-value column" in { + val op = configured + op.pvalueColumn = "padj" + val code = op.generateStandaloneCode() + code should include("""table["-log10(padj)"] = -np.log10(table["padj"])""") + code should include("""y="-log10(padj)",""") + code should include("""yaxis_title="-log10(padj)",""") + code should not include "-log10(pvalue)" + // The derived y column is the one literal built from a column name rather than + // taken from a field, so a quote in that name must survive the wrap and the escape. + op.pvalueColumn = "p\"adj" + val quoted = op.generateStandaloneCode() + quoted should include("table[\"-log10(p\\\"adj)\"] = -np.log10(table[\"p\\\"adj\"])") + quoted should include("yaxis_title=\"-log10(p\\\"adj)\",") + } + + it should "fall back to the column-derived labels when no label is set" in { + val code = configured.generateStandaloneCode() + code should include("""title="Volcano Plot"""") + code should include("""xaxis_title="log2fc",""") + code should include("""yaxis_title="-log10(pvalue)",""") + code should include("""coloraxis_colorbar_title_text="log2fc"""") + } + + it should "emit every configured label as an escaped Python literal" in { + // The export has no decoder, so the text itself is in the script: a quote or + // a backslash must come out escaped, or the label would end the literal early. + val op = configured + op.title = "TITLE_SENT \"quoted\" 火山" + op.xLabel = "X_LBL_SENT log₂ fold change" + op.yLabel = "Y_LBL_SENT -log₁₀(BH-adjusted p) \\ back\\slash" + val code = op.generateStandaloneCode() + code should include("title=\"TITLE_SENT \\\"quoted\\\" 火山\"") + code should include("xaxis_title=\"X_LBL_SENT log₂ fold change\",") + code should include("yaxis_title=\"Y_LBL_SENT -log₁₀(BH-adjusted p) \\\\ back\\\\slash\",") + // The color bar follows the x label, since both show the effect column. + code should include("coloraxis_colorbar_title_text=\"X_LBL_SENT log₂ fold change\"") + // A set label replaces the default rather than being emitted next to it. + code should not include """title="Volcano Plot"""" + code should not include """xaxis_title="log2fc"""" + code should not include """yaxis_title="-log10(pvalue)"""" + code should not include """coloraxis_colorbar_title_text="log2fc"""" + // The y column itself keeps the derived name: a label is text on the axis, + // not a column rename. + code should include("""y="-log10(pvalue)",""") + } + + it should "treat a whitespace-only label as empty and keep the default" in { + val op = configured + op.title = " " + op.xLabel = "\t" + op.yLabel = " \n " + op.generateStandaloneCode() shouldBe configured.generateStandaloneCode() + } + + "VolcanoPlotOpDesc.generatePythonCode" should "currently render code even when required fields are empty (no assert guard)" in { // Documents the present behavior: VolcanoPlotOpDesc does not assert on // its required fields inside `generatePythonCode`. An empty // configuration therefore renders syntactically valid Python that
