macでインフォマティクス

macでインフォマティクス

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

ロングリードゲノムアセンブリの完全性および捉えにくい配列モチーフを評価する Klumpy

 

 第3世代シーケンサー技術の向上とコスト削減により、研究者がde novoゲノムアセンブリで取り組める生物学的問題の範囲が広がっている。リファレンスゲノムの数が増加する中、その完全性を最小限のオーバーヘッドで検証することは、その応用において信頼できる結果を確立するために不可欠である。ここでは、Klumpyを紹介する。Klumpyは、ゲノムアセンブリ中のミスアセンブリー領域と、配列中の注目すべき遺伝的要素(遺伝子、プロモーター、トランスポーザブルエレメントなど)の両方を検出し、可視化するツールである。Klumpyの有用性を、2種類の氷魚の不凍糖タンパク質(afgp)遺伝子座の調査、ノーザンスネークヘッドフィッシュの欠失遺伝子の検索、ムツゴロウとマルハナバチのリファレンスゲノムのミスアセンブル領域のスキャンによって説明する。前者の2つのケースでは、氷魚におけるafgp遺伝子座の非正規配置を支持し、欠失したスネークヘッド遺伝子を突き止めることができた。さらに、ゲノムスキャンによって、ムツゴロウのリファレンスゲノムに隠蔽された遺伝子座を同定し、数種のハチの間で共有されている反復エレメントを同定することができた。

 

インストール

macでpython3.14の環境を作ってテストした。

bitbucket

mamba create -n klumpy -c conda-forge python=3.12 cairo pycairo pkg-config pip "setuptools<82"
conda activate klumpy

#本体
git clone https://bitbucket.org/Gio12/klumpy.git
cd klumpy/
python3 -m pip install klumpy

> klumpy -h

 % klumpy -h

/Users/kazu/Documents/ProteinView/klumpy/klumpy/__init__.py:30: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.

  import pkg_resources

klumpy v1.1.2

 

klumpy [analysis choice] --param1 input1 --param2 input2 etc...

 

Analysis Choices [must select one]:

    # primary subprograms

    find_klumps:                Find query klumps in a set of subject sequences

    scan_alignments:            Scan a SAM/BAM file for misassembled candidate regions

 

    # visualization subprograms

        alignment_plot:             Plot the alignments at a specified region using a SAM/BAM file

        klump_plot:                 Create a figure illustrating the klumps on the subject sequences

    

    # accessory subprograms

        combine_klumps:             Combine klump tsv files from multiple runs

        find_gaps:                  Create a tsv file containing the positions of gaps from a reference genome

        get_exons:                  Create a fasta file of exonic sequences from a list of genes

        kmerize:                    Find the coordinates of the query k-mers in the subject sequences

        klump_sizes:                Print out the expected klump sizes for each sequence

 

        

Options for `find_klumps`:

    --subject:                  Subject sequences in FAST[A|Q] format    

    --query:                    Query sequences in subject sequences, in FAST[A|Q] format

    --query_map:                The query_map file containing query matches generated after `find_klumps` or `kmerize`

    --output:                   Name of output file

    --range:                    Maximum distance two k-mers must be in order to be considered within the same klump (default = 1000)

    --min_kmers:                Minimum number of k-mers needed to form a klump (default = 1)

    --threads:                  Number of threads (default = 1)

    

    Advanced options:

        --ksize:                    Length of k-mer (must be an integer greater than 0) (default = 17)

        --query_count:              Minimum number of different queries a sequence is matched to (default = 1) 

        --klump_count:              Minimum number of klumps a sequence must have (default = 1)

        --limit:                    Number of subject sequences to load into memory at once (default 10000)        

 

        

