macでインフォマティクス

macでインフォマティクス

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

アセンブリグラフを操作するためのソフトウェアフレームワーク agtools

 

 アセンブリグラフは、ゲノムおよびメタゲノムのアセンブラが配列とその重複情報を表現するために用いる基本的なデータ構造であり、より長いゲノム断片を構築する上で重要な役割を果たす。アセンブラでの本来の用途に加え、アセンブリグラフは、メタゲノムビニング、プラスミド検出、ウイルスゲノムの解明、ハプロタイプフェージングといった様々な後続の解析(ダウンストリーム解析)においても重要性を増している。しかし、異なるアセンブリグラフ形式にまたがって、プログラムによる操作(解析、変換、フィルタリング、分析など)を可能にする包括的なツールが求められている。本論文では、広く利用されているアセンブラが生成したアセンブリグラフを操作するためのオープンソースPythonフレームワークagtoolsを紹介する。agtoolsは、アセンブリグラフ形式の変換、セグメントのフィルタリング、コンポーネントの抽出といったタスクを実行するためのコマンドラインインターフェースを提供する。また、主要なゲノムおよびメタゲノムアセンブラのアセンブリグラフを読み込み、クエリを実行し、分析するためのPythonパッケージインターフェースも提供する。これにより、他のバイオインフォマティクス・ソフトウェアやワークフローに組み込み可能な、効率的なアセンブリグラフ解析が可能になる。agtoolsのソースコードはGitHub(https://github.com/Vini2/agtools)で公開されており、ドキュメントは https://agtools.readthedocs.io/ で閲覧できる。また、agtoolsはBioconda(https://anaconda.org/bioconda/agtools)やPyPI(https://pypi.org/project/agtools/)からもインストールできる。

 

Documentation

https://agtools.readthedocs.io/en/latest/

 

インストール

Github

mamba create -n agtools -y
conda activate agtools
mamba install -c bioconda agtools -y

> agtools

Usage: agtools [OPTIONS] COMMAND [ARGS]...

 

  agtools: A Software Framework to Manipulate Assembly Graphs

 

Options:

  -v, --version  Show the version and exit.

  -h, --help     Show this message and exit.

 

Commands:

  stats      Compute statistics about the graph

  rename     Rename segments, paths and walks in a GFA file

  concat     Concatenate two or more GFA files

  filter     Filter segments from GFA file

  clean      Clean a GFA file based on segments in a FASTA file

  component  Extract a component containing a given segment

  fastg2gfa  Convert FASTG file to GFA format

  gfa2fastg  Convert GFA file to FASTG format

  asqg2gfa   Convert ASQG file to GFA format

  gfa2asqg   Convert GFA file to ASQG format

  gfa2dot    Convert GFA file to DOT format (GraphViz)

  gfa2fasta  Get segments in FASTA format

  gfa2adj    Get adjacency matrix of the assembly graph

> agtools stats

Usage: agtools stats [OPTIONS]

 

  Compute statistics about the graph

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

> agtools rename

Usage: agtools rename [OPTIONS]

 

  Rename segments, paths and walks in a GFA file

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -p, --prefix TEXT     prefix for the graph elements  [default: ""]

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

> agtools concat

Usage: agtools concat [OPTIONS]

 

  Concatenate two or more GFA files

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

> agtools filter

Usage: agtools filter [OPTIONS]

 

  Filter segments from GFA file

 

Options:

  -g, --graph PATH          path(s) to the assembly graph file(s)  [required]

  -l, --min-length INTEGER  minimum length of segments to keep  [default: 100;

                            required]

  -o, --output FILE         path to the output file, or '-' to write to stdout

                            [required]

  -lf, --log-file FILE      optional path to write output logs; by default no

                            log file is created

  -h, --help                Show this message and exit.

> agtools clean 

Usage: agtools clean [OPTIONS]

 

  Clean a GFA file based on segments in a FASTA file

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -f, --fasta PATH      path to the FASTA file  [required]

  -a, --assembler TEXT  assembler name (if assembler used is myloasm)

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

> agtools component

Usage: agtools component [OPTIONS]

 

  Extract a component containing a given segment

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -s, --segment TEXT    segment ID  [required]

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

> agtools fastg2gfa

Usage: agtools fastg2gfa [OPTIONS]

 

  Convert FASTG file to GFA format

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -k, --ksize INTEGER   k-mer size used for the assembly  [default: 141;

                        required]

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

> agtools gfa2fastg

Usage: agtools gfa2fastg [OPTIONS]

 

  Convert GFA file to FASTG format

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

> agtools asqg2gfa 

Usage: agtools asqg2gfa [OPTIONS]

 

  Convert ASQG file to GFA format

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

> agtools gfa2asqg 

Usage: agtools gfa2asqg [OPTIONS]

 

  Convert GFA file to ASQG format

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

> agtools gfa2dot 

Usage: agtools gfa2dot [OPTIONS]

 

  Convert GFA file to DOT format (GraphViz)

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -ab, --abyss          use the ABySS DOT format for the output

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

> agtools gfa2fasta

Usage: agtools gfa2fasta [OPTIONS]

 

  Get segments in FASTA format

 

Options:

  -g, --graph PATH      path(s) to the assembly graph file(s)  [required]

  -o, --output FILE     path to the output file, or '-' to write to stdout

                        [required]

  -lf, --log-file FILE  optional path to write output logs; by default no log

                        file is created

  -h, --help            Show this message and exit.

>  agtools gfa2adj

Usage: agtools gfa2adj [OPTIONS]

 

  Get adjacency matrix of the assembly graph

 

Options:

  -g, --graph PATH         path(s) to the assembly graph file(s)  [required]

  --delimiter [comma|tab]  delimiter for adjacency file. Supports a comma and

                           a tab.  [default: comma]

  -o, --output FILE        path to the output file, or '-' to write to stdout

                           [required]

  -lf, --log-file FILE     optional path to write output logs; by default no

                           log file is created

  -h, --help               Show this message and exit.

 

実行方法

こちらに沿って使い方を確認する。

https://agtools.readthedocs.io/en/latest/quickstart/

 

ダウンロードしたquickstart_assembly_graph.gfaをBandageで開いた。

5つのセグメント(ノード)からなるグラフ。途中で2つのパスに分岐して、再び共通の1つのパスに戻る。

 

agtools stats - アセンブリグラフに関する統計

アセンブリグラフに関する基本的な統計や配列ベースの統計情報を生成する。

agtools stats -g quickstart_assembly_graph.gfa -o graph_stats.txt

2026-07-26 16:46:51.077 | INFO     | agtools.cli:begin_agtools:386 - agtools: A Software Framework to Manipulate Assembly Graphs

2026-07-26 16:46:51.077 | INFO     | agtools.cli:begin_agtools:387 - You are using agtools version 1.1.1

2026-07-26 16:46:51.077 | INFO     | agtools.cli:begin_agtools:389 - Repository homepage is https://github.com/Vini2/agtools

2026-07-26 16:46:51.077 | INFO     | agtools.cli:begin_agtools:390 - You are running agtools stats

2026-07-26 16:46:51.077 | INFO     | agtools.cli:begin_agtools:391 - Listing parameters

2026-07-26 16:46:51.077 | INFO     | agtools.cli:begin_agtools:394 - Parameter: --graph ('quickstart_assembly_graph.gfa',)

2026-07-26 16:46:51.077 | INFO     | agtools.cli:begin_agtools:394 - Parameter: --output results/graph_stats.txt

2026-07-26 16:46:51.077 | INFO     | agtools.cli:begin_agtools:394 - Parameter: --log-file None

2026-07-26 16:46:51.077 | INFO     | agtools.cli:stats:98 - Computing statistics of the graph file quickstart_assembly_graph.gfa

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:112 - Basic graph statistics for quickstart_assembly_graph.gfa:

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:113 - Number of segments: 5

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:114 - Number of links: 5

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:115 - Number of self-loops: 0

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:116 - Number of connected components: 1

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:117 - Average node degree: 2.0

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:118 - Sequence-based statistics for quickstart_assembly_graph.gfa:

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:119 - Total length of segments: 40 bp

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:120 - Average segment length: 8.0 bp

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:121 - N50: 8 bp

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:122 - L50: 3 segment(s)

2026-07-26 16:46:51.078 | INFO     | agtools.commands.stats:stats:123 - GC content: 50.00%

2026-07-26 16:46:51.078 | INFO     | agtools.cli:stats:102 - Computed statistics can be found in results/graph_stats.txt

 

=> graph_stats.txtが出力される。

Basic graph statistics for quickstart_assembly_graph.gfa:

Number of segments: 5

Number of links: 5

Number of self-loops: 0

Number of connected components: 1

Average node degree: 2.0

 

Sequence-based statistics for quickstart_assembly_graph.gfa:

Total length of segments: 40 bp

Average segment length: 8.0 bp

N50: 8 bp

L50: 3 segment(s)

GC content: 50.00%%                                                                                                                                            

セグメント数(ノード数)、リンク数(エッジ数)、全長、ノードの平均長、N50、L50、GC %などがでている。また、ノードあたりの平均リンク数(エッジ数)、Number of self-loops(同じノードから出て、そのノード自身へ戻る接続)もなども表示されている。

 

agtools rename - セグメントID、パスID、およびウォークIDの名前を修正

ノード名にTESTを追加。

agtools rename -g quickstart_assembly_graph.gfa -p TEST -o renamed_graph.gfa
  • -p    prefix for the graph elements  [default: ""]

もとは1、2、3だったのがTEST1、TEST2、TEST3に変更された。画像では分からないが、パス名も同様にprefixがTEST~に修正されている。

 

agtools concat - 複数のGFAファイルを結合

複数のGFAファイルを結合する。これは、複数のサンプルを含むアセンブリのその後の解析を行う際に役立つ。

agtools concat -g test_graph_1.gfa -g test_graph_2.gfa -g test_graph_3.gfa -o concatenated_graph.gfa
  • -g    path(s) to the assembly graph file(s)  [required]

リネームしたグラフと元のグラフを連結した。

 

agtools filter - セグメントを最小セグメント長に基づいてフィルタリング

このコマンドでは、最小長に満たないセグメントは、それらを含む他の要素とともに削除される。

agtools filter -g quickstart_assembly_graph.gfa -l 15 -o filtered_graph.gfa
  • -l    minimum length of segments to keep  [default: 100; required]
                                

agtools gfa2fasta - GFAをFASTAに変換

agtools gfa2fasta -g quickstart_assembly_graph.gfa -o segments.fasta

出力例

 

agtools clean - GFA内のセグメントをFASTAと照合して整合性を取る

FASTAに存在しないセグメントはGFAから除去され、GFA内で配列情報が欠けている既存セグメントには、FASTAから対応する配列が補完される(FASTAにのみ存在する新規セグメントがGFAへ追加されるわけではない。)。

agtools clean -g quickstart_assembly_graph.gfa -f segments.fasta -o cleeaned_graph.gfa

 

 agtools component - 指定したセグメントが属する連結成分をGFAファイルとして抽出

指定したセグメントを含む連結成分をGFAから抽出する。指定したセグメント単独や、その直接隣接セグメントだけではなく、リンクをたどって到達できるセグメント群全体が出力される()。

agtools component -g quickstart_assembly_graph.gfa -s A3 -o component_graph.gfa

上のGFAだと、全体がつながっているので1~5のどれを指定しても全体が出力される。

 

他にも以下のフォーマット変換コマンドが用意されている。

 

引用

agtools: a software framework to manipulate assembly graphs 

Vijini Mallawaarachchi , George Bouras , Ryan R Wick , Susanna R Grigson , Bhavya Papudeshi , Robert A Edwards

Bioinformatics Advances, Volume 6, Issue 1, 2026

 

関連