ieugwasr :: ld_matrix无法提取LD矩阵

发布于 2025-02-08 06:41:23 字数 6101 浏览 1 评论 0原文

我希望使用ieugwasr :: ld_matrix提取LD矩阵。但是,我无法这样做,因为ld_matrix不会将.bim文件写入我的TMP文件夹。可重现的示例如下:

variants <- c("rs12167289", "rs186528764", "rs12168819", "rs547447196", "rs117281477", "rs62230011", "rs6519012",   "rs71314992",  "rs555424086", "rs140000", "rs8140240", "rs62230012", "rs73169675")

extracted_matrix <- ld_matrix(
  variants = variants,
  plink_bin = genetics.binaRies::get_plink_binary(),
  bfile = 'path/to/LD/reference/local/dataset/EUR')

输出:

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'C:\Users\jajoko\AppData\Local\Temp\RtmpW0YWmm\file2c90686ec4.bim': No such file or directory

trackback()给出了

4: file(file, "rt")
3: read.table(paste0(fn, ".bim"), stringsAsFactors = FALSE)
2: ld_matrix_local(variants, bfile = bfile, plink_bin = plink_bin, 
       with_alleles = with_alleles)
1: ld_matrix(variants = variants, plink_bin = genetics.binaRies::get_plink_binary(), 
       bfile = "path/to/LD/reference/local/dataset/EUR")

临时折叠器的确没有陈述的.bim文件。相反,它具有具有相同名称的文件,但没有包含变体名称的.bim扩展名。查看ld_matrix_local(),该> 是ld_matrix()在本地给出plink引用时,变体似乎传递了第一部分,其中tmp文件没有文件,没有文件进行扩展是进行了扩展的

plink_bin = genetics.binaRies::get_plink_binary()
bfile = "path/to/LD/reference/local/dataset/EUR"

ld_matrix_local <- function(variants, bfile, plink_bin, with_alleles=TRUE)
{

    # Make textfile
  shell <- ifelse(Sys.info()['sysname'] == "Windows", "cmd", "sh")
  fn <- tempfile()
  write.table(data.frame(variants), file=fn, row.names=F, col.names=F, quote=F)

,但似乎失败了第二部分,即

    shQuote(plink_bin, type=shell),
    " --bfile ", shQuote(bfile, type=shell),
    " --extract ", shQuote(fn, type=shell), 
    " --make-just-bim ", 
    " --keep-allele-order ",
    " --out ", shQuote(fn, type=shell)
  )
  system(fun1)

在尝试读取.bim文件时最终失败

bim <- read.table(paste0(fn, ".bim"), stringsAsFactors=FALSE)

的第二部分似乎在ld_matrix_local()从同一文件中制作一个.ld文件

 
  fun2 <- paste0(
    shQuote(plink_bin, type=shell),
    " --bfile ", shQuote(bfile, type=shell),
    " --extract ", shQuote(fn, type=shell), 
    " --r square ", 
    " --keep-allele-order ",
    " --out ", shQuote(fn, type=shell)
  )
  system(fun2)
  res <- read.table(paste0(fn, ".ld"), header=FALSE) %>% as.matrix
  if(with_alleles)
  {
    rownames(res) <- colnames(res) <- paste(bim$V2, bim$V5, bim$V6, sep="_")
  } else {
    rownames(res) <- colnames(res) <- bim$V2
  }
  return(res)
}

我在做什么错?我成功地重新安装了遗传学。使用devtools :: install_github()的binaries,以防万一,因为最初使用远程安装时我在安装远程:: install_github时会收到一些错误消息(“ mrcieu/genetics.binaries”)。这甚至是正确的论坛吗?

sessioninfo()

R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393)

Matrix products: default

locale:
[1] LC_COLLATE=Finnish_Finland.1252  LC_CTYPE=Finnish_Finland.1252    LC_MONETARY=Finnish_Finland.1252 LC_NUMERIC=C                     LC_TIME=Finnish_Finland.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.5.1   stringr_1.4.0   dplyr_1.0.8     purrr_0.3.4     readr_2.1.2     tidyr_1.2.0     tibble_3.1.6    ggplot2_3.3.6   tidyverse_1.3.1 ieugwasr_0.1.5  workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] httr_1.4.2                   pkgload_1.2.4                jsonlite_1.8.0               modelr_0.1.8                 brio_1.1.3                   assertthat_0.2.1            
 [7] getPass_0.2-2                cellranger_1.1.0             yaml_2.3.5                   remotes_2.4.2                sessioninfo_1.2.2            pillar_1.7.0                