Options for `scan_alignment`:

    --alignment_map:            A sorted and indexed SAM/BAM file [Required]

    --min_len:                  Minimum length a sequence must be to retain an alignment in the grouping analysis (default = 2000)

    --min_percent:              Minimum percent a sequence must be aligned for the alignment to be retained in the grouping analysis (default = 50)

    --threads:                  Number of threads (default = 1)

    --annotation:               Gene annotations in GTF/GFF3 format [Optional]

 

    Advanced options:

        --deletion_len:             Minimum length of deletion to draw and split alignment into blocks (default = 100)

        --assume_sep_del:           If set, remove the assumption that overlapping alignments with deletions can be automatically grouped if compatible

        --clip_tolerance:           Number of clipped base pairs to tolerate when comparing two alignments for compatibility (default = 400)

        --del_tolerance:            Length (in bp) covered by a deletion to be tolerated when comparing two alignments for compatibility (default = 50)

        --per_overlap:              Minimum percent two sequences need to overlap one another in order to confidently consider them compatible (default = 75)

        --t_len:                    Minimum length a sequence must be in order to trust its assignment when grouping (default = 2000)

        --t_per:                    Minimum percentage a sequence must be aligned in order to trust its assignment when grouping (default = 30)

        --align_offset:             Maximum number of base pairs apart for two sequences to be considered aligned at the same position (default = 100)

        --min_grp:                  Minimum number of sequences in a group in order to retain the group (default = 10)

        --window_size:              Length (in bp) for the sliding window to be (default = 50000)

        --window_step:              Length (in bp) for the sliding window to slide down to establish the next window (default = 25000) 

        --limit:                    Maximum number of alignments to process in a window (default 10000)

        --num_of_groups:            Number of groups at a window to flag the window (default = 3)

        --flag_excess_groups:       If set, will report regions with --num_of_groups Groups or more regardless if the region was tiled or not (default = False)

 

 

Options for `alignment_plot`:

    --alignment_map:            A sorted and indexed SAM/BAM file [Required]

    --reference:                Name of reference sequence

    --leftbound:                Leftmost Position in the reference genome (default = 0)

    --rightbound:               Rightmost Position in the reference genome (default = 50000)

    --region_num:               Region Number in a *_Candidate_Regions.tsv file generated by `scan_alignments` (default = 1)

    --candidates:               A *_Candidate_Regions.tsv file generated from `scan_alignments`

    --min_len:                  The Minimum length a sequence must be in order to retain it in the plot (default = 2000)

    --min_percent:              The Minimum percent of base pairs from a sequence that must be aligned for it to be retained in the plot (default = 50)

    --klumps_tsv:               Klump tsv output generated from `find_klumps`

    --gap_file:                 File containing locations of gaps in the reference (generated using `find_gaps`)

    --color:                    Color to use for drawing klumps (default = blue)

    --annotation:               Gene annotations in GTF/GFF3 format

    --list_colors:              If set, the program will list the available colors for klumps and exit

    --vertical_line_gaps:       If set, a vertical line above gaps will be drawn

    --vertical_line_klumps:     If set, a vertical line above the reference klumps will be drawn

    --vertical_line_exons:      If set, a vertical line above the exons will be drawn

    --format:                   Output format to draw image on. Choices are `pdf`, `png`, and `svg` (default = pdf)

    --group_seqs:               If set, the sequences in the plot will be grouped based on alignment patterns

 

    Advanced options:

        --min_klump_size:           Minimum number of k-mers a klump must contain to retain in the plot (default = 1)    

        --max_percent:              Maximum percent a sequence must be aligned for it to be retained in the plot (default = 100) 

        --height:                   Height (in pixels) of the pdf to be generated (default = 2000)

        --width:                    Width (in pixels) of the pdf to be generated (default = 2000)

        --klump_colors:             A tsv file containing the names of the klump sources and the color to use for drawing these klumps

        --color_by_gene:            If set and in combination with --klump_colors, will color all klumps belonging to the same gene

        --plotting_list:            List of sequences to plot (filters remain on)

        --deletion_len:             Minimum length of deletion to draw and split alignment into blocks (default = 100)

        --view_span:                Length (in bp) to view from the leftbound and the rightbound when parsing SAM/BAM file (default = 1000000)

        --number:                   If set, sequences on the plot will be numbered 

        --tick_count                If used, specify the number of ticks to use on the reference genome [Optional]

        --tick_span                 If used, specify how many base pairs the ticks on the reference genome should be apart [Optional]

        --write_table:              If set, general information on the sequences on the plot will be written out to a TSV file

        --paired:                   Set if working with paired-end data

        --no_primary:               If set, primary alignments will be filtered out

        --no_subsample:             If set, will not randomly subsample alignments when the number of alignments is greater than --limit

        --supplementary:            If set, supplementary alignments will be kept if they pass all other filters

        --secondary:                If set, secondary alignments will be kept if they pass all other filters

        --write_groups:             If set, the sequences for each group will be written out in fasta format (one file per group)

        --write_seqs:               If set, the sequences that were plotted will be written in fasta format

        --write_edge_seqs:          If set, sequences with clipped alignments at the edges/ends of their groups will have their names written to a list

        --assume_sep_del:           If set, remove the assumption that overlapping alignments with deletions can be automatically grouped if compatible

        --clip_tolerance:           Number of clipped base pairs to tolerate when comparing two alignments for compatibility (default = 150)

        --del_tolerance:            Length (in bp) covered by a deletion to be tolerated when comparing two alignments for compatibility (default = 50)

        --limit:                    Maximum number of alignments to process in a group analysis and draw (default 10000)

        --per_overlap:              Minimum percent two sequences need to overlap one another in order to confidently consider them compatible

        --t_len:                    Minimum length a sequence must be in order to trust its assignment when grouping (default = 2000)

        --t_per:                    Minimum percentage a sequence must be aligned in order to trust its assignment when grouping (default = 30)

        --align_offset:             Maximum number of base pairs apart for two sequences to be considered aligned at the same position (default = 100)

        --min_grp:                  Minimum number of sequences in a group in order to retain the group (default = 10)

 

        

