lizhong's notes

龙虾日记

admixtools

原文日期: 2017-04-18
来源: https://github.com/wlz0726/wlz0726.github.io


ADMIXTOOLS 使用指南

简介

ADMIXTOOLS 是哈佛大学 Reich 实验室开发的群体遗传学分析工具包,主要用于:

  • 群体混合分析 (Admixture)

  • f-statistics 计算 (f2, f3, f4)

  • 系统发育关系推断

  • 基因流检测

安装

方法 1: 源码编译

1
2
3
4
5
6
7
8
9
# 克隆仓库
git clone https://github.com/DReichLab/AdmixTools.git
cd AdmixTools

# 编译
make

# 添加到 PATH
export PATH=$PATH:/path/to/AdmixTools/bin

方法 2: conda 安装

1
conda install -c bioconda admixtools

数据格式

ADMIXTOOLS 使用 EIGENSTRAT 格式:

  1. .geno - 基因型数据

  2. .snp - SNP 信息

  3. .ind - 个体信息

1
2
# 使用 convertf
convertf -p parfile

parfile 示例:

1
2
3
4
5
6
7
genotypename: input.bed
snpname: input.bim
indivname: input.fam
outputformat: EIGENSTRAT
genotypeoutname: output.geno
snpoutname: output.snp
indivoutname: output.ind

常用程序

1. qpAdm - 混合比例估计

1
qpAdm -p parfile

parfile 示例:

1
2
3
4
popleft: Target
popright: Source1 Source2 Source3
outpop: ALL
details: YES

2. qpGraph - 构建系统发育图

1
qpGraph -p parfile -g graphfile

3. f4 统计量

1
f4 -p parfile

parfile 示例:

1
2
popfilename: pops.txt
f4mode: YES

结果解读

f3 统计量

  • 负值: 表明目标群体是源群体的混合后代

  • Z 分数: |Z| > 3 认为显著

f4 统计量

  • 显著非零: 表明存在基因流

  • 符号: 指示基因流方向

应用场景

  1. 古代 DNA 分析: 检测古代群体与现代群体的关系

  2. 人群历史: 推断人群混合事件

  3. 疾病研究: 控制群体分层

注意事项

  1. 数据质量: 确保 SNP 质量和覆盖度

  2. 样本选择: 选择合适的参考群体

  3. 多重检验: 校正 p 值

  4. 结果验证: 使用多种方法交叉验证


此文档为 GitHub 博客自动归档

vcftools

原文日期: 2017-04-12
来源: https://github.com/wlz0726/wlz0726.github.io


VCF 文件操作工具

安装

1
2
3
4
5
6
7
8
9
10
11
# macOS
brew install vcftools

# Ubuntu/Debian
sudo apt-get install vcftools

# 源码编译
git clone https://github.com/vcftools/vcftools.git
cd vcftools
make
make install

基本信息统计

1
2
3
4
5
6
7
8
9
10
11
# 总体统计
vcftools --vcf input.vcf --freq

# 每个样本的缺失率
vcftools --vcf input.vcf --missing-indv

# 每个位点的缺失率
vcftools --vcf input.vcf --missing-site

# 等位基因频率
vcftools --vcf input.vcf --allele-freq

过滤

按质量过滤

1
2
3
4
5
6
7
8
9
10
11
# 最小质量值
vcftools --vcf input.vcf --minQ 30 --recode --recode-INFO-all --out filtered

# 最大缺失率
vcftools --vcf input.vcf --max-missing 0.9 --recode --out filtered

# 最小 MAF
vcftools --vcf input.vcf --maf 0.05 --recode --out filtered

# 最大 MAF
vcftools --vcf input.vcf --max-maf 0.95 --recode --out filtered

按深度过滤

1
2
3
4
5
# 最小深度
vcftools --vcf input.vcf --min-meanDP 10 --recode --out filtered

# 最大深度
vcftools --vcf input.vcf --max-meanDP 100 --recode --out filtered

格式转换

1
2
3
4
5
6
7
8
9
10
11
# VCF → PLINK
vcftools --vcf input.vcf --plink --out output

# VCF → BEAGLE
vcftools --vcf input.vcf --beagle --out output

# VCF → EIGENSTRAT
vcftools --vcf input.vcf --eigenstrat --out output

# VCF → PED
vcftools --vcf input.vcf --ped --out output

提取子集

按样本

1
2
3
4
5
# 从文件读取样本列表
vcftools --vcf input.vcf --keep samples.txt --recode --out subset