[13] backports_1.4.1              glue_1.6.2                   digest_0.6.29                promises_1.2.0.1             rvest_1.0.2                  colorspace_2.0-3            
[19] htmltools_0.5.2              httpuv_1.6.5                 pkgconfig_2.0.3              devtools_2.4.3               broom_0.7.12                 haven_2.4.3                 
[25] scales_1.2.0                 processx_3.5.2               whisker_0.4                  later_1.3.0                  tzdb_0.2.0                   git2r_0.30.1                
[31] generics_0.1.2               usethis_2.1.5                ellipsis_0.3.2               cachem_1.0.6                 pacman_0.5.1                 withr_2.5.0                 
[37] cli_3.1.0                    readxl_1.3.1                 magrittr_2.0.2               crayon_1.5.0                 memoise_2.0.1                evaluate_0.15               
[43] ps_1.6.0                     fs_1.5.2                     fansi_1.0.3                  xml2_1.3.3                   pkgbuild_1.3.1               tools_4.1.3                 
[49] prettyunits_1.1.1            hms_1.1.1                    lifecycle_1.0.1              reprex_2.0.1                 munsell_0.5.0                callr_3.7.0                 
[55] compiler_4.1.3               rlang_1.0.2                  grid_4.1.3                   rstudioapi_0.13              rmarkdown_2.14               testthat_3.1.2              
[61] gtable_0.3.0                 DBI_1.1.2                    curl_4.3.2                   R6_2.5.1                     lubridate_1.8.0              knitr_1.39                  
[67] fastmap_1.1.0                utf8_1.2.2                   rprojroot_2.0.2              desc_1.4.1                   stringi_1.7.6                genetics.binaRies_0.0.0.9000
[73] Rcpp_1.0.8.3                 vctrs_0.4.1                  dbplyr_2.1.1                 tidyselect_1.1.2             xfun_0.30                    

function ieugwasr :: ld_matrix()可以找到在这里

I would wish to extract LD matrix using ieugwasr::ld_matrix. However, I am unable to do so, because ld_matrix does not write a .bim file to my tmp folder. A reproducible example as follows:

variants <- c("rs12167289", "rs186528764", "rs12168819", "rs547447196", "rs117281477", "rs62230011", "rs6519012",   "rs71314992",  "rs555424086", "rs140000", "rs8140240", "rs62230012", "rs73169675")

extracted_matrix <- ld_matrix(
  variants = variants,
  plink_bin = genetics.binaRies::get_plink_binary(),
  bfile = 'path/to/LD/reference/local/dataset/EUR')

Output:

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'C:\Users\jajoko\AppData\Local\Temp\RtmpW0YWmm\file2c90686ec4.bim': No such file or directory

traceback() gives

4: file(file, "rt")
3: read.table(paste0(fn, ".bim"), stringsAsFactors = FALSE)
2: ld_matrix_local(variants, bfile = bfile, plink_bin = plink_bin, 
       with_alleles = with_alleles)
1: ld_matrix(variants = variants, plink_bin = genetics.binaRies::get_plink_binary(), 
       bfile = "path/to/LD/reference/local/dataset/EUR")

The Temp-folder indeed does not have the stated .bim-file. Instead, it has a file with the same name but without the .bim extension that includes the names of the variants. When looking at the ld_matrix_local(), which is used by ld_matrix() when plink references are given locally, the variants seem to pass the first part where tmp file without a file extension is made

plink_bin = genetics.binaRies::get_plink_binary()
bfile = "path/to/LD/reference/local/dataset/EUR"

ld_matrix_local <- function(variants, bfile, plink_bin, with_alleles=TRUE)
{

    # Make textfile
  shell <- ifelse(Sys.info()['sysname'] == "Windows", "cmd", "sh")
  fn <- tempfile()
  write.table(data.frame(variants), file=fn, row.names=F, col.names=F, quote=F)

but seems to fail the second part where plink is called to make a .bim file

    shQuote(plink_bin, type=shell),
    " --bfile ", shQuote(bfile, type=shell),
    " --extract ", shQuote(fn, type=shell), 
    " --make-just-bim ", 
    " --keep-allele-order ",
    " --out ", shQuote(fn, type=shell)
  )
  system(fun1)

