GeneSuite
Documentation / R packages

Direct genotype-to-score and SumHer workflow

This development workflow connects genotype-derived LD scores to bounded SumHer heritability and genetic-correlation fits. It is not included in the current public source archives. The statistical and release limits below remain part of the interface contract.

Ownership and interfaces

Responsibility Native owner Standalone R interface
Direct BED-to-LD scores gmat: ldscore_sumher_style() gbase: gprep(task = "ldscores")
GWAS glma (existing route) glma (existing route)
Bounded paired SumHer fit gcorr: fit_sumher_ldak_style() gcorr: gcorr(Glist, stat, method = "sumher")
Dense eigensystem gsolve (existing public API) Internal dependency

The root gsuite R integration and existing gcorr_sumher() are unchanged. The new fitter’s regression, jackknife and derived estimates run in C++. R validates labels and shapes and packages native output.

Example: reusable LD cache and paired fit

Run LD once per reference cohort and annotation definition, save it, and reuse it across phenotype cases. Cache provenance must include the genotype selection, annotation, powers, window and correction settings.

library(gbase)
library(gcorr)
# Set the configured BLAS library to one thread before starting R when using
# multiple OpenMP workers (e.g. MKL_NUM_THREADS=1 or OPENBLAS_NUM_THREADS=1).
Glist <- gprep(bedfiles = c("chr1.bed", "chr2.bed"))
ids <- unlist(Glist$rsids, use.names = FALSE)
annotation <- matrix(1, length(ids), 1,
                     dimnames = list(ids, "Base"))
Glist <- gprep(Glist, task = "ldscores", annotation = annotation,
               window_cm = 1, min_r2 = 0, nthreads = 4)
ld <- Glist$ldscore_models
saveRDS(Glist, "cohort_sumher_reference.rds")

# After GWAS: stat1/stat2 contain rsids, chr, pos, ea, nea, n and
# b/seb (or a signed Z column named stat).
statistics <- lapply(list(trait1 = stat1, trait2 = stat2), function(s)
  checkStat(Glist, stat = s))

# Marker sets and row order may differ after QC. gcorr matches them internally.
fit <- gcorr(Glist, statistics, method = "sumher")
fit$h2
fit$h2_se
fit$rg
fit$rg_se
stopifnot(all(fit$diagnostics$converged))
fit$estimates

For multiple bins, supply their marker-by-bin annotation columns in place of the Base column and preserve their order. Do not combine a Base column with an exhaustive set of bins unless the intended model includes that redundant design. For exact parity using a printed LDAK tagging file, use its printed scores, tagging and contribution footer together; direct full-precision scores and footer values can follow different iterative trajectories.

Statistical limits

The default uses the bounded marginal and paired continuous-trait stages, with additive intercepts, estimated pairwise overlap, and no genomic control or regression cutoff. Signed corrected LD scores are allowed. Tagging is floored at one during fitting. Delete blocks are consecutive in supplied marker order; final weights are frozen. Undefined rg and SE values remain undefined, and nonconvergence remains flagged. The default limit permits 101 updates, matching the frozen workflow convention.

The earlier cluster study validated the experimental LD implementation and R fitter. It reported 4318 converged fits out of 4320, with two failed solver stages. Those data are not a full qualification of this new native fitter. Retain both difficult cases when checking the port; do not silently accept their raw estimates or loosen tolerances to manufacture agreement.

Review and release gates

These are development source additions. Source commits do not publish R archives or website snapshots. Native CMake lists include the new implementations, so the source-package builder extracts them from their owners. gbase’s generated build flags now include R’s BLAS and Fortran link libraries.

Focused verification and current local toolchain limitations are recorded in the review record (unpublished development review). Before release, use the complete canonical dependency checkouts and qualified prefix, run the focused native CTest targets and R package tests, then run the saved cluster fitter/LD parity cases. Review package versions, ABI requirements and generated source archives before publishing. This proposal leaves existing release version numbers and native qualification manifest constraints unchanged.

Direct-score arguments

