OSCR

Multivariate genetic analysis reveals three distinct pathological dimensions in musculoskeletal disorders.

Code ↔ Paper

11 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 11 matches
  1. [1] § Methods › Multi-trait colocalization ↔ R/hyprcoloc.R, lines 911–958 · score 0.72 · HyPrColoc, posterior probability, causal variants, branch, bound, algorithm
  2. [2] § Methods › Colocalization ↔ R/hyprcoloc.R, lines 911–958 · score 0.71 · posterior probabilities, prior probabilities, genomic region, causal variant, colocalization, signals
  3. [3] § Methods › SMR analysis ↔ R/input_eqtl.r, lines 1–109 · score 0.70 · GTEx v8, sQTL, eQTL, tissue, GWAS, genes
  4. [4] § Methods › Multivariate genetic modeling ↔ R/paLDSC.R, lines 1–62 · score 0.67 · sampling covariance matrix, genetic variance, components, multivariate, latent, Genomic
  5. [5] § Methods › Multivariate genetic modeling ↔ R/commonfactor.R, lines 231–272 · score 0.66 · chi square, sampling covariance matrix, model parameters, CFI, fit, weighted
  6. [6] § Methods › Spatial mapping of cells using gsMAP ↔ src/gsMap/report.py, lines 80–174 · score 0.65 · Cauchy combination, gsMap, gene expression, mapping, LDSC, latent
  7. [7] § Methods › Heritability and genetic correlation ↔ R/input_eqtl.r, lines 314–396 · score 0.64 · binary phenotypes, genetic correlation matrix, sample overlap, prevalence, population, Heritability
  8. [8] § Methods › Heritability and genetic correlation ↔ R/rgmodel.R, lines 1–35 · score 0.62 · liability scale, genetic correlation matrix, LD scores, Heritability, intercept, multivariate
  9. [9] § Results › Three distinct genetic factors were identified in MSK phenotypes ↔ R/paLDSC.R, lines 1–62 · score 0.57 · genetic variance, genetic correlation matrix, genetic covariance, mass, dimensions, multivariate
  10. [10] § Results › Three distinct genetic factors were identified in MSK phenotypes ↔ R/commonfactor.R, lines 314–403 · score 0.54 · model fit, correlation matrix, genetic covariance, AIC, SRMR, CFI
  11. [11] § Methods › Spatial mapping of cells using gsMAP ↔ src/gsMap/run_all_mode.py, lines 177–241 · score 0.52 · Cauchy combination, gsMap, mapping, LDSC, correlation, gene

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