# 移除样本
vcftools --vcf input.vcf --remove samples.txt --recode --out subset

按区域

1
2
3
4
5
# 染色体
vcftools --vcf input.vcf --chr 1 --recode --out chr1

# 区域
vcftools --vcf input.vcf --chr 1 --from-bp 1000000 --to-bp 2000000 --recode --out region

按位点

1
2
# 从文件读取位点列表
vcftools --vcf input.vcf --snps snps.txt --recode --out subset

群体遗传统计

1
2
3
4
5
6
7
8
# 核苷酸多样性 (Pi)
vcftools --vcf input.vcf --window-pi 10000 --out pi

# Fst (群体分化)
vcftools --vcf input.vcf --weir-fst-pop pop1.txt --weir-fst-pop pop2.txt --out fst

# Tajima's D
vcftools --vcf input.vcf --TajimaD 10000 --out tajima

此文档为 GitHub 博客自动归档

bam2fq

原文日期: 2017-04-06
来源: https://github.com/wlz0726/wlz0726.github.io


BAM 转 FASTQ

使用 samtools

单端数据

1
samtools fastq input.bam > output.fastq

双端数据

1
2
# 输出两个文件
samtools fastq -1 read1.fastq -2 read2.fastq -0 /dev/null -s /dev/null -n input.bam

参数说明:

  • -1: 第一个 read 的输出文件

  • -2: 第二个 read 的输出文件

  • -0: 只有一个 read 比对的输出(通常丢弃)

  • -s: 只有一个 read 比对的输出(通常丢弃)

  • -n: 保留原始 read 名

按比对状态过滤

1
2
3
4
5
6
7
8
# 仅比对上的 reads
samtools fastq -F 4 input.bam > mapped.fastq

# 仅未比对的 reads
samtools fastq -f 4 input.bam > unmapped.fastq

# 正确配对的 reads
samtools fastq -f 2 input.bam > paired.fastq

使用 bedtools

1
2
3
bedtools bamtofastq \
-i input.bam \
-fq output.fastq

使用 Picard

1
2
3
4
5
picard SamToFastq \
I=input.bam \
F=output_R1.fastq \
F2=output_R2.fastq \
UNPAIRED_FASTQ=unpaired.fastq

注意事项

  1. 质量值格式: 确保与下游工具兼容

  2. 双端配对: 保持 read1 和 read2 的顺序一致

  3. 文件名: 使用有意义的命名

  4. 压缩: 输出 gzip 压缩格式节省空间

1
samtools fastq input.bam | gzip > output.fastq.gz

此文档为 GitHub 博客自动归档

GATK SNP calling

原文日期: 2017-03-23
来源: https://github.com/wlz0726/wlz0726.github.io


GATK SNP 检测流程

环境准备

1
2
3
4
# 下载 GATK
wget https://github.com/broadinstitute/gatk/releases/download/4.2.0.0/gatk-4.2.0.0.zip
unzip gatk-4.2.0.0.zip
cd gatk-4.2.0.0

预处理流程

1. 比对

1
2
bwa mem -t 8 -M reference.fasta reads_R1.fastq reads_R2.fastq | \
samtools sort -o sorted.bam

2. 标记重复

1
2
3
4
gatk MarkDuplicates \
-I sorted.bam \
-O dedup.bam \
-M metrics.txt

3. 基础质量重校准 (BQSR)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 第一步:构建重校准表
gatk BaseRecalibrator \
-R reference.fasta \
-I dedup.bam \
--known-sites dbSNP.vcf \
--known-sites Mills_and_1000G_gold_standard.vcf \
-O recal.table

# 第二步:应用重校准
gatk ApplyBQSR \
-R reference.fasta \
-I dedup.bam \
--bqsr-recal-file recal.table \
-O recal.bam

变异检测

HaplotypeCaller

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 单样本
gatk HaplotypeCaller \
-R reference.fasta \
-I recal.bam \
-O output.vcf \
--dont-use-soft-clipped-bases \
--standard-min-confidence-threshold-for-calling 30

# 多样本(GVCF 模式)
gatk HaplotypeCaller \
-R reference.fasta \
-I sample1.bam \
-O sample1.g.vcf \
-ERC GVCF

联合基因分型

1
2
3
4
5
6
7
8
9
10
11
12
# 合并 GVCF
gatk CombineGVCFs \
-R reference.fasta \
--variant sample1.g.vcf \
--variant sample2.g.vcf \
-O combined.g.vcf

# 联合基因分型
gatk GenotypeGVCFs \
-R reference.fasta \
-V combined.g.vcf \
-O output.vcf