And ultimately fails when trying to read the .bim file

bim <- read.table(paste0(fn, ".bim"), stringsAsFactors=FALSE)

The same seems to happen with the second part of the ld_matrix_local() that makes a .ld file from the same file

 
  fun2 <- paste0(
    shQuote(plink_bin, type=shell),
    " --bfile ", shQuote(bfile, type=shell),
    " --extract ", shQuote(fn, type=shell), 
    " --r square ", 
    " --keep-allele-order ",
    " --out ", shQuote(fn, type=shell)
  )
  system(fun2)
  res <- read.table(paste0(fn, ".ld"), header=FALSE) %>% as.matrix
  if(with_alleles)
  {
    rownames(res) <- colnames(res) <- paste(bim$V2, bim$V5, bim$V6, sep="_")
  } else {
    rownames(res) <- colnames(res) <- bim$V2
  }
  return(res)
}

What am I doing wrong? I succesfully reinstalled genetics.binaRies using devtools::install_github() just in case, because initially I got some error messages when installing it using remotes::install_github("MRCIEU/genetics.binaRies"). Is this even the right forum to ask this?

sessionInfo()

R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393)

Matrix products: default

locale:
[1] LC_COLLATE=Finnish_Finland.1252  LC_CTYPE=Finnish_Finland.1252    LC_MONETARY=Finnish_Finland.1252 LC_NUMERIC=C                     LC_TIME=Finnish_Finland.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.5.1   stringr_1.4.0   dplyr_1.0.8     purrr_0.3.4     readr_2.1.2     tidyr_1.2.0     tibble_3.1.6    ggplot2_3.3.6   tidyverse_1.3.1 ieugwasr_0.1.5  workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] httr_1.4.2                   pkgload_1.2.4                jsonlite_1.8.0               modelr_0.1.8                 brio_1.1.3                   assertthat_0.2.1            
 [7] getPass_0.2-2                cellranger_1.1.0             yaml_2.3.5                   remotes_2.4.2                sessioninfo_1.2.2            pillar_1.7.0                
[13] backports_1.4.1              glue_1.6.2                   digest_0.6.29                promises_1.2.0.1             rvest_1.0.2                  colorspace_2.0-3            
[19] htmltools_0.5.2              httpuv_1.6.5                 pkgconfig_2.0.3              devtools_2.4.3               broom_0.7.12                 haven_2.4.3                 
[25] scales_1.2.0                 processx_3.5.2               whisker_0.4                  later_1.3.0                  tzdb_0.2.0                   git2r_0.30.1                
[31] generics_0.1.2               usethis_2.1.5                ellipsis_0.3.2               cachem_1.0.6                 pacman_0.5.1                 withr_2.5.0                 
[37] cli_3.1.0                    readxl_1.3.1                 magrittr_2.0.2               crayon_1.5.0                 memoise_2.0.1                evaluate_0.15               
[43] ps_1.6.0                     fs_1.5.2                     fansi_1.0.3                  xml2_1.3.3                   pkgbuild_1.3.1               tools_4.1.3                 
[49] prettyunits_1.1.1            hms_1.1.1                    lifecycle_1.0.1              reprex_2.0.1                 munsell_0.5.0                callr_3.7.0                 
[55] compiler_4.1.3               rlang_1.0.2                  grid_4.1.3                   rstudioapi_0.13              rmarkdown_2.14               testthat_3.1.2              
[61] gtable_0.3.0                 DBI_1.1.2                    curl_4.3.2                   R6_2.5.1                     lubridate_1.8.0              knitr_1.39                  
[67] fastmap_1.1.0                utf8_1.2.2                   rprojroot_2.0.2              desc_1.4.1                   stringi_1.7.6                genetics.binaRies_0.0.0.9000
[73] Rcpp_1.0.8.3                 vctrs_0.4.1                  dbplyr_2.1.1                 tidyselect_1.1.2             xfun_0.30                    

code for function ieugwasr::ld_matrix() can be found here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话里做英雄 2025-02-15 06:41:23

由于您的代码无法运行PLINK,因此您可以在服务器上下载PLINK1.9,请测试PLINK以确保其有效,然后设置plink_bin ='plink'或plink二进制的路径。

Because your code can't run plink, you can download plink1.9 on the server, test plink to make sure it works, then set plink_bin = 'plink' or the path to plink binary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文