R · 1,451 lines · 66 KB · no license · 2 matches

  1. ##########################################################
  2. ##### Prior #####
  3. ##########################################################
  4. #' prior
  5. #'
  6. #' @param p.1 probability of one trait having a causal variant in the genetic region
  7. #' @param gamma step probability
  8. #' @param k number of traits
  9. #' @export
  10. prior <- function(p.1, gamma, k){
  11. if(k==1){
  12. p.1;
  13. }else{
  14. i=c(2:k);G=(1-gamma^(i-1));p.1*prod(G);
  15. }
  16. }
  17. ##########################################################
  18. ##### SNP scores #####
  19. ##########################################################
  20. #' p.0
  21. #'
  22. #' @param j number of traits
  23. #' @param Q number of SNPs
  24. #' @export
  25. p.0 <- function(j, Q){
  26. (j-1)*Q - j*(j-1)/2 + 1;
  27. }
  28. #' ind.snp.score
  29. #'
  30. #' @param Q the number of traits
  31. #' @param snp.scores vector of per snp contributions to the posterior probability of colocalization
  32. #' @export
  33. ind.snp.score <- function(Q, snp.scores){
  34. loc = vector("numeric", Q-1);
  35. res = vector("numeric", Q);
  36. for(j in 1:Q){
  37. i = 1;
  38. while(i < j){
  39. loc[i] = p.0(i, Q) + j - (i + 1);
  40. i = i+1;
  41. }
  42. if(j<=Q-1){
  43. loc[i : (Q-1)] = (p.0(j, Q)):(p.0(j+1, Q) - 1);
  44. }
  45. res[j] = sum(snp.scores[loc]);
  46. }
  47. return(res)
  48. }
  49. ##########################################################
  50. ##### Reduce dimensions of datasets #####
  51. ##########################################################
  52. #' samp.reduc
  53. #'
  54. #' @param Z matrix of Z-scores
  55. #' @param W ratio matrix of prior standard deviation and observed standard errors
  56. #' @param ld.matrix LD matrix
  57. #' @param trait.cor correlation matrix between traits
  58. #' @param sample.overlap matrix of sample overlap between traits
  59. #' @param trts vector of traits
  60. #' @param window.size size of window for 2CV testing
  61. #' @param sentinel sentinel variant
  62. #' @param Zsq matrix of Z-scores squared
  63. #' @param Wsq matrix of W squared
  64. #' @export
  65. samp.reduc <- function(Z, W, ld.matrix, trait.cor, sample.overlap, trts, window.size = dim(Z)[1], sentinel = 0, Zsq, Wsq){
  66. q = dim(Z)[1];
  67. Z = Z[,trts];
  68. W = W[,trts];
  69. Zsq = Zsq[,trts];
  70. Wsq = Wsq[,trts];
  71. trait.cor = trait.cor[trts,trts];
  72. sample.overlap = sample.overlap[trts,trts];
  73. if(window.size < q){
  74. if(sentinel == 0){
  75. max.Z = which(abs(Z) == max(abs(Z)));
  76. if(length(max.Z)>1){max.Z = sample(max.Z,1)};
  77. row.Z = max.Z%%dim(Z)[1];
  78. if(row.Z == 0){row.Z = dim(Z)[1]};
  79. }else{ row.Z = sentinel;}
  80. Q = window.size;
  81. if(Q%%2 == 1){Q = Q-1;}
  82. if(max(row.Z - Q/2,1) == 1){
  83. row.col = 1:(Q+1);
  84. Z = Z[row.col,];
  85. W = W[row.col,];
  86. Zsq = Zsq[row.col,];
  87. Wsq = Wsq[row.col,];
  88. ld.matrix = ld.matrix[row.col,row.col];
  89. }else if(min(row.Z + Q/2,q)==q){
  90. row.col = (q - Q):q;
  91. Z = Z[row.col,];
  92. W = W[row.col,];
  93. Zsq = Zsq[row.col,];
  94. Wsq = Wsq[row.col,];
  95. ld.matrix = ld.matrix[row.col,row.col];
  96. }else{
  97. row.col = (row.Z-Q/2):(row.Z+Q/2);
  98. Z = Z[row.col,];
  99. W = W[row.col,];
  100. Zsq = Zsq[row.col,];
  101. Wsq = Wsq[row.col,];
  102. ld.matrix = ld.matrix[row.col,row.col];
  103. }
  104. }else{row.col = 1:q}
  105. return(list(Z, W, ld.matrix, trait.cor, sample.overlap, row.col, Zsq, Wsq))
  106. }
  107. #' colMax
  108. #'
  109. #' @param x data.frame or matrix
  110. #' @export
  111. colMax <- function(x){
  112. apply(x, MARGIN = c(2), max)
  113. }
  114. ################################################################################
  115. ##### Compute credible sets of snps for each clusetr of colocalized traits #####
  116. ################################################################################
  117. #' cred.sets
  118. #'
  119. #' @param res list of results from hyprcoloc when setting "snpscores = TRUE"
  120. #' @param value the sum of the probabilities of the snps included in the credible set
  121. #' @export
  122. cred.sets = function(res, value = 0.95){
  123. clusters = which(! is.na(res[[1]]$traits));
  124. results = vector('list', length(clusters));
  125. if(length(clusters)>0){
  126. count = 1;
  127. for(i in clusters){
  128. snp.scores = res[[2]][[i]];
  129. snp.scores = snp.scores[order(-snp.scores)];
  130. tmp.rmv = which(snp.scores < (1- value)/length(snp.scores));
  131. tmp.lgt = length(snp.scores) - length(tmp.rmv);
  132. snp.scores = snp.scores[- tmp.rmv];
  133. if(tmp.lgt >1){
  134. row.col = combn(tmp.lgt,2)
  135. row = c(1:tmp.lgt, row.col[1,]);
  136. col = c(1:tmp.lgt, row.col[2,]);
  137. snp.cols = sparseMatrix(i = row, j = col, x = 1, dims = c(tmp.lgt,tmp.lgt));
  138. wch.snps = snp.cols[,min(which(colSums(snp.scores*snp.cols) >= value))]==1;
  139. results[[count]] = snp.scores[wch.snps];
  140. }else{ results[[count]] = snp.scores[tmp.lgt];}
  141. count = count + 1;
  142. }
  143. }
  144. return(results)
  145. }
  146. ###########################################################################################################################################
  147. ##### Perform a sensitivity analysis by varying the algorithm (regional and alignment) thresholds and coloclaization prior (prior.c) #####
  148. ###########################################################################################################################################
  149. #' sensitivity.plot
  150. #'
  151. #' sensitivity.plot is a function which repeatedly calls the hyprcoloc function to compute a similarity matrix which illustrates how strongly clustered/colocalized pairs of traits are across different input thresholds and priors
  152. #' @param effect.est matrix of snp regression coefficients (i.e. regression beta values) in the genomic region
  153. #' @param effect.se matrix of standard errors associated with the beta values
  154. #' @param binary.outcomes a binary vector of dimension the number of traits: 1 represents a binary trait 0 otherwise
  155. #' @param trait.subset vector of trait names (or number) from the full trait list: used for trageted colocalization analysis in a region
  156. #' @param trait.names vector of trait names corresponding to the columns in the effect.est matrix
  157. #' @param snp.id vector of SNP IDs
  158. #' @param ld.matrix LD matrix
  159. #' @param trait.cor matrix of pairwise correlations between traits
  160. #' @param sample.overlap matrix of pairwise sample overlap between traits
  161. #' @param bb.alg branch and bound algorithm: TRUE, employ BB algorithm; FALSE, do not
  162. #' @param bb.selection branch and bound algorithm type, e.g. regional or alignment selection
  163. #' @param reg.steps regional step paramter
  164. #' @param reg.thresh a vector of regional probability thresholds
  165. #' @param align.thresh a vector of alignment probability thresholds
  166. #' @param prior.1 prior probability of a SNP being associated with one trait
  167. #' @param prior.c vector of conditional colocalization priors: where prior.c is the probability of a SNP being associated with an additional trait given that the SNP is associated with at least 1 other trait
  168. #' @param prior.12 COLOC prior p12: prior probability of a SNP being associated with any two traits
  169. #' @param uniform.priors uniform priors
  170. #' @param ind.traits are the traits independent or to be treated as independent
  171. #' @param equal.thresholds fix the regional and alignment thresholds to be equal
  172. #' @param similarity.matrix To be viewed as a similarity matrix. Default FALSE.
  173. #' @import pheatmap RColorBrewer
  174. #' @export
  175. sensitivity.plot = function(effect.est, effect.se, binary.outcomes = rep(0, dim(effect.est)[2]),
  176. trait.subset = c(1:dim(effect.est)[2]), trait.names = c(1:dim(effect.est)[2]),
  177. snp.id = c(1:dim(effect.est)[1]), ld.matrix = diag(1, dim(effect.est)[1], dim(effect.est)[1]),
  178. trait.cor = diag(1, dim(effect.est)[2], dim(effect.est)[2]),
  179. sample.overlap = matrix(rep(1,dim(effect.est)[2]^2), nrow = dim(effect.est)[2]),
  180. bb.alg = TRUE, bb.selection = "regional",
  181. reg.steps = 1, reg.thresh = c(0.6,0.7,0.8,0.9), align.thresh = c(0.6,0.7,0.8,0.9),
  182. prior.1 = 1e-4, prior.c = c(0.02, 0.01, 0.005), prior.12 = NULL,
  183. uniform.priors = FALSE,
  184. ind.traits = TRUE, equal.thresholds = FALSE, similarity.matrix = FALSE){
  185. m = dim(effect.est)[2];
  186. snp.combin = function(x, y, vec){I = iterpc(x, y, labels = vec);return(getall(I)+0.0)};
  187. sim.mat = diag(0,m);
  188. if(!is.null(prior.12)){
  189. prior.c = prior.12/(prior.1 + prior.12);
  190. }
  191. for(i in reg.thresh){
  192. for(k in prior.c){
  193. if(equal.thresholds){
  194. j = i;
  195. tmp.mat = diag(1,m);
  196. res = hyprcoloc(effect.est, effect.se, binary.outcomes = binary.outcomes, trait.subset = trait.subset, trait.names = trait.names,
  197. snp.id = snp.id, ld.matrix = ld.matrix, trait.cor = trait.cor, sample.overlap = sample.overlap, bb.alg = bb.alg, bb.selection = bb.selection,
  198. reg.steps = reg.steps, reg.thresh = i, align.thresh = j,
  199. prior.1 = prior.1, prior.c = k, uniform.priors = uniform.priors, ind.traits = ind.traits);
  200. trt.clusts = res[[1]]$traits;
  201. for(its in 1:length(trt.clusts)){
  202. tmp.clust = unlist(strsplit(trt.clusts[its], split=", "));
  203. if(tmp.clust[1]!="None"){
  204. tmp.vec = which(trait.names %in% tmp.clust);
  205. # coloc.pairs = t(snp.combin(m, 2, tmp.vec));
  206. coloc.pairs = t(snp.combin(length(tmp.vec), 2, tmp.vec));
  207. tmp.mat[t(coloc.pairs)] = 1;
  208. }
  209. }
  210. sim.mat = sim.mat + tmp.mat + t(tmp.mat) - diag(1,m);
  211. }else{
  212. for(j in align.thresh){
  213. tmp.mat = diag(1,m);
  214. res = hyprcoloc(effect.est, effect.se, binary.outcomes = binary.outcomes, trait.subset = trait.subset, trait.names = trait.names,
  215. snp.id = snp.id, ld.matrix = ld.matrix, trait.cor = trait.cor, sample.overlap = sample.overlap, bb.alg = bb.alg, bb.selection = bb.selection,
  216. reg.steps = reg.steps, reg.thresh = i, align.thresh = j,
  217. prior.1 = prior.1, prior.c = k, uniform.priors = uniform.priors, ind.traits = ind.traits);
  218. trt.clusts = res[[1]]$traits;
  219. for(its in 1:length(trt.clusts)){
  220. tmp.clust = unlist(strsplit(trt.clusts[its], split=", "));
  221. if(tmp.clust[1]!="None"){
  222. tmp.vec = which(trait.names %in% tmp.clust);
  223. # coloc.pairs = t(snp.combin(m, 2, tmp.vec));
  224. coloc.pairs = t(snp.combin(length(tmp.vec), 2, tmp.vec));
  225. tmp.mat[t(coloc.pairs)] = 1;
  226. }
  227. }
  228. sim.mat = sim.mat + tmp.mat + t(tmp.mat) - diag(1,m);
  229. }
  230. }
  231. }
  232. }
  233. sim.mat = sim.mat/length(reg.thresh)/length(align.thresh)/length(prior.c);
  234. if(equal.thresholds){
  235. sim.mat = sim.mat*length(align.thresh);
  236. }
  237. rownames(sim.mat) = trait.names;
  238. colnames(sim.mat) = trait.names;
  239. # annotation_row = data.frame(
  240. # Clusters = factor(dta$cluster.class[match(rownames(smat), obs.names)])
  241. # )
  242. # rownames(annotation_row) <- rownames(smat)
  243. breaksList = seq(0,1,by=0.02);
  244. plot = pheatmap(
  245. mat = sim.mat,
  246. color = colorRampPalette((brewer.pal(n = 9, name = "Blues")))(length(breaksList)),
  247. breaks = breaksList,
  248. cluster_cols = FALSE,
  249. cluster_rows = FALSE,
  250. border_color = NA,
  251. show_colnames = TRUE,
  252. show_rownames = TRUE,
  253. #annotation_col = annotation_row,
  254. drop_levels = TRUE,
  255. fontsize = 6,
  256. main = "Prior sensitivity heatmap"
  257. )
  258. if(!similarity.matrix){
  259. return(plot)}else{
  260. return(list(plot, sim.mat))
  261. }
  262. }
  263. ##########################################################
  264. ##### Regional colocalisation (rapid) #####
  265. ##########################################################
  266. #' rapid.reg
  267. #'
  268. #' @param Zsq matrix of Z-scores
  269. #' @param Wsq ratio matrix of prior standard deviation and observed standard errors squared
  270. #' @param prior.1 prior probability of a SNP being associated with one trait
  271. #' @param prior.2 1 - prior probability of a SNP being associated with an additional trait given that the SNP is associated with at least 1 other trait
  272. #' @param uniform.priors uniform priors
  273. #' @export
  274. rapid.reg <- function(Zsq, Wsq, prior.1, prior.2, uniform.priors){
  275. m = dim(Zsq)[2];
  276. Q = dim(Zsq)[1];
  277. if(uniform.priors==T){
  278. I.unif = 1;
  279. }else{
  280. I.unif = 0;
  281. }
  282. p.1 = prior.1;
  283. p.1.m = p.1/Q;
  284. prior.all = I.unif*p.1.m + (1-I.unif)*prior(prior.1, prior.2, k = m);
  285. prior.sub = I.unif*p.1.m + (1-I.unif)*prior(prior.1, prior.2, k = m-1);
  286. labf = 0.5*(log(Wsq) + (Zsq)*(1- Wsq));
  287. sum.labf = rowSums(labf);
  288. mx.labf = which.max(labf);
  289. clc.max = which.max(sum.labf);
  290. chi = sum.labf - sum.labf[clc.max];
  291. exp.chi = exp(chi);
  292. sum.exp.chi = sum(exp.chi);
  293. sum.labf.subset = colSums(exp(chi - labf));
  294. rm.trt = which.max(sum.labf.subset);
  295. reg.prob = sum.exp.chi/(exp(-sum.labf[clc.max] - log(prior.all)) + sum.exp.chi + (prior.sub/prior.all)*sum(sum.labf.subset));
  296. return(list(reg.prob, clc.max, rm.trt, exp.chi/sum.exp.chi))
  297. }
  298. ##########################################################
  299. ##### Regional colocalisation #####
  300. ##########################################################
  301. #' regional.ABF
  302. #'
  303. #' @param Z matrix of Z-scores
  304. #' @param W ratio matrix of prior standard deviation and observed standard errors
  305. #' @param snps.clc SNPs colocalisation
  306. #' @param rho LD matrix
  307. #' @param trait.cor correlation matrix between traits
  308. #' @param sample.overlap matrix of sample overlap between traits
  309. #' @param epsilon tolerance parameter
  310. #' @param reg.thresh regional probability threshold
  311. #' @param prior.1 prior probability of a SNP being associated with one trait
  312. #' @param prior.2 1 - prior probability of a SNP being associated with an additional trait given that the SNP is associated with at least 1 other trait
  313. #' @param prior.3 prior probability that a trait contains a second causal variant given it contains one already
  314. #' @param prior.4 1 - prior probability that trait two co-localises with trait one given traits one and two already share a causal variant and trait one contains a second causal variant
  315. #' @param flag flag variable
  316. #' @param test.2 test for 2CV
  317. #' @param reg.steps regional step paramter
  318. #' @param cor.adj.priors correlation adjusted priors
  319. #' @param uniform.priors uniform priors
  320. #' @param branch.jump branch jump
  321. #' @param Zsq matrix of Z-scores squared
  322. #' @param Wsq matrix of W squared
  323. #' @param ind.traits are the traits independent or to be treated as independent
  324. #' @export
  325. regional.ABF <- function(Z, W, snps.clc, rho, trait.cor, sample.overlap, epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, test.2, reg.steps, cor.adj.priors, uniform.priors, branch.jump, Zsq, Wsq, ind.traits){
  326. m = dim(Z)[2];
  327. Q = dim(Z)[1];
  328. trait.cor =trait.cor*sample.overlap;
  329. if(reg.steps>m){reg.steps = m;}
  330. if(uniform.priors == T){
  331. I.unif = 1;
  332. }else{
  333. I.unif = 0;
  334. }
  335. p.1 = prior.1;
  336. p.1.m = p.1/Q;
  337. p.2.m = p.1*2/(Q*(Q-1));
  338. if(cor.adj.priors==T){
  339. ave.cor = trait.cor[lower.tri(trait.cor)];
  340. ave.cor = mean(abs(ave.cor));
  341. prior.2 = min(prior.2, 1-ave.cor^2);
  342. prior.4 = min(prior.4, 1-ave.cor^4);
  343. }
  344. if(branch.jump == T & reg.steps > 2){
  345. jmp = 1;
  346. }else{
  347. jmp = 0;
  348. }
  349. ones=matrix(1,nrow=dim(snps.clc)[1],ncol=dim(snps.clc)[1]);
  350. trait.cor = as.matrix(kronecker(trait.cor, ones));
  351. log.sum.max.ABF.1 = sum.max.ABF.1 = log.sum.max.ABF.2 = sum.max.ABF.2 = mpfr(0,120);
  352. log.sum.ABF.1 = sum.ABF.1 = sum.ABF.all.1 = log.sum.ABF.2 = sum.ABF.2 = sum.ABF.all.2 = mpfr(0,120);
  353. log.all.traits.ABF.1 = log.all.traits.ABF.2 = mpfr(0,120);
  354. log.max.ABF.1 = log.max.ABF.2 = mpfr(0,120)
  355. mx.ABF.k = mpfr(0,120);
  356. NAs = 0;
  357. if(test.2 ==0){
  358. df = data.frame(matrix(vector(), 0,10, dimnames=list(c(), c("log.sum.ABF.full", "log.sum.ABF.all.combs", "log.max.sum.ABF.all.traits", "log.max.SNP.ABF.full", "Post.ratio.2.vs.1and2", "Traits", "SNPs", "NaNs", "reg_bb_alg" , "reg_only_trts" ))), stringsAsFactors=F);
  359. df[1,]$reg_bb_alg = FALSE;
  360. reg.prob = 1;
  361. i = m;
  362. count = 0;
  363. while(reg.prob > (1-jmp)*reg.thresh & i > 0){
  364. clc.trt=combn(m,i);
  365. count = count + dim(clc.trt)[2];
  366. prior1 = I.unif*p.1.m + (1-I.unif)*prior(prior.1,prior.2, k = i);
  367. prior2 = I.unif*p.2.m + (1-I.unif)*prior(prior.1,prior.2, k = i)*prior(prior.3, prior.4, k = i);
  368. for(j in 1:dim(clc.trt)[2]){
  369. trt.clc = clc.trt[,j] + 0.0;
  370. if(flag==0){
  371. if(ind.traits == T){
  372. output = regional1ind(Zsq, Wsq, trt.clc);
  373. }else{
  374. output = regional1(Z, W, trt.clc, trait.cor, epsilon);
  375. }
  376. if(i == m){
  377. max.ABF.1 = prior1*exp(mpfr(output[[1]][1], 120));
  378. sum.ABF.1 = max.ABF.1*output[[1]][2];
  379. clc.max.cvs.1 = output[[1]][3];
  380. }else{
  381. max.ABF.1 = prior1*exp(mpfr(output[[1]][1], 120));
  382. sum.ABF.1 = max.ABF.1*output[[2]][1];
  383. clc.max.cvs.1 = output[[3]][1];
  384. if(mx.ABF.k < sum.ABF.1){
  385. mx.ABF.k = sum.ABF.1;
  386. df[1,]$reg_only_trts = toString(clc.trt[,j]);
  387. }
  388. }
  389. if(!is.na(sum.ABF.1)){
  390. sum.ABF.all.1 = sum.ABF.all.1 + sum.ABF.1;
  391. if(sum.max.ABF.1<sum.ABF.1){
  392. sum.max.ABF.1 = sum.ABF.1;
  393. df[1,]$Traits = toString(clc.trt[,j]);
  394. df[1,]$SNPs = toString(clc.max.cvs.1)
  395. }
  396. }else{NAs = NAs + 1;}
  397. }else{
  398. output = regional2(Z, W, snps.clc, trt.clc, rho, trait.cor, epsilon);
  399. max.ABF.1 = prior1*exp(mpfr(output[[1]][1], 120));
  400. sum.ABF.1 = max.ABF.1*output[[1]][2];
  401. clc.max.cvs.1 = output[[1]][3];
  402. if(!is.na(sum.ABF.1)){
  403. sum.ABF.all.1 = sum.ABF.all.1 + sum.ABF.1;
  404. if(sum.max.ABF.1<sum.ABF.1){
  405. sum.max.ABF.1 = sum.ABF.1;
  406. df[1,]$Traits = toString(clc.trt[,j]);
  407. df[1,]$SNPs = toString(clc.max.cvs.1)
  408. }
  409. }else{NAs = NAs + 1;}
  410. max.ABF.2 = prior2*exp(mpfr(output[[2]][1], 120));
  411. sum.ABF.2 = max.ABF.2*output[[2]][2];
  412. clc.max.cvs.2 = snps.clc[,output[[2]][3]];
  413. if(!is.na(sum.ABF.2)){
  414. sum.ABF.all.2 = sum.ABF.all.2 + sum.ABF.2;
  415. if(sum.max.ABF.2<sum.ABF.2){
  416. sum.max.ABF.2 = sum.ABF.2;
  417. df[2,]$Traits = toString(clc.trt[,j]);
  418. df[2,]$SNPs = toString(clc.max.cvs.2)
  419. }
  420. }else{NAs = NAs + 1;}
  421. }
  422. }
  423. if(i==m){
  424. log.max.ABF.1 = log(max.ABF.1)
  425. sum.ABF.full.1 = sum.ABF.all.1;
  426. log.sum.ABF.1=asNumeric(log(sum.ABF.1));
  427. df[1,]$log.sum.ABF.full=log.sum.ABF.1;
  428. df[1,]$log.max.SNP.ABF.full=asNumeric(log.max.ABF.1);
  429. snp.scores.1 = output[[2]];
  430. if(flag==1){
  431. log.max.ABF.2 = log(max.ABF.2);
  432. sum.ABF.full.2 = sum.ABF.all.2;
  433. log.sum.ABF.2=asNumeric(log(sum.ABF.2));
  434. df[2,]$log.sum.ABF.full=log.sum.ABF.2;
  435. df[2,]$log.max.SNP.ABF.full=asNumeric(log.max.ABF.2);
  436. snp.scores.1 = output[[3]];
  437. snp.scores.2.tmp = output[[4]];
  438. snp.scores.2 = ind.snp.score(Q, snp.scores.2.tmp);
  439. }
  440. }
  441. if(flag==0){
  442. reg.prob = sum.ABF.full.1/(sum.ABF.all.1);
  443. }else{
  444. reg.prob = (sum.ABF.full.1+sum.ABF.full.2)/(sum.ABF.all.1+sum.ABF.all.2);
  445. }
  446. i = i - 1;
  447. if(reg.steps!=0 & i == (m-reg.steps-1)){i=0;}
  448. }
  449. if(jmp == 1 | sum.ABF.full.1/mx.ABF.k >= (1/min(9,m))*count){df[1,]$reg_bb_alg = TRUE;}
  450. log.sum.max.ABF.1=asNumeric(log(sum.max.ABF.1));
  451. log.all.traits.ABF.1=asNumeric(log(sum.ABF.all.1));
  452. df[1,]$log.sum.ABF.all.combs=log.all.traits.ABF.1;
  453. df[1,]$log.max.sum.ABF.all.traits=log.sum.max.ABF.1;
  454. df[1,]$NaNs=NAs;
  455. out.list = list(df, snp.scores.1);
  456. if(flag==1){
  457. log.sum.max.ABF.2=asNumeric(log(sum.max.ABF.2));
  458. log.all.traits.ABF.2=asNumeric(log(sum.ABF.all.2));
  459. df[2,]$log.sum.ABF.all.combs=log.all.traits.ABF.2;
  460. df[2,]$log.max.sum.ABF.all.traits=log.sum.max.ABF.2;
  461. df[2,]$NaNs=NAs;
  462. df[2,]$Post.ratio.2.vs.1and2 = asNumeric(sum.ABF.all.2/(sum.ABF.all.1 + sum.ABF.all.2));
  463. out.list = list(df, snp.scores.1, snp.scores.2);
  464. }
  465. }else{
  466. prior1 = I.unif*p.1.m + (1-I.unif)*prior(prior.1,prior.2, k = m);
  467. prior2 = I.unif*p.2.m + (1-I.unif)*prior(prior.1,prior.2, k = m)*prior(prior.3, prior.4, k = m);
  468. output = regional2(Z, W, snps.clc, c(1:m)+0.0, rho, trait.cor, epsilon);
  469. max.ABF.1 = prior1*exp(mpfr(output[[1]][1], 120));
  470. sum.ABF.1 = max.ABF.1*output[[1]][2];
  471. max.ABF.2 = prior2*exp(mpfr(output[[2]][1], 120));
  472. sum.ABF.2 = max.ABF.2*output[[2]][2];
  473. out.list = list(sum.ABF.2/(sum.ABF.2 + sum.ABF.1));
  474. }
  475. return(out.list)
  476. }
  477. ##########################################################
  478. ##### Alignment (rapid) #####
  479. ##########################################################
  480. #' rapid.align
  481. #'
  482. #' @param Zsq matrix of Z-scores
  483. #' @param Wsq ratio matrix of prior standard deviation and observed standard errors squared
  484. #' @param prior.1 prior probability of a SNP being associated with one trait
  485. #' @param prior.2 1 - prior probability of a SNP being associated with an additional trait given that the SNP is associated with at least 1 other trait
  486. #' @param uniform.priors uniform priors
  487. #' @export
  488. rapid.align <- function(Zsq, Wsq, prior.1, prior.2, uniform.priors){
  489. m = dim(Zsq)[2];
  490. Q = dim(Zsq)[1];
  491. if(uniform.priors==T){
  492. I.unif = 1;
  493. }else{
  494. I.unif = 0;
  495. }
  496. p.1 = prior.1;
  497. p.1.m = p.1/Q;
  498. p.m.1 = p.1/(m*Q*(Q-1));
  499. if(m==2){
  500. p.m.1 = 2*p.m.1;
  501. cnst = 0.25;
  502. }else{
  503. cnst = 1
  504. }
  505. prior.all = I.unif*p.1.m + (1-I.unif)*prior(prior.1, prior.2, k = m);
  506. prior.align= I.unif*p.m.1 + (1-I.unif)*prior.1*prior(prior.1, prior.2, k = m-1);
  507. labf = 0.5*(log(Wsq) + (Zsq)*(1- Wsq));
  508. sum.labf = rowSums(labf);
  509. mx.labf = which.max(labf);
  510. clc.max = which.max(sum.labf);
  511. chi = sum.labf - sum.labf[clc.max];
  512. sum.exp.chi = sum(exp(chi));
  513. col.max.labf = colMax(labf);
  514. exp.labf.std = exp(t(t(labf) - col.max.labf));
  515. labf.tmp = t(colSums(exp.labf.std) - t(exp.labf.std));
  516. sum.tmp = colSums(exp(t(t(chi - labf)+col.max.labf))*labf.tmp);
  517. rm.trt = which.max(sum.tmp);
  518. align.prob = sum.exp.chi/(sum.exp.chi + cnst*(prior.align/prior.all)*sum(sum.tmp));
  519. return(list(align.prob, rm.trt))
  520. }
  521. ##########################################################
  522. ##### Alignment #####
  523. ##########################################################
  524. #' align.ABF.1
  525. #'
  526. #' @param Z matrix of Z-scores
  527. #' @param W ratio matrix of prior standard deviation and observed standard errors
  528. #' @param trait.cor correlation matrix between traits
  529. #' @param sample.overlap matrix of sample overlap between traits
  530. #' @param ld.matrix LD matrix
  531. #' @param epsilon tolerance parameter
  532. #' @param reg.res regional result
  533. #' @param align.thresh alignment probability threshold
  534. #' @param prior.1 prior probability of a SNP being associated with one trait
  535. #' @param prior.2 1 - prior probability of a SNP being associated with an additional trait given that the SNP is associated with at least 1 other trait
  536. #' @param cor.adj.priors correlation adjusted priors
  537. #' @param uniform.priors uniform priors
  538. #' @param Zsq matrix of Z-scores squared
  539. #' @param Wsq matrix of W squared
  540. #' @param ind.traits are the traits independent or to be treated as independent
  541. #' @export
  542. align.ABF.1 <- function(Z, W, trait.cor, sample.overlap, ld.matrix, epsilon, reg.res, align.thresh, prior.1, prior.2, cor.adj.priors, uniform.priors, Zsq, Wsq, ind.traits){
  543. m = dim(Z)[2];
  544. Q = dim(Z)[1];
  545. traits = c(1:m);
  546. trait.cor =trait.cor*sample.overlap;
  547. if(uniform.priors == T){
  548. I.unif = 1;
  549. }else{
  550. I.unif = 0;
  551. }
  552. p.1 = prior.1;
  553. p.m.1 = p.1/(m*Q*(Q-1));
  554. if(m==2){
  555. p.m.1 = 2*p.m.1;
  556. }
  557. prior.3 = prior.1;
  558. kappa = 2;
  559. if(cor.adj.priors==T){
  560. ave.cor = trait.cor[lower.tri(trait.cor)];
  561. ave.cor = mean(abs(ave.cor));
  562. prior.2 = min(prior.2, 1-ave.cor^2);
  563. prior.3 = prior.1*(10^(-kappa*ave.cor^2));
  564. p.m.1 = p.m.1*(1-ave.cor)^kappa;
  565. }
  566. max.ABF.overall = sum.max.ABF.co = mpfr(0,120);
  567. log.sum.ABF.all.combs = sum.ABF = sum.ABF.co = mpfr(0,120);
  568. NaNs = 0;
  569. df = data.frame(matrix(vector(), 0,3, dimnames=list(c(), c("log.sum.ABF.all.combs", "Trait.no.clc", "NaNs"))), stringsAsFactors=F)
  570. j = 1;
  571. align.prob = 1;
  572. trt.combn = sample(c(1:m));
  573. prior.algn= I.unif*p.m.1 + (1-I.unif)*prior.3*prior(prior.1, prior.2, k = m-1);
  574. if(m>2){
  575. while(j <=m){
  576. trt.no.clc = trt.combn[j] + 0.0;
  577. trt.clc = traits[-trt.no.clc] + 0.0;
  578. if(ind.traits==T){
  579. output = align1ind(Zsq, Wsq, trt.clc, trt.no.clc);
  580. }else{
  581. output = align1(Z, W, 1, trt.clc, trt.no.clc, trait.cor, ld.matrix, epsilon);
  582. }
  583. max.ABF = prior.algn*exp(mpfr(output[[1]][1], 120));
  584. sum.ABF.tmp = max.ABF*output[[2]][1];
  585. if(!is.nan(sum.ABF.tmp)){
  586. sum.ABF= sum.ABF + sum.ABF.tmp;
  587. if(max.ABF.overall<sum.ABF.tmp){
  588. max.ABF.overall = sum.ABF.tmp;
  589. df[1,]$Trait.no.clc = toString(trt.no.clc);
  590. }
  591. }else{NaNs = NaNs + 1}
  592. align.prob = (reg.res)/(reg.res + sum.ABF);
  593. j = j+1;
  594. }
  595. }else{
  596. trt.no.clc = 1.0;
  597. trt.clc = traits[-trt.no.clc] + 0.0;
  598. if(ind.traits == TRUE){
  599. output = align1ind(Zsq, Wsq, trt.clc, trt.no.clc);
  600. }else{
  601. output = align1(Z, W, 1, trt.clc, trt.no.clc, trait.cor, ld.matrix, epsilon);
  602. }
  603. max.ABF = prior.algn*exp(mpfr(output[[1]][1], 120));
  604. sum.ABF.tmp = max.ABF*output[[2]][1];
  605. if(!is.nan(sum.ABF.tmp)){
  606. sum.ABF= (sum.ABF + sum.ABF.tmp)/2;
  607. df[1,]$Trait.no.clc = toString(trt.no.clc);
  608. }else{NaNs = NaNs + 1}
  609. }
  610. log.sum.ABF.all.combs=asNumeric(log(sum.ABF));
  611. df[1,]$log.sum.ABF.all.combs=log.sum.ABF.all.combs;
  612. df[1,]$NaNs = NaNs;
  613. return(df)
  614. }
  615. ##########################################################
  616. ##### Alignment 1CV and 2CV #####
  617. ##########################################################
  618. #' align.ABF.2
  619. #'
  620. #' @param Z matrix of Z-scores
  621. #' @param W ratio matrix of prior standard deviation and observed standard errors
  622. #' @param snps.clc SNPs colocalisation
  623. #' @param trait.cor correlation matrix between traits
  624. #' @param sample.overlap matrix of sample overlap between traits
  625. #' @param ld.matrix LD matrix
  626. #' @param epsilon tolerance parameter
  627. #' @param reg.res regional result
  628. #' @param align.thresh alignment probability threshold
  629. #' @param prior.1 prior probability of a SNP being associated with one trait
  630. #' @param prior.2 1 - prior probability of a SNP being associated with an additional trait given that the SNP is associated with at least 1 other trait
  631. #' @param prior.3 prior probability that a trait contains a second causal variant given it contains one already
  632. #' @param prior.4 1 - prior probability that trait two co-localises with trait one given traits one and two already share a causal variant and trait one contains a second causal variant
  633. #' @param cor.adj.priors correlation adjusted priors
  634. #' @param uniform.priors uniform priors
  635. #' @export
  636. align.ABF.2 <- function(Z, W, snps.clc, trait.cor, sample.overlap, ld.matrix, epsilon, reg.res, align.thresh, prior.1, prior.2, prior.3, prior.4, cor.adj.priors, uniform.priors){
  637. m = dim(Z)[2];
  638. Q = dim(Z)[1];
  639. traits = c(1:m);
  640. n.cv = dim(snps.clc)[1];
  641. trait.cor =trait.cor*sample.overlap;
  642. if(uniform.priors == T){
  643. I.unif = 1;
  644. }else{
  645. I.unif = 0;
  646. }
  647. p.1 = prior.1;
  648. p.m.1 = p.1/(m*Q*(Q-1));
  649. p.1.m.2 = 2*p.1/(m*Q*(Q-1)*(Q-2));
  650. p.2.m.1 = 2*p.1/(m*Q*(Q-1)*(Q-2));
  651. p.2.m.2 = 4*p.1/(m*Q*(Q-1)*(Q-2)*(Q-3));
  652. p.co.m.1.2 = p.1/(m*Q*(Q-1));
  653. p.co.m.2.1 = p.1/(m*Q*(Q-1));
  654. p.co.m.2.2 = p.1/(m*Q*(Q-1)*(Q-2));
  655. if(m==2){
  656. p.m.1 = 2*p.m.1;
  657. p.2.m.2 = 2*p.2.m.2
  658. p.co.m.1.2 = p.co.m.1.2/2;
  659. p.co.m.2.1 = p.co.m.2.1/2;
  660. p.co.m.2.2 = 2*p.co.m.2.2
  661. }
  662. prior.5 = prior.1
  663. kappa = 10;
  664. if(cor.adj.priors==T){
  665. ave.cor = trait.cor[lower.tri(trait.cor)];
  666. ave.cor = mean(abs(ave.cor));
  667. prior.2 = min(prior.2, 1-ave.cor^2);
  668. prior.3 = prior.3*(10^(-kappa*ave.cor^2));
  669. prior.4 = min(prior.4, 1-ave.cor^4);
  670. prior.5 = prior.1*(10^(-kappa*ave.cor^2));
  671. p.m.1 = p.m.1*(1-ave.cor)^2;
  672. p.1.m.2 = p.1.m.2*(1-ave.cor)^4;
  673. p.2.m.1 = p.2.m.1/(1-ave.cor)^2;
  674. p.2.m.2 = p.2.m.2*(1-ave.cor)^4;
  675. p.co.m.1.2 = p.co.m.1.2*(1-ave.cor)^2
  676. p.co.m.2.1 = p.co.m.2.1*(1-ave.cor)^2
  677. p.co.m.2.2 = p.co.m.2.2*(1-ave.cor)^2
  678. }
  679. ones=matrix(1,nrow=dim(snps.clc)[1], ncol=dim(snps.clc)[1]);
  680. trait.cor = as.matrix(kronecker(trait.cor, ones));
  681. max.ABF.overall = sum.max.ABF.co = mpfr(0,120);
  682. log.sum.ABF.align = sum.ABF = sum.ABF.co = mpfr(0,120);
  683. NAs = 0;
  684. df = data.frame(matrix(vector(), 0,7, dimnames=list(c(), c("log.sum.ABF.co.loc", "log.sum.ABF.align", "log.max.SNP.ABF.full", "Trait.no.clc", "Traits.clc", "SNPs.clc", "NaNs"))), stringsAsFactors=F)
  685. j = 1;
  686. align.prob = 1;
  687. trt.combn = sample(c(1:m));
  688. prior.no.11 = I.unif*p.m.1 + (1-I.unif)*prior.5*prior( prior.1, prior.2, k = m-1);
  689. prior.no.12 = I.unif*p.1.m.2 + (1-I.unif)*(prior.5*prior.3)*prior(prior.1, prior.2, k = m-1);
  690. prior.co.12 = I.unif*p.co.m.1.2 + (1-I.unif)*prior.3*prior(prior.1, prior.2, k = m);
  691. prior.no.21 = I.unif*p.2.m.1 + (1-I.unif)*prior.5*prior( prior.1, prior.2, k = m-1)*prior(prior.3, prior.4, k = m-1);
  692. prior.no.22 = I.unif*p.2.m.2 + (1-I.unif)*(prior.5*prior.3)*prior( prior.1, prior.2, k = m-1)*prior(prior.3, prior.4, k = m-1);
  693. prior.co.21 = I.unif*p.co.m.2.1 + (1-I.unif)*prior(prior.1, prior.2, k = m)*prior(prior.3, prior.4, k = m-1);
  694. prior.co.22 = I.unif*p.co.m.2.2 + (1-I.unif)*prior.3*prior(prior.1, prior.2, k = m)*prior(prior.3, prior.4, k = m-1);
  695. while(align.prob > align.thresh & j <=m){
  696. trt.no.clc = trt.combn[j] + 0.0;
  697. trt.clc = traits[-trt.no.clc] + 0.0;
  698. output_1 = align12(Z, W, snps.clc, trt.clc, trt.no.clc, ld.matrix, trait.cor, epsilon);
  699. max.ABF = c(prior.no.11*exp(mpfr(output_1[[1]][1], 120)),prior.no.12*exp(mpfr(output_1[[2]][1], 120)));
  700. sum.ABF.no = sum(max.ABF*c(output_1[[1]][2], output_1[[2]][2]));
  701. if(!is.nan(sum.ABF.no)){
  702. sum.ABF= sum.ABF + sum.ABF.no;
  703. if(max.ABF.overall<sum.ABF.no){
  704. max.ABF.overall = sum.ABF.no;
  705. df[1,]$Trait.no.clc = toString(trt.no.clc);
  706. }
  707. }else{NAs = NAs + 1}
  708. max.ABF.1 = prior.co.12*exp(mpfr(output_1[[3]][1], 120));
  709. sum.ABF.1 = max.ABF.1*output_1[[3]][2];
  710. clc.max.cvs.1 = output_1[[3]][3];
  711. if(!is.na(sum.ABF.1)){
  712. sum.ABF.co = sum.ABF.co + sum.ABF.1;
  713. if(sum.max.ABF.co<sum.ABF.1){
  714. sum.max.ABF.co = sum.ABF.1;
  715. log.max.ABF.co = log(max(max.ABF.1))
  716. df[1,]$Traits.clc = toString(trt.clc);
  717. df[1,]$SNPs.clc = toString(clc.max.cvs.1)
  718. }
  719. }else{NAs = NAs + 1;}
  720. output_2 = align2(Z, W, snps.clc, trt.clc, trt.no.clc, ld.matrix, trait.cor, epsilon);
  721. max.ABF = c(prior.no.21*exp(mpfr(output_2[[1]][1], 120)),prior.no.22*exp(mpfr(output_2[[2]][1], 120)));
  722. sum.ABF.no = sum(max.ABF*c(output_2[[1]][2], output_2[[2]][2]));
  723. if(!is.nan(sum.ABF.no)){
  724. sum.ABF= sum.ABF + sum.ABF.no;
  725. if(max.ABF.overall<sum.ABF.no){
  726. max.ABF.overall = sum.ABF.no;
  727. df[1,]$Trait.no.clc = toString(trt.no.clc);
  728. }
  729. }else{NAs = NAs + 1}
  730. max.ABF.2 = c(prior.co.21*exp(mpfr(output_2[[3]][1], 120)), prior.co.22*exp(mpfr(output_2[[4]][1], 120)));
  731. sum.ABF.2 = sum(max.ABF.2*c(output_2[[3]][2], output_2[[4]][2]));
  732. clc.max.cvs.2 = snps.clc[output_2[[2+which(max.ABF.2==max(max.ABF.2))]][3],output_2[[2+which(max.ABF.2==max(max.ABF.2))]][4]];
  733. if(!is.na(sum.ABF.2)){
  734. sum.ABF.co = sum.ABF.co + sum.ABF.2;
  735. if(sum.max.ABF.co<sum.ABF.2){
  736. sum.max.ABF.co = sum.ABF.2;
  737. log.max.ABF.co = log(max(max.ABF.2));
  738. df[1,]$Traits.clc = toString(trt.clc);
  739. df[1,]$SNPs.clc = toString(clc.max.cvs.2)
  740. }
  741. }else{NAs = NAs + 1;}
  742. align.prob = (reg.res + sum.ABF.co)/(reg.res + sum.ABF.co + sum.ABF);
  743. j = j+1;
  744. }
  745. log.sum.ABF.align=asNumeric(log(sum.ABF));
  746. df[1,]$log.sum.ABF.align=log.sum.ABF.align;
  747. df[1,]$NaNs=NAs;
  748. log.sum.ABF.co.loc = asNumeric(log(sum.ABF.co));
  749. df[1,]$log.sum.ABF.co.loc=log.sum.ABF.co.loc;
  750. df[1,]$log.max.SNP.ABF.full=asNumeric(log.max.ABF.co);
  751. return(df)
  752. }
  753. ##########################################################
  754. ##### HyPrColoc (rapid) #####
  755. ##########################################################
  756. #' rapid.hyprcoloc
  757. #'
  758. #' @param Zsq matrix of Z-scores
  759. #' @param Wsq ratio matrix of prior standard deviation and observed standard errors squared
  760. #' @param prior.1 prior probability of a SNP being associated with one trait
  761. #' @param prior.2 1 - prior probability of a SNP being associated with an additional trait given that the SNP is associated with at least 1 other trait
  762. #' @param uniform.priors uniform priors
  763. #' @export
  764. rapid.hyprcoloc <- function(Zsq, Wsq, prior.1, prior.2, uniform.priors){
  765. m = dim(Zsq)[2];
  766. Q = dim(Zsq)[1];
  767. if(uniform.priors==T){
  768. I.unif = 1;
  769. }else{
  770. I.unif = 0;
  771. }
  772. p.1 = prior.1;
  773. p.1.m = p.1/Q;
  774. p.m.1 = p.1/(m*Q*(Q-1));
  775. if(m==2){
  776. p.m.1 = 2*p.m.1;
  777. cnst = 0.25;
  778. }else{
  779. cnst = 1
  780. }
  781. prior.all = I.unif*p.1.m + (1-I.unif)*prior(prior.1, prior.2, k = m);
  782. prior.sub = I.unif*p.1.m + (1-I.unif)*prior(prior.1, prior.2, k = m-1);
  783. prior.align= I.unif*p.m.1 + (1-I.unif)*prior.1*prior(prior.1, prior.2, k = m-1);
  784. labf = 0.5*(log(Wsq) + (Zsq)*(1- Wsq));
  785. sum.labf = rowSums(labf);
  786. mx.labf = which.max(labf);
  787. clc.max = which.max(sum.labf);
  788. chi = sum.labf - sum.labf[clc.max];
  789. exp.chi = exp(chi);
  790. sum.exp.chi = sum(exp.chi);
  791. sum.labf.subset = colSums(exp(chi - labf));
  792. rm.trt = which.max(sum.labf.subset);
  793. reg.prob = sum.exp.chi/(exp(-sum.labf[clc.max] - log(prior.all)) + sum.exp.chi + (prior.sub/prior.all)*sum(sum.labf.subset));
  794. col.max.labf = colMax(labf);
  795. exp.labf.std = exp(t(t(labf) - col.max.labf));
  796. labf.tmp = t(colSums(exp.labf.std) - t(exp.labf.std));
  797. sum.tmp = colSums(exp(t(t(chi - labf)+col.max.labf))*labf.tmp);
  798. align.prob = sum.exp.chi/(sum.exp.chi + cnst*(prior.align/prior.all)*sum(sum.tmp));
  799. return(list(reg.prob, reg.prob*align.prob, clc.max, exp.chi/sum.exp.chi))
  800. }
  801. ##########################################################
  802. ##### HyPrColoc #####
  803. ##########################################################
  804. #' HyPrColoc
  805. #'
  806. #' hyprcoloc is a function used to identify clusters of colocalized traits and candidate causal SNPs in genomic regions
  807. #' @param effect.est matrix of snp regression coefficients (i.e. regression beta values) in the genomic region
  808. #' @param effect.se matrix of standard errors associated with the beta values
  809. #' @param binary.outcomes a binary vector of dimension the number of traits: 1 represents a binary trait 0 otherwise
  810. #' @param trait.subset vector of trait names (or number) from the full trait list: used for trageted colocalization analysis in a region
  811. #' @param trait.names vector of trait names corresponding to the columns in the effect.est matrix
  812. #' @param snp.id vector of SNP IDs
  813. #' @param ld.matrix LD matrix
  814. #' @param trait.cor matrix of pairwise correlations between traits
  815. #' @param sample.overlap matrix of pairwise sample overlap between traits
  816. #' @param bb.alg branch and bound algorithm: TRUE, employ BB algorithm; FALSE, do not
  817. #' @param bb.selection branch and bound algorithm type, e.g. regional or alignment selection
  818. #' @param reg.steps regional step paramter
  819. #' @param reg.thresh threshold probability beyond which traits are believed to share a regional association signal
  820. #' @param align.thresh threshold probability beyond which traits are believed to align at a single causal variant
  821. #' @param prior.1 prior probability of a SNP being associated with one trait
  822. #' @param prior.c conditional colocalization prior: probability of a SNP being associated with an additional trait given that the SNP is associated with at least 1 other trait
  823. #' @param prior.12 COLOC prior p12: prior probability of a SNP being associated with any two traits
  824. #' @param sensitivity perform senstivity analysis
  825. #' @param sense.1 first sensitivity analysis
  826. #' @param sense.2 second sensitivity analysis
  827. #' @param uniform.priors uniform priors
  828. #' @param ind.traits are the traits independent or to be treated as independent
  829. #' @param snpscores output estimated posterior probability explained each SNP
  830. #' @return A data.frame of HyPrColoc results: each row is a cluster of colocalized traits or is coded NA (if no colocalization is identified)
  831. #' @return If snpscores=TRUE: additionally returns a list of posterior probability explained by each SNPs and for each cluster of colocalized traits identified
  832. #' @import compiler Rmpfr iterpc Matrix
  833. #' @importFrom Rcpp evalCpp
  834. #' @useDynLib hyprcoloc
  835. #' @author Christopher N Foley <[email hidden]> and James R Staley <[email hidden]>
  836. #' @examples
  837. #' # Regression coefficients and standard errors from ten GWAS studies
  838. #' # (Traits 1-5, 6-8 & 9-10 are the clusters of colocalized traits)
  839. #' betas <- hyprcoloc::test.betas
  840. #' head(betas)
  841. #' ses <- hyprcoloc::test.ses
  842. #' head(ses)
  843. #'
  844. #' # Trait names and SNP IDs
  845. #' traits <- paste0("T", 1:10)
  846. #' rsid <- rownames(betas)
  847. #'
  848. #' # Colocalisation analyses
  849. #' results <- hyprcoloc(betas, ses, trait.names=traits, snp.id=rsid)
  850. #' @export
  851. hyprcoloc <- function(effect.est, effect.se, binary.outcomes = rep(0, dim(effect.est)[2]),
  852. trait.subset = c(1:dim(effect.est)[2]), trait.names = c(1:dim(effect.est)[2]),
  853. snp.id = c(1:dim(effect.est)[1]), ld.matrix = diag(1, dim(effect.est)[1], dim(effect.est)[1]),
  854. trait.cor = diag(1, dim(effect.est)[2], dim(effect.est)[2]),
  855. sample.overlap = matrix(rep(1,dim(effect.est)[2]^2) , nrow = dim(effect.est)[2]),
  856. bb.alg = TRUE, bb.selection = "regional",
  857. reg.steps = 1, reg.thresh = "default", align.thresh = "default",
  858. prior.1 = 1e-4, prior.c = 0.02, prior.12 = NULL,
  859. sensitivity = FALSE, sense.1 = 1, sense.2 = 2,
  860. uniform.priors = FALSE, ind.traits = FALSE, snpscores=FALSE){
  861. if(any(is.na(effect.est))) stop("there are missing values in effect.est")
  862. if(any(is.na(effect.se))) stop("there are missing values in effect.se")
  863. if(any(effect.se==0)) stop("there are zero values in effect.se")
  864. if(any(is.na(binary.outcomes))) stop("there are missing values in binary.outcomes")
  865. if(any(!(binary.outcomes %in% c(0,1)))) stop("there are missing values in binary.outcomes")
  866. if(any(is.na(trait.subset))) stop("there are missing values in trait.subset")
  867. if(any(is.na(trait.names))) stop("there are missing values in trait.names")
  868. if(any(is.na(snp.id))) stop("there are missing values in snp.id")
  869. if(any(is.na(ld.matrix))) stop("there are missing values in ld.matrix")
  870. if(any(is.na(trait.cor))) stop("there are missing values in trait.cor")
  871. if(any(is.na(sample.overlap))) stop("there are missing values in sample.overlap")
  872. if(!is.null(prior.12)){
  873. prior.c = prior.12/(prior.1 + prior.12);
  874. }
  875. prior.2 = 1-prior.c;
  876. n.cvs = 1;
  877. test.2 = F;
  878. sentinel = 0;
  879. epsilon = 0;
  880. window.size = dim(effect.est)[1];
  881. prior.3 = 1e-3;
  882. prior.4 = 0.995;
  883. reg.tol = 0.699;
  884. cor.adj.priors = F;
  885. branch.jump = F;
  886. Z = effect.est/effect.se;
  887. m = dim(Z)[2];
  888. Q = dim(Z)[1];
  889. if(uniform.priors==F & (reg.thresh == "default" | align.thresh == "default")){
  890. if(reg.thresh == "default"){reg.thresh = 0.5; reg.tol = 0.499;}
  891. if(align.thresh == "default"){align.thresh = 0.5;}
  892. }else if(uniform.priors==T & (reg.thresh == "default" | align.thresh == "default")){
  893. if(reg.thresh == "default"){reg.thresh =0.7;}
  894. if(align.thresh == "default"){align.thresh = 0.7;}
  895. }
  896. if(reg.tol >= reg.thresh){
  897. reg.tol = reg.thresh-0.001;
  898. }
  899. if(bb.alg == T & uniform.priors==F & (reg.thresh < 0.5 | align.thresh < 0.5)){stop("Do not run branch and bound algorithm with reg.thresh or align.thresh < 0.5 when using non-uniform priors")};
  900. if(bb.alg == T & uniform.priors==T & (reg.thresh < 0.6 | align.thresh < 0.6)){stop("Do not run branch and bound algorithm with reg.thresh or align.thresh < 0.6 when using uniform priors")};
  901. if(! n.cvs %in% c(1,2)){stop("Current version of HyPrMTMC is limited to assessment of a maximum of 2 CVs in a region: set n.cvs to either 1 or 2")};
  902. if(n.cvs == 2 & window.size >= 4E2){print("Computation likely to take a long time. Consider utilising the window.size and sentinel variables to focus assessment within a specified window of a sentinel SNP, default is the lead SNP across all traits")};
  903. if(sensitivity == T){bb.alg = F; print("Performing a regional probability sensitivity assessment: posterior probability of co-localisation will not be computed")};
  904. if(! reg.steps %in% 0:m){stop("reg.steps parameter must be an integer between 0 and number of traits m")};
  905. if(! sense.1 %in% 0:m | ! sense.2 %in% 0:m ){stop("Sensitivity parameters must be intergers between 0 and number of traits m")};
  906. if(sense.1 >= sense.2){stop("Sensitivity parameter sense.2 must be greater than sensitivity parameter sense.1")};
  907. if(window.size > Q){stop("Window size cannot be larger than the number of SNPs Q in the region")}
  908. if((length(trait.subset)<m & typeof(trait.subset)!="integer") & length(trait.names) < m){stop("When using character names in 'trait.subset' the variable 'trait.names' must be of length m, containing names for all traits considered")}
  909. if(bb.selection == "reg.only" & reg.thresh < 0.9){warning("Posterior evaluation and the BB algorithm are based on values of the regional statistic only.\n Consider setting a larger value for the regional threshold, e.g. > 0.9, to avoid difficulties in interpreting any regional association signals.");}
  910. if(class(trait.subset)=="character" & class(trait.names)=="character"){
  911. tmp.traits = c(1:m);
  912. traits = tmp.traits[tolower(trait.names) %in% tolower(trait.subset)];
  913. trait.names = trait.names[traits];
  914. }else if(class(trait.subset)=="integer"){
  915. traits = trait.subset;
  916. trait.names = trait.names[traits];
  917. }else{stop("trait.subset must be character or intger valued")}
  918. if(n.cvs==1 & test.2==F){
  919. W = 0.15/effect.se;
  920. W[, which(binary.outcomes==1)] = 0.2/(effect.se[, which(binary.outcomes==1)]);
  921. }else if(n.cvs==1 & test.2==T){
  922. W = 0.15/effect.se;
  923. W[, which(binary.outcomes==1)] = 0.2/(effect.se[, which(binary.outcomes==1)]);
  924. W.nudge = matrix(0.15 + runif(m*Q, -0.015, 0.015), nrow=Q)/effect.se;
  925. W.nudge[, which(binary.outcomes==1)] = matrix(0.2 + runif(Q*length(which(binary.outcomes==1)), -0.02, 0.02), nrow=Q)/(effect.se[, which(binary.outcomes==1)]);
  926. }else{
  927. if(epsilon == 0){epsilon = 0.01;}
  928. W = matrix(0.15 + runif(m*Q, -0.015, 0.015), nrow=Q)/effect.se;
  929. W[, which(binary.outcomes==1)] = matrix(0.2 + runif(Q*length(which(binary.outcomes==1)), -0.02, 0.02), nrow=Q)/(effect.se[, which(binary.outcomes==1)]);
  930. }
  931. if(n.cvs==1 & (all(trait.cor[lower.tri(trait.cor)] == 0) | ind.traits == TRUE)){
  932. ind.traits = TRUE;
  933. Zsq = Z^2;
  934. Wsq = 1/(1+ W^2);
  935. if(reg.steps == 1 & test.2 == FALSE){rapid = TRUE}else{rapid = FALSE};
  936. }else{
  937. Zsq = Wsq = sparseMatrix(i=1, j=1, dims=c(Q,m));
  938. rapid = FALSE;
  939. }
  940. if(isTRUE(test.2)){
  941. test.2 = 1;
  942. }else{
  943. test.2 = 0;
  944. }
  945. snp.combin = function(x, y, vec){I = iterpc(x, y, labels = vec);return(getall(I)+0.0)};
  946. snp.scores = NA;
  947. if(class(sentinel)=="character"){sentinel = which(snp.id == sentinel);}
  948. tmp.vars = samp.reduc(Z, W, ld.matrix, trait.cor, sample.overlap, traits, window.size, sentinel, Zsq = Zsq, Wsq = Wsq);
  949. Z = tmp.vars[[1]];
  950. W = tmp.vars[[2]];
  951. Zsq = tmp.vars[[7]];
  952. Wsq = tmp.vars[[8]]
  953. ld.matrix = tmp.vars[[3]];
  954. trait.cor = tmp.vars[[4]];
  955. sample.overlap = tmp.vars[[5]];
  956. m = dim(Z)[2];
  957. Q = dim(Z)[1];
  958. snp.id = snp.id[tmp.vars[[6]]];
  959. traits = 1:length(traits);
  960. cor.trts = identical(trait.cor, diag(m));
  961. if(branch.jump == T & cor.trts == F){branch.jump = F};
  962. snp.scores = list();
  963. bb.selection = tolower(bb.selection);
  964. if(n.cvs==1){
  965. if(rapid == F){
  966. snps = c(1:Q);
  967. snps.clc = as.matrix(t(snp.combin(Q, 2, snps)));
  968. flag = 0;
  969. }
  970. if(bb.alg==T){
  971. df = data.frame(matrix(vector(), 0,9, dimnames=list(c(), c("Algorithm_iteration", "Putatively_co_localised_traits", "HyPr_MTC_posterior", "Regional_probability", "Putatively_causal_SNP", "Posterior_explained_by_SNP", "Posterior_ratio_2CVs_vs_1_or_2CVs", "Dropped_trait", "NaNs"))), stringsAsFactors=F)
  972. i=m;
  973. count = 1;
  974. reg.prob = align.prob = 0;
  975. while(i>1){
  976. trts=traits;
  977. while(reg.prob <= reg.thresh | align.prob <= align.thresh){
  978. reg.prob = reg.only = 0;
  979. if(bb.selection == "align"){
  980. tmp.vars = samp.reduc(Z, W, ld.matrix, trait.cor, sample.overlap, trts, Zsq = Zsq, Wsq = Wsq);
  981. if(rapid == F){
  982. reg.result = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, 0, reg.steps, cor.adj.priors, uniform.priors, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  983. reg.res = reg.result[[1]];
  984. reg.full = exp(mpfr(reg.res$log.sum.ABF.full,120));
  985. reg.prob = reg.full/(1 + exp(mpfr(reg.res$log.sum.ABF.all.combs,120)));
  986. }else{
  987. reg.res = rapid.reg(tmp.vars[[7]], tmp.vars[[8]], prior.1, prior.2, uniform.priors)
  988. reg.prob = reg.res[[1]];
  989. }
  990. }else{
  991. while(reg.prob <= reg.thresh){
  992. tmp.vars = samp.reduc(Z, W, ld.matrix, trait.cor, sample.overlap, trts, Zsq = Zsq, Wsq = Wsq);
  993. if(rapid == F){
  994. reg.result = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, 0, reg.steps, cor.adj.priors, uniform.priors, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  995. reg.res = reg.result[[1]];
  996. trts.tmp = as.numeric(unlist(strsplit(reg.res$Traits, split=", ")));
  997. reg.full = exp(mpfr(reg.res$log.sum.ABF.full,120));
  998. reg.prob = reg.full/(1 + exp(mpfr(reg.res$log.sum.ABF.all.combs,120)));
  999. if(reg.prob <= reg.thresh & length(trts) > length(trts.tmp)){
  1000. trts = trts[trts.tmp];
  1001. }else if(reg.prob <= reg.thresh & length(trts) == length(trts.tmp) & reg.prob < reg.tol){
  1002. reg.only.trts = as.numeric(unlist(strsplit(reg.res$reg_only_trts, split=", ")));
  1003. trts = trts[reg.only.trts];
  1004. }else if(reg.prob <= reg.thresh & length(trts) == length(trts.tmp) & reg.prob >= reg.tol){
  1005. break;
  1006. }else{
  1007. if(length(trts) != length(trts.tmp)){reg.prob = 0;trts = trts[trts.tmp];}
  1008. }
  1009. }else{
  1010. reg.res = rapid.reg(tmp.vars[[7]], tmp.vars[[8]], prior.1, prior.2, uniform.priors)
  1011. reg.prob = reg.res[[1]];
  1012. if(reg.prob <= reg.thresh){trts = trts[-reg.res[[3]]]}
  1013. }
  1014. if(length(trts)<=1){reg.only = 1; break;}
  1015. }
  1016. }
  1017. if(length(trts)<=1){break;}
  1018. if(bb.selection != "reg.only"){
  1019. if(ind.traits == F){
  1020. align.res = align.ABF.1(tmp.vars[[1]], tmp.vars[[2]], tmp.vars[[4]], tmp.vars[[5]], tmp.vars[[3]], epsilon, reg.full, align.thresh, prior.1, prior.2, cor.adj.priors, uniform.priors, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1021. align.prob = asNumeric(reg.full/(reg.full + exp(mpfr(align.res$log.sum.ABF.all.combs, 120))));
  1022. if(align.prob <= align.thresh | reg.prob <= reg.thresh){
  1023. drop.trait = as.numeric(unlist(strsplit(align.res$Trait.no.clc, split=", ")))
  1024. trts = trts[-drop.trait];
  1025. }
  1026. }else{
  1027. align.res = rapid.align(tmp.vars[[7]], tmp.vars[[8]], prior.1, prior.2, uniform.priors);
  1028. align.prob = align.res[[1]];
  1029. if(align.prob <= align.thresh | reg.prob <= reg.thresh){trts = trts[-align.res[[2]]];}
  1030. }
  1031. }else{
  1032. reg.only = 1; break;
  1033. }
  1034. if(length(trts)<=1)break
  1035. }
  1036. df[count,]$Regional_probability = asNumeric(reg.prob);
  1037. if(length(trts)>=2){
  1038. df[count,]$Algorithm_iteration = count;
  1039. df[count,]$Putatively_co_localised_traits = toString(trait.names[trts]);
  1040. df[count,]$HyPr_MTC_posterior = asNumeric(reg.prob*align.prob);
  1041. if(test.2 == 1){
  1042. tmp.vars = samp.reduc(Z, W.nudge, ld.matrix, trait.cor, sample.overlap, trts, Zsq = Zsq, Wsq = Wsq);
  1043. reg.tmp = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, 1, reg.steps, cor.adj.priors, uniform.priors=FALSE, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1044. df[count,]$Posterior_ratio_2CVs_vs_1_or_2CVs = asNumeric(reg.tmp[[1]]);
  1045. }
  1046. if(rapid == F){
  1047. if(bb.selection != "reg.only" & ind.traits == F){
  1048. df[count,]$NaNs = reg.res$NaNs + align.res$NaNs;
  1049. }else{df[count,]$NaNs = reg.res$NaNs;}
  1050. df[count,]$Putatively_causal_SNP = toString(snp.id[as.numeric(reg.res$SNPs)]);
  1051. df[count,]$Posterior_explained_by_SNP = exp(reg.res$log.max.SNP.ABF.full-reg.res$log.sum.ABF.full);
  1052. snp.scores[[count]] = reg.result[[2]];
  1053. }else{
  1054. df[count,]$Putatively_causal_SNP = toString(snp.id[reg.res[[2]]]);
  1055. df[count,]$Posterior_explained_by_SNP = reg.res[[4]][reg.res[[2]]];
  1056. snp.scores[[count]] = reg.res[[4]];
  1057. }
  1058. }else{
  1059. df[count,]$Algorithm_iteration = count;
  1060. df[count,]$Putatively_co_localised_traits = "None";
  1061. df[count,]$Dropped_trait = toString(trait.names[trts]);
  1062. if(reg.only == 1 & rapid == F){df[count,]$NaNs = reg.res$NaNs;
  1063. }else if(rapid == F){df[count,]$NaNs = reg.res$NaNs + align.res$NaNs;}
  1064. }
  1065. traits = traits[! traits %in% trts];
  1066. reg.prob = align.prob = reg.only = 0;
  1067. i = length(traits);
  1068. count = count + 1;
  1069. }
  1070. }else{
  1071. if(sensitivity == F){
  1072. df = data.frame(matrix(vector(), 0,7, dimnames=list(c(), c("Traits", "HyPr_MTC_posterior", "Regional_probability", "Putatively_causal_SNP", "Posterior_explained_by_SNP", "Posterior_ratio_2CVs_vs_1_or_2CVs", "NaNs"))), stringsAsFactors=F)
  1073. df[1,]$Traits = toString(trait.names);
  1074. tmp.vars = samp.reduc(Z, W, ld.matrix, trait.cor, sample.overlap, traits, Zsq = Zsq, Wsq = Wsq);
  1075. if(rapid == F){
  1076. reg.result = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, 0, reg.steps, cor.adj.priors, uniform.priors, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1077. reg.res = reg.result[[1]];
  1078. reg.full = exp(mpfr(reg.res$log.sum.ABF.full,120));
  1079. reg.prob = asNumeric(reg.full/(1 + exp(mpfr(reg.res$log.sum.ABF.all.combs,120))));
  1080. df[1,]$Regional_probability = reg.prob;
  1081. if(reg.prob < reg.thresh*align.thresh){
  1082. df[1,]$NaNs = reg.res$NaNs;
  1083. }else{
  1084. if(ind.traits == F){
  1085. align.res = align.ABF.1(tmp.vars[[1]], tmp.vars[[2]], tmp.vars[[4]], tmp.vars[[5]], tmp.vars[[3]], epsilon, reg.full, align.thresh, prior.1, prior.2, cor.adj.priors, uniform.priors, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1086. align.prob = asNumeric(reg.full/(reg.full + exp(mpfr(align.res$log.sum.ABF.all.combs, 120))));
  1087. df[1,]$NaNs = reg.res$NaNs + align.res$NaNs;
  1088. }else{
  1089. align.res = rapid.align(tmp.vars[[7]], tmp.vars[[8]], prior.1, prior.2, uniform.priors);
  1090. align.prob = align.res[[1]];
  1091. df[1,]$NaNs = reg.res$NaNs;
  1092. }
  1093. hypr_post = reg.prob*align.prob;
  1094. df[1,]$HyPr_MTC_posterior = hypr_post;
  1095. if(hypr_post>=(reg.thresh*align.thresh)){
  1096. df[1,]$Putatively_causal_SNP = toString(snp.id[as.numeric(reg.res$SNPs)])
  1097. df[1,]$Posterior_explained_by_SNP = exp(reg.res$log.max.SNP.ABF.full-reg.res$log.sum.ABF.full);
  1098. if(test.2 == 1){
  1099. reg.tmp = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, 1, reg.steps, cor.adj.priors, uniform.priors = FALSE, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1100. df[1,]$Posterior_ratio_2CVs_vs_1_or_2CVs = asNumeric(reg.tmp[[1]]);
  1101. }
  1102. snp.scores = reg.result[[2]];
  1103. }
  1104. }
  1105. }else{
  1106. rapid.result = rapid.hyprcoloc(tmp.vars[[7]], tmp.vars[[8]], prior.1, prior.2, uniform.priors);
  1107. df[1,]$Regional_probability = rapid.result[[1]];
  1108. df[1,]$HyPr_MTC_posterior = rapid.result[[2]];
  1109. df[1,]$Putatively_causal_SNP = toString(snp.id[rapid.result[[3]]]);
  1110. df[1,]$Posterior_explained_by_SNP = rapid.result[[4]][rapid.result[[3]]];
  1111. snp.scores = rapid.result[[4]];
  1112. }
  1113. }else{
  1114. df = data.frame(matrix(vector(), 0,4, dimnames=list(c(), c("Traits", "Regional_Pr_1", "Regional_Pr_2", "Relative_diff"))), stringsAsFactors=F)
  1115. df[1,]$Traits = toString(trait.names);
  1116. tmp.vars = samp.reduc(Z, W, ld.matrix, trait.cor, sample.overlap, traits, Zsq = Zsq, Wsq = Wsq);
  1117. reg.steps = sense.1 ;
  1118. reg.result = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, 0, reg.steps, cor.adj.priors, uniform.priors, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1119. reg.res = reg.result[[1]];
  1120. reg.full = exp(mpfr(reg.res$log.sum.ABF.full,120));
  1121. reg.prob.1 = asNumeric(reg.full/(1 + exp(mpfr(reg.res$log.sum.ABF.all.combs,120))));
  1122. df[1,]$Regional_Pr_1 = reg.prob.1;
  1123. reg.steps = sense.2;
  1124. reg.result = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, 0, reg.steps, cor.adj.priors, uniform.priors, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1125. reg.res = reg.result[[1]];
  1126. reg.full = exp(mpfr(reg.res$log.sum.ABF.full,120));
  1127. reg.prob.2 = asNumeric(reg.full/(1 + exp(mpfr(reg.res$log.sum.ABF.all.combs,120))));
  1128. df[1,]$Regional_Pr_2 = reg.prob.2;
  1129. df[1,]$Relative_diff = abs(reg.prob.1-reg.prob.2)/reg.prob.2;
  1130. }
  1131. }
  1132. }else{
  1133. flag = 1;
  1134. test.2 = 0;
  1135. snps = c(1:Q);
  1136. snps.clc = as.matrix(t(snp.combin(Q, 2, snps)));
  1137. if(bb.alg==T){
  1138. NaNs = 0;
  1139. i=m;
  1140. count = 1;
  1141. reg.prob = align.prob = 0;
  1142. df = data.frame(matrix(vector(), 0,8, dimnames=list(c(), c("Algorithm_iteration", "Putatively_co_localised_traits", "HyPr_MTC_posterior", "Regional_probability", "Putatively_causal_SNPs", "Posterior_explained_by_SNPs", "Dropped_trait", "NaNs"))), stringsAsFactors=F)
  1143. while(i>1){
  1144. trts=traits;
  1145. tmp.vars = samp.reduc(Z, W, ld.matrix, trait.cor, sample.overlap, trts, Zsq = Zsq, Wsq = Wsq)
  1146. while(reg.prob <= reg.thresh | align.prob <= align.thresh){
  1147. reg.prob = 0;
  1148. while(reg.prob <= reg.thresh){
  1149. reg.full = reg.all = reg.only = 0;
  1150. reg.result = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, test.2, reg.steps, cor.adj.priors, uniform.priors, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1151. reg.res = reg.result[[1]];
  1152. reg.full = sum(exp(mpfr(reg.res$log.sum.ABF.full,120)));
  1153. reg.all = sum(exp(mpfr(reg.res$log.sum.ABF.all.combs,120)));
  1154. trts.tmp = as.numeric(unlist(strsplit(reg.res$Traits[1], split=", ")));
  1155. tmp.mx = which(reg.res$log.sum.ABF.full==max(reg.res$log.sum.ABF.full));
  1156. clc.snp = reg.res$SNPs[tmp.mx];
  1157. reg.max.snp = reg.res$log.max.SNP.ABF.full[tmp.mx];
  1158. reg.max.full = reg.res$log.sum.ABF.full[tmp.mx];
  1159. reg.prob = asNumeric(reg.full/(1+reg.all));
  1160. if(reg.prob < reg.thresh){
  1161. if(length(trts) == length(trts.tmp)){
  1162. trts = sample(trts, (length(trts)-1));
  1163. }else{trts = trts[trts.tmp];}
  1164. if(length(trts)>1){
  1165. tmp.vars = samp.reduc(Z, W, ld.matrix, trait.cor, sample.overlap, trts, Zsq = Zsq, Wsq = Wsq);
  1166. }
  1167. }else{
  1168. if(length(trts) != length(trts.tmp)){
  1169. reg.prob = 0;
  1170. trts = trts[trts.tmp];
  1171. tmp.vars = samp.reduc(Z, W, ld.matrix, trait.cor, sample.overlap, trts, Zsq = Zsq, Wsq = Wsq);
  1172. }
  1173. }
  1174. if(length(trts)<=1){reg.only = 1; break;}
  1175. }
  1176. if(reg.only == 1){break;}
  1177. align.res = align.ABF.2(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[4]], tmp.vars[[5]], tmp.vars[[3]], epsilon, reg.full, align.thresh, prior.1, prior.2, prior.3, prior.4, cor.adj.priors, uniform.priors);
  1178. align.tot = exp(mpfr(align.res$log.sum.ABF.align,120));
  1179. reg.full.align = sum(exp(mpfr(align.res$log.sum.ABF.co.loc,120)));
  1180. if(reg.full.align > reg.full){
  1181. clc.snp = align.res$SNPs.clc;
  1182. reg.max.snp = exp(mpfr(align.res$log.max.SNP.ABF.full, 120));
  1183. reg.max.full = reg.full.align;
  1184. tmp.mx = 1;
  1185. }
  1186. reg.full = reg.full + reg.full.align;
  1187. drop.trait = as.numeric(unlist(strsplit(align.res$Trait.no.clc, split=", ")));
  1188. align.prob = asNumeric(reg.full/(reg.full + align.tot));
  1189. if(align.prob < align.thresh){
  1190. trts = trts[-drop.trait];
  1191. }
  1192. if(length(trts)<=1)break
  1193. }
  1194. if(reg.only !=1){reg.prob = asNumeric(reg.full/(reg.full.align + reg.all));}
  1195. df[count,]$Regional_probability = reg.prob;
  1196. if(length(trts)>=2){
  1197. NaNs = sum(reg.res$NaNs) + align.res$NaNs
  1198. hypr_post = reg.prob*align.prob;
  1199. df[count,]$Algorithm_iteration = count;
  1200. df[count,]$Putatively_co_localised_traits = toString(trait.names[trts]);
  1201. df[count,]$HyPr_MTC_posterior = hypr_post;
  1202. df[count,]$Putatively_causal_SNPs = toString(snp.id[as.numeric(unlist(strsplit(clc.snp, split=", ")))]);
  1203. df[count,]$Posterior_explained_by_SNPs = asNumeric(reg.max.snp/reg.max.full);
  1204. df[count,]$NaNs = NaNs;
  1205. snp.scores[[count]] = reg.result[[tmp.mx+1]];
  1206. }else{
  1207. df[count,]$Algorithm_iteration = count;
  1208. df[count,]$Dropped_trait =toString(trait.names[trts]);
  1209. if(reg.only == 1){df[count,]$NaNs = sum(reg.res$NaNs);
  1210. }else{df[count,]$NaNs = NaNs;}
  1211. }
  1212. traits = traits[! traits %in% trts];
  1213. reg.prob = align.prob = reg.only = 0;
  1214. i = length(traits);
  1215. count = count + 1;
  1216. }
  1217. }else{
  1218. if(sensitivity == F){
  1219. df = data.frame(matrix(vector(), 0,6, dimnames=list(c(), c("Traits", "HyPr_MTC_posterior", "Regional_probability", "Putatively_causal_SNPs", "Posterior_explained_by_SNPs", "NaNs"))), stringsAsFactors=F)
  1220. reg.full = reg.all = NaNs = 0;
  1221. align.tot = drop.trait = vector("numeric", window.size+2);
  1222. df[1,]$Traits = toString(trait.names);
  1223. reg.result = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, test.2, reg.steps, cor.adj.priors, uniform.priors, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1224. reg.res = reg.result[[1]];
  1225. reg.full = sum(exp(mpfr(reg.res$log.sum.ABF.full,120)));
  1226. reg.all = sum(exp(mpfr(reg.res$log.sum.ABF.all.combs,120)));
  1227. reg.prob = asNumeric(reg.full/(1 + reg.all));
  1228. df[1,]$Regional_probability = reg.prob;
  1229. NaNs = sum(reg.res$NaNs)
  1230. if(reg.prob < reg.thresh*align.thresh){
  1231. df[1,]$NaNs = NaNs;
  1232. }else{
  1233. trts.tmp = as.numeric(unlist(strsplit(reg.res$Traits[1], split=", ")));
  1234. tmp.mx = which(reg.res$log.sum.ABF.full==max(reg.res$log.sum.ABF.full));
  1235. clc.snp = reg.res$SNPs[tmp.mx];
  1236. reg.max.snp = reg.res$log.max.SNP.ABF.full[tmp.mx];
  1237. reg.max.full = reg.res$log.sum.ABF.full[tmp.mx];
  1238. align.res = align.ABF.2(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[4]], tmp.vars[[5]], tmp.vars[[3]], epsilon, reg.full, align.thresh, prior.1, prior.2, prior.3, prior.4, cor.adj.priors, uniform.priors);
  1239. align.tot = exp(mpfr(align.res$log.sum.ABF.align,120));
  1240. reg.full.align = sum(exp(mpfr(align.res$log.sum.ABF.co.loc,120)));
  1241. if(reg.full.align > reg.full){
  1242. clc.snp = align.res$SNPs.clc;
  1243. reg.max.full = reg.full.align;
  1244. tmp.mx = 1;
  1245. }
  1246. reg.full = reg.full + reg.full.align;
  1247. drop.trait = as.numeric(unlist(strsplit(align.res$Trait.no.clc, split=", ")));
  1248. NaNs = NaNs + align.res$NaNs;
  1249. reg.prob = asNumeric(reg.full/(1 + reg.full.align + reg.all));
  1250. align.prob = asNumeric(reg.full/(1 + reg.full + align.tot));
  1251. hypr_post = reg.prob*align.prob;
  1252. df[1,]$Regional_probability = reg.prob;
  1253. df[1,]$HyPr_MTC_posterior = hypr_post;
  1254. df[1,]$NaNs = NaNs;
  1255. if(hypr_post>=(reg.thresh*align.thresh)){
  1256. df[1,]$Putatively_causal_SNPs = toString(snp.id[as.numeric(unlist(strsplit(clc.snp, split=", ")))]);
  1257. df[1,]$Posterior_explained_by_SNPs = asNumeric(reg.max.snp/reg.max.full);
  1258. snp.scores = reg.result[[tmp.mx + 1]];
  1259. }
  1260. }
  1261. }else{
  1262. df = data.frame(matrix(vector(), 0,4, dimnames=list(c(), c("Traits", "Regional_Pr_1", "Regional_Pr_2", "Relative_diff"))), stringsAsFactors=F)
  1263. df[1,]$Traits = toString(trait.names);
  1264. tmp.vars = samp.reduc(Z, W, ld.matrix, trait.cor, sample.overlap, traits, Zsq = Zsq, Wsq = Wsq);
  1265. reg.steps = sense.1;
  1266. reg.result = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, test.2, reg.steps, cor.adj.priors, uniform.priors, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1267. reg.res = reg.result[[1]];
  1268. reg.full = sum(exp(mpfr(reg.res$log.sum.ABF.full,120)));
  1269. reg.all = sum(exp(mpfr(reg.res$log.sum.ABF.all.combs,120)));
  1270. reg.prob.1 = asNumeric(reg.full/(1 + reg.all));
  1271. df[1,]$Regional_Pr_1 = reg.prob.1;
  1272. reg.steps = sense.2;
  1273. reg.result = regional.ABF(tmp.vars[[1]], tmp.vars[[2]], snps.clc, tmp.vars[[3]], tmp.vars[[4]], tmp.vars[[5]], epsilon, reg.thresh, prior.1, prior.2, prior.3, prior.4, flag, test.2, reg.steps, cor.adj.priors, uniform.priors, branch.jump, tmp.vars[[7]], tmp.vars[[8]], ind.traits);
  1274. reg.res = reg.result[[1]];
  1275. reg.full = sum(exp(mpfr(reg.res$log.sum.ABF.full,120)));
  1276. reg.all = sum(exp(mpfr(reg.res$log.sum.ABF.all.combs,120)));
  1277. reg.prob.2 = asNumeric(reg.full/(1 + reg.all));
  1278. df[1,]$Regional_Pr_2 = reg.prob.2;
  1279. df[1,]$Relative_diff = abs(reg.prob.1-reg.prob.2)/reg.prob.2;
  1280. }
  1281. }
  1282. }
  1283. if(length(which(df$NaNs!=0)) > 1){print("Results include NAs. Possible the Z score correlation matrix or adjusted prior matrix has a high condition number somewhere: consider increasing epsilon by a small amount");}
  1284. names(df)[names(df)=="Algorithm_iteration"] <- "iteration"
  1285. names(df)[names(df)=="Putatively_co_localised_traits"] <- "traits"
  1286. names(df)[names(df)=="Traits"] <- "traits"
  1287. names(df)[names(df)=="HyPr_MTC_posterior"] <- "posterior_prob"
  1288. names(df)[names(df)=="Regional_probability"] <- "regional_prob"
  1289. names(df)[names(df)=="Posterior_ratio_2CVs_vs_1_or_2CVs"] <- "posterior_ratio_2cvs_vs_1_or_2cvs"
  1290. names(df)[names(df)=="Putatively_causal_SNP"] <- "candidate_snp"
  1291. names(df)[names(df)=="Putatively_causal_SNPs"] <- "candidate_snp"
  1292. names(df)[names(df)=="Posterior_explained_by_SNP"] <- "posterior_explained_by_snp"
  1293. names(df)[names(df)=="Posterior_explained_by_SNPs"] <- "posterior_explained_by_snp"
  1294. names(df)[names(df)=="Dropped_trait"] <- "dropped_trait"
  1295. names(df)[names(df)=="Regional_Pr_1"] <- "regional_prob_1"
  1296. names(df)[names(df)=="Regional_Pr_2"] <- "regional_prob_2"
  1297. names(df)[names(df)=="Relative_diff"] <- "relative_diff"
  1298. df$NaNs <- NULL
  1299. rownames(df) <- NULL
  1300. if(test.2==F){df$posterior_ratio_2cvs_vs_1_or_2cvs <- NULL}
  1301. if(any(!is.na(df$posterior_prob))){df$posterior_prob[!is.na(df$posterior_prob)] <- round(as.numeric(df$posterior_prob[!is.na(df$posterior_prob)]),4); df$regional_prob[!is.na(df$regional_prob)] <- round(as.numeric(df$regional_prob[!is.na(df$regional_prob)]),4); df$posterior_explained_by_snp[!is.na(df$posterior_explained_by_snp)] <- round(as.numeric(df$posterior_explained_by_snp[!is.na(df$posterior_explained_by_snp)]),4)}
  1302. if(any(!is.na(df$regional_prob))){df$regional_prob[!is.na(df$regional_prob)] <- round(as.numeric(df$regional_prob[!is.na(df$regional_prob)]),4); df$posterior_explained_by_snp[!is.na(df$posterior_explained_by_snp)] <- round(as.numeric(df$posterior_explained_by_snp[!is.na(df$posterior_explained_by_snp)]),4)}
  1303. if(length(df$posterior_ratio_2cvs_vs_1_or_2cvs)>0){if(any(!is.na(df$posterior_ratio_2cvs_vs_1_or_2cvs))){df$posterior_ratio_2cvs_vs_1_or_2cvs[!is.na(df$posterior_ratio_2cvs_vs_1_or_2cvs)] <- round(as.numeric(df$posterior_ratio_2cvs_vs_1_or_2cvs[!is.na(df$posterior_ratio_2cvs_vs_1_or_2cvs)]),4)}}
  1304. if(sum(is.na(snp.scores))==0 & length(snp.scores)>0 & snpscores==T){results = list(results=df, snpscores=snp.scores)}else{results = list(results=df)};
  1305. class(results) <- "hyprcoloc";
  1306. return(results)
  1307. }
  1308. #' Print HyPrColoc
  1309. #'
  1310. #' print method for class "hyprcoloc"
  1311. #' @param x an object of class "hyprcoloc"
  1312. #' @author Christopher N Foley (University of Cambridge) <[email hidden]> and James R Staley (University of Bristol) <[email hidden]>
  1313. #' @param ... Other arguments passed to or from other methods
  1314. #'
  1315. #' @export print.hyprcoloc
  1316. #' @export
  1317. print.hyprcoloc <- function(x, ...){
  1318. cat("\nCall: \nhyprcoloc")
  1319. cat("\n\nResults:\n")
  1320. print(x$results)
  1321. cat("\n")
  1322. }
  1323. # prevents R check throwing errors about unassigned global variables
  1324. utils::globalVariables(c("colorRampPalette", "combn", "runif"))