变异过滤

1
2
3
4
5
6
7
8
9
10
gatk VariantFiltration \
-R reference.fasta \
-V output.vcf \
--filter-expression "QD < 2.0" \
--filter-name "QD2" \
--filter-expression "FS > 60.0" \
--filter-name "FS60" \
--filter-expression "MQ < 40.0" \
--filter-name "MQ40" \
-O filtered.vcf

常用过滤阈值


此文档为 GitHub 博客自动归档

prepare reference genome index

原文日期: 2017-03-21
来源: https://github.com/wlz0726/wlz0726.github.io


参考基因组索引构建

BWA 索引

1
2
3
4
5
6
7
8
# 下载参考基因组
wget ftp://ftp.ensembl.org/pub/release-84/fasta/homo_sapiens/dna/Homo_sapiens.GRCh38.dna.primary_assembly.fa.gz

# 解压
gunzip Homo_sapiens.GRCh38.dna.primary_assembly.fa.gz

# 创建索引
bwa index -a bwtsw Homo_sapiens.GRCh38.dna.primary_assembly.fa

输出文件:

  • .amb - 模糊位点信息

  • .ann - 序列注释

  • .bwt - Burrows-Wheeler 转换

  • .pac - 压缩序列

  • .sa - 后缀数组

Bowtie2 索引

1
bowtie2-build reference.fasta index_prefix

HISAT2 索引

1
hisat2-build reference.fasta index_prefix

STAR 索引

1
2
3
4
5
6
STAR --runMode genomeGenerate \
--genomeDir /path/to/index \
--genomeFastaFiles reference.fasta \
--sjdbGTFfile annotation.gtf \
--sjdbOverhang 100 \
--runThreadN 8

参数说明:

  • --sjdbOverhang: 读长 -1(如 101bp 读长设为 100)

  • --runThreadN: 线程数

注意事项

  1. 磁盘空间: 人类基因组索引约需 30-50GB

  2. 内存: STAR 索引需要约 30GB 内存

  3. 时间: 完整索引约需 1-4 小时

  4. 版本: 记录参考基因组版本(GRCh37/GRCh38)

验证索引

1
2
3
4
# BWA
bwa mem -t 4 reference.fasta reads.fastq | samtools view -c

# 应该输出比对上的 reads 数

此文档为 GitHub 博客自动归档

PPT

原文日期: 2017-02-12
来源: https://github.com/wlz0726/wlz0726.github.io


PPT 制作技巧

设计原则

1. 简洁 (Keep It Simple)

  • 每页一个核心观点

  • 避免文字堆砌

  • 留白是美德

2. 一致 (Consistency)

  • 字体统一(标题 + 正文不超过 2 种)

  • 颜色统一(主色 + 辅色 + 强调色)

  • 风格统一(扁平化/拟物化)

3. 可视化 (Visualize)

  • 多用图表,少用文字

  • 一图胜千言

  • 使用高质量图片

4. 对比 (Contrast)

  • 大小对比(标题 vs 正文)

  • 颜色对比(重点突出)

  • 空间对比(层次分明)

配色方案

推荐配色

配色工具

字体选择

中文推荐

  • 标题: 思源黑体、微软雅黑

  • 正文: 思源宋体、苹方

英文推荐

  • 标题: Arial, Helvetica, Montserrat

  • 正文: Georgia, Lato, Open Sans

资源推荐

演讲技巧

  1. 开场: 用问题/故事吸引注意力

  2. 结构: 总 - 分 - 总

  3. 结尾: 总结 + 行动号召

  4. 互动: 适时提问


此文档为 GitHub 博客自动归档

hello-world

原文日期: 2017-01-03
来源: https://github.com/wlz0726/wlz0726.github.io


Hello World

这是我的 Hexo 博客的第一篇文章!

博客主题

  • 生物信息学学习笔记

  • 编程技巧分享

  • 科研工具推荐

  • 生活随笔

更新计划

  • 每周至少更新一篇

  • 分享实用代码片段

  • 记录学习心得

  • 总结踩坑经验

关于我

Lizhong Wang

  • 生物信息学研究者

  • 编程爱好者

  • 终身学习者

联系方式


技术栈

编程语言

  • Perl

  • Python

  • R

工具

  • Linux/Unix

  • Git

  • Docker

研究方向

  • 群体遗传学

  • 基因组学

  • 生物信息学算法


🎉 博客正式开通!欢迎交流!


此文档为 GitHub 博客自动归档

0%