gprep(Glist, task = "ldscores") returns the existing descriptor with ldscore_models containing the score array, tagging, expected heritability and resolved settings. Defaults are a 1 Mb physical window, no marker-distance limit, min_r2 = 0, U/D powers, finite-sample correction and Hardy-Weinberg heritability variance. To reproduce the imported cM workflow, set window_cm = 1; cM and nonzero physical/marker windows cannot be combined. All-zero genetic maps do not represent meaningful cM windows.

min_r2 is the preferred name; r2 remains a compatibility alias and supplying both is an error. Existing sparse-LD defaults remain 1 Mb, 1000 markers and 0.01. The historical msize-only sparse call still sets its cutoff to zero. The direct-score cutoff filters architecture scores; tagging and neighbour counts still include all in-window polymorphic pairs.

write_ld = FALSE does not write pairwise LD. Existing sparse resources on the supplied descriptor are preserved. With physical/marker windows, write_ld = TRUE and out_prefix also construct the existing sparse resource in a separate pass. This writer does not support cM windows; such requests are rejected rather than silently substituting a physical window. The former standalone R score entry point is removed; the native gmat API remains available.

The established Glist$ldscores field remains a per-component list of ordinary uncorrected scores. Direct model arrays and metadata are in Glist$ldscore_models. If an existing sparse resource is retained, its ordinary score fields remain unchanged and the new direct model results are separate.

Ordinary compatibility scores retain a unit self-contribution for monomorphic markers, matching the sparse writer. Their architecture-score and tagging contributions remain zero under the direct SumHer formulas.

One public SumHer entry point

Use gcorr(..., method = "sumher"). The default fitter selects the stored D model when available, or the sole model in a single-model cache. Thus gcorr(Glist, stat, method = "sumher") needs no additional selector arguments for the ordinary U/D cache. Select score_model = "U" to request the Uniform model. Other multiple-model caches require an explicit choice. The previous estimator and illustrative ordinary score baseline remain available with sumher_fitter = "standard". The default returns h2 per trait and, for multiple traits, rg for every pair. The newly introduced focused paired-fit R export is removed. Existing gcorr_sumher() remains available as a compatibility entry point for the standard fitter.

The stored workflow automatically intersects markers shared by all traits and the score reference, restoring reference order for both checked frames and named Z/N matrices. No manual intersection/reordering step is needed. Checked frames must have unique IDs and matching coordinates/alleles on the retained markers. Keep checkStat() for reference allele harmonization and QC. Diagnostics record input and omitted marker counts per trait. Annotation contribution totals use the entire stored reference, including SNPs with no regression statistics; they are not recalculated on the regression subset. The bounded fitter defaults to min(200, retained markers) consecutive delete blocks, absolute tolerance 1e-4 and maximum_iterations 100 (up to 101 updates). Use num_blocks to override the block count; arbitrary labels, standard-fitter inflation controls and genomic control are not accepted by this route.

It returns gcorr_sumher_ldak_fit, with metric-labelled estimates, standard errors, delete estimates, convergence diagnostics, the selected model and score provenance. This is deliberately distinct from gcorr_sumher_fit; the standard fitter’s category/joint-covariance adapters do not automatically apply to the bounded port.

For imported scores and a supplied contribution footer, omit Glist and pass architecture_ld_scores, tagging, and component_contributions through gcorr(statistics, method = "sumher", sumher_fitter = "ldak", ...). These explicit inputs retain the paired fitter’s validation and default count of 200 blocks; set num_blocks for smaller inputs.

Trait summaries

The normal call is fit <- gcorr(Glist, stat, method = "sumher"). Read fit$h2 and fit$h2_se for named trait heritabilities. With multiple traits, fit$rg and fit$rg_se are symmetric trait-labelled matrices. A single-trait fit evaluates only its marginal h2/intercept stage; it does not duplicate the trait or compute an artificial correlation. For three or more traits the workflow fits all unique pairs, deduplicates partner-independent marginal results and retains fit$pairwise. fit$computation records repeated marginal and pair evaluation counts. Pairwise estimates are not a joint likelihood or a positive-semidefinite genetic covariance constraint. Undefined rg/SE and nonconvergence remain explicit. All fits use the same retained marker universe and consecutive block scheme.