Options for `klump_plot`:

    --klumps_tsv:               Klump tsv output generated from `find_klumps` [Required]

    --color:                    Color to use for drawing klumps (default = blue)

    --list_colors:              If set, the program will list the available colors for klumps and exit

    --fix_width:                If set, all the sequences in the figure will have the same `image` width

    --gap_file:                 File containing locations of gaps in the sequences (generated using `find_gaps`)

    --seq_name:                 Name of specific sequence to plot

    --format:                   Output format to draw image on. Choices are `pdf`, `png`, and `svg` (default = pdf)

    

    Advanced options:

        --klump_colors:             A tsv file containing the names of the query sources and the color to paint the query-specific klumps

        --color_by_gene:            If set and in combination with --klump_colors, will color all exons belonging to the same gene

        --leftbound:                Leftmost Position to plot --seq_name (default = 1) [requires --seq_name]

        --rightbound:               Rightmost Position to plot --seq_name (default = 50000) [requires --seq_name]

        --tick_count                If used, specify the number of ticks to use on the specified sequence [requires --seq_name]

        --tick_span                 If used, specify how many base pairs the ticks on the specified sequence should be apart [requires --seq_name]

 

 

Options for `combine_klumps`:

    --output:                   Name of output file [Optional]

    --klumps_tsv_list:          Names of files to combine (--klump_tsv_list file1.tsv file2.tsv file3.tsv etc...) [Required]

 

    

Options for `find_gaps`:

    --fasta:                    Reference genome in fasta format [Required]

 

    

Options for `get_exons`:

    --fasta:                    Reference genome in fasta format [Required]

    --annotation:               Gene annotations in GTF/GFF3 format [Required]

    --genes:                    Names of genes from which to extract exons from [Required] (e.g., --genes gene_name1 gene_name2 gene_name3)

 

    

Options for `kmerize`:

    --subject:                  Subject sequences to look for queried k-mers in FAST[A|Q] format [Required]    

    --query:                    Query sequences to generate query k-mers to search for in subject sequences, in FAST[A|Q] format [Required]

    --threads:                  Number of threads (default = 1)

    

    Advanced options:

        --ksize:                    Length of k-mer (must be an integer greater than 0) (default = 17)

        --output:                   Name of output file

        --limit:                    Number of subject sequences to load into memory at once (default 10000)

    

 

Options for `klump_sizes`:

    --fasta:                    Sequences to break down to k-mers, in FASTA format [Required]

    --ksize:                    Length of k-mer (must be an integer greater than 0) (default = 17)

 

実行方法

klumpyは9つの異なるサブプログラムから構成されており、2つは主要なサブプログラムで、2つは結果を図示するためのものである。残りの5つは他の4つのサブプログラムを補足するように設計されている。

 

1、マッピング

minimap2 -ax map-hifi -t 20 GCA_000001735.2.fna ERR11437307.fq.gz \
| samtools sort -@ 8 -o ERR11437307.sorted.bam

#index
samtools index ERR11437307.sorted.bam

 

2、 scan_alignments

アセンブリ中のmisassembly候補領域を探索する。--alignment_map でsorted/indexed BAMを指定する。

klumpy scan_alignments --alignment_map ERR11437307.sorted.bam --threads 8

scan_alignments はゲノム上をwindowスキャンし、ロングリードのアライメントパターンが不整合なグループに分かれる領域を検出する。デフォルトでは、50 kb windowを25 kbずつ動かし、グループ数が3以上になった領域を候補とする。また、1グループを成立させる最低リード数は --min_grp 2で、かなり高感度よりの設定になっている。

シロイヌナズナゲノムと3GBのHiFiロングリードbamを使ってtestした。計算には5分ほどかかった(9900X)。

 

出力例

> head candidates.tsv

Region_Number    候補領域の番号
Reference_Seq    染色体・コンティグのID
Start    候補領域の開始位置
End    候補領域の終了位置
Tiled    何個の連続ウィンドウからこの候補領域が構成されたか
Number_of_Groups    各ウィンドウで検出されたリードのグループ数

