草榴电影

亚洲成人网址 孟德尔立时化R包TwoSampleMR安设教程并开拓token

发布日期:2025-07-03 14:46    点击次数:98

亚洲成人网址 孟德尔立时化R包TwoSampleMR安设教程并开拓token

公共好亚洲成人网址,我是邓飞,今天先容一下TwoSampleMR包奈何开拓token,从而不错使用数据库的数据进行孟德尔立时化的分析。

1,安设TwoSampleMR包

这个包在github上头,之前流行用devtools包安设github上的R包,然而devtools自身就特别难安设,好在现时有了 remotes包,这个包相比好安设,进而github上头的包也相比好安设了。

# install.packages("remotes")library(remotes)install_github("MRCIEU/TwoSampleMR")

将上头的代码贴到Rstudio中扩充,就不错了。要是走漏莫得 remote包,就把防卫去掉,再启动就行了。

图片

2, 启动MR示例数据
library(TwoSampleMR)# List available GWASsao <- available_outcomes()# Get instrumentsexposure_dat <- extract_instruments("ieu-a-2")# Get effects of instruments on outcomeoutcome_dat <- extract_outcome_data(snps=exposure_dat$SNP, outcomes = "ieu-a-7")# Harmonise the exposure and outcome datadat <- harmonise_data(exposure_dat, outcome_dat)# Perform MR

然后发现报错了:

> library(TwoSampleMR)TwoSampleMR version 0.6.8 载入程辑包:'TwoSampleMR’The following object is masked from 'package:remotes’:    add_metadata> # List available GWASs> ao <- available_outcomes()Error in `dplyr::bind_rows()`:! Argument 1 must be a data frame or a named atomic vector.

报错的信息是:Error in dplyr::bind_rows():! Argument 1 must be a data frame or a named atomic vector.Run rlang::last_trace() to see where the error occurred.

看起来是dplyr的错,其实不是,赓续启动望望能不可读取ieu的数据:

> bmi_exp_dat <- extract_instruments(outcomes = 'ieu-a-2')

现时的报错信息是:> bmi_exp_dat <- extract_instruments(outcomes = 'ieu-a-2')Error in if (nrow(d) == 0) return(NULL) : 参数长度为零

忧伤,要是你认为我方是R话语大神,思从R话语包安设的角度,包突破的角度去解决问题,临了很大可能是 砸电脑!!!

正确的解决顺次,是稽查官网,要是你把报错信息贴到网上头,大略率亦然找不到谜底,因为之前TwoSampleMR还莫得这个问题,网上的东西是相互抄,垃圾信息满天飞,第一手府上弥远是官网。

https://mrcieu.github.io/ieugwasr/articles/guide.html

内部有一句话:

From 1st May 2024, most queries to the OpenGWAS API will require user authentication. For more information on why this is necessary, see this [blog post](https://blog.opengwas.io/posts/user-auth-spring-2024/).

从2024年5月1号,TwoSampleMR包需要开拓token之后,才不错探访数据库,是以,底下等于奈何开拓token的问题了。

3,TwoSampleMR开拓token

官方保举决策:

A:更新你的R包

Please update your TwoSampleMR and ieugwasr packages - you can use the following command to do this.

install.packages("TwoSampleMR", repos = c("https://mrcieu.r-universe.dev", "https://cran.r-project.org"))

B:开拓token

Then you need to obtain an OPENGWAS_JWT token - see the ieugwasr documentation https://mrcieu.github.io/ieugwasr/articles/guide.html - and store it in your .Renviron file - then restart R.

Login to https://api.opengwas.io/profile/

Generate a new token

Add OPENGWAS_JWT=<token> to your .Renviron file. This file could be either in your home directory or in the working directory of your R session. You can check the location of your .Renviron file by running Sys.getenv("R_ENVIRON_USER") in R.

Restart your R session

To check that your token is being recognised, run [ieugwasr::get_opengwas_jwt()](https://mrcieu.github.io/ieugwasr/reference/get_opengwas_jwt.html). If it returns a long random string then you are authenticated.

To check that your token is working, run [user()](https://mrcieu.github.io/ieugwasr/reference/user.html). It will make a request to the API for your user information using your token. It should return a list with your user information. If it returns an error, then your token is not working.

底下,我将上头的圭臬,联接我我方的得胜操作历程,先容一下,随着我的圭臬,你也详情能管束啦!

3.1 登录opengwas,注册一下

登录注册,用github账号,https://api.opengwas.io/profile/

3.2 创建token

按照底下的截图就能管束。

图片

把token复制一下。

3.3 在R话语中检测是否有token

要是之前莫得开拓过,详情是莫得的。

 Sys.getenv("R_ENVIRON_USER")

我的复返效用:

> Sys.getenv("R_ENVIRON_USER")[1] ""

不错看到,莫得开拓。

黑丝捆绑

那就需要在文档文献夹中,新建一个.Renviron文献

图片

3.4 把token放到新建的.Renviron文献中
OPENGWAS_JWT="这里粘贴你的token"

图片

3.5 重启R话语(必须)

重启R话语,然后键入底下代码,测试token是否开拓得胜:

## 测试token是否灵验library(ieugwasr)user()

图片

不错看到个东说念主的信息,就开拓得胜了。

4. 测试MR示例数据
library(TwoSampleMR)# List available GWASsao <- available_outcomes()# Get instrumentsexposure_dat <- extract_instruments("ieu-a-2")# Get effects of instruments on outcomeoutcome_dat <- extract_outcome_data(snps=exposure_dat$SNP, outcomes = "ieu-a-7")# Harmonise the exposure and outcome datadat <- harmonise_data(exposure_dat, outcome_dat)# Perform MRres <- mr(dat)

启动效用:

图片

作图效用:

图片

这就管束了亚洲成人网址。

本站仅提供存储做事,系数现实均由用户发布,如发现存害或侵权现实,请点击举报。

 




Powered by 草榴电影 @2013-2022 RSS地图 HTML地图

Copyright Powered by站群系统 © 2013-2024