Skip to content

8a. Tiny example Francisellaceae base and tularensis modification

jaclew edited this page Nov 21, 2023 · 4 revisions

Tiny example: Francisellaceae base and tularensis modification

In this example, the Francisellaceae example dataset (taxonomy: ftd.tree2tax.tsv and genome-map: genomes_map.tsv) will be used to create a new FlexTaxD database (Fdb). The Fdb will be modified to expand taxonomy for tularensis species using tularensis dataset (taxonomy: ftd.tree2tax.tul.tsv and genome-map: genomes_map.tul.tsv). The Fdb will be visualised before and after the modification.

Create environment using mamba (or conda) and install FlexTaxD with dependencies for visualisation and compilation of Kraken2 database:

mamba create -n flextaxd_example flextaxd ncbi-datasets-cli inquirer biopython matplotlib kraken2
conda activate flextaxd_example

Obtain example dataset files:

wget https://github.com/FOI-Bioinformatics/flextaxd/raw/master/wiki/example_data/ftd.tree2tax.tsv
wget https://github.com/FOI-Bioinformatics/flextaxd/raw/master/wiki/example_data/genomes_map.tsv
wget https://github.com/FOI-Bioinformatics/flextaxd/raw/master/wiki/example_data/tularensis/ftd.tree2tax.tul.tsv
wget https://github.com/FOI-Bioinformatics/flextaxd/raw/master/wiki/example_data/tularensis/genomes_map.tul.tsv

Creating the FlexTaxD database (Fdb)

Create the Fdb:

flextaxd --db francisellaceae.fdb --taxonomy_file ftd.tree2tax.tsv --genomeid2taxid genomes_map.tsv

Visualise the Fdb:

flextaxd --db francisellaceae.fdb --vis_type tree --vis_node root --vis_depth 0 --vis_label_size 7

francisellaceae Figure 1: The Francisellaceae database with tularensis species marked by a red box.

Modifying the Fdb

The Fdb will be modified, expanding tularensis taxonomy by replacing tularensis-node.

First, a copy is made to preserve the original non-modified Fdb

cp francisellaceae.fdb francisellaceae_tul.fdb

Before proceeding, must ensure that the root-name in "ftd.tree2tax.tul.tsv" matches the node-name in the Fdb. It can be done by changing the root-name in "ftd.tree2tax.tul.tsv". Replace "Francisella tularensis" by "Francisellaceae_Francisella_tularensis_GCF_000008985.1", see Figure 1 (red box) above:

nano ftd.tree2tax.tul.tsv

>child   parent
>Francisellaceae_Francisella_tularensis_GCF_016604535.1  Francisella tularensis
>Francisellaceae_Francisella_tularensis_GCF_000742085.1  tul1
>tul1    Francisella tularensis
>Francisellaceae_Francisella_tularensis_GCF_001870885.1  tul2
>tul2    tul1
>Francisellaceae_Francisella_tularensis_GCF_001044315.2  tul3
>tul3    tul2
>Francisellaceae_Francisella_tularensis_GCF_002952075.1  tul5
>tul5    tul4
>tul4    tul3
>Francisellaceae_Francisella_tularensis_GCF_000014645.1  tul5
>Francisellaceae_Francisella_tularensis_GCF_001865695.1  tul6
>tul6    tul4
>Francisellaceae_Francisella_tularensis_GCF_000833355.1  tul7
>tul7    tul6
>Francisellaceae_Francisella_tularensis_GCF_000195535.1  tul7

On the first and third rows in the second column, replace "Francisella tularensis" to "Francisellaceae_Francisella_tularensis_GCF_000008985.1":

head ftd.tree2tax.tul.tsv -n5

>child   parent
>Francisellaceae_Francisella_tularensis_GCF_016604535.1  Francisellaceae_Francisella_tularensis_GCF_000008985.1
>Francisellaceae_Francisella_tularensis_GCF_000742085.1  tul1
>tul1    Francisellaceae_Francisella_tularensis_GCF_000008985.1
>Francisellaceae_Francisella_tularensis_GCF_001870885.1  tul2

Replace the old tularensis species with the imported taxonomy:

flextaxd --db francisellaceae_tul.fdb --mod_file ftd.tree2tax.tul.tsv --genomeid2taxid genomes_map.tul.tsv --parent Francisellaceae_Francisella_tularensis_GCF_000008985.1 --replace

Visualise the Fdb:

flextaxd --db francisellaceae_tul.fdb --vis_type tree --vis_node root --vis_depth 0 --vis_label_size 7

Note that the old tularensis leaf-node has become a branch-node. The name of this node can be changed by:

flextaxd --db francisellaceae_tul.fdb --rename_from Francisellaceae_Francisella_tularensis_GCF_000008985.1 --rename_to tul0

After executing the visualising-command again: francisellaceae_tularensis Figure 2: The Francisellaceae database with tularensis expansion. The replaced node is indicated by a red box.

Obtaining genomes and exporting the Fdb to Kraken2

FlexTaxD can download the missing genomes.

flextaxd-create --db francisellaceae_tul.fdb --genomes_path genomes --dbprogram kraken2 --create_db --db_name kraken2.francisellaceae --processes 20

>Warning: directory for downloaded genomes does not exist, do you want to create it? (y/n): y
>There is a discrepancy of genomes found in the database and the specified genome-folder, 0 genomes were found and 36 genomes are missing.
>You may want to purge your database from missing genomes using "flextaxd --purge_database"
>Do you want to download these genomes from NCBI? (y)es, (n)o, (c)ancel:

First, FlexTaxD prompts to create the directory for genomes if it does not exist. Second, FlexTaxD identifies 36 genomes as missing and prompts for download. If yes is entered, FlexTaxD attempts to download these genomes from NCBI.

After the download has completed, FlexTaxD proceeds to compile the Kraken2 database.

flextaxd-create --db francisellaceae_tul.fdb --genomes_path genomes --dbprogram kraken2 --create_db --db_name kraken2.francisellaceae --processes 20

>Warning: directory for downloaded genomes does not exist, do you want to create it? (y/n): y
>There is a discrepancy of genomes found in the database and the specified genome-folder, 0 genomes were found and 36 genomes are missing.
>You may want to purge your database from missing genomes using "flextaxd --purge_database"
>Do you want to download these genomes from NCBI? (y)es, (n)o, (c)ancel: y
>                Collecting 36  records [================================================] 100% 36/36
>[NCBI-DATASETS] Downloading: tmp//ncbi_download.zip    21.8MB done
>Creating sequence ID to taxonomy ID map (step 1)...
>Sequence ID to taxonomy ID map complete. [0.023s]
>Estimating required capacity (step 2)...
>Estimated hash table requirement: 99101256 bytes
>Capacity estimation complete. [1.211s]
>Building database files (step 3)...
>Taxonomy parsed and converted.
>CHT created with 7 bits reserved for taxid.
>Completed processing of 1219 sequences, 74943995 bp
>Writing data to disk...  complete.
>Database files completed. [15.102s]
>Database construction complete. [Total: 16.373s]

Alternative download

To save a list of accession identifiers, FlexTaxD can be run with parameter --keep to save a file that lists missing genomes:

flextaxd-create --db francisellaceae_tul.fdb --genomes_path another_genomes_directory --dbprogram kraken2 --create_db --db_name kraken2.francisellaceae --processes 20 --keep

>Warning: directory for downloaded genomes does not exist, do you want to create it? (y/n): y
>There is a discrepancy of genomes found in the database and the specified genome-folder, 0 genomes were found and 36 genomes are missing.
>You may want to purge your database from missing genomes using "flextaxd --purge_database"
>Do you want to download these genomes from NCBI? (y)es, (n)o, (c)ancel: c
>Genomes were missing, you can find the names of these genomes in file FlexTaxD.missing, located in ./tmp directory (you might need to specify --keep)
>Terminated.

The missing file is located by default at ./tmp/FlexTaxD.missing

head -n5 tmp/FlexTaxD.missing

>GCF_001865695.1
>GCF_008711525.1
>GCF_007923265.1
>GCF_003574425.1
>GCF_000195535.1

Clone this wiki locally