kunwp1 commented on code in PR #9041:
URL: https://github.com/apache/texera/pull/9041#discussion_r4569543067
##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDescSpec.scala:
##########
@@ -68,6 +84,335 @@ class VolcanoPlotOpDescSpec extends AnyFlatSpec with
Matchers {
decodeOccurrences should be >= 2
}
+ it should "draw no cut-off line and keep the continuous effect-size coloring
by default" in {
+ val code = configured.generatePythonCode()
+ code should not include "add_hline"
+ code should not include "add_vline"
+ assertContinuousColoring(code)
+ }
+
+ it should "draw a dashed horizontal line at -log10 of the significance
threshold" in {
+ val op = configured
+ op.significanceThreshold = Some(0.05)
+ val code = op.generatePythonCode()
+ code should include(hline)
+ code should not include "add_vline"
+ assertContinuousColoring(code)
+ }
+
+ it should "draw dashed vertical lines at plus and minus the effect-size
threshold" in {
+ val op = configured
+ op.effectSizeThreshold = Some(1.0)
+ val code = op.generatePythonCode()
+ code should include(vlines)
+ code should not include "add_hline"
+ assertContinuousColoring(code)
+ }
Review Comment:
A few of the new tests pin nothing another one doesn't:
- These two single-threshold tests: the fallback test further down already
checks that each threshold alone draws only its own lines with the continuous
coloring, and the toggle-off test checks the lines don't depend on the toggle.
- "hold Doubles" repeats "deserialize numeric strings", which already fails
without `contentAs`.
- The export path's toggle-off and saved-workflow tests: both paths draw the
lines from the same `thresholdLines`, the parity test covers the toggle-off
row, and the engine's saved-workflow test already shows a saved operator
matches a default one (its assertions after the equality check can go too).
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDesc.scala:
##########
@@ -67,13 +69,123 @@ class VolcanoPlotOpDesc extends PythonVisualizationOpDesc
with PlotlyStandaloneC
@NotNull(message = "P-Value Column cannot be empty")
var pvalueColumn: EncodableString = ""
+ // Numeric: both are compared against the data and the first is log10'd.
contentAs
+ // names the boxed class — Option erases its element type, and a blank must
not read as 0.
+ @JsonProperty(required = false)
+ @JsonSchemaTitle("Significance threshold")
+ @JsonPropertyDescription(
+ "P-value cut-off such as 0.05; draws a dashed horizontal line at -log10 of
it"
+ )
+ @JsonSchemaInject(json = """{"exclusiveMinimum": 0, "maximum": 1}""")
+ @JsonDeserialize(contentAs = classOf[java.lang.Double])
+ var significanceThreshold: Option[Double] = None
+
+ @JsonProperty(required = false)
+ @JsonSchemaTitle("Effect-size threshold")
+ @JsonPropertyDescription(
+ "Effect-size cut-off such as 1; draws dashed vertical lines at plus and
minus it"
+ )
+ @JsonSchemaInject(json = """{"exclusiveMinimum": 0}""")
+ @JsonDeserialize(contentAs = classOf[java.lang.Double])
+ var effectSizeThreshold: Option[Double] = None
+
+ @JsonProperty(required = false, defaultValue = "false")
+ @JsonSchemaTitle("Color by significance")
+ @JsonPropertyDescription(
+ "Color points Up, Down or Not significant by both thresholds instead of by
effect size; " +
+ "needs both thresholds, otherwise the effect-size coloring is kept"
+ )
+ var colorBySignificance: Boolean = false
+
override def operatorInfo: OperatorInfo =
OperatorInfo.forVisualization(
userFriendlyName = "Volcano Plot",
operatorDescription = "Displays statistical significance versus effect
size",
operatorGroupName = OperatorGroupConstants.VISUALIZATION_SCIENTIFIC_GROUP
)
+ /** A cut-off is used only when it can be drawn: finite, above zero and, for
the
+ * p-value, at most one. Anything else counts as unset. The schema bounds
keep such
+ * values out of the property panel; this keeps a hand-edited workflow from
failing.
+ */
+ private def isUsable(cutoff: Double): Boolean =
+ !cutoff.isNaN && !cutoff.isInfinite && cutoff > 0
+
+ private def significanceCutoff: Option[Double] =
+ significanceThreshold.filter(sig => isUsable(sig) && sig <= 1)
+
+ private def effectCutoff: Option[Double] =
effectSizeThreshold.filter(isUsable)
+
+ /** Both cut-offs are needed to call a point Up or Down. */
+ private def colorByCategory: Boolean =
+ colorBySignificance && significanceCutoff.isDefined &&
effectCutoff.isDefined
+
+ /** Strict comparisons: a point exactly on a cut-off is not significant. */
+ private def significanceColumn: PythonTemplateBuilder =
+ if (colorByCategory) {
+ val sig = significanceCutoff.get
+ val eff = effectCutoff.get
+ pyb"""significant = table[$pvalueColumn] < $sig
+ | table["Significance"] = np.select(
Review Comment:
Writing the categories into `table["Significance"]` overwrites an input
column of that name before px reads the table. If that column is the selected
effect column, the x axis turns into the Up / Down / Not significant labels (I
checked with plotly 5.24.1). Passing the categories straight to px leaves the
table alone: `significance = np.select(...)`, then `color=significance,
labels={"color": "Significance"}` and `category_orders={"color": [...]}` keep
the same legend title, colors and order. The standalone twin below needs the
same change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]