macでインフォマティクス

macでインフォマティクス

HTS (NGS) 関連のインフォマティクス情報についてまとめています。

BAM/SAM/CRAM、VCF、FASTQ、GFF3の効率的な圧縮器 genozipのバージョン14アップデート

2022/12/05, 06 HP更新

 

 Genozip は、広く利用されている FASTQ、BAM、VCF ファイル形式を含む、幅広いゲノムデータの圧縮を行う。ここでは、BAMおよびCRAMファイルの圧縮に焦点を当てた、Genozip技術の最新の進歩を紹介する。様々な種類の研究(全ゲノムシーケンス、DNAメチル化、RNASeqなど)、シーケンス技術、アライナーによって生成されたデータを、現在の最新圧縮機であるCRAMバージョン3.1よりも最大2.7倍圧縮するGenozipの能力を実証した。

 Genozipは学術研究用として自由に利用でき、LinuxMacWindowsでテスト済みである。インストール方法は、https://genozip.com/installing.html にある。ユーザーマニュアルは https://genozip.com/manual.html で入手できる。

 

 (2022/12/05更新)

HP

https://www.genozip.com/

Pricing

https://www.genozip.com/get-genozip

アカデミアの基礎研究に従事している場合、無料で使用できる。営利企業での使用は有料になっているが、その代わりに会社からのサポートを受けることができる。

Compression - Quick Guide

https://www.genozip.com/compression

Installing

https://www.genozip.com/installing

Genozip users (institution list)

特徴

  • 何百もの機関、病院、企業で広く利用されている
  • 様々なケース(ベンチマーク、論文)で利用可能な最高の圧縮率
  • FASTQ、BAM、VCF、GFF3、FASTAなど、一般的なゲノム形式をすべて圧縮可能
  • ロスレスMD5で検証済み
  • 手頃な価格、特定の研究用途では無料 (Pricingを参照)

 

インストール

#conda(link)、ここでは高速なmambaを使う
mamba install -c conda-forge genozip=14 -y

#HP(link)から実行形式ファイルをダウンロードすることもできる

> genozip -V

 

実行方法

初回は端末上で非商用の利用か商用利用かの確認と、ユーザー登録のためのメッセージが表示される。

1、genozip;あらゆるファイルを圧縮することができる。特にファイルタイプ;VCF/BCF, SAM/BAM/CRAM, FASTQ, FASTA, GFF3/GVF, PHYLIP, Chain, Kraken, 23andMe, BCL and LOCS.を圧縮するのに最適な設計になっている。ただし、.bcf, .cram, .xzファイルを圧縮するには、それぞれbcftools, samtools, xzがインストールされている必要がある。

マニュアルより。

 

ファイルを指定する。

#fastqを圧縮。通常コアあたり 1.1 スレッドを割り当て最大数使うため、--threadsオプションの指定は不要。
genozip input.fastq

#fastq.gzをさらに圧縮
genozip input.fq.gz

#BAMをさらに圧縮
genozip input.bam

#VCF.gzをさらに圧縮 (vcf.gz, .vcf.bz2, .vcf.xz and .bcf)
genozip input.vcf.gz

#パスワード付きで圧縮(解凍やgenocatで閲覧時に必要になる)
genozip --password xxxxxxxx input.fq.gz