が載っている。TiledがT,T,T,T,T,T,Tなら7個のウィンドウが連続して候補になったことを意味している。グループは、似たマッピングパターンを示すロングリードのまとまりのことで、グループ数が多いほど、その領域でリードのマッピングの仕方が何種類にも分かれていることを意味する。

 

3、alignment_plot

検出された領域のリードアラインメントを可視化する。可視化対象は、さきほどのTSVの1列目のRegion_Numberで指定する。リード量が多いと解釈しにくいことが多い。その場合は--limitをつける。小さな領域なら100でも十分に解釈できる。SVG出力指定。

klumpy alignment_plot --alignment_map ERR11437307.sorted.bam \
--candidates candidates.tsv --region_num 95 --group_seqs --format svg --limit 500
  • --limit    Number of subject sequences to load into memory at once (default 10000)

このコマンドは、検出された候補領域について、実際にPacBioリードがどのようにマッピングされているかを可視化する。--group_seqs を付けると、似たアライメントパターンを示すリードが同じ色のグループとして表示されるため、リードが一貫してマッピングしているか、複数の異なるパターンに分かれているかを視覚的に確認できる。

 

出力例

エラーの疑いがある領域周辺のロングリードのマッピングパターンが可視化される。

Klumpy は似たアライメントパターンを示すリードを同じ色のグループとして表示する。この領域では、アライメントパターンから中央付近に欠失が存在する領域を検出していると考えられる。Klumpyはリードをアライメントパターンごとにグループ化するため、この例では、中央に欠失を持つリード群に1つの色が割り当てられ、その左右にマッピングするリード群はそれぞれ異なるパターンとして別の色で表示されている。

 

ほかのコマンド

find_klumps -  指定したDNA配列をk-merに分割し、ゲノムやリード中のどこにその配列が集中して存在するかを探索する。

--query に指定した配列からk-merを作成し、--subject の配列中から一致するk-merを検索する。

klumpy find_klumps --subject input1.fa.gz --query input2.fa --min_kmers 2 --range 50

find_klumps は、マッチした k-mers の位置を用いて klumps (すなわち、マッチした k-mers のクラスター) を構築する。

 

klump_plot - find_klumpsで検出した領域を図として表示する。

klumpy klump_plot --klumps_tsv input1_klumps.tsv \
--color blue --format svg

指定した配列がゲノム上のどこに、どのようなまとまりで存在するかを可視化する。

 

出力例(レポジトリより)

find_klumpsで検出されたk-merのクラスターは青色で示される。指定した配列が対象配列(ゲノムなど)のどこに存在するか、また複数コピーとして存在するかを視覚的に把握できる。

 

その他

  • Klumpyは、ロングリードをアセンブリへ再マッピングし、misassemblyが疑われる位置を可視化する。read alignmentの切れ方を利用して、misassembly、構造的な異常、反復配列周辺の怪しい領域を局所的に探すことができる。さらに任意の遺伝子や配列モチーフを重ねられるため、この遺伝子領域が本当assembledされているのか確認にも使える。論文では魚類などのゲノムを使って、misassembled regionの探索をしている。
  • Klumpyでは、リードのclipping、deletion、alignment位置、リード同士のオーバーラップなどを使って整合性を判定している。
  • 論文では、find_klumpsで既知の遺伝子や反復性の高い遺伝子ファミリーの配列をqueryにして、ゲノム中のどこに類似配列がまとまって存在するかを探している。

     

  1. アイスフィッシュの反復性の強い特殊な不凍糖タンパク質遺伝子afgpをqueryとし、2種のアイスフィッシュのゲノム中でafgpに由来するk-merが集中する場所を探索している。その結果、従来とは異なる位置にある非典型的なafgp 遺伝子座が発見された。
  2. Northern snakeheadで存在しないと報告されていた遺伝子を検索したところ、その遺伝子を実際に見つけた。アノテーション上は欠失しているように見えるが、配列自体はゲノム中に存在するケースの確認に利用できる。

 

引用

Klumpy: A tool to evaluate the integrity of long‐read genome assemblies and illusive sequence motifs
Giovanni Madrigal, Bushra Fazal Minhas, Julian Catchen

Mol Ecol Resour. 2024 May 27;25(1):e13982

 

Klumpy: A Tool to Evaluate the Integrity of Long-Read Genome Assemblies and Illusive Sequence Motifs
Giovanni Madrigal,  Bushra Fazal Minhas,  Julian Catchen

bioRxiv, Posted February 15, 2024.

 

関連