eugenegujing commented on code in PR #9041:
URL: https://github.com/apache/texera/pull/9041#discussion_r4609581588
##########
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:
Good catch, the old code did overwrite an input column called `Significance`.
I first tried your suggestion of passing the array to px directly, but it
caused two new problems:
1. px gives the array the name `color`. If the user's effect column or hover
column is also called `color`, px fails with `NameError: A name conflict was
encountered for argument 'color'` (plotly 5.24.1).
2. If the effect column is called `Significance`, the hover box ends up with
two lines of the same name, and px only shows one of them.
So I went with a third way: the categories are saved in a new column with a
name the input table does not use. It starts as `Significance`, and adds `_`
until the name is free. px then colors by that column. This way no input column
is overwritten, and the legend and hover box still say `Significance`. The
exported script is changed the same way.
One small thing remains: if the effect column itself is called
`Significance`, the category is shown as `Significance_`, so the hover box can
show both lines.
--
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]