#複数ファイル(個別に圧縮される)
genozip fastq_dir/*.fq.gz

#bam
genozip sample*bam
  • --replace    Replace the source file with the result file rather than leaving it unchanged
  • -b, --best  Best compression.
    Note: Running with this option is a bit slower and consumes more memory.

    Note: Subsetting files compressed with --best with genocat --regions or --regions-file is slower than usual.

    Note: When using --best with SAM/BAM or FASTQ, --reference must be used as well (except for long-read FASTQ files and long-read, unmapped SAM/BAM files); This can be overridden with --best=NO_REF.

    Tip: To avoid running out of memory on a low-resource personal computer, combine with limiting threads using --threads.

  • -F, --fast    Faster compression but lower compression ratio than normal. Files compressed with this option also decompress faster.

  • -p, --password <password>   Password-protected - encrypted with 256-bit AES.

  • -@, --threads <number>   Specify the maximum number of threads. By default genozip allocates 1.1 threads per core in order to maximize usage of all available cores. An exception is on Mac and Windows (including WSL) where the default allocation is 0.75 threads per core to maintain the operating system's UI's feeling of interactivity.
  • -t, --test    After compressing normally - decompress in memory (i.e. without writing the decompressed file to disk) - comparing the digest of resulting decompressed file to that of the original file. The digest algorithm used is Adler32 - this may be changed to (slower) MD5 by combining with --md5. This option is set by default.
    Note: Running genozip --test is the same as running genozip followed by genounzip --test.

    Note: If the file is compressed (eg with .gz), the digest calculated is of the uncompressed file.

コマンド実行時、genozipはデフォルトで--test付きでランさらる。このオプションは圧縮後にインメモリーで解凍して、Adler32というアルゴリズムで元のファイルと同じかどうかチェックサムが検証される(結果は標準出力されて表示される)。

 

リファレンスを提供すると圧縮率を上げることができる。リファレンスは先にgenozip形式に圧縮しておく必要がある。fastaファイルを提供した時はその場で作成される。

genozip sample.R1.fq.gz sample.R2.fq.gz --pair --reference hg19.ref.genozip -o sample.genozip
  • -e, --reference <filename>    Use a reference file (filename extension .ref.genozip) - this is a FASTA file genozipped with the --make-reference option. The same reference needs to be provided to genounzip or genocat. While genozip is capabale of compressing without a reference it can utilize a reference file to improve compression of FASTQ SAM/BAM and VCF files. The improvement for FASTQ files is substantial; for SAM/BAM it may be significant, in particular for low-coverage files; for VCF if it is significant only if REFALT content is a significant percentage of the zip content (see "% of zip" in --stats)
    Note: this is equivalent of setting the environment variable $GENOZIP_REFERENCE with the reference filename.

  • -E, --REFERENCE <filename>    Similar to --reference except genozip copies the reference (or part of it) to the output file so there is no need to specify --reference in genounzip and genocat. Note on using with --password: the copy of the reference file stored in the compressed file is never encrypted.

  • -2, --pair    Compress a pairs of paired-end FASTQ files resulting in compression ratios better than compressing the files individually. When using this option every two consecutive files on the file list should be paired-end FASTQ files with an identical number of reads and consistent file names and --reference or --REFERENCE must be specified. To display the genozip file interleaved use genocat. To uncompress the genozip file back to its original FASTQ files use genounzip.

あるペアエンドfastqデータでリファレンス使用圧縮を試したところ、gzip圧縮と比較して40%ほどのファイルサイズになった。--bestをつけるとより高い圧縮率が達成できると思われる(注;圧縮解凍でデータの損失は起こらない)。

 

2、genounzip; genozipで圧縮されたファイルを解凍する。

#ファイルを指定(.genozipは残る)
genounzip sample.fq.genozip

#複数ファイルを指定
genounzip file1.vcf.genozip file2.sam.genozip

#出力を指定
genounzip file.vcf.genozip --output file.vcf.gz

#出力prefixを指定
genounzip sample*.fq.genozip --output out
=>out~が出力される(例;out_R1.fq.gz, out_R2.fq.gz)。

# --reference付きで圧縮されたファイルを解凍(リファレンスの.genozipファイルがカレントにあるなら不要)
genounzip sample1.fq.GRCh39.genozip --reference GRCh39_genome.fasta
  • -e, --reference <filename>   Load a reference file prior to decompressing. Required only for files compressed with --reference
    Note: this is equivalent of setting the environment variable $GENOZIP_REFERENCE with the reference filename.

  • -o, --output <output-filename>  Output to this filename.
    Note: output-filename can also be a directory name, in which case the output file is written to the specified directory. If the name has a ‘/’ suffix (e.g. “-o my-dir/”), then the directory is created if it doesn’t already exist.

  • -p, --password <password>  Provide password to access file(s) that were compressed with --password.

 

3、genocatコマンド

genozip で圧縮されたファイルの内容やメタデータを表示する。

#R1 fastqを閲覧
genocat --fastq --FLAG +0x40 sample.fq.genozip

##R2 fastqを閲覧
genocat --fastq --FLAG +0x80 sample.fq.genozip

#全て閲覧
genocat --fastq=all sample.fq.genozip

#bam.genozipからfq.gz(注;BGZF-compressed FASTQ)を出力 (未テスト)
genocat myfile.bam.genozip --output myfile.fq.gz

 

manualより

  • Genozip では、krakenの出力ファイルを用いて、SAM、BAM、FASTQ、FASTA ファイルを taxid でフィルタリングすることができる。これにより、例えば、既存のBAMファイルから、再マッピングの必要なく、汚染をフィルタリングすることができる。
  • genozip形式のfastqから前処理とマッピングを行い、結果をbam.genozipとして出力する(manual
  • Dual coordinates VCF files(二重座標VCFファイル、DVCF)は、GRCh37とGRCh38のように、2つの座標系を同時に含むVCFファイル。VCFフォーマットに準拠しており、デュアル座標を維持したままシームレスに解析に使用できる。こちらを参照(manual

感想

Sequence Read Archiveに公開したデータや、(公開し且つ)既に論文になったシークエンシングデータは消えてしまっても問題にはなりませんが、DRAやSRA, ENAに公開する訳でもなく、論文にする訳でもないいわゆる死蔵のシークエンシングデータ"は、扱いに困ることになります。削除すると取り返しがつきませんが、genozipによる高効率な圧縮が解決手段になるかもしれません。試してみるのはいかがでしょうか。(データによりますが、汎用圧縮より数倍以上圧縮可能なデータもあります。これはつまり、死蔵のデータだけでいっぱいのディスクがあった場合、おそらく半分以上の領域は空き領域にできることを意味しています)

引用

Genozip 14 - advances in compression of BAM and CRAM files
Divon Lan, Bastien Llamas

bioRxiv, Posted September 14, 2022

 

関連