123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836 |
- <!DOCTYPE html>
- <html lang="en" data-default-color-scheme=auto>
- <head><!-- hexo injector head_begin start -->
- <script defer src="https://api.limour.top/vue/0d2f95c1-755d-436b-adf8-eee12a80ed32/script.js"></script>
- <!-- hexo injector head_begin end -->
- <meta charset="UTF-8">
- <link rel="apple-touch-icon" sizes="76x76" href="https://img.limour.top/2023/08/29/64ee07361815a.webp">
- <link rel="icon" href="https://img.limour.top/2023/08/29/64ee07361815a.webp">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
- <meta http-equiv="x-ua-compatible" content="ie=edge">
-
- <meta name="theme-color" content="#2f4154">
- <meta name="author" content="Limour">
- <meta name="keywords" content="">
-
- <meta name="description" content="MR定义 孟德尔随机化是一种基于全基因组测序数据(GWAS数据),利用单核首酸多态性(SNPs)作为工具变量(IV),用于揭示因果关系的新型流行病学方法,相较于队列研究等观察性研究,暴露在出生前便已确定,较少受到反向因果及混杂因素的影响,因而能够有效减少偏倚。 MR的核心是运用遗传学数据作为桥梁,来探索某一暴露和某一结局之间的因果关联。与RCT将参与者随机分配到试验组或对照组类似,MR研究基于影">
-
-
-
- <title>【学习】孟德尔随机化 - Limour's Blog</title>
- <link rel="stylesheet" href="https://jscdn.limour.top/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" />
- <link rel="stylesheet" href="https://jscdn.limour.top/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
- <link rel="stylesheet" href="https://jscdn.limour.top/npm/hint.css@2.7.0/hint.min.css" />
- <!-- 主题依赖的图标库,不要自行修改 -->
- <!-- Do not modify the link that theme dependent icons -->
- <link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">
- <link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">
- <link rel="stylesheet" href="/css/main.css" />
- <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
-
- <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
-
-
- <link rel="stylesheet" href="/theme-inject/custom.css">
- <link rel="stylesheet" href="/theme-inject/iconfont.css">
- <script id="fluid-configs">
- var Fluid = window.Fluid || {};
- Fluid.ctx = Object.assign({}, Fluid.ctx)
- var CONFIG = {"hostname":"hexo.limour.top","root":"/","version":"1.9.7","typing":{"enable":false,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":"§"},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":false,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"https://jscdn.limour.top/gh/Limour-dev/Sakurairo_Vision/load_svg/inload.svg","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};
- if (CONFIG.web_analytics.follow_dnt) {
- var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
- Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
- }
- </script>
- <script src="/js/utils.js" ></script>
- <script src="/js/color-schema.js" ></script>
-
-
- <link rel="canonical" href="https://hexo.limour.top/Mendelian-Randomization"/>
- <meta name="generator" content="Hexo 7.1.1"><link rel="alternate" href="/atom.xml" title="Limour's Blog" type="application/atom+xml">
- <link rel="alternate" href="/rss2.xml" title="Limour's Blog" type="application/rss+xml">
- </head>
- <body>
-
- <header>
-
- <div class="header-inner" style="height: 70vh;">
- <nav id="navbar" class="navbar fixed-top navbar-expand-lg navbar-dark scrolling-navbar">
- <div class="container">
- <a class="navbar-brand" href="/">
- <strong>Limour's Blog</strong>
- </a>
- <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
- data-target="#navbarSupportedContent"
- aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
- <div class="animated-icon"><span></span><span></span><span></span></div>
- </button>
- <!-- Collapsible content -->
- <div class="collapse navbar-collapse" id="navbarSupportedContent">
- <ul class="navbar-nav ml-auto text-center">
-
-
-
-
-
- <li class="nav-item">
- <a class="nav-link" href="https://hexo.limour.top/" target="_self">
- <i class="iconfont icon-home-fill"></i>
- <span>Home</span>
- </a>
- </li>
-
-
-
-
-
-
- <li class="nav-item">
- <a class="nav-link" href="/archives/" target="_self">
- <i class="iconfont icon-archive-fill"></i>
- <span>Archive1</span>
- </a>
- </li>
-
-
-
-
-
-
- <li class="nav-item">
- <a class="nav-link" href="https://occdn.limour.top/archives/" target="_self">
- <i class="iconfont icon-archive-fill"></i>
- <span>Archive2</span>
- </a>
- </li>
-
-
-
-
-
-
- <li class="nav-item">
- <a class="nav-link" href="https://b.limour.top/archives/" target="_self">
- <i class="iconfont icon-archive-fill"></i>
- <span>Archive3</span>
- </a>
- </li>
-
-
-
-
-
-
- <li class="nav-item">
- <a class="nav-link" href="https://od.limour.top/" target="_self">
- <i class="iconfont icon-onedrive"></i>
- <span>Alist</span>
- </a>
- </li>
-
-
-
-
-
-
- <li class="nav-item">
- <a class="nav-link" href="https://orcid.org/0000-0001-8897-1685" target="_self">
- <i class="iconfont icon-orcid"></i>
- <span>Orcid</span>
- </a>
- </li>
-
-
-
-
-
-
- <li class="nav-item">
- <a class="nav-link" href="/links/" target="_self">
- <i class="iconfont icon-link-fill"></i>
- <span>Links</span>
- </a>
- </li>
-
-
-
-
-
-
- <li class="nav-item">
- <a class="nav-link" href="/atom.xml" target="_self">
- <i class="iconfont icon-rss"></i>
- <span>RSS</span>
- </a>
- </li>
-
-
-
- <li class="nav-item" id="search-btn">
- <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
- <i class="iconfont icon-search"></i>
- </a>
- </li>
-
-
-
- <li class="nav-item" id="color-toggle-btn">
- <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
- <i class="iconfont icon-dark" id="color-toggle-icon"></i>
- </a>
- </li>
-
- </ul>
- </div>
- </div>
- </nav>
-
- <div id="banner" class="banner" parallax=true
- style="background: url('https://img.limour.top/2023/08/29/64ee08e108638.webp') no-repeat center center; background-size: cover;">
- <div class="full-bg-img">
- <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
- <div class="banner-text text-center fade-in-up">
- <div class="h2">
-
- <span id="subtitle">【学习】孟德尔随机化</span>
-
- </div>
-
-
- <div class="mt-3">
-
- <span class="post-meta mr-2">
- <i class="iconfont icon-author" aria-hidden="true"></i>
- Limour
- </span>
-
-
- <span class="post-meta">
- <i class="iconfont icon-date-fill" aria-hidden="true"></i>
- <time datetime="2023-10-14 17:18" pubdate>
- October 14, 2023 pm
- </time>
- </span>
-
- </div>
- <div class="mt-1">
-
- <span class="post-meta mr-2">
- <i class="iconfont icon-chart"></i>
-
- 2.7k words
-
- </span>
-
-
- <span class="post-meta mr-2">
- <i class="iconfont icon-clock-fill"></i>
-
-
-
- 23 mins
-
- </span>
-
-
-
- </div>
-
- </div>
-
- </div>
- </div>
- </div>
- </div>
- </header>
- <main>
-
-
- <div class="container-fluid nopadding-x">
- <div class="row nomargin-x">
- <div class="side-col d-none d-lg-block col-lg-2">
-
- </div>
- <div class="col-lg-8 nopadding-x-md">
- <div class="container nopadding-x-md" id="board-ctn">
- <div id="board">
- <article class="post-content mx-auto">
- <h1 id="seo-header">【学习】孟德尔随机化</h1>
-
- <p id="updated-time" class="note note-info" style="">
-
-
- Last updated on March 19, 2024 pm
-
-
- </p>
-
-
- <div class="markdown-body">
-
- <h2 id="MR定义">MR定义</h2>
- <p>孟德尔随机化是一种基于全基因组测序数据(GWAS数据),利用单核首酸多态性(SNPs)作为工具变量(IV),用于揭示因果关系的新型流行病学方法,相较于队列研究等观察性研究,暴露在出生前便已确定,较少受到反向因果及混杂因素的影响,因而能够有效减少偏倚。<br>
- <img src="https://img.limour.top/2023/10/14/652a61ab222a4.webp" srcset="https://jscdn.limour.top/gh/Limour-dev/Sakurairo_Vision/load_svg/inload.svg" lazyload alt="RCT与MR的比较"><br>
- MR的核心是运用遗传学数据作为桥梁,来探索某一暴露和某一结局之间的因果关联。与RCT将参与者随机分配到试验组或对照组类似,MR研究基于影响危险因素的一个或多个等位基因,对参与基因进行"随机化"(自然的随机化),以确定这些遗传变异的携带者与非携带者相比,是否具有不同的疾病发生风险,因此,孟德尔随机化可以被认为类似于<a href="https://hexo.limour.top/go/#aHR0cHM6Ly93d3cubmNiaS5ubG0ubmloLmdvdi9wbWMvYXJ0aWNsZXMvUE1DMjQ1ODE0NA==" rel="noopener external nofollow noreferrer">"自然的随机对照试验"</a>。<a href="https://hexo.limour.top/go/#aHR0cHM6Ly9tci1kaWN0aW9uYXJ5Lm1yY2lldS5hYy51ay8=" rel="noopener external nofollow noreferrer">MR的相关术语</a></p>
- <h2 id="理论假设">理论假设</h2>
- <ol>
- <li>the variant is associated with the exposure</li>
- <li>the variant is not associated with the outcome via a confounding pathway</li>
- <li>the variant does not affect the outcome directly, only possibly indirectly via the exposure</li>
- </ol>
- <p><img src="https://img.limour.top/2023/10/14/652a651b96f98.webp" srcset="https://jscdn.limour.top/gh/Limour-dev/Sakurairo_Vision/load_svg/inload.svg" lazyload alt="孟德尔随机化框架的有向无环图表示"></p>
- <ol>
- <li>关联性假设:变异与暴露有关</li>
- <li>独立性假设:变异与结果之间没有通过混杂途径相关</li>
- <li>排他性假设:变异不直接影响结果,只可能通过暴露途径间接影响</li>
- </ol>
- <ul>
- <li>关联性假设:p值,F统计量,R^2</li>
- <li>排他性假设:与结局的相关性计算时,p值要大于0.05</li>
- <li><a href="https://hexo.limour.top/go/#aHR0cHM6Ly9kb2kub3JnLzEwLjEwOTMvaWplL2R5djA4MA==" rel="noopener external nofollow noreferrer">MR-Egger</a>回归相比线性回归可以弱化对排他性假设的要求</li>
- </ul>
- <h2 id="适用范围">适用范围</h2>
- <ul>
- <li>不确定先有鸡还是先有蛋,比如,到底是抑郁导致肺癌还是肺癌导致了抑郁?</li>
- <li>暴露因素难以测量,或者花费昂贵。例如,水溶性维生素等生物标志物的检测金标准可能成本太高,大样本无法承受,或者空腹血糖的测量需要隔夜空腹,可能不现实。</li>
- <li>暴露与结局数据来自同一人群,且不存在或存在少量可接受范围内的样本重叠</li>
- </ul>
- <h2 id="配置环境">配置环境</h2>
- <ul>
- <li><a href="/-ji-lu--an-zhuang-sheng-xin-de-dai-ma-bian-xie-huan-jing">基础编程环境</a></li>
- <li><a href="/-fu-ke-GitHub-wen-jian-jia-su">GitHub 下载加速</a></li>
- <li><a href="/-ji-lu-SOCKS5-zhuan-QUIC">可能需要用到的加速服务</a></li>
- </ul>
- <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs bash">conda create -n MR -c conda-forge r-devtools -y<br>conda activate MR<br>conda install -c conda-forge r-irkernel -y<br>Rscript -e <span class="hljs-string">"IRkernel::installspec(name='MR', displayname='MR')"</span><br><span class="hljs-comment"># Rscript -e "usethis::edit_r_environ()" # 设置 GITHUB_PAT</span><br><span class="hljs-comment"># nano ~/.Renviron # MRCIEU 真是超喜欢GITHUB,要访问一万次 api.github.com</span><br>conda install -c conda-forge r-rmarkdown -y<br>conda install -c conda-forge r-meta -y<br>wget https://github.com/MRCIEU/TwoSampleMR/archive/refs/heads/master.zip -O TwoSampleMR.zip<br>Rscript -e <span class="hljs-string">"devtools::install_local('TwoSampleMR.zip')"</span><br>wget https://github.com/MRCIEU/MRInstruments/archive/refs/heads/master.zip -O MRInstruments.zip<br>Rscript -e <span class="hljs-string">"devtools::install_local('MRInstruments.zip')"</span><br>conda install -c conda-forge r-susier -y<br>conda install -c bioconda bioconductor-variantannotation -y<br>wget https://github.com/MRCIEU/gwasglue/archive/refs/heads/master.zip -O gwasglue.zip<br>Rscript -e <span class="hljs-string">"devtools::install_local('gwasglue.zip')"</span><br><span class="hljs-comment"># wget https://github.com/MRCIEU/genetics.binaRies/archive/refs/heads/master.zip -O genetics.binaRies.zip</span><br><span class="hljs-comment"># Rscript -e "devtools::install_local('genetics.binaRies.zip')"</span><br>conda install -c bioconda plink -y<br><span class="hljs-comment"># whereis plink # /opt/conda/envs/MR/bin/plink</span><br>Rscript -e <span class="hljs-string">'install.packages("MendelianRandomization")'</span><br></code></pre></td></tr></table></figure>
- <h2 id="数据来源">数据来源</h2>
- <ul>
- <li>精神病学基因组:<a href="https://hexo.limour.top/go/#aHR0cHM6Ly9wZ2MudW5jLmVkdS8=" rel="noopener external nofollow noreferrer">PGC</a></li>
- <li>社会科学遗传学:<a href="https://hexo.limour.top/go/#aHR0cHM6Ly93d3cudGhlc3NnYWMub3JnLw==" rel="noopener external nofollow noreferrer">SSGAC</a></li>
- <li>大脑健康和疾病:<a href="https://hexo.limour.top/go/#aHR0cHM6Ly9jdGcuY25jci5ubC9zb2Z0d2FyZS9zdW1tYXJ5X3N0YXRpc3RpY3M=" rel="noopener external nofollow noreferrer">CTG</a></li>
- <li>MRCIEU汇总数据库:<a href="https://hexo.limour.top/go/#aHR0cHM6Ly9nd2FzLm1yY2lldS5hYy51ay8=" rel="noopener external nofollow noreferrer">IEU</a></li>
- <li>GWAS研究目录:<a href="https://hexo.limour.top/go/#aHR0cHM6Ly93d3cuZWJpLmFjLnVrL2d3YXMvc2VhcmNo" rel="noopener external nofollow noreferrer">NHGRI-EBI</a></li>
- <li><a href="/shi-yong-GATK-zhao-SNP">自己分析出数据</a></li>
- <li><a target="_blank" rel="noopener" href="https://od.limour.top/archives/GWAS/MR">更多相关网站</a></li>
- </ul>
- <h3 id="一些参考数据">一些参考数据</h3>
- <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs bash">wget http://fileserve.mrcieu.ac.uk/ld/1kg.v3.tgz<br>tar -zxvf 1kg.v3.tgz<br><span class="hljs-comment"># mkdir EUR && mv EUR.* EUR</span><br></code></pre></td></tr></table></figure>
- <h3 id="示例结局数据">示例结局数据</h3>
- <ul>
- <li>浏览器下载 <a href="https://hexo.limour.top/go/#aHR0cHM6Ly9maWdzaGFyZS5jb20vbmRvd25sb2FkZXIvZmlsZXMvNDAwMzY2ODQ=" rel="noopener external nofollow noreferrer">ADHD2022_iPSYCH_deCODE_PGC.meta.gz</a></li>
- <li><a href="/Rclone-bei-fen-VPS-shu-ju-dao-onedrive">上传到服务器</a></li>
- </ul>
- <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># zcat ADHD2022_iPSYCH_deCODE_PGC.meta.gz | head</span><br>CHR SNP BP A1 A2 FRQ_A_38691 FRQ_U_186843 INFO OR SE P Direction Nca Nco<br>8 rs62513865 101592213 C T 0.925 0.937 0.981 0.99631 0.0175 0.8325 +---+++0-++-+ 38691 186843<br>8 rs79643588 106973048 G A 0.91 0.917 1 1.00411 0.0159 0.7967 ++--++-+-+-++ 38691 186843<br>8 rs17396518 108690829 T G 0.561 0.577 0.998 0.99611 0.0096 0.6876 --++-++??-+-- 37367 184388<br>8 rs983166 108681675 A C 0.57 0.586 0.996 0.99491 0.0096 0.5956 --++-++++-+-- 38691 186843<br>8 rs28842593 103044620 T C 0.839 0.836 0.982 0.98314 0.0135 0.2081 ----++0+??--+ 37504 184525<br>8 rs7014597 104152280 G C 0.824 0.824 0.997 0.99950 0.0122 0.9679 +-++-+++++--- 38691 186843<br>8 rs3134156 100479917 T C 0.841 0.833 0.997 0.98866 0.0128 0.3762 -+----+--++-- 38691 186843<br>8 rs6980591 103144592 A C 0.783 0.79 1 1.01106 0.0108 0.3075 ++-++---+++++ 38691 186843<br>8 rs72670434 108166508 A T 0.642 0.623 0.983 1.00672 0.0103 0.5171 +++-+++--+++- 38691 186843<br></code></pre></td></tr></table></figure>
- <figure class="highlight txt"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs txt">CHR Chromosome (hg19)<br>SNP Marker name<br>BP Base pair location (hg19)<br>A1 Reference allele for OR (may or may not be minor allele)<br>A2 Alternative allele<br>FRQ_A_38691 allele frequency of A1 in 38,691 ADHD cases<br>FRQ_U_186843 allele frequency of A1 in 38,691 controls<br>INFO Imputation information score (the reported imputation INFO score is a weighted average across the<br>cohorts contributing to the meta-analysis for that variant)<br>OR Odds ratio for the effect of the A1 allele<br>SE Standard error of the log(OR)<br>P P-value for association test in the meta-analysis<br>Direction direction of effect in the included cohorts<br>Nca number of cases with variant information<br>Nco number of controls with variant information<br></code></pre></td></tr></table></figure>
- <p>其中<code>SNP</code>,<code>Effect allele</code>,<code>Beta(OR)</code>,<code>SE</code>,<code>P</code>这五列是必须的。遇到没有提供EAF的数据,可以<a href="https://hexo.limour.top/go/#aHR0cHM6Ly9naXRodWIuY29tL0hhb2Jpblpob3UvR2V0X01S" rel="noopener external nofollow noreferrer">匹配千人基因组数据的EAF</a>,<code>get_eaf_from_1000G</code>。</p>
- <h3 id="示例暴露数据">示例暴露数据</h3>
- <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">wget -c https://gwas.mrcieu.ac.uk/files/ieu-a-2/ieu-a-2.vcf.gz<br></code></pre></td></tr></table></figure>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><code class="hljs R">VCF_dat <span class="hljs-operator">=</span> VariantAnnotation<span class="hljs-operator">::</span>readVcf<span class="hljs-punctuation">(</span><span class="hljs-string">'~/upload/GWAS/IEU/ieu-a-2.vcf.gz'</span><span class="hljs-punctuation">)</span><br>exp_dat <span class="hljs-operator">=</span> gwasglue<span class="hljs-operator">::</span>gwasvcf_to_TwoSampleMR<span class="hljs-punctuation">(</span>vcf <span class="hljs-operator">=</span> VCF_dat<span class="hljs-punctuation">)</span><br>saveRDS<span class="hljs-punctuation">(</span>file <span class="hljs-operator">=</span> <span class="hljs-string">'ieu-a-2.exp_dat'</span><span class="hljs-punctuation">,</span> exp_dat<span class="hljs-punctuation">)</span><br>exp_dat <span class="hljs-operator">=</span> subset<span class="hljs-punctuation">(</span>exp_dat<span class="hljs-punctuation">,</span> pval.exposure <span class="hljs-operator"><</span> <span class="hljs-number">5e-08</span><span class="hljs-punctuation">)</span> <span class="hljs-comment"># 关联性假设</span><br><span class="hljs-comment"># 去除连锁不平衡</span><br><span class="hljs-comment"># exp_dat = TwoSampleMR::clump_data(dat = exp_dat, clump_kb = 10000, clump_r2 = 0.001) # MRCIEU太喜欢用cloud api了</span><br>fix_ld_clump_local <span class="hljs-operator">=</span> <span class="hljs-keyword">function</span> <span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">,</span> tempfile<span class="hljs-punctuation">,</span> clump_kb<span class="hljs-punctuation">,</span> clump_r2<span class="hljs-punctuation">,</span> clump_p<span class="hljs-punctuation">,</span> bfile<span class="hljs-punctuation">,</span> plink_bin<span class="hljs-punctuation">)</span> <span class="hljs-punctuation">{</span><br> shell <span class="hljs-operator"><-</span> ifelse<span class="hljs-punctuation">(</span>Sys.info<span class="hljs-punctuation">(</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">[</span><span class="hljs-string">"sysname"</span><span class="hljs-punctuation">]</span> <span class="hljs-operator">==</span> <span class="hljs-string">"Windows"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"cmd"</span><span class="hljs-punctuation">,</span> <br> <span class="hljs-string">"sh"</span><span class="hljs-punctuation">)</span><br> write.table<span class="hljs-punctuation">(</span>data.frame<span class="hljs-punctuation">(</span>SNP <span class="hljs-operator">=</span> dat<span class="hljs-punctuation">[[</span><span class="hljs-string">"rsid"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span> P <span class="hljs-operator">=</span> dat<span class="hljs-punctuation">[[</span><span class="hljs-string">"pval"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span> <br> file <span class="hljs-operator">=</span> tempfile<span class="hljs-punctuation">,</span> row.names <span class="hljs-operator">=</span> <span class="hljs-built_in">F</span><span class="hljs-punctuation">,</span> col.names <span class="hljs-operator">=</span> <span class="hljs-built_in">T</span><span class="hljs-punctuation">,</span> <span class="hljs-built_in">quote</span> <span class="hljs-operator">=</span> <span class="hljs-built_in">F</span><span class="hljs-punctuation">)</span><br> fun2 <span class="hljs-operator"><-</span> paste0<span class="hljs-punctuation">(</span>shQuote<span class="hljs-punctuation">(</span>plink_bin<span class="hljs-punctuation">,</span> type <span class="hljs-operator">=</span> shell<span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span> <span class="hljs-string">" --bfile "</span><span class="hljs-punctuation">,</span> <br> shQuote<span class="hljs-punctuation">(</span>bfile<span class="hljs-punctuation">,</span> type <span class="hljs-operator">=</span> shell<span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span> <span class="hljs-string">" --clump "</span><span class="hljs-punctuation">,</span> shQuote<span class="hljs-punctuation">(</span>tempfile<span class="hljs-punctuation">,</span> <br> type <span class="hljs-operator">=</span> shell<span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span> <span class="hljs-string">" --clump-p1 "</span><span class="hljs-punctuation">,</span> clump_p<span class="hljs-punctuation">,</span> <span class="hljs-string">" --clump-r2 "</span><span class="hljs-punctuation">,</span> <br> clump_r2<span class="hljs-punctuation">,</span> <span class="hljs-string">" --clump-kb "</span><span class="hljs-punctuation">,</span> clump_kb<span class="hljs-punctuation">,</span> <span class="hljs-string">" --out "</span><span class="hljs-punctuation">,</span> shQuote<span class="hljs-punctuation">(</span>tempfile<span class="hljs-punctuation">,</span> <br> type <span class="hljs-operator">=</span> shell<span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span><br> print<span class="hljs-punctuation">(</span>fun2<span class="hljs-punctuation">)</span><br> system<span class="hljs-punctuation">(</span>fun2<span class="hljs-punctuation">)</span><br> res <span class="hljs-operator"><-</span> read.table<span class="hljs-punctuation">(</span>paste<span class="hljs-punctuation">(</span>tempfile<span class="hljs-punctuation">,</span> <span class="hljs-string">".clumped"</span><span class="hljs-punctuation">,</span> sep <span class="hljs-operator">=</span> <span class="hljs-string">""</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span> header <span class="hljs-operator">=</span> <span class="hljs-built_in">T</span><span class="hljs-punctuation">)</span><br> unlink<span class="hljs-punctuation">(</span>paste<span class="hljs-punctuation">(</span>tempfile<span class="hljs-punctuation">,</span> <span class="hljs-string">"*"</span><span class="hljs-punctuation">,</span> sep <span class="hljs-operator">=</span> <span class="hljs-string">""</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span><br> y <span class="hljs-operator"><-</span> subset<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">,</span> <span class="hljs-operator">!</span>dat<span class="hljs-punctuation">[[</span><span class="hljs-string">"rsid"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span> <span class="hljs-operator">%in%</span> res<span class="hljs-punctuation">[[</span><span class="hljs-string">"SNP"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">)</span><br> <span class="hljs-keyword">if</span> <span class="hljs-punctuation">(</span>nrow<span class="hljs-punctuation">(</span>y<span class="hljs-punctuation">)</span> <span class="hljs-operator">></span> <span class="hljs-number">0</span><span class="hljs-punctuation">)</span> <span class="hljs-punctuation">{</span><br> message<span class="hljs-punctuation">(</span><span class="hljs-string">"Removing "</span><span class="hljs-punctuation">,</span> <span class="hljs-built_in">length</span><span class="hljs-punctuation">(</span>y<span class="hljs-punctuation">[[</span><span class="hljs-string">"rsid"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span> <span class="hljs-string">" of "</span><span class="hljs-punctuation">,</span> nrow<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span> <br> <span class="hljs-string">" variants due to LD with other variants or absence from LD reference panel"</span><span class="hljs-punctuation">)</span><br> <span class="hljs-punctuation">}</span><br> <span class="hljs-built_in">return</span><span class="hljs-punctuation">(</span>subset<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">,</span> dat<span class="hljs-punctuation">[[</span><span class="hljs-string">"rsid"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span> <span class="hljs-operator">%in%</span> res<span class="hljs-punctuation">[[</span><span class="hljs-string">"SNP"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span><br><span class="hljs-punctuation">}</span><br>fuck <span class="hljs-operator">=</span> fix_ld_clump_local<span class="hljs-punctuation">(</span><br> dat <span class="hljs-operator">=</span> dplyr<span class="hljs-operator">::</span>tibble<span class="hljs-punctuation">(</span>rsid<span class="hljs-operator">=</span>exp_dat<span class="hljs-operator">$</span>SNP<span class="hljs-punctuation">,</span> pval<span class="hljs-operator">=</span>exp_dat<span class="hljs-operator">$</span>pval.exposure<span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><br> tempfile <span class="hljs-operator">=</span> file.path<span class="hljs-punctuation">(</span>getwd<span class="hljs-punctuation">(</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><span class="hljs-string">'tmp.ld_clump.exp_dat'</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><br> clump_kb <span class="hljs-operator">=</span> <span class="hljs-number">10000</span><span class="hljs-punctuation">,</span> clump_r2 <span class="hljs-operator">=</span> <span class="hljs-number">0.001</span><span class="hljs-punctuation">,</span> clump_p <span class="hljs-operator">=</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span><br> <span class="hljs-comment"># pop = "EUR", # Super-population. Options are "EUR", "SAS", "EAS", "AFR", "AMR"</span><br> plink_bin <span class="hljs-operator">=</span> <span class="hljs-string">'/opt/conda/envs/MR/bin/plink'</span><span class="hljs-punctuation">,</span> <span class="hljs-comment"># 千万别用什么 genetics.binaRies::get_plink_binary(),他们自己编译的文件有问题</span><br> bfile <span class="hljs-operator">=</span> <span class="hljs-string">"/home/jovyan/upload/GWAS/ld/EUR"</span> <span class="hljs-comment"># 前缀,不是文件夹也不是文件</span><br><span class="hljs-punctuation">)</span><br>exp_dat_clumped <span class="hljs-operator">=</span> exp_dat<span class="hljs-punctuation">[</span>exp_dat<span class="hljs-operator">$</span>SNP <span class="hljs-operator">%in%</span> fuck<span class="hljs-operator">$</span>rsid<span class="hljs-punctuation">,</span><span class="hljs-punctuation">]</span><br>saveRDS<span class="hljs-punctuation">(</span>file <span class="hljs-operator">=</span> <span class="hljs-string">'ieu-a-2.exp_gwas'</span><span class="hljs-punctuation">,</span> exp_dat_clumped<span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h2 id="获取暴露数据">获取暴露数据</h2>
- <h3 id="自己的数据">自己的数据</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs R">df_gwas <span class="hljs-operator"><-</span> data.frame<span class="hljs-punctuation">(</span><br> SNP <span class="hljs-operator">=</span> <span class="hljs-built_in">c</span><span class="hljs-punctuation">(</span><span class="hljs-string">"rs1"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"rs2"</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><br> beta <span class="hljs-operator">=</span> <span class="hljs-built_in">c</span><span class="hljs-punctuation">(</span><span class="hljs-number">1</span><span class="hljs-punctuation">,</span> <span class="hljs-number">2</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><br> se <span class="hljs-operator">=</span> <span class="hljs-built_in">c</span><span class="hljs-punctuation">(</span><span class="hljs-number">1</span><span class="hljs-punctuation">,</span> <span class="hljs-number">2</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><br> effect_allele <span class="hljs-operator">=</span> <span class="hljs-built_in">c</span><span class="hljs-punctuation">(</span><span class="hljs-string">"A"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"T"</span><span class="hljs-punctuation">)</span><br><span class="hljs-punctuation">)</span><br>head<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br>exp_dat <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>format_data<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">,</span> type <span class="hljs-operator">=</span> <span class="hljs-string">"exposure"</span><span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h3 id="gwas-catalog">gwas_catalog</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs R">df_gwas <span class="hljs-operator"><-</span><br> subset<span class="hljs-punctuation">(</span>MRInstruments<span class="hljs-operator">::</span>gwas_catalog<span class="hljs-punctuation">,</span><br> grepl<span class="hljs-punctuation">(</span><span class="hljs-string">"Speliotes"</span><span class="hljs-punctuation">,</span> Author<span class="hljs-punctuation">)</span> <span class="hljs-operator">&</span><br> Phenotype <span class="hljs-operator">==</span> <span class="hljs-string">"Body mass index"</span><span class="hljs-punctuation">)</span><br>head<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br>exp_dat <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>format_data<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h3 id="metab-qtls">metab_qtls</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs R">df_gwas <span class="hljs-operator"><-</span><br> subset<span class="hljs-punctuation">(</span>MRInstruments<span class="hljs-operator">::</span>metab_qtls<span class="hljs-punctuation">,</span><br> phenotype <span class="hljs-operator">==</span> <span class="hljs-string">"Ala"</span><br> <span class="hljs-punctuation">)</span><br>head<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br>exp_dat <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>format_metab_qtls<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h3 id="proteomic-qtls">proteomic_qtls</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs R">df_gwas <span class="hljs-operator"><-</span><br> subset<span class="hljs-punctuation">(</span>MRInstruments<span class="hljs-operator">::</span>proteomic_qtls<span class="hljs-punctuation">,</span><br> analyte <span class="hljs-operator">==</span> <span class="hljs-string">"ApoH"</span><br> <span class="hljs-punctuation">)</span><br>head<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br>exp_dat <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>format_proteomic_qtls<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h3 id="某个基因">某个基因</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs R">df_gwas <span class="hljs-operator"><-</span><br> subset<span class="hljs-punctuation">(</span>MRInstruments<span class="hljs-operator">::</span>gtex_eqtl<span class="hljs-punctuation">,</span><br> gene_name <span class="hljs-operator">==</span> <span class="hljs-string">"IRAK1BP1"</span> <span class="hljs-operator">&</span> tissue <span class="hljs-operator">==</span> <span class="hljs-string">"Adipose Subcutaneous"</span><br> <span class="hljs-punctuation">)</span><br>head<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br>exp_dat <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>format_gtex_eqtl<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h3 id="某个性状的某个甲基化位点相关QTL">某个性状的某个甲基化位点相关QTL</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs R">df_gwas <span class="hljs-operator"><-</span><br> subset<span class="hljs-punctuation">(</span>MRInstruments<span class="hljs-operator">::</span>aries_mqtl<span class="hljs-punctuation">,</span><br> cpg <span class="hljs-operator">==</span> <span class="hljs-string">"cg25212131"</span> <span class="hljs-operator">&</span> age <span class="hljs-operator">==</span> <span class="hljs-string">"Birth"</span><br> <span class="hljs-punctuation">)</span><br>head<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br>exp_dat <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>format_aries_mqtl<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h3 id="IEU的ID">IEU的ID</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs R">exp_gwas <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>extract_instruments<span class="hljs-punctuation">(</span>outcomes <span class="hljs-operator">=</span> <span class="hljs-string">'ieu-a-2'</span><span class="hljs-punctuation">)</span><br>head<span class="hljs-punctuation">(</span>exp_gwas<span class="hljs-punctuation">)</span><br>saveRDS<span class="hljs-punctuation">(</span>file <span class="hljs-operator">=</span> <span class="hljs-string">'ieu-a-2.exp_gwas'</span><span class="hljs-punctuation">,</span> exp_gwas<span class="hljs-punctuation">)</span> <span class="hljs-comment"># 和自己从VCF开始经过clump得到的差不多</span><br></code></pre></td></tr></table></figure>
- <h3 id="UK-Biobank">UK_Biobank</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs R">hyperten_tophits <span class="hljs-operator"><-</span> ieugwasr<span class="hljs-operator">::</span>tophits<span class="hljs-punctuation">(</span>id<span class="hljs-operator">=</span><span class="hljs-string">"ukb-b-12493"</span><span class="hljs-punctuation">,</span> clump<span class="hljs-operator">=</span><span class="hljs-number">0</span><span class="hljs-punctuation">)</span><br>hyperten_gwas <span class="hljs-operator"><-</span> dplyr<span class="hljs-operator">::</span>rename<span class="hljs-punctuation">(</span>hyperten_tophits<span class="hljs-punctuation">,</span> <span class="hljs-built_in">c</span><span class="hljs-punctuation">(</span><br> <span class="hljs-string">"SNP"</span><span class="hljs-operator">=</span><span class="hljs-string">"rsid"</span><span class="hljs-punctuation">,</span><br> <span class="hljs-string">"effect_allele.exposure"</span><span class="hljs-operator">=</span><span class="hljs-string">"ea"</span><span class="hljs-punctuation">,</span><br> <span class="hljs-string">"other_allele.exposure"</span><span class="hljs-operator">=</span><span class="hljs-string">"nea"</span><span class="hljs-punctuation">,</span><br> <span class="hljs-string">"beta.exposure"</span><span class="hljs-operator">=</span><span class="hljs-string">"beta"</span><span class="hljs-punctuation">,</span><br> <span class="hljs-string">"se.exposure"</span><span class="hljs-operator">=</span><span class="hljs-string">"se"</span><span class="hljs-punctuation">,</span><br> <span class="hljs-string">"eaf.exposure"</span><span class="hljs-operator">=</span><span class="hljs-string">"eaf"</span><span class="hljs-punctuation">,</span><br> <span class="hljs-string">"pval.exposure"</span><span class="hljs-operator">=</span><span class="hljs-string">"p"</span><span class="hljs-punctuation">,</span><br> <span class="hljs-string">"N"</span><span class="hljs-operator">=</span><span class="hljs-string">"n"</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span><br>fuck <span class="hljs-operator">=</span> fix_ld_clump_local<span class="hljs-punctuation">(</span><br> dat <span class="hljs-operator">=</span> dplyr<span class="hljs-operator">::</span>tibble<span class="hljs-punctuation">(</span>rsid<span class="hljs-operator">=</span>hyperten_gwas<span class="hljs-operator">$</span>SNP<span class="hljs-punctuation">,</span> pval<span class="hljs-operator">=</span>hyperten_gwas<span class="hljs-operator">$</span>pval.exposure<span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><br> tempfile <span class="hljs-operator">=</span> file.path<span class="hljs-punctuation">(</span>getwd<span class="hljs-punctuation">(</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><span class="hljs-string">'tmp.ld_clump.exp_dat'</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><br> clump_kb <span class="hljs-operator">=</span> <span class="hljs-number">10000</span><span class="hljs-punctuation">,</span> clump_r2 <span class="hljs-operator">=</span> <span class="hljs-number">0.001</span><span class="hljs-punctuation">,</span> clump_p <span class="hljs-operator">=</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span><br> <span class="hljs-comment"># pop = "EUR", # Super-population. Options are "EUR", "SAS", "EAS", "AFR", "AMR"</span><br> plink_bin <span class="hljs-operator">=</span> <span class="hljs-string">'/opt/conda/envs/MR/bin/plink'</span><span class="hljs-punctuation">,</span> <span class="hljs-comment"># 千万别用什么 genetics.binaRies::get_plink_binary(),他们自己编译的文件有问题</span><br> bfile <span class="hljs-operator">=</span> <span class="hljs-string">"/home/jovyan/upload/GWAS/ld/EUR"</span> <span class="hljs-comment"># 前缀,不是文件夹也不是文件</span><br><span class="hljs-punctuation">)</span><br>exp_dat_clumped <span class="hljs-operator">=</span> hyperten_gwas<span class="hljs-punctuation">[</span>hyperten_gwas<span class="hljs-operator">$</span>SNP <span class="hljs-operator">%in%</span> fuck<span class="hljs-operator">$</span>rsid<span class="hljs-punctuation">,</span><span class="hljs-punctuation">]</span><br>MR_calc_r2_F<span class="hljs-punctuation">(</span><br> beta <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>beta.exposure<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Vector of Log odds ratio. beta = log(OR)</span><br> eaf <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>eaf.exposure<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Vector of allele frequencies.</span><br> N <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>N<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Array of sample sizes</span><br> se <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>se.exposure <span class="hljs-comment"># Vector of SE.</span><br><span class="hljs-punctuation">)</span> <span class="hljs-comment"># 取 F>10 的</span><br></code></pre></td></tr></table></figure>
- <h2 id="计算统计效力">计算统计效力</h2>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs R"><span class="hljs-comment"># 分类变量</span><br>tmp_r2 <span class="hljs-operator">=</span>TwoSampleMR<span class="hljs-operator">::</span>get_r_from_lor<span class="hljs-punctuation">(</span><br> lor <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>beta.exposure<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Vector of Log odds ratio. beta = log(OR)</span><br> af <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>eaf.exposure<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Vector of allele frequencies.</span><br> ncase <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>ncase.exposure<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Vector of Number of cases. </span><br> ncontrol <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>ncontrol.exposure<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Vector of Number of controls. </span><br> prevalence <span class="hljs-operator">=</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span> <span class="hljs-comment"># Vector of Disease prevalence in the population.</span><br><span class="hljs-punctuation">)</span><br><span class="hljs-comment"># 连续变量</span><br>tmp_r2 <span class="hljs-operator">=</span>TwoSampleMR<span class="hljs-operator">::</span>get_r_from_pn<span class="hljs-punctuation">(</span><br> p <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>pval.exposure<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Array of pvals</span><br> n <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>samplesize.exposure <span class="hljs-comment"># Array of sample sizes</span><br><span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs R">MR_calc_r2_F <span class="hljs-operator">=</span> <span class="hljs-keyword">function</span><span class="hljs-punctuation">(</span>beta<span class="hljs-punctuation">,</span> eaf<span class="hljs-punctuation">,</span> N<span class="hljs-punctuation">,</span> se<span class="hljs-punctuation">)</span><span class="hljs-punctuation">{</span><br> <span class="hljs-comment"># https://doi.org/10.1038/s41467-020-14389-8</span><br> <span class="hljs-comment"># https://doi.org/10.1371/journal.pone.0120758</span><br> r2 <span class="hljs-operator">=</span> <span class="hljs-punctuation">(</span><span class="hljs-number">2</span> <span class="hljs-operator">*</span> <span class="hljs-punctuation">(</span>beta<span class="hljs-operator">^</span><span class="hljs-number">2</span><span class="hljs-punctuation">)</span> <span class="hljs-operator">*</span> eaf <span class="hljs-operator">*</span> <span class="hljs-punctuation">(</span><span class="hljs-number">1</span> <span class="hljs-operator">-</span> eaf<span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span> <span class="hljs-operator">/</span><br> <span class="hljs-punctuation">(</span><span class="hljs-number">2</span> <span class="hljs-operator">*</span> <span class="hljs-punctuation">(</span>beta<span class="hljs-operator">^</span><span class="hljs-number">2</span><span class="hljs-punctuation">)</span> <span class="hljs-operator">*</span> eaf <span class="hljs-operator">*</span> <span class="hljs-punctuation">(</span><span class="hljs-number">1</span> <span class="hljs-operator">-</span> eaf<span class="hljs-punctuation">)</span> <span class="hljs-operator">+</span><br> <span class="hljs-number">2</span> <span class="hljs-operator">*</span> N <span class="hljs-operator">*</span> eaf <span class="hljs-operator">*</span> <span class="hljs-punctuation">(</span><span class="hljs-number">1</span> <span class="hljs-operator">-</span> eaf<span class="hljs-punctuation">)</span> <span class="hljs-operator">*</span> se<span class="hljs-operator">^</span><span class="hljs-number">2</span><span class="hljs-punctuation">)</span><br> <span class="hljs-built_in">F</span> <span class="hljs-operator">=</span> r2 <span class="hljs-operator">*</span> <span class="hljs-punctuation">(</span>N <span class="hljs-operator">-</span> <span class="hljs-number">2</span><span class="hljs-punctuation">)</span> <span class="hljs-operator">/</span> <span class="hljs-punctuation">(</span><span class="hljs-number">1</span> <span class="hljs-operator">-</span> r2<span class="hljs-punctuation">)</span><br> print<span class="hljs-punctuation">(</span>mean<span class="hljs-punctuation">(</span><span class="hljs-built_in">F</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span><br> <span class="hljs-built_in">return</span><span class="hljs-punctuation">(</span>dplyr<span class="hljs-operator">::</span>tibble<span class="hljs-punctuation">(</span>r2<span class="hljs-operator">=</span>r2<span class="hljs-punctuation">,</span> <span class="hljs-built_in">F</span><span class="hljs-operator">=</span><span class="hljs-built_in">F</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span><br><span class="hljs-punctuation">}</span><br>MR_calc_r2_F<span class="hljs-punctuation">(</span><br> beta <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>beta.exposure<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Vector of Log odds ratio. beta = log(OR)</span><br> eaf <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>eaf.exposure<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Vector of allele frequencies.</span><br> N <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>samplesize.exposure<span class="hljs-punctuation">,</span> <span class="hljs-comment"># Array of sample sizes</span><br> se <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>se.exposure <span class="hljs-comment"># Vector of SE.</span><br><span class="hljs-punctuation">)</span> <span class="hljs-comment"># 取 F>10 的</span><br></code></pre></td></tr></table></figure>
- <h2 id="获取结局数据">获取结局数据</h2>
- <h3 id="IEU">IEU</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs R">out_gwas <span class="hljs-operator">=</span> TwoSampleMR<span class="hljs-operator">::</span>extract_outcome_data<span class="hljs-punctuation">(</span>snps <span class="hljs-operator">=</span> exp_gwas<span class="hljs-operator">$</span>SNP<span class="hljs-punctuation">,</span> outcomes <span class="hljs-operator">=</span> <span class="hljs-string">'ieu-a-7'</span><span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h3 id="UK-Biobank-2">UK_Biobank</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs R">anxiety_hyperten_liberal <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>extract_outcome_data<span class="hljs-punctuation">(</span>snps <span class="hljs-operator">=</span> exp_dat_clumped<span class="hljs-operator">$</span>SNP<span class="hljs-punctuation">,</span> outcomes <span class="hljs-operator">=</span> <span class="hljs-string">"ukb-b-11311"</span><span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h3 id="PGC的示例">PGC的示例</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs R">df_gwas <span class="hljs-operator">=</span> read.table<span class="hljs-punctuation">(</span>gzfile<span class="hljs-punctuation">(</span><span class="hljs-string">'~/upload/GWAS/PGC/ADHD2022_iPSYCH_deCODE_PGC.meta.gz'</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span> header <span class="hljs-operator">=</span> <span class="hljs-built_in">T</span><span class="hljs-punctuation">)</span><br>head<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">)</span><br>df_gwas <span class="hljs-operator">=</span> df_gwas<span class="hljs-punctuation">[</span>df_gwas<span class="hljs-operator">$</span>SNP <span class="hljs-operator">%in%</span> exp_gwas<span class="hljs-operator">$</span>SNP<span class="hljs-punctuation">,</span><span class="hljs-punctuation">]</span><br>out_gwas <span class="hljs-operator">=</span> data.frame<span class="hljs-punctuation">(</span><br> SNP <span class="hljs-operator">=</span> df_gwas<span class="hljs-operator">$</span>SNP<span class="hljs-punctuation">,</span><br> chr <span class="hljs-operator">=</span> <span class="hljs-built_in">as.character</span><span class="hljs-punctuation">(</span>df_gwas<span class="hljs-operator">$</span>CHR<span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><br> pos <span class="hljs-operator">=</span> df_gwas<span class="hljs-operator">$</span>BP<span class="hljs-punctuation">,</span><br> beta.outcome <span class="hljs-operator">=</span> <span class="hljs-built_in">log</span><span class="hljs-punctuation">(</span>df_gwas<span class="hljs-operator">$</span>OR<span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><br> se.outcome <span class="hljs-operator">=</span> df_gwas<span class="hljs-operator">$</span>SE<span class="hljs-punctuation">,</span><br> samplesize.outcome <span class="hljs-operator">=</span> df_gwas<span class="hljs-operator">$</span>Nca <span class="hljs-operator">+</span> df_gwas<span class="hljs-operator">$</span>Nco<span class="hljs-punctuation">,</span><br> pval.outcome <span class="hljs-operator">=</span> df_gwas<span class="hljs-operator">$</span>P<span class="hljs-punctuation">,</span><br> eaf.outcome <span class="hljs-operator">=</span> with<span class="hljs-punctuation">(</span>df_gwas<span class="hljs-punctuation">,</span> <span class="hljs-punctuation">(</span>FRQ_A_38691<span class="hljs-operator">*</span>Nca<span class="hljs-operator">+</span>FRQ_U_186843<span class="hljs-operator">*</span>Nco<span class="hljs-punctuation">)</span><span class="hljs-operator">/</span><span class="hljs-punctuation">(</span>Nca<span class="hljs-operator">+</span>Nco<span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><br> effect_allele.outcome <span class="hljs-operator">=</span> df_gwas<span class="hljs-operator">$</span>A1<span class="hljs-punctuation">,</span><br> other_allele.outcome <span class="hljs-operator">=</span> df_gwas<span class="hljs-operator">$</span>A2<span class="hljs-punctuation">,</span><br> outcome <span class="hljs-operator">=</span> <span class="hljs-string">'ADHD'</span><span class="hljs-punctuation">,</span><br> id.outcome <span class="hljs-operator">=</span> <span class="hljs-string">'ADHD2022_iPSYCH_deCODE_PGC'</span> <br><span class="hljs-punctuation">)</span><br>out_gwas <span class="hljs-operator">=</span> subset<span class="hljs-punctuation">(</span>out_gwas<span class="hljs-punctuation">,</span> pval.outcome <span class="hljs-operator">></span> <span class="hljs-number">5e-08</span><span class="hljs-punctuation">)</span> <span class="hljs-comment"># 排他性假设</span><br></code></pre></td></tr></table></figure>
- <h2 id="附加-代理SNP">附加 代理SNP</h2>
- <p>一部分暴露的SNPs在结局中找不到,可以找和这部分SNPs连锁不平衡的SNPs来代替。相关网站:<a href="https://hexo.limour.top/go/#aHR0cHM6Ly9zbmlwYS5vcmcvc25pcGEzLw==" rel="noopener external nofollow noreferrer">snipa</a></p>
- <h2 id="Harmonization">Harmonization</h2>
- <ul>
- <li>将Exposure-SNP及Outcome-SNP等位基因方向协同</li>
- <li>根据EAF大小,剔除不能判断方向的回文SNP</li>
- <li>剔除incompatible SNP</li>
- </ul>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs R">dat <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>harmonise_data<span class="hljs-punctuation">(</span><br> exposure_dat <span class="hljs-operator">=</span> exp_gwas<span class="hljs-punctuation">,</span> <br> outcome_dat <span class="hljs-operator">=</span> out_gwas<br><span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h2 id="附加-一键报告">附加 一键报告</h2>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs R">TwoSampleMR<span class="hljs-operator">::</span>mr_report<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">,</span> output_type <span class="hljs-operator">=</span> <span class="hljs-string">"md"</span><span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h2 id="MR分析">MR分析</h2>
- <h3 id="回归分析">回归分析</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs R">TwoSampleMR<span class="hljs-operator">::</span>mr_method_list<span class="hljs-punctuation">(</span><span class="hljs-punctuation">)</span> <span class="hljs-comment"># 查看mr支持的MR分析方法</span><br>mr_regression <span class="hljs-operator">=</span> TwoSampleMR<span class="hljs-operator">::</span>mr<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">,</span> method_list <span class="hljs-operator">=</span> <span class="hljs-built_in">c</span><span class="hljs-punctuation">(</span><span class="hljs-string">'mr_ivw'</span><span class="hljs-punctuation">,</span> <span class="hljs-string">'mr_egger_regression'</span><span class="hljs-punctuation">,</span> <span class="hljs-string">'mr_weighted_median'</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span><br>mr_regression_or <span class="hljs-operator">=</span> TwoSampleMR<span class="hljs-operator">::</span>generate_odds_ratios<span class="hljs-punctuation">(</span>mr_res <span class="hljs-operator">=</span> mr_regression<span class="hljs-punctuation">)</span> <span class="hljs-comment"># 分类变量</span><br><span class="hljs-punctuation">{</span>pdf<span class="hljs-punctuation">(</span>file <span class="hljs-operator">=</span> <span class="hljs-string">'MR.BMIvsADHD.plot.pdf'</span><span class="hljs-punctuation">,</span> width <span class="hljs-operator">=</span> <span class="hljs-number">6</span><span class="hljs-punctuation">,</span> height <span class="hljs-operator">=</span> <span class="hljs-number">6</span><span class="hljs-punctuation">)</span>; <span class="hljs-comment"># 导出 PDF 开始</span><br>print<span class="hljs-punctuation">(</span>TwoSampleMR<span class="hljs-operator">::</span>mr_scatter_plot<span class="hljs-punctuation">(</span>mr_results <span class="hljs-operator">=</span> mr_regression<span class="hljs-punctuation">,</span> dat <span class="hljs-operator">=</span> dat<span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span>; <span class="hljs-comment"># 返回的是一个ggplot2对象</span><br>dev.off<span class="hljs-punctuation">(</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">}</span> <span class="hljs-comment"># 导出 PDF 结束</span><br></code></pre></td></tr></table></figure>
- <p><img src="https://img.limour.top/2023/10/15/652bd26b9010d.webp" srcset="https://jscdn.limour.top/gh/Limour-dev/Sakurairo_Vision/load_svg/inload.svg" lazyload alt="mr_scatter_plot"></p>
- <h3 id="异质性检测">异质性检测</h3>
- <ul>
- <li>有异质性用随机效应模型<code>ivw</code>,无异质性用固定效应模型(也可以用随机效应模型,两者结果一致)</li>
- <li>异质性可能带来多效性,如果没有多效性,则可以说异质性没有带来多效性</li>
- </ul>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs R">TwoSampleMR<span class="hljs-operator">::</span>mr_heterogeneity<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">)</span> <span class="hljs-comment"># ivw的 Q_pval < 0.05 则说明有异质性</span><br>heterogeneity_presso <span class="hljs-operator">=</span> TwoSampleMR<span class="hljs-operator">::</span>run_mr_presso<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">,</span> NbDistribution <span class="hljs-operator">=</span> <span class="hljs-number">3000</span><span class="hljs-punctuation">)</span> <span class="hljs-comment"># NbDistribution越高分辨率越高,找不到离群的SNP时需要提高</span><br>heterogeneity_presso<span class="hljs-punctuation">[[</span><span class="hljs-number">1</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span><span class="hljs-operator">$</span>`MR-PRESSO results`<span class="hljs-operator">$</span>`Global Test`<span class="hljs-operator">$</span>Pvalue <span class="hljs-comment"># < 0.05 说明有异质性</span><br>heterogeneity_presso<span class="hljs-punctuation">[[</span><span class="hljs-number">1</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span><span class="hljs-operator">$</span>`MR-PRESSO results`<span class="hljs-operator">$</span>`Distortion Test`<span class="hljs-operator">$</span>`Outliers Indices` <span class="hljs-comment"># 显示离群的SNP,将其剔除后重新分析</span><br></code></pre></td></tr></table></figure>
- <h3 id="水平多效性">水平多效性</h3>
- <ul>
- <li>P < 0.05 说明不满足独立性假设,建议放弃继续做这个课题</li>
- <li>P < 0.05 拒绝了截距为0的假设,说明SNP效应为0时依然有影响(截距存在),有其他因素在起作用</li>
- </ul>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs R">TwoSampleMR<span class="hljs-operator">::</span>mr_pleiotropy_test<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h3 id="敏感性分析">敏感性分析</h3>
- <ul>
- <li>Leave-one-out analysis</li>
- <li>所有结果都不应该存在跨过0的情况,否则说明结果不稳定,不再能说明因果关系</li>
- </ul>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs R">mr_loo <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>mr_leaveoneout<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">)</span><br><span class="hljs-punctuation">{</span>pdf<span class="hljs-punctuation">(</span>file <span class="hljs-operator">=</span> <span class="hljs-string">'MR.BMIvsADHD.leaveoneout.plot.pdf'</span><span class="hljs-punctuation">,</span> width <span class="hljs-operator">=</span> <span class="hljs-number">6</span><span class="hljs-punctuation">,</span> height <span class="hljs-operator">=</span> <span class="hljs-number">6</span><span class="hljs-punctuation">)</span>; <span class="hljs-comment"># 导出 PDF 开始</span><br>print<span class="hljs-punctuation">(</span>TwoSampleMR<span class="hljs-operator">::</span>mr_leaveoneout_plot<span class="hljs-punctuation">(</span>leaveoneout_results <span class="hljs-operator">=</span> mr_loo<span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span>; <span class="hljs-comment"># 返回的是一个ggplot2对象</span><br>dev.off<span class="hljs-punctuation">(</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">}</span> <span class="hljs-comment"># 导出 PDF 结束</span><br></code></pre></td></tr></table></figure>
- <h3 id="单SNP分析">单SNP分析</h3>
- <ul>
- <li>对每个暴露-结果组合进行多次分析,每次使用不同的单 SNP 进行分析</li>
- </ul>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs R">mr_res_single <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>mr_singlesnp<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">)</span><br>TwoSampleMR<span class="hljs-operator">::</span>mr_funnel_plot<span class="hljs-punctuation">(</span>mr_res_single<span class="hljs-punctuation">)</span><br>TwoSampleMR<span class="hljs-operator">::</span>mr_forest_plot<span class="hljs-punctuation">(</span>mr_res_single<span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h3 id="方向性检测">方向性检测</h3>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs R">TwoSampleMR<span class="hljs-operator">::</span>directionality_test<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">)</span> <span class="hljs-comment"># TRUE表示确实是暴露导致了结果</span><br></code></pre></td></tr></table></figure>
- <h2 id="附加-稳健回归">附加 稳健回归</h2>
- <figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs R">dat2 <span class="hljs-operator"><-</span> TwoSampleMR<span class="hljs-operator">::</span>dat_to_MRInput<span class="hljs-punctuation">(</span>dat<span class="hljs-punctuation">)</span><br>mr_ivw_robust <span class="hljs-operator"><-</span> MendelianRandomization<span class="hljs-operator">::</span>mr_ivw<span class="hljs-punctuation">(</span>dat2<span class="hljs-punctuation">[[</span><span class="hljs-number">1</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span> model<span class="hljs-operator">=</span> <span class="hljs-string">"default"</span><span class="hljs-punctuation">,</span> <span class="hljs-comment"># “random”指的就是随机效应模型,“fixed”指的是固定效应模型</span><br> robust <span class="hljs-operator">=</span> <span class="hljs-literal">TRUE</span><span class="hljs-punctuation">,</span> penalized <span class="hljs-operator">=</span> <span class="hljs-literal">TRUE</span><span class="hljs-punctuation">,</span>correl <span class="hljs-operator">=</span> <span class="hljs-literal">FALSE</span><span class="hljs-punctuation">,</span> <span class="hljs-comment"># 参数penalized代表下调异常值的权重</span><br> weights <span class="hljs-operator">=</span><span class="hljs-string">"simple"</span><span class="hljs-punctuation">,</span> psi <span class="hljs-operator">=</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>distribution <span class="hljs-operator">=</span> <span class="hljs-string">"normal"</span><span class="hljs-punctuation">,</span>alpha <span class="hljs-operator">=</span> <span class="hljs-number">0.05</span><span class="hljs-punctuation">)</span><br></code></pre></td></tr></table></figure>
- <h2 id="附加-绘制森林图">附加 绘制森林图</h2>
- <ul>
- <li><a href="/Forest-plot-displays-the-results-of-regression-analysis">美化森林图</a></li>
- </ul>
- <h2 id="附加-计算Power">附加 计算Power</h2>
- <ul>
- <li><a href="https://hexo.limour.top/go/#aHR0cHM6Ly9kb2kub3JnLzEwLjEwOTMvaWplL2R5dDE3OQ==" rel="noopener external nofollow noreferrer">Calculating statistical power in Mendelian randomization studies</a></li>
- <li><a href="https://hexo.limour.top/go/#aHR0cHM6Ly9zaGlueS5jbnNnZW5vbWljcy5jb20vbVJuZC8=" rel="noopener external nofollow noreferrer">Power calculations for Mendelian Randomization</a></li>
- <li>Sample size: 结局总的样本量,不是暴露的样本量</li>
- <li>K: 结局中病例的比例,case/(case+control)</li>
- <li>OR: IVW的OR值,exp(beta)</li>
- <li>R2: MR_calc_r2_F 计算得到的所有R2的sum</li>
- </ul>
-
- </div>
-
- <hr/>
- <div>
- <div class="post-metas my-3">
-
-
- <div class="post-meta">
- <i class="iconfont icon-tags"></i>
-
- <a href="/tags/SNP/" class="print-no-link">#SNP</a>
-
- <a href="/tags/MR/" class="print-no-link">#MR</a>
-
- </div>
-
- </div>
-
-
- <div class="license-box my-3">
- <div class="license-title">
- <div>【学习】孟德尔随机化</div>
- <div>https://hexo.limour.top/Mendelian-Randomization</div>
- </div>
- <div class="license-meta">
-
- <div class="license-meta-item">
- <div>Author</div>
- <div>Limour</div>
- </div>
-
-
- <div class="license-meta-item license-meta-date">
- <div>Posted on</div>
- <div>October 14, 2023</div>
- </div>
-
-
- <div class="license-meta-item license-meta-date">
- <div>Updated on</div>
- <div>March 19, 2024</div>
- </div>
-
-
- <div class="license-meta-item">
- <div>Licensed under</div>
- <div>
-
-
-
- <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- <span class="hint--top hint--rounded" aria-label="BY - Attribution">
- <i class="iconfont icon-by"></i>
- </span>
- </a>
-
- <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- <span class="hint--top hint--rounded" aria-label="NC - Non-commercial">
- <i class="iconfont icon-nc"></i>
- </span>
- </a>
-
- <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- <span class="hint--top hint--rounded" aria-label="SA - Share-alike">
- <i class="iconfont icon-sa"></i>
- </span>
- </a>
-
-
- </div>
- </div>
-
- </div>
- <div class="license-icon iconfont"></div>
- </div>
-
- <div class="post-prevnext my-3">
- <article class="post-prev col-6">
-
-
- <a href="/Protocol-for-intranet-penetration-based-on-QUIC" title="【探索】基于QUIC的内网穿透协议">
- <i class="iconfont icon-arrowleft"></i>
- <span class="hidden-mobile">【探索】基于QUIC的内网穿透协议</span>
- <span class="visible-mobile">Previous</span>
- </a>
-
- </article>
- <article class="post-next col-6">
-
-
- <a href="/Aggregating-Azure-and-OpenAI-APIs-with-OneAPI" title="【记录】使用one-api聚合Azure和OpenAI的API">
- <span class="hidden-mobile">【记录】使用one-api聚合Azure和OpenAI的API</span>
- <span class="visible-mobile">Next</span>
- <i class="iconfont icon-arrowright"></i>
- </a>
-
- </article>
- </div>
-
- </div>
-
-
-
- <article id="comments" lazyload>
-
- <div id="waline"></div>
- <script type="text/javascript">
- Fluid.utils.loadComments('#waline', function() {
- Fluid.utils.createCssLink('https://cdn.staticfile.org/waline/2.15.5/waline.min.css')
- Fluid.utils.createScript('https://cdn.staticfile.org/waline/2.15.5/waline.min.js', function() {
- var options = Object.assign(
- {"serverURL":"https://comments.limour.top","path":"window.location.pathname","meta":["nick","mail","link"],"requiredMeta":["nick"],"lang":"zh-CN","emoji":["https://jscdn.limour.top/gh/walinejs/emojis/weibo"],"dark":"html[data-user-color-scheme=\"dark\"]","wordLimit":0,"pageSize":10},
- {
- el: '#waline',
- path: window.location.pathname
- }
- )
- Waline.init(options);
- Fluid.utils.waitElementVisible('#waline .vcontent', () => {
- var imgSelector = '#waline .vcontent img:not(.vemoji)';
- Fluid.plugins.imageCaption(imgSelector);
- Fluid.plugins.fancyBox(imgSelector);
- })
- });
- });
- </script>
- <noscript>Please enable JavaScript to view the comments</noscript>
- </article>
-
- </article>
- </div>
- </div>
- </div>
- <div class="side-col d-none d-lg-block col-lg-2">
-
- <aside class="sidebar" style="margin-left: -1rem">
- <div id="toc">
- <p class="toc-header">
- <i class="iconfont icon-list"></i>
- <span>Table of Contents</span>
- </p>
- <div class="toc-body" id="toc-body"></div>
- </div>
- </aside>
- </div>
- </div>
- </div>
-
-
-
-
-
-
- <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
- <i class="iconfont icon-arrowup" aria-hidden="true"></i>
- </a>
-
-
- <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
- aria-hidden="true">
- <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
- <div class="modal-content">
- <div class="modal-header text-center">
- <h4 class="modal-title w-100 font-weight-bold">Search</h4>
- <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <div class="modal-body mx-3">
- <div class="md-form mb-5">
- <input type="text" id="local-search-input" class="form-control validate">
- <label data-error="x" data-success="v" for="local-search-input">Keyword</label>
- </div>
- <div class="list-group" id="local-search-result"></div>
- </div>
- </div>
- </div>
- </div>
-
-
- </main>
- <footer>
- <div class="footer-inner">
-
- <div class="footer-content">
- <a target="_blank" rel="nofollow noopener" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=43130202000203"><img src="https://img.limour.top/2023/08/27/64eadeb81d6a0.webp" srcset="https://jscdn.limour.top/gh/Limour-dev/Sakurairo_Vision/load_svg/inload.svg" lazyload>湘公网安备43130202000203号 </a> <a target="_blank" rel="nofollow noopener" href="https://beian.miit.gov.cn/">湘ICP备20008299号 </a> <a target="_blank" rel="nofollow noopener" href="https://icp.gov.moe/?keyword=20210128">萌ICP备20210128号</a> <br> <a href="https://www.foreverblog.cn/" target="_blank"> <img src="https://img.foreverblog.cn/logo_en_default.png" srcset="https://jscdn.limour.top/gh/Limour-dev/Sakurairo_Vision/load_svg/inload.svg" lazyload alt="" style="width:auto;height:24px"> </a> <br> <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/limour-blog/limour-blog.github.io" target="_blank" rel="nofollow noopener"><span>SRC</span></a> <i class="iconfont icon-love"></i> <a href="https://web.archive.org/web/20231130095837/https://effectiveacceleration.tech/" target="_blank" rel="nofollow noopener"><span>e/Acc</span></a>
- </div>
-
-
-
-
- </div>
- </footer>
- <!-- Scripts -->
-
- <script src="https://jscdn.limour.top/npm/nprogress@0.2.0/nprogress.min.js" ></script>
- <link rel="stylesheet" href="https://jscdn.limour.top/npm/nprogress@0.2.0/nprogress.min.css" />
- <script>
- NProgress.configure({"showSpinner":false,"trickleSpeed":100})
- NProgress.start()
- window.addEventListener('load', function() {
- NProgress.done();
- })
- </script>
- <script src="https://jscdn.limour.top/npm/jquery@3.6.4/dist/jquery.min.js" ></script>
- <script src="https://jscdn.limour.top/npm/bootstrap@4.6.1/dist/js/bootstrap.min.js" ></script>
- <script src="/js/events.js" ></script>
- <script src="/js/plugins.js" ></script>
-
- <script src="/js/img-lazyload.js" ></script>
-
-
- <script>
- Fluid.utils.createScript('https://jscdn.limour.top/npm/tocbot@4.20.1/dist/tocbot.min.js', function() {
- var toc = jQuery('#toc');
- if (toc.length === 0 || !window.tocbot) { return; }
- var boardCtn = jQuery('#board-ctn');
- var boardTop = boardCtn.offset().top;
- window.tocbot.init(Object.assign({
- tocSelector : '#toc-body',
- contentSelector : '.markdown-body',
- linkClass : 'tocbot-link',
- activeLinkClass : 'tocbot-active-link',
- listClass : 'tocbot-list',
- isCollapsedClass: 'tocbot-is-collapsed',
- collapsibleClass: 'tocbot-is-collapsible',
- scrollSmooth : true,
- includeTitleTags: true,
- headingsOffset : -boardTop,
- }, CONFIG.toc));
- if (toc.find('.toc-list-item').length > 0) {
- toc.css('visibility', 'visible');
- }
- Fluid.events.registerRefreshCallback(function() {
- if ('tocbot' in window) {
- tocbot.refresh();
- var toc = jQuery('#toc');
- if (toc.length === 0 || !tocbot) {
- return;
- }
- if (toc.find('.toc-list-item').length > 0) {
- toc.css('visibility', 'visible');
- }
- }
- });
- });
- </script>
- <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>
- <script>Fluid.plugins.codeWidget();</script>
-
- <script>
- Fluid.utils.createScript('https://jscdn.limour.top/npm/anchor-js@4.3.1/anchor.min.js', function() {
- window.anchors.options = {
- placement: CONFIG.anchorjs.placement,
- visible : CONFIG.anchorjs.visible
- };
- if (CONFIG.anchorjs.icon) {
- window.anchors.options.icon = CONFIG.anchorjs.icon;
- }
- var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
- var res = [];
- for (var item of el) {
- res.push('.markdown-body > ' + item.trim());
- }
- if (CONFIG.anchorjs.placement === 'left') {
- window.anchors.options.class = 'anchorjs-link-left';
- }
- window.anchors.add(res.join(', '));
- Fluid.events.registerRefreshCallback(function() {
- if ('anchors' in window) {
- anchors.removeAll();
- var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
- var res = [];
- for (var item of el) {
- res.push('.markdown-body > ' + item.trim());
- }
- if (CONFIG.anchorjs.placement === 'left') {
- anchors.options.class = 'anchorjs-link-left';
- }
- anchors.add(res.join(', '));
- }
- });
- });
- </script>
- <script>Fluid.plugins.imageCaption();</script>
- <script src="/js/local-search.js" ></script>
- <!-- 主题的启动项,将它保持在最底部 -->
- <!-- the boot of the theme, keep it at the bottom -->
- <script src="/js/boot.js" ></script>
-
- <noscript>
- <div class="noscript-warning">Blog works best with JavaScript enabled</div>
- </noscript>
- <!-- hexo injector body_end start -->
- <script defer src="/theme-inject/timeliness.js"></script>
- <!-- hexo injector body_end end --></body>
- </html>
|