Computes per-node z-scores from the experiment p-values and the Monte-Carlo mean / standard deviation of the raw subnetwork score at every possible subnetwork size, used to calibrate (normalise) scores.

build_score_context(network, experiment, params)

Arguments

network

A network as returned by build_network().

experiment

A data frame of gene / p-value pairs.

params

A list of run parameters. params$seed must match the Java -seedForRandom value (Java default 1234) for identical calibration.

Value

A list with elements z (named z-score vector), means and stds (numeric vectors indexed by subnetwork size), and nodes.

Details

The Monte-Carlo step is an exact replica of the Java reference's ScoreCalculations.calculateMeanAndStdForMonteCarlo: it shuffles the z-score vector 2000 times with a java.util.Random-equivalent generator and Fisher-Yates shuffle (see get_java_mc_calibration() in score_calculation_utils.cpp). Because Collections.shuffle starts from networkNodeList order, the z-score vector MUST be in Java node order; network$nodes (from build_network()) provides exactly that, so z is built over it directly. With the matching seed this reproduces the Java means/stds to floating-point precision, which is what aligns the calibrated scores and rankings with the Java output.

P-values are clamped to a safe range, the smallest p-value is kept when a gene appears more than once, and network nodes without a p-value are given params$p_for_nonsignificant.