Hifiasm 使用教程
介紹
Hifiasm 是一個快速的單倍型解析 de novo 組裝軟件,最初設計用于 PacBio HiFi 讀取。其最新版本可以通過利用超長的 Oxford Nanopore 讀取支持端粒到端粒的組裝。Hifiasm 可以生成單樣本端粒到端粒的組裝,結合了 HiFi、超長和 Hi-C 讀取,可以說是最好的組裝軟件之一。對于 trio-binning 組裝來說,它是最好的單倍型解析組裝軟件之一,適用于父本短讀取。對于人類基因組來說,hifiasm 可以在一天內完成端粒到端粒的組裝。
安裝
# 安裝 hifiasm (需要有g++和zlib)
git clone https://github.com/chhylp123/hifiasm
cd hifiasm && make
# 用conda安裝
conda install -c bioconda hifiasm
# 直接使用集群module
module load hifiasm/0.19.9
# 用測試數據運行 (用-f0來處理較小的數據集)
wget https://github.com/chhylp123/hifiasm/releases/download/v0.7/chr11-2M.fa.gz
./hifiasm -o test -t4 -f0 chr11-2M.fa.gz 2> test.log
awk '/^S/{print ">"$2;print $3}' test.bp.p_ctg.gfa > test.p_ctg.fa # 在FASTA獲得主要的contigs
軟件參數
$ hifiasm
Usage: hifiasm [options] <in_1.fq> <in_2.fq> <...>
Options:
Input/Output:
-o STR prefix of output files [hifiasm.asm]
-i ignore saved read correction and overlaps
-t INT number of threads [1]
-z INT length of adapters that should be removed [0]
--version show version number
Overlap/Error correction:
-k INT k-mer length (must be <64) [51]
-w INT minimizer window size [51]
-f INT number of bits for bloom filter; 0 to disable [37]
-D FLOAT drop k-mers occurring >FLOAT*coverage times [5.0]
-N INT consider up to max(-D*coverage,-N) overlaps for each oriented read [100]
-r INT round of correction [3]
Assembly:
-a INT round of assembly cleaning [4]
-m INT pop bubbles of <INT in size in contig graphs [10000000]
-p INT pop bubbles of <INT in size in unitig graphs [0]
-n INT remove tip unitigs composed of <=INT reads [3]
-x FLOAT max overlap drop ratio [0.8]
-y FLOAT min overlap drop ratio [0.2]
-u disable post join contigs step which may improve N50
--lowQ INT
output contig regions with >=INT% inconsistency in BED format; 0 to disable [70]
--b-cov INT
break contigs at positions with <INT-fold coverage; work with '--m-rate'; 0 to disable [0]
--h-cov INT
break contigs at positions with >INT-fold coverage; work with '--m-rate'; -1 to disable [-1]
--m-rate FLOAT
break contigs at positions with <=FLOAT*coverage exact overlaps;
only work with '--b-cov' or '--h-cov'[0.75]
--primary output a primary assembly and an alternate assembly
Trio-partition:
-1 FILE hap1/paternal k-mer dump generated by "yak count" []
-2 FILE hap2/maternal k-mer dump generated by "yak count" []
-c INT lower bound of the binned k-mer's frequency [2]
-d INT upper bound of the binned k-mer's frequency [5]
-3 FILE list of hap1/paternal read names []
-4 FILE list of hap2/maternal read names []
--t-occ INT
force remove unitigs with >INT unexpected haplotype-specific reads;
ignore graph topology; [60]
Purge-dups:
-l INT purge level. 0: no purging; 1: light; 2/3: aggressive [0 for trio; 3 for unzip]
-s FLOAT similarity threshold for duplicate haplotigs [0.75 for -l1/-l2, 0.55 for -l3]
-O INT min number of overlapped reads for duplicate haplotigs [1]
--purge-cov INT
coverage upper bound of Purge-dups [auto]
--n-hap INT
number of haplotypes [2]
Hi-C-partition:
--h1 FILEs file names of Hi-C R1 [r1_1.fq,r1_2.fq,...]
--h2 FILEs file names of Hi-C R2 [r2_1.fq,r2_2.fq,...]
--seed INT RNG seed [11]
--n-weight INT
rounds of reweighting Hi-C links [3]
--n-perturb INT
rounds of perturbation [10000]
--f-perturb FLOAT
fraction to flip for perturbation [0.1]
格式轉換
# bam --> fasta
samtools view *.bam | awk '{print ">"$1"\n"$10}' > fasta
#補充一下其他格式的轉換
## sam ---> fasta
cat *.sam | awk '{print ">"$1"\n"$10}' > *.fasta
## fasta ---> sam
bowtie2 -1 *_1.fa -2 *_2.fa -p 16 -x prefix -S *.sam
## sam --> bam
# -@:線程 -b:輸出格式為BAM -S:自動檢測輸入格式 -o:輸出文件
samtools view -@ 16 -b -S final.sam -o final.bam
## bam --> sam
samtools view *.bam -O SAM > *.sam
用途
# 組裝近交/同源基因組(-l0 禁用重復清除功能)
hifiasm -o CHM13.asm -t 32 -l0 CHM13-HiFi.fa.gz 2> CHM13.asm.log
# 利用內置的重復清除功能組裝雜合基因組
hifiasm -o HG002.asm -t 32 HG002-file1.fq.gz HG002-file2.fq.gz
# 用兩個FASTQ文件中的成對端短reads進行 Hi-C 相位分析
hifiasm -o HG002.asm --h1 read1.fq.gz --h2 read2.fq.gz HG002-HiFi.fq.gz
# 雙親二代測序組件 (需要文件 https://github.com/lh3/yak)
yak count -b37 -t16 -o pat.yak <(cat pat_1.fq.gz pat_2.fq.gz) <(cat pat_1.fq.gz pat_2.fq.gz)
yak count -b37 -t16 -o mat.yak <(cat mat_1.fq.gz mat_2.fq.gz) <(cat mat_1.fq.gz mat_2.fq.gz)
hifiasm -o HG002.asm -t 32 -1 pat.yak -2 mat.yak HG002-HiFi.fa.gz
# 使用 HiFi、超長(ont)和 Hi-C reads進行端粒到端粒的單倍體組裝
hifiasm -o HG002.asm --h1 read1.fq.gz --h2 read2.fq.gz --ul ul.fq.gz HG002-HiFi.fq.gz
注意事項
- no need polish
- 無需合并多個輸入文件
- 絕大多數二倍體基因組,只需要組裝2n中的n,所以參數一般給 -l 2 -n 4
只有Hifi數據
- 無需額外的數據類型組裝 HiFi reads
hifiasm -o NA12878.asm -t 32 NA12878.fq.gz#其中NA12878.fq.gz提供輸入reads,-t設置使用中的CPU數,-o輸出文件的前綴名
# no need haplotype
hifiasm --primary -o NA12878.asm -t 32 NA12878.fq.gz
# -l:0:沒有對組裝去冗余,組裝結果包括全部組裝出來的contig,可能包含多個單倍體基因組;2/3:會對組裝出來的基因組進行去冗余,對于二倍體,得到的結果基本上是全基因組一半的大小
# -n: 一般給3或者4,默認3,表示組裝的contig中,unitigs支持大于3或4才保留,該參數會將支持度比較低的contig去掉
使用ONT數據
- Hifiasm 可以集成超長 ONT 讀取來生成端粒到端粒的組裝:
# only ONT
hifiasm -o NA12878.asm -t32 --ul ul.fq.gz HiFi-reads.fq.gz
# + Hi-C
hifiasm -o NA12878.asm -t32 --ul ul.fq.gz --h1 read1.fq.gz --h2 read2.fq.gz HiFi-reads.fq.gz
# + parental
hifiasm -o NA12878.asm -t32 --ul ul.fq.gz -1 pat.yak -2 mat.yak HiFi-reads.fq.gz
使用trio binning組件
- 當有父本的短讀取可用時,hifiasm 還可以通過 trio binning 生成一對單倍型解析的組裝。要進行這樣的組裝,您首先需要使用 yak 對 k-mer 進行計數,然后再進行組裝。
yak count -k31 -b37 -t16 -o pat.yak paternal.fq.gz
yak count -k31 -b37 -t16 -o mat.yak maternal.fq.gz
hifiasm -o NA12878.asm -t 32 -1 pat.yak -2 mat.yak NA12878.fq.gz
也可以通過merqury來確定 k-mer的大小
使用HI-C數據
- 利用成對的端到端 Hi-C reads 生成一對單倍型解析的組裝。
hifiasm -o NA12878.asm -t 32 --h1 read1.fq.gz --h2 read2.fq.gz HiFi-reads.fq.gz
# --h1 --h2 HiC 數據
# -t 線程數
# -o 輸出文件前綴
結果
hifiasm 輸出結果有哪些?
一般來說,用hifiasm組裝基因組,純合材料用- l0
,非純系材料,參數-l3
,分出兩個單倍型,是默認參數,所以默認可以不設置。
兩個模式大體輸出結果如下圖:
可以看出來,區別在于前者多輸出了一個a_ctg
而后者則多輸出了hap1.p_ctg
和hap2.p_ctg
邏輯上,看過文獻應該比較容易理解
理解共同的輸出文件
r_utg
r 代表 raw,也就是最初組裝出來的原始結果。其中 utg 表示 unitig,或理解為初步組裝且沒有拆分氣泡或者沖突的結果。
p_utg
p 代表 primary,基本上是在 raw 的基礎上去除掉一些覆蓋率低的連接(或叫氣泡)。看起來簡潔了不少,其實是少了 60000 條邊(當然圖太大,看不太出區別....不過確實是小了四分之一)
或許高雜合材料里面,覆蓋率低的區域,也可能是另一個單倍型區域?用于后續HiC掛載,可能也要考慮進去。在 p_utg 和 p_ctg 上的選擇,或需要考量。
p_ctg
p 代表 primary,ctg 代表了拆分結果。
邏輯上 p_ctg 包含了全部單倍型結果(含 hap1 和 hap2)。事實上,這個文件在l0
和l3
的表現不相同,可以從文件大小看出區別。個人感覺,l0
下 p_ctg 約等于 canu 軟件的組裝結果;而l3
模式下,p_ctg 比較接近于主要的一套單倍型結果,大體是hap1
和hap2
中表現最好的每個contig的hap的組合。
a_ctg
a 代表 alternative,大體是拆分出來 p_ctg 之后剩下的就放在 alternative。
hap1/hap2 ctg
亦即兩個單倍型的拆分結果。
假如有 HiC 數據
結果類似。phased的效果會好很多。
對于三重組裝,hifiasm會生成以下文件:
prefix.r_utg.gfa(Haplotype-resolved raw unitig graph in GFA format):保存了所有的單倍型信息。
prefix.hap1.p_ctg.gfa(Phased paternal/haplotype1 contig graph):保留了階段性父系/單倍型1組裝。
prefix.hap2.p_ctg.gfa(Phased maternal/haplotype2 contig graph):保留了階段性母系/單倍型2組裝。
- 獲取組裝結果
# get fasta
awk '/^S/{print ">"$2;print $3}' test.p_ctg.gfa > test.p_ctg.fa
參考
1.Cheng, H., Concepcion, G.T., Feng, X., Zhang, H., Li H. (2021) Haplotype-resolved de novo assembly using phased assembly graphs with hifiasm. Nat Methods, 18:170-175. https://doi.org/10.1038/s41592-020-01056-5
2.Cheng, H., Jarvis, E.D., Fedrigo, O., Koepfli, K.P., Urban, L., Gemmell, N.J., Li, H. (2022) Haplotype-resolved assembly of diploid genomes without parental data. Nature Biotechnology, 40:1332–1335. https://doi.org/10.1038/s41587-022-01261-x
3.使用hifiasm組裝hifi基因組的方法介紹 作者:生信技術 http://t.csdnimg.cn/UBXEm
4.基因組裝 | hifiasm 輸出結果文件細究 作者:生信石頭基因組裝 | hifiasm 輸出結果文件細究 - 簡書 (jianshu.com)
5.單倍體組裝工具Hifiasm簡介及基本運行命令(一) 作者:呂強強學生信單倍體組裝工具Hifiasm簡介及基本運行命令(一) - 簡書 (jianshu.com)
6.基因組組裝:Hifiasm 使用教程 作者:科學冷凍工廠 基因組組裝:Hifiasm 使用教程-騰訊云開發者社區-騰訊云 (tencent.com)