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

Output Options for ldfast() #7

Open
dcgerard opened this issue Jul 21, 2022 · 1 comment
Open

Output Options for ldfast() #7

dcgerard opened this issue Jul 21, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@dcgerard
Copy link
Owner

It would be great if

  1. ldfast() kept SNP names (as row and column names)
  2. ldfast() allowed for a return type of data.frame
  3. ldfast() had an option to keep SNP locations.

Thanks to Heather Tuttle for the suggestion.

As a workaround until I make this a feature, you can use:

library(updog)
library(ldsep)
library(reshape2)

## Get data and fit ldfast ----
data("uit", package = "ldsep")
gp <- format_multidog(x = uit, varname = paste0("Pr_", 0:4))
ldout <- ldfast(gp = gp, type = "r2")

## Format to data frame ----
colnames(ldout$ldmat) <- rownames(ldout$ldmat) <- dimnames(gp)$snp
ldout$ldmat[lower.tri(ldout$ldmat, diag = TRUE)] <- NA
lddf <- melt(ldout$ldmat, na.rm = TRUE)
lddf

You can then use a tool like merge() or dplyr::left_join() to add genomic positions to this data frame.

@dcgerard dcgerard added the enhancement New feature or request label Jul 21, 2022
@dcgerard dcgerard changed the title Data Frame Output Option for ldfast() Output Options for ldfast() Jul 21, 2022
@dcgerard
Copy link
Owner Author

dcgerard commented Aug 3, 2022

To finish off this example, and provide code for an LD decay plot (as also suggested by @lfelipe-ferrao), here is some quick and dirty code:

library(dplyr)
library(ggplot2)
library(scam) ## monotone constraint

## Suppose we have the following genotype locations
dfloc <- data.frame(SNP = rownames(ldout$ldmat), loc = 1:10)

## Merge LD estimates
lddf |>
  left_join(dfloc, by = c("Var1" = "SNP")) |>
  left_join(dfloc, by = c("Var2" = "SNP")) |>
  rename(SNP1 = Var1, SNP2 = Var2, r2 = value, Loc1 = loc.x, Loc2 = loc.y) |>
  mutate(dist = abs(Loc1 - Loc2)) |>
  distinct(SNP1, SNP2, .keep_all = TRUE) ->
  lddf

## Make plot
ggplot(data = lddf, mapping = aes(x = dist, y = r2)) +
  geom_point() +
  geom_smooth(method = scam, formula = y ~ s(x, bs = c("mdcx", k = 8)), se = FALSE)

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

No branches or pull requests

1 participant