春药网

孟德尔立时化R包TwoSampleMR装置教程并诞生token

发布日期:2025-05-10 21:13    点击次数:94

全球好,我是邓飞,今天先容一下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] ""

不错看到,莫得诞生。

365站群VIP

那就需要在文档文献夹中,新建一个.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)

运转成果:

图片

作图成果:

迷水商城

图片

这就处理了。

本站仅提供存储劳动,通盘本色均由用户发布,如发现存害或侵权本色,请点击举报。

上一篇:S妈被曝哀悼过度被送急诊,腹黑难过致呼吸贫困
下一篇:医学三基现实题库及谜底(完满版)