Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update ld_matrix_local to create variant ID and standardise #33

Open
explodecomputer opened this issue May 18, 2023 · 1 comment
Open
Assignees

Comments

@explodecomputer
Copy link
Collaborator

explodecomputer commented May 18, 2023

Update https://github.com/MRCIEU/ieugwasr/blob/master/R/ld_matrix.R#L92

  • extract by chr:pos
  • Rows and columns are variant ID
  • r values in matrix are flipped according to variant ID.

Example:

  harmonise_ld <- function(d, rho)  {
    toflip <- d$effect_allele.exposure < d$other_allele.exposure
    d$beta.exposure[toflip] <- d$beta.exposure[toflip] * -1
    d$beta.outcome[toflip] <- d$beta.outcome[toflip] * -1
    temp <- d$effect_allele.exposure[toflip]
    d$effect_allele.exposure[toflip] <- d$other_allele.exposure[toflip]
    d$other_allele.exposure[toflip] <- temp
    rhoid <- do.call(rbind, strsplit(rownames(rho), split = "_")) |> as.data.frame(stringsAsFactors=FALSE)
    toflip2 <- rhoid$V2 < rhoid$V3
    temp <- rhoid$V2[toflip]
    rhoid$V2[toflip] <- rhoid$V3[toflip]
    rhoid$V3[toflip] <- temp
    rho[toflip, ] <- rho[toflip, ] * -1
    rho[, toflip] <- rho[, toflip] * -1
    return(list(d=d, rho=rho))
  }
@JonnyBaseball
Copy link

Thanks! I tried to do the same but not as elegantly! To be clear, this not only aligns alleles with the reference 1000G but also returns the ld matrix in same order as input data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants