前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >plink2.0和plink1.9的忧伤笔记

plink2.0和plink1.9的忧伤笔记

作者头像
邓飞
发布于 2022-12-13 09:53:15
发布于 2022-12-13 09:53:15
2.3K03
代码可运行
举报
运行总次数:3
代码可运行

飞哥真心话:

虽然plink2.0已经存在好久了,但是一直用的都是plink1.9,因为语法熟悉。更主要是plink2.0语法变动太大,害怕步子迈得太大了……

plink2.0用是不会用的,2022年都不会用!!!但是碰到bgen,pgen数据进行转化为bed,bim,fam文件,然后用plink1.9使用的想法还是有的,而且很大!!!

本篇目的:使用plink2.0软件将下面格式随便输入、输出

  • • plink1.9的ped和map数据,不如:a.ped, a.map
  • • plink1.9的bed和bim和fam数据,比如:a.bim, a.bed, a.fam
  • • plink2.0的bgen和sample数据,比如:a.bgen, a.sample
  • • plink2.0的pgen和bim和fam数据,比如a.pgen,a.fam,a.bim
  • •vcf数据,比如a.vcf

1,plink2.0的提升

plink2.0主要是从以下几个方面,相对于plink1.9有较大的提升:

  • • 1,保留参考等位基因的信息,比如vcf格式的数据,不要添加参数 --keep-allele-order。这样vcf变为plink,plink变为vcf就可以不用指定ref和alt了,切换无障碍!
  • • 2,新的.pgen文件,结合SNPack-style的压缩,可以节约80%的文件大小。比如1000个Genomes,比压缩的gzip文件小70%,且不丢失任何信息。压缩文件空间更小,速度更快。
  • • 3,旧版的二进制文件(bed,bim和fam)文件,plink2.0依旧支持,输出文件包括两种:--make-bpgen 和 --make-bpfile文件。可以支持plink1.9的文件格式,无论是map和ped数据,还是bed,bim和fam格式。
  • • 4,分析模块,进行了优化。标准的logistic回归分析失败产生NA或者无意义的结果,--glm比plink1.9的--linear速度提升1000倍。尤其是填充的剂量效应的基因型值(比如0.2,1.8这样的非整数型数据)。PCA分析汇总,增加了参数PCA approx,当样本超过1万,这个参数可以不影响精度(影响不到1%),大大提升计算效率。样本量支持得更多,处理速度更快!

2,plink2.0 安装

plink2.0 网站:https://www.cog-genomics.org/plink/2.0/

二进制文件,直接执行,支持:

  • • Intel
  • • AMD
  • • 苹果M1

建议:plink1.9简写为plink,plink2.0 简写为plink2

3,plink帮助文档

可以通过官网查询具体参数:https://www.cog-genomics.org/plink/2.0/

也可以在命令行中调出帮助文档:

比如直接键入plink2,出现基础参数:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$ plink2



PLINK v2.00a3.7LM AVX2 Intel (24 Oct 2022)     www.cog-genomics.org/plink/2.0/
(C) 2005-2022 Shaun Purcell, Christopher Chang   GNU General Public License v3

  plink2 <input flag(s)...> [command flag(s)...] [other flag(s)...]
  plink2 --help [flag name(s)...]

Commands include --rm-dup list, --make-bpgen, --export, --freq, --geno-counts,
--sample-counts, --missing, --hardy, --het, --fst, --indep-pairwise, --ld,
--sample-diff, --make-king, --king-cutoff, --pmerge, --pgen-diff,
--write-samples, --write-snplist, --make-grm-list, --pca, --glm, --adjust-file,
--score, --variant-score, --genotyping-rate, --pgen-info, --validate, and
--zst-decompress.

"plink2 --help | more" describes all functions.

想查看一下--export的用法,可以看到主要功能:

  • • A,是0-1-2编码
  • • ped,是map和ped格式
  • • vcf,是vcf格式
  • • bgen-1.x,包括1.1, 1.2, 1.3,都是bgen格式
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$ plink2 --export --help
PLINK v2.00a3.7LM AVX2 Intel (24 Oct 2022)     www.cog-genomics.org/plink/2.0/
(C) 2005-2022 Shaun Purcell, Christopher Chang   GNU General Public License v3
--help present, ignoring other flags.

--export <output format(s)...> [{01 | 12}] ['bgz'] ['id-delim='<char>]
         ['id-paste='<column set descriptor>] ['include-alt']
         ['omit-nonmale-y'] ['spaces'] ['vcf-dosage='<field>] ['ref-first']
         ['bits='<#>] ['sample-v2']
  Create a new fileset with all filters applied.  The following output
  formats are supported:
  (actually, only A, AD, Av, bcf, bgen-1.x, haps, hapslegend, ind-major-bed,
  oxford, ped, tped, and vcf are implemented for now)
  * '23': 23andMe 4-column format.  This can only be used on a single
          sample's data (--keep may be handy), and does not support
          multicharacter allele codes.
  * 'A': Sample-major additive (0/1/2) coding, suitable for loading from R.
         If you need uncounted alleles to be named in the header line, add
         the 'include-alt' modifier.
  * 'AD': Sample-major additive (0/1/2) + dominant (het=1/hom=0) coding.
          Also supports 'include-alt'.
  * 'Av': Variant-major 0/1/2.
  * 'beagle': Unphased per-autosome .dat and .map files, readable by early
              BEAGLE versions.
  * 'beagle-nomap': Single .beagle.dat file.
  * 'bgen-1.x': Oxford-format .bgen + .sample.  For v1.2/v1.3, sample
                identifiers are stored in the .bgen (with id-delim and
                id-paste settings applied), and default precision is 16-bit
                (use the 'bits' modifier to reduce this).
  * 'bimbam': Regular BIMBAM format.
  * 'bimbam-1chr': BIMBAM format, with a two-column .pos.txt file.  Does not
                   support multiple chromosomes.
  * 'fastphase': Per-chromosome fastPHASE files, with
                 .chr-<chr #>.phase.inp filename extensions.
  * 'fastphase-1chr': Single .phase.inp file.  Does not support
                      multiple chromosomes.
  * 'haps', 'hapslegend': Oxford-format .haps + .sample[ + .legend].  All
                          data must be biallelic and phased.  When the 'bgz'
                          modifier is present, the .haps file is
                          block-gzipped.
  * 'HV': Per-chromosome Haploview files, with .chr-<chr #>{.ped,.info}
          filename extensions.
  * 'HV-1chr': Single Haploview .ped + .info file pair.  Does not support
               multiple chromosomes.
  * 'ind-major-bed': PLINK 1 sample-major .bed (+ .bim + .fam).
  * 'lgen': PLINK 1 long-format (.lgen + .fam + .map), loadable with --lfile.
  * 'lgen-ref': .lgen + .fam + .map + .ref, loadable with --lfile +
                --reference.
  * 'list': Single genotype-based list, up to 4 lines per variant.  To omit
            nonmale genotypes on the Y chromosome, add the 'omit-nonmale-y'
            modifier.
  * 'rlist': .rlist + .fam + .map fileset, where the .rlist file is a
              genotype-based list which omits the most common genotype for
              each variant.  Also supports 'omit-nonmale-y'.
  * 'oxford', 'oxford-v2': Oxford-format .gen + .sample.  When the 'bgz'
                           modifier is present, the .gen file is
                           block-gzipped.  'oxford' requests the original
                           .gen file format with 5 leading columns
                           (understood by older PLINK builds); 'oxford-v2'
                           requests the current 6-leading-column flavor.
  * 'ped', 'compound-genotypes': PLINK 1 sample-major (.ped + .map),
                                 loadable with --pedmap.
  * 'structure': Structure-format.
  * 'tped': PLINK 1 variant-major (.tped + .tfam), loadable with --tfile.
  * 'vcf',     : VCF (default version 4.3).  If PAR1 and PAR2 are present,
    'vcf-4.2',   they are automatically merged with chrX, with proper
    'bcf',       handling of chromosome codes and male ploidy.
    'bcf-4.2'    When the 'bgz' modifier is present, the VCF file is
                 block-gzipped.  (This always happens with BCF output.)
                 The 'id-paste' modifier controls which .psam columns are
                 used to construct sample IDs (choices are maybefid, fid,
                 iid, maybesid, and sid; default is maybefid,iid,maybesid),
                 while the 'id-delim' modifier sets the character between the
                 ID pieces (default '_').
                 Genotypes are always exported.  If you want to export a
                 sites-only VCF instead, see --make-pgen/--make-just-pvar's
                 'vcfheader' column set.
                 Dosages are not exported unless the 'vcf-dosage=' modifier
                 is present.  The following six dosage export modes are
                 supported:
                 'GP': genotype posterior probabilities (v4.3 only).
                 'DS': Minimac3-style dosages, omitted for hardcalls.
                 'DS-force': Minimac3-style dosages, never omit.
                 'DS-only': Same as DS-force, except GT field is omitted.
                 'HDS': Minimac3-style phased dosages, omitted for hardcalls
                        and unphased calls.  Also includes 'DS' output.
                 'HDS-force': Always report DS and HDS.
  In addition,
  * The '12' modifier causes alt1 alleles to be coded as '1' and ref alleles
    to be coded as '2', while '01' maps alt1 -> 0 and ref -> 1.
  * The 'spaces' modifier makes the output space-delimited instead of
    tab-delimited, whenever both are permitted.
  * For biallelic formats where it's unspecified whether the reference/major
    allele should appear first or second, --export defaults to second for
    compatibility with PLINK 1.9.  Use 'ref-first' to change this.
    (Note that this doesn't apply to the 'A', 'AD', and 'Av' formats; use
    --export-allele to control which alleles are counted there.)
  * 'sample-v2' exports .sample files according to the QCTOOLv2 rather than
    the original specification.  Only one ID column is exported ('id-paste'
    and 'id-delim' settings apply), parental IDs are exported if present, and
    category names are preserved rather than converted to positive integers.

--export-allele <file> : With --export A/AD/Av, count alleles named in the
                         file, instead of REF alleles.

4. plink2.0 笔记

4.1 读取plink的ped和map数据

plink2.0,没有--file这个参数了,变为了:--pedmap,也可以分开写,比如 --ped --map分别接ped和map数据。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
plink2 --ped yuanshi.ped --map yuanshi.map

或者写为:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
plink2 --pedmap yuanshi

默认输出文件:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
plink2.log  plink2.pgen  plink2.psam  plink2.pvar
  • • plink2.log,log日志,不用理会
  • • plink2.pgen,二进制文件,类似plink1.9的bim文件
  • • plink2.psam,个体和性别信息
  • • plink2.pvar,snp的信息,包括染色体、物理位置、名称、ref和alt

4.2 读取plink的bed,bim和fam数据

plink1.9的二进制数据是bed,bim和fam数据,plink2.0通过--bfile指定。

比如读取plink1.9的二进制文件,输出bgen格式:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
plink2 --bfile a1 --export bgen-1.1 --out t1

日志:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$ plink2 --bfile a1 --export bgen-1.1 --out t1
PLINK v2.00a3.7LM AVX2 Intel (24 Oct 2022)     www.cog-genomics.org/plink/2.0/
(C) 2005-2022 Shaun Purcell, Christopher Chang   GNU General Public License v3
Logging to t1.log.
Options in effect:
  --bfile a1
  --export bgen-1.1
  --out t1

Start time: Thu Dec  1 18:59:10 2022
1031523 MiB RAM detected; reserving 515761 MiB for main workspace.
Using up to 96 threads (change this with --threads).
86 samples (0 females, 0 males, 86 ambiguous; 86 founders) loaded from a1.fam.
50904 variants loaded from a1.bim.
Note: No phenotype data present.
Writing t1.bgen ... done.
Writing t1.sample ... done.

4.3 读取bgen和sample格式

导出ped和map的格式:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
plink2 --bgen t1.bgen 'ref-last' --sample t1.sample --export ped --out x1

注意:bgen和sample是一对数据,读取时,要分开指定,--bgen, --sample,同时要指定‘ref-last’,即后面的是ref,前面的是alt,也可以修改。

4.4 读取vcf数据

导出ped和map数据

读取vcf,导出ped和map数据:需要定义--export ped

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
plink2 --vcf x2.vcf --export ped --out y1

导出bed和bim和fam数据

读取vcf数据,导出bim,bed和fam数据:需要定义--make-bed

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
plink2 --vcf x2.vcf --make-bed --out y2

导出bgen数据

读取vcf数据,导出bgen和sample数据,需要定义--export bgen-1.1

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
plink2 --vcf x2.vcf --export bgen-1.1 --out y3

上面就是我的总结,更多内容,欢迎关注我的公众号:育种数据分析之放飞自我

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-12-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 育种数据分析之放飞自我 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
一文搞定基因型数据清洗
我已经下载整理好了,下载本书的电子版pdf+数据+代码,链接:书籍及配套代码领取--统计遗传分析导论
邓飞
2022/12/13
9430
一文搞定基因型数据清洗
统计遗传学:第八章,基因型数据质控
大家好,我是飞哥,本章节是理论+实操,干货满满,这里我将书中的数据用代码进行了实现,你可以下载相关的数据,用我整理好的代码进行操作,666!
邓飞
2022/12/12
1.8K0
统计遗传学:第八章,基因型数据质控
解决方案 | 多个plink文件合并的方法
典型的情况:现在有4条染色体的数据,每个染色体一套plink文件,如何合并在一起。
邓飞
2023/10/27
1K0
解决方案 | 多个plink文件合并的方法
BGEN格式如何使用?有经验的家长已经给孩子收藏了。。。
大家好,我是邓飞,我本来以为vcftools处理gvcf已经天下无敌了,没想到bgen格式更豪横,快看,这是谁的部下?
邓飞
2022/12/13
1.2K0
BGEN格式如何使用?有经验的家长已经给孩子收藏了。。。
plink软件cookbook
快,真的是快,我用perl或者Python编写的代码运行需要50s,plink不到1s完成,在C语言面前,我掌握的语言是苍白的。所以,好好利用plink软件,对于速度的提升非常显著。
邓飞
2021/03/30
2.2K0
plink软件cookbook
bioinfo05-GWAS学习
发现plink2 和plink 差别还是挺大的,没什么plink2 教程,还是用老版。
北野茶缸子
2022/05/19
4470
bioinfo05-GWAS学习
一文掌握Plink文件格式转换
Plink是我们常用的全基因关联分析工具,具有多种文件格式。许多分析工具都需要Plink的文件格式作为输入文件,今天小编就带大家掌握多种Plink文件格式的转换,解决分析过程中遇到的输入文件问题。
生信小王子
2020/08/10
2.5K0
如何使用plink进行二分类性状的GWAS分析并计算PRS得分
这篇博客,用之前GWAS教程中的示例数据(快来领取 | 飞哥的GWAS分析教程),把数据分为Base数据和Target数据,通过plink运行二分类的logistic模型进行GWAS分析,然后通过PRSice-2软件,进行PRS分析。最终,选出最优SNP组合,并计算Target的PRS得分,主要结果如下:
邓飞
2022/12/13
2.9K0
如何使用plink进行二分类性状的GWAS分析并计算PRS得分
利用GCAT工具做PCA分析
在PCA(Principal Component Analysis)分析中,常用的工具有EIGENSOFT工具的smartpca,GCTA工具的PCA模块和R包中做PCA分析的princomp函数或glPCA功能。EIGENSOFT工具只支持linux系统,从安装到使用都很复杂。GCTA工具支持不同平台(wins/linux/mac),常用于群体遗传相关分析。在群体遗传中,R包从读取vcf文件、PCA分析到可视化,对内存要求较高。
阿凡亮
2020/04/13
2.3K0
snakemake 学习笔记4
我在stackoverflow中问了一个问题, 获得了答案, 对snakemake的理解也加深了一步.
邓飞
2019/07/07
9160
snakemake 学习笔记4
VCF转换PLINK格式的3种方法
plink是目前使用的最为广泛的关联分析软件,其定义的ped/map文件系统,及其对应的二进制bed/bim/fam已经成为关联分析的标准文件格式。在进行关联分析之前,我们首先要做的就是将其他格式的文件转换为plink对应的文件格式。
生信修炼手册
2019/12/19
11.1K0
VCF转换PLINK格式的3种方法
数据质控中:先进行SNP缺失质控还是样本缺失质控?
「先对SNP进行缺失质控:」这里--geno 0.02是plink中对SNP进行的缺失质控,质控标准为0.02,即删除缺失率大于2%的SNP。
邓飞
2021/10/18
1.6K1
数据质控中:先进行SNP缺失质控还是样本缺失质控?
笔记 | GWAS 操作流程2-1:缺失质控
清洗数据的时间占80%的时间,有句话这样讲:“Garbage in, Garbage out(垃圾进,垃圾出)”,所以清洗数据非常重要,今天学习一下基因组数据如何清洗。
邓飞
2020/05/18
2.3K0
笔记 | GWAS 操作流程2-1:缺失质控
如何计算群体中的单倍型频率
昨天写了一篇(单倍型的显著性分析)的博文,里面介绍了为什么GWAS分析后,要进行单倍型的显著性分析,简而言之,如果显著性位点在block中,以block为代表进行利用,可以进行PRS(多基因评分)或者MAS(分子标记辅助选择。
邓飞
2025/04/04
2200
如何计算群体中的单倍型频率
SAIGE用户手册笔记1
群体遗传学领域,看起来华人(中国人)至少是占据前线的,至少很多软件的一作就是中国人的名字,至少活主要是我们干的。当然,也有很多华人(国人)大牛开发了史诗级别的软件,向勤劳的华夏人致敬!SAIGE 这个软件也是如此。最新更新了1.0版,一起来学习下新的软件文档。
用户1075469
2022/04/15
2K2
SAIGE用户手册笔记1
笔记 | GWAS 操作流程2-6:去掉亲缘关系近的个体
这是使用plink学习GWAS中质控的最后一篇,后面是使用GLM和MLM模型进行建模,以及对结果的整理和可视化。
邓飞
2020/05/13
2.9K1
笔记GWAS 操作流程2-3:MAF过滤
因为这里是人的数据,所以染色体只需要去1~22的常染色体,提取它的家系ID和个体ID,后面用于提取。
邓飞
2020/04/14
5.7K0
笔记GWAS 操作流程2-3:MAF过滤
plink软件初体验2--常用参数
plink软件是GWAS分析中常用的软件,它也是一个数据格式,plink里面有很多非常强大的功能,运算速度很快,是我日常分析中常用的软件之一。
邓飞
2020/11/26
3.4K0
R语言实现GWAS数据文件格式转化
全基因组关联分析(GWAS)大家都不陌生,今天我们给大家介绍下各种格式之间转化在R语言是怎么实现的。首先我们来看下GWAS都有哪些数据格式:
一粒沙
2019/07/31
4.6K0
笔记 | GWAS 操作流程4-2:LM模型+数值协变量
上一篇,我们介绍了数量性状进行GWAS的一般线性模型分析的方法(笔记 | GWAS 操作流程4:LM模型assoc),这里我们考虑一下数字协变量,然后用R语言进行对比。
邓飞
2020/05/26
1.3K0
推荐阅读
相关推荐
一文搞定基因型数据清洗
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档