hyprcoloc.R at commit 26ea595, no license · at the source

Overview

Authors: Weiming Gong1,2, Yantong Guo1,2, Xiubin Sun1,2, Shukang Wang1,2, Fuzhong Xue1,2,3, Wei Zhao4, Xiang Zhou5,6, Lu Liu1,2, Zhongshang Yuan1,2
  1. Department of Biostatistics, School of Public Health, Cheeloo College of Medicine, Shandong University,Jinan, China
  2. Institute for Medical Dataology, Cheeloo College of Medicine, Shandong University,Jinan, China
  3. Qilu Hospital, Cheeloo College of Medicine, Shandong University,Jinan, China
  4. Department of Pathogenic Biology, Key Laboratory of Infection and Immunity of Shandong Province, and Key Laboratory for Experimental Teratology of the Chinese Ministry of Education, School of Basic Medical Science, Cheeloo College of Medicine, Shandong University,Jinan, China
  5. Department of Biostatistics, University of Michigan,Ann Arbor, MI USA
  6. Center for Statistical Genetics, University of Michigan,Ann Arbor, MI USA
Institutions: Shandong University (China); University of Michigan (United States)
Journal: Nature communications, volume 17, issue 1, article 5482
Dates: received 7 May 2025; accepted 9 April 2026; published online 21 April 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s41467-026-72164-7 · PMID 42014408 · PMCID PMC13284391 · OpenAlex W7155065151
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: genetics / omics (modality), human (organism), mouse (organism)
Methods: Statistics, Preprocessing
Keywords: Genetic association study, Musculoskeletal abnormalities, Computational biology and bioinformatics
MeSH: Genetic Predisposition to Disease*, Musculoskeletal Diseases*, Animals, Autoimmune Diseases, Female, Genome-Wide Association Study, Humans, Mice, Multifactorial Inheritance, Multivariate Analysis, Polymorphism, Single Nucleotide (* major topic)
Topic: Genetic Associations and Epidemiology (Genetics, Biochemistry, Genetics and Molecular Biology), according to OpenAlex
Citations: cited by 1 paper (Europe PMC); 126 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repositories

Its files are read in the Code ↔ Paper reader above, with 11 matches between paragraphs and lines of code.

Zenodo 19012445

License: CC-BY-4.0
State: the link answers, verified on 29 September 2026
Evidence: files inventoried
Size: 4 files
Software Heritage: not checked
Found in: the references
Holds: README
Not found: license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 29 September 2026: the link answers (HTTP 200)
  • 29 September 2026: the link answers (HTTP 200)
1 file
At the source:

GenomicSEM/GenomicSEM

License: GPL-3.0
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 6b65ca5db39fdade08b0d811477be1cdd57b5039, 26 August 2026
Languages: R (32)
Size: 82 files, 32 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README, license file, environment (DESCRIPTION), documentation
Not found: CITATION.cff, tests, continuous integration
Tools: tidyverse (4 files), data.table (3 files), ggplot2 (2 files), ggpubr (2 files), lavaan (2 files), psych (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
34 files

josefin-werme/LAVA

License: none: the authors keep all their rights
State: the link answers, verified on 29 September 2026
Evidence: files inventoried
Commit: e729a245f7b6923967a96804fbf5246eadf2d6c6, 28 July 2026
Languages: R (12), C/C++ (5), C++ (3)
Size: 56 files, 20 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README, environment (DESCRIPTION), documentation, 2 notebooks
Not found: license file, CITATION.cff, tests, continuous integration
Tools: data.table (2 files)
Availability: 1 check, the latest on 29 September 2026: the link answers
  • 29 September 2026: the link answers
21 files

bulik/ldsc

License: GPL-3.0
State: the link answers, verified on 26 September 2026
Evidence: files inventoried
Commit: 2fdeeb3b44379408794154993dbd6101b8946b7e, 16 January 2026
Languages: Python (19), MATLAB (4), Perl (1), R (1)
Size: 1,093 files, 25 scripts
Software Heritage: archived
Found in: “Code availability”
Holds: README, license file, environment (environment.yml, requirements.txt, setup.py), tests
Not found: CITATION.cff, continuous integration, documentation
Tools: NumPy (18 files), pandas (11 files), SciPy (5 files), BEDTools (2 files)
Availability: 1 check, the latest on 26 September 2026: the link answers
  • 26 September 2026: the link answers
27 files
At the source: github.com/bulik/ldsc

cnfoley/hyprcoloc

License: none: the authors keep all their rights
State: the link answers, verified on 29 September 2026
Evidence: files inventoried
Commit: 26ea5953a46b3e204dfa8eadd202f746244afa13, 12 February 2021
Languages: C++ (8), R (3)
Size: 45 files, 11 scripts
Software Heritage: archived
Found in: “Code availability”
Holds: README, environment (DESCRIPTION), documentation, 1 notebook
Not found: license file, CITATION.cff, tests, continuous integration
Tools: pheatmap (1 file)
Availability: 1 check, the latest on 29 September 2026: the link answers
  • 29 September 2026: the link answers
12 files

chr1swallace.github.io/coloc

License: none: the authors keep all their rights
State: the link answers, verified on 29 September 2026
Evidence: the link answers
Software Heritage: not checked
Found in: “Code availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 29 September 2026: the link answers (HTTP 200)
  • 29 September 2026: the link answers (HTTP 200)

JianYang-Lab/gsMap

License: MIT
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 7fbdcf80cb3e35a341cf1a955bb4809f3e5e6e02, 19 August 2026
Languages: Python (37)
Size: 95 files, 37 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README, license file, environment (docker-compose.yml, Dockerfile, pyproject.toml, docs/requirements.txt, gsmap_vibe/pyproject.toml, visualization_web_docs/requirements.txt, src/gsMap/setup.py), tests, continuous integration, documentation
Not found: CITATION.cff
Tools: pandas (14 files), NumPy (13 files), SciPy (10 files), PyTorch (6 files), Scanpy (6 files), scikit-learn (3 files), anndata (2 files), Plotly (2 files), Numba (1 file), PyTorch Geometric (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
39 files

Code availability statement

The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s41467-026-72164-7.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 7 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 125 scripts, each with its path and the digest of its content;
  • 11 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Code and data availability statement

The paper has a code and data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s41467-026-72164-7.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 29 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 9 authors, 3 keywords, 11 MeSH terms, 3 funders, 126 references.

Cite

This paper

Gong, W., Guo, Y., Sun, X., Wang, S., Xue, F., Zhao, W., Zhou, X., Liu, L., & Yuan, Z. (2026). Multivariate genetic analysis reveals three distinct pathological dimensions in musculoskeletal disorders. Nature communications, 17(1), 5482. https://doi.org/10.1038/s41467-026-72164-7

BibTeX

@article{gong2026multivariate,
author = {Gong, Weiming and Guo, Yantong and Sun, Xiubin and Wang, Shukang and Xue, Fuzhong and Zhao, Wei and Zhou, Xiang and Liu, Lu and Yuan, Zhongshang},
title = {{Multivariate genetic analysis reveals three distinct pathological dimensions in musculoskeletal disorders}},
journal = {Nature communications},
year = {2026},
month = apr,
volume = {17},
number = {1},
pages = {5482},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/s41467-026-72164-7},
url = {https://doi.org/10.1038/s41467-026-72164-7},
pmid = {42014408},
pmcid = {PMC13284391}
}

RIS

TY - JOUR
AU - Gong, Weiming
AU - Guo, Yantong
AU - Sun, Xiubin
AU - Wang, Shukang
AU - Xue, Fuzhong
AU - Zhao, Wei
AU - Zhou, Xiang
AU - Liu, Lu
AU - Yuan, Zhongshang
TI - Multivariate genetic analysis reveals three distinct pathological dimensions in musculoskeletal disorders
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/04/21
VL - 17
IS - 1
SP - 5482
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/s41467-026-72164-7
UR - https://doi.org/10.1038/s41467-026-72164-7
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41467-026-72164-7",
"type": "article-journal",
"title": "Multivariate genetic analysis reveals three distinct pathological dimensions in musculoskeletal disorders",
"container-title": "Nature communications",
"author": [
{
"family": "Gong",
"given": "Weiming"
},
{
"family": "Guo",
"given": "Yantong"
},
{
"family": "Sun",
"given": "Xiubin"
},
{
"family": "Wang",
"given": "Shukang"
},
{
"family": "Xue",
"given": "Fuzhong"
},
{
"family": "Zhao",
"given": "Wei"
},
{
"family": "Zhou",
"given": "Xiang"
},
{
"family": "Liu",
"given": "Lu"
},
{
"family": "Yuan",
"given": "Zhongshang"
}
],
"container-title-short": "Nat Commun",
"volume": "17",
"issue": "1",
"page": "5482",
"DOI": "10.1038/s41467-026-72164-7",
"PMID": "42014408",
"PMCID": "PMC13284391",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41467-026-72164-7",
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
21
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-026-73428-y [code]
Regional heterogeneity in phenotypic and genetic associations between bone and brain in humans.
Journal: Nature communications
In common: lavaan, BEDTools, psych, 7 other tools, genetics / omics, 9 references
[2] doi:10.1038/s43856-026-01510-z [code]
Mapping genetic convergence across brain structure, mental health, and cardiometabolic disease.
Journal: Communications medicine
In common: lavaan, BEDTools, psych, 8 other tools, genetics / omics, 4 references
[3] doi:10.1038/s41467-026-71803-3 [code]
Charting the transition from in vitro gliogenesis to the in vivo maturation of human glial progenitor cells transplanted into the hypomyelinated mouse brain.
Journal: Nature communications
In common: BEDTools, anndata, Numba, 12 other tools, genetics / omics, mouse
[4] doi:10.1038/s41562-026-02486-5 [code]
Genome-wide association studies of infant and toddler temperament in European and multi-ancestry populations.
Journal: Nature human behaviour
In common: psych, data.table, ggplot2, 4 other tools, genetics / omics, 8 references
[5] doi:10.1038/s41592-026-03194-8 [code]
Beyond benchmarking: an expert-guided consensus approach to spatially aware clustering.
Journal: Nature methods
In common: PyTorch Geometric, anndata, Scanpy, 10 other tools, genetics / omics, 1 reference
[6] doi:10.1186/s13059-026-04177-w [code]
Genomic sequence evolution underlying human neocortical interareal diversification.
Journal: Genome biology
In common: BEDTools, anndata, Scanpy, 10 other tools, genetics / omics, mouse
[7] doi:10.1016/j.isci.2026.116055 [code]
Mapping the transcriptional diversity of calcium signaling in the mouse and human brain.
Journal: iScience
In common: PyTorch Geometric, anndata, Numba, 10 other tools, genetics / omics, mouse
[8] doi:10.1016/j.xcrm.2026.102766 [code]
A longitudinal single-cell and spatial multiomic atlas of pediatric high-grade glioma.
Journal: Cell reports. Medicine
In common: anndata, Numba, Scanpy, 10 other tools, genetics / omics
[9] doi:10.1038/s41467-026-71682-8 [code]
GWAS meta-analysis of cerebrospinal fluid Alzheimer's biomarkers reveals loci regulating lipids, brain volume and autophagy.
Journal: Nature communications
In common: BEDTools, data.table, ggplot2, 5 other tools, genetics / omics, 6 references
[10] doi:10.1002/imt2.70163 [code]
Spatial multi-omics unveils sphingolipid metabolic reprogramming within the retinal pathological niche.
Journal: iMeta
In common: anndata, Scanpy, pheatmap, 9 other tools, genetics / omics, mouse, 1 reference

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.