Skip to content

Repository files navigation

YACHT

GitHub Workflow StatuscodecovQuality Gate StatusCodeQLLicense: MIT

YACHT is a mathematically rigorous hypothesis test for the presence or absence of organisms in a metagenomic sample, based on average nucleotide identity (ANI).

The associated preprint can be found at: https://doi.org/10.1101/2023.04.18.537298. Please cite via:

Koslicki, D., White, S., Ma, C., & Novikov, A. (2023). YACHT: an ANI-based statistical test to detect microbial presence/absence in a metagenomic sample. bioRxiv, 2023-04.


Quick start

We provide a demo to show how to use YACHT. Please follow the command lines below to try it out:

NUM_THREADS=64 # if your machine doesn't have so many CPU cores, feel free to reduce this value.cd demo
# build k-mer sketches for the query sample and ref genomes
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip query_data/query_data.fq
sourmash sketch fromfile ref_paths.csv -p dna,k=31,scaled=1000,abund -o ref.sig.zip --force-output-already-exists
# preprocess the reference genomes (training step)
python ../make_training_data_from_sketches.py --ref_file ref.sig.zip --ksize 31 --num_threads ${NUM_THREADS} --ani_thresh 0.95 --prefix 'demo_ani_thresh_0.95' --outdir ./ --force
# run YACHT algorithm to check the presence of reference genomes in the query sample (inference step)
python ../run_YACHT.py --json demo_ani_thresh_0.95_config.json --sample_file sample.sig.zip --significance 0.99 --num_threads ${NUM_THREADS} --min_coverage_list 1 0.6 0.2 0.1 --out ./result.xlsx
# convert result to CAMI profile format (Optional)
python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./

There will be an output EXCEL file result.xlsx recoding the presence of reference genomes with different spreadsheets given the minimum coverage of 1 0.6 0.2 0.1.


Contents

Installation

Conda

A conda release will be coming soon. In the meantime, please install manually.

Manual installation

YACHT requires Python 3 or higher. We recommend using a virtual environment (such as conda) to run YACHT. To create a virtual environment, run:

# Clone the repo
git clone https://github.com/KoslickiLab/YACHT.git
cd YACHT
# Set up an environment for YACHT
bash setup.sh
# Activiate YACHT environment
conda activate yacht_env

Usage

The workflow for YACHT is as follows:

  1. Create sketches of your reference database genomes and of your sample
  2. Preprocess the reference genomes by removing the "too similar" genomes based on ANI using the ani_thresh parameter
  3. Run YACHT to detect the presence of reference genomes in your sample

Creating sketches of your reference database genomes

You will need a reference database in the form of Sourmash sketches of a collection of microbial genomes. There are a variety of pre-created databases available at: https://sourmash.readthedocs.io/en/latest/databases.html. Our code uses the "Zipfile collection" format, and we suggest using the GTDB genomic representatives database:

wget https://farm.cse.ucdavis.edu/~ctbrown/sourmash-db/gtdb-rs214/gtdb-rs214-reps.k31.zip

If you want to use a custom database, you will need to create a Sourmash sketch Zipfile collection from the FASTA/FASTQ files of your reference database genomes (see Sourmash documentation for details). In brief, this can be accomplished via the following:

If you have a single FASTA file with one genome per record:

sourmash sketch dna -f -p k=31,scaled=1000,abund --singleton <your multi-FASTA file> -o training_database.sig.zip

If you have a directory of FASTA files, one per genome:

## Method 1 (suggested)# put all full paths of FASTA/FASTQ file into a file, one path per line
find <path of foler containg FASTA/FASTQ files>> dataset.csv
sourmash sketch fromfile dataset.csv -p dna,k=31,scaled=1000,abund -o ../training_database.sig.zip
# cd back to YACHT## Method 2# cd into the relevant directory
sourmash sketch dna -f -p k=31,scaled=1000,abund *.fasta -o ../training_database.sig.zip
# cd back to YACHT

Creating sketches of your sample

You will then create a sketch of your sample metagenome, using the same k-mer size and scale factor

# For a single-end FASTA/Q file
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip <input FASTA/Q file># For pair-end FASTA/Q files, you need to combine them into a single file first
cat <FASTA/Q file 1><FASTA/Q file 2>> combine.fastq (or combine.fasta)
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip combine.fastq (or combine.fasta)

Parameters

Sourmash database offers three available k values (21, 31, and 51), allowing you to select the one that best suits your particular analytical needs. The scale factor serves as an indicator of data compression, and if your dataset is small, you might consider using a smaller value (corresponding to a higher portion of genomes retained in the sketch).

ParameterExplanation
k=31the length of k-mer
scaled=1000fraction of k-mers to be kept in the sketch
-o sample.sig.ziparbitrary output name for sketch files (must be in zip format)

Output

In the two preceding steps, you will obtain a k-mer sketch file in zip format (in each step) for the reference data and the input sample.

FileContent
gtdb-rs214-reps.k31.zipPre-built k-mer sketch file for GTDB representative genomes
training_database.sig.zipK-mer sketch file for your selected reference genomes
sample.sig.zipK-mer sketch file for your input sample

Preprocess the reference genomes (Training Step)

Warning: the training process is time-consuming on large database

In our benchmark with GTDB representive genomes, it takes 15 minutes using 16 threads, 50GB of MEM on a system equipped with a 3.5GHz AMD EPYC 7763 64-Core Processor. The processing time can be significant when executed on GTDB all genomes OR with limited resources. If only part of genomes are needed, one may use sourmash sig command to extract signatures of interests only.


The script make_training_data_from_sketches.py extracts the sketches from the Zipfile-format reference database, and then turns them into a form usable by YACHT. In particular, it removes one of any two organisms that have ANI greater than the user-specified threshold as these two organisms are too close to be "distinguishable".

python make_training_data_from_sketches.py --ref_file gtdb-rs214-reps.k31.zip --ksize 31 --num_threads 32 --ani_thresh 0.95 --prefix 'gtdb_ani_thresh_0.95' --outdir ./

Parameter

The most important parameter of this script is --ani_thresh: this is average nucleotide identity (ANI) value equal to or below which two organisms are considered distinct. For example, if --ani_thresh is set to 0.95, then two organisms with ANI > 0.95 will be considered indistinguishable. For the organisms with ANI > 0.95, only the one with the largest number of unique kmers will be kept. If there is a tie in the number of unique kmers, one organism will be randomly selected. The default value of --ani_thresh is 0.95. The --ani_thresh value chosen here must match the one chosen for the YACHT algorithm (see below).

ParameterExplanation
--ref_filethe path to the sourmash signature database zip file
--ksizethe length of k-mer, must match the k size used in previous sketching steps (default: 31)
--num_threadsthe number of threads to use for parallelization (default: 16)
--ani_threshthe cutoff by which two organisms are considered indistinguishable (default: 0.95)
--prefixthe prefix for output folders and files (see details below)
--outdirthe path to output directory where the results and intermediate files will be genreated

Output

File (names starting with prefix)Content
_config.jsonA JSON file stores the required information needed to run the next YACHT algorithm
_manifest.tsvA TSV file contains organisms and their relevant info after removing the similar ones
_removed_orgs_to_corr_orgas_mapping.tsvA TSV file with two columns: removed organism names ('removed_org') and their similar genomes ('corr_orgs')

Run the YACHT algorithm

After this, you are ready to perform the hypothesis test for each organism in your reference database. This can be accomplished with something like:

python run_YACHT.py --json 'gtdb_ani_thresh_0.95_config.json' --sample_file 'sample.sig.zip' --num_threads 32 --keep_raw --significance 0.99 --min_coverage_list 1 0.5 0.1 0.05 0.01 --out ./result.xlsx

Parameter

The --significance parameter is basically akin to your confidence level: how sure do you want to be that the organism is present? Higher leads to more false negatives, lower leads to more false positives.

The --min_coverage_list parameter dictates a list of min_coverage which indicates what percentage (value in [0,1]) of the distinct k-mers (think: whole genome) must have been sequenced and present in my sample to qualify as that organism as being "present." Setting this to 1 is usually safe, but if you have a very low coverage sample, you may want to lower this value. Setting it higher will lead to more false negatives, setting it lower will lead to more false positives (pretty rapidly).

ParameterExplanation
--jsonthe path to a json file generated by the make_training_data_from_sketches.py script (see above)
--significanceminimum probability of individual true negative (default: 0.99)
--num_threadsthe number of threads to use for parallelization (default: 16)
--keep_rawkeep the raw result (i.e. min_coverage=1) no matter if the user specifies it
--show_allShow all organisms (no matter if present)
--min_coverage_lista list of min_coverage values, see more detailed description above (default: 1, 0.5, 0.1, 0.05, 0.01)
--outpath to output excel result (default: './result.xlsx')

Output

The output file will be an EXCEL file; column descriptions can be found here. The most important are the following:

  • organism_name: The name of the organism
  • in_sample_est: A boolean value either False or True: if False, there was not enough evidence to claim this organism is present in the sample.
  • p_vals: Probability of observing this or more extreme result at the given ANI threshold, assuming the null hypothesis.

Other interesting columns include:

  • num_exclusive_kmers_to_genome: How many k-mers were found in this organism and no others
  • num_matches: How many k-mers were found in this organism and the sample
  • acceptance_threshold_*: How many k-mers must be found in this organism to be considered "present" at the given ANI threshold. Hence, in_sample_est is True if num_matches >= acceptance_threshold_* (adjusting by coverage if desired).
  • alt_confidence_mut_rate_*: What the mutation rate (1-ANI) would need to be to get your false positive to match the false negative rate of 1-significance (adjusting by coverage if desired).

Convert YACHT result to other popular output formats (e.g., CAMI profiling format, BIOM format, GraphPlAn)

When we get the EXCEL result file from run_YACHT.py, you can run standardize_yacht_output.py under srcs folder to covert the YACHT result to other popular output formats (Currently, only cami, biom, graphplan are supported).

Note: Before you run srcs/standardize_yacht_output.py, you need to prepare a TSV file genome_to_taxid.tsv containing two columns: genome ID (genome_id) and its corresponding taxid (taxid). An example can be found here. You need to prepare it according to the reference database genomes you used.

Then you are ready to run standardize_yacht_output.py with something like:

python srcs/standardize_yacht_output.py --yacht_output 'result.xlsx' --sheet_name 'min_coverage0.01' --genome_to_taxid 'genome_to_taxid.tsv' --mode 'cami' --sample_name 'MySample' --outfile_prefix 'cami_result' --outdir ./
ParameterExplanation
--yacht_outputthe path to the output excel file generated by run_YACHT.py
--sheet_namespecify which spreadsheet result you want to covert from
--genome_to_taxidthe path to the location of genome_to_taxid.tsv you prepared
--modespecify to which output format you want to convert (e.g., 'cami', 'biom', 'graphplan')
--sample_nameA random name you would like to show in header of the cami file. Default: Sample1.'
--outfile_prefixthe prefix of the output file. Default: result
--outdirthe path to output directory where the results will be genreated

About

A mathematically characterized hypothesis test for organism presence/absence in a metagenome

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - mfl15/YACHT: A mathematically characterized hypothesis test for organism presence/absence in a metagenome · GitHub
Skip to content

Repository files navigation

YACHT

GitHub Workflow StatuscodecovQuality Gate StatusCodeQLLicense: MIT

YACHT is a mathematically rigorous hypothesis test for the presence or absence of organisms in a metagenomic sample, based on average nucleotide identity (ANI).

The associated preprint can be found at: https://doi.org/10.1101/2023.04.18.537298. Please cite via:

Koslicki, D., White, S., Ma, C., & Novikov, A. (2023). YACHT: an ANI-based statistical test to detect microbial presence/absence in a metagenomic sample. bioRxiv, 2023-04.


Quick start

We provide a demo to show how to use YACHT. Please follow the command lines below to try it out:

NUM_THREADS=64 # if your machine doesn't have so many CPU cores, feel free to reduce this value.cd demo
# build k-mer sketches for the query sample and ref genomes
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip query_data/query_data.fq
sourmash sketch fromfile ref_paths.csv -p dna,k=31,scaled=1000,abund -o ref.sig.zip --force-output-already-exists
# preprocess the reference genomes (training step)
python ../make_training_data_from_sketches.py --ref_file ref.sig.zip --ksize 31 --num_threads ${NUM_THREADS} --ani_thresh 0.95 --prefix 'demo_ani_thresh_0.95' --outdir ./ --force
# run YACHT algorithm to check the presence of reference genomes in the query sample (inference step)
python ../run_YACHT.py --json demo_ani_thresh_0.95_config.json --sample_file sample.sig.zip --significance 0.99 --num_threads ${NUM_THREADS} --min_coverage_list 1 0.6 0.2 0.1 --out ./result.xlsx
# convert result to CAMI profile format (Optional)
python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./

There will be an output EXCEL file result.xlsx recoding the presence of reference genomes with different spreadsheets given the minimum coverage of 1 0.6 0.2 0.1.


Contents

Installation

Conda

A conda release will be coming soon. In the meantime, please install manually.

Manual installation

YACHT requires Python 3 or higher. We recommend using a virtual environment (such as conda) to run YACHT. To create a virtual environment, run:

# Clone the repo
git clone https://github.com/KoslickiLab/YACHT.git
cd YACHT
# Set up an environment for YACHT
bash setup.sh
# Activiate YACHT environment
conda activate yacht_env

Usage

The workflow for YACHT is as follows:

  1. Create sketches of your reference database genomes and of your sample
  2. Preprocess the reference genomes by removing the "too similar" genomes based on ANI using the ani_thresh parameter
  3. Run YACHT to detect the presence of reference genomes in your sample

Creating sketches of your reference database genomes

You will need a reference database in the form of Sourmash sketches of a collection of microbial genomes. There are a variety of pre-created databases available at: https://sourmash.readthedocs.io/en/latest/databases.html. Our code uses the "Zipfile collection" format, and we suggest using the GTDB genomic representatives database:

wget https://farm.cse.ucdavis.edu/~ctbrown/sourmash-db/gtdb-rs214/gtdb-rs214-reps.k31.zip

If you want to use a custom database, you will need to create a Sourmash sketch Zipfile collection from the FASTA/FASTQ files of your reference database genomes (see Sourmash documentation for details). In brief, this can be accomplished via the following:

If you have a single FASTA file with one genome per record:

sourmash sketch dna -f -p k=31,scaled=1000,abund --singleton <your multi-FASTA file> -o training_database.sig.zip

If you have a directory of FASTA files, one per genome:

## Method 1 (suggested)# put all full paths of FASTA/FASTQ file into a file, one path per line
find <path of foler containg FASTA/FASTQ files>> dataset.csv
sourmash sketch fromfile dataset.csv -p dna,k=31,scaled=1000,abund -o ../training_database.sig.zip
# cd back to YACHT## Method 2# cd into the relevant directory
sourmash sketch dna -f -p k=31,scaled=1000,abund *.fasta -o ../training_database.sig.zip
# cd back to YACHT

Creating sketches of your sample

You will then create a sketch of your sample metagenome, using the same k-mer size and scale factor

# For a single-end FASTA/Q file
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip <input FASTA/Q file># For pair-end FASTA/Q files, you need to combine them into a single file first
cat <FASTA/Q file 1><FASTA/Q file 2>> combine.fastq (or combine.fasta)
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip combine.fastq (or combine.fasta)

Parameters

Sourmash database offers three available k values (21, 31, and 51), allowing you to select the one that best suits your particular analytical needs. The scale factor serves as an indicator of data compression, and if your dataset is small, you might consider using a smaller value (corresponding to a higher portion of genomes retained in the sketch).

ParameterExplanation
k=31the length of k-mer
scaled=1000fraction of k-mers to be kept in the sketch
-o sample.sig.ziparbitrary output name for sketch files (must be in zip format)

Output

In the two preceding steps, you will obtain a k-mer sketch file in zip format (in each step) for the reference data and the input sample.

FileContent
gtdb-rs214-reps.k31.zipPre-built k-mer sketch file for GTDB representative genomes
training_database.sig.zipK-mer sketch file for your selected reference genomes
sample.sig.zipK-mer sketch file for your input sample

Preprocess the reference genomes (Training Step)

Warning: the training process is time-consuming on large database

In our benchmark with GTDB representive genomes, it takes 15 minutes using 16 threads, 50GB of MEM on a system equipped with a 3.5GHz AMD EPYC 7763 64-Core Processor. The processing time can be significant when executed on GTDB all genomes OR with limited resources. If only part of genomes are needed, one may use sourmash sig command to extract signatures of interests only.


The script make_training_data_from_sketches.py extracts the sketches from the Zipfile-format reference database, and then turns them into a form usable by YACHT. In particular, it removes one of any two organisms that have ANI greater than the user-specified threshold as these two organisms are too close to be "distinguishable".

python make_training_data_from_sketches.py --ref_file gtdb-rs214-reps.k31.zip --ksize 31 --num_threads 32 --ani_thresh 0.95 --prefix 'gtdb_ani_thresh_0.95' --outdir ./

Parameter

The most important parameter of this script is --ani_thresh: this is average nucleotide identity (ANI) value equal to or below which two organisms are considered distinct. For example, if --ani_thresh is set to 0.95, then two organisms with ANI > 0.95 will be considered indistinguishable. For the organisms with ANI > 0.95, only the one with the largest number of unique kmers will be kept. If there is a tie in the number of unique kmers, one organism will be randomly selected. The default value of --ani_thresh is 0.95. The --ani_thresh value chosen here must match the one chosen for the YACHT algorithm (see below).

ParameterExplanation
--ref_filethe path to the sourmash signature database zip file
--ksizethe length of k-mer, must match the k size used in previous sketching steps (default: 31)
--num_threadsthe number of threads to use for parallelization (default: 16)
--ani_threshthe cutoff by which two organisms are considered indistinguishable (default: 0.95)
--prefixthe prefix for output folders and files (see details below)
--outdirthe path to output directory where the results and intermediate files will be genreated

Output

File (names starting with prefix)Content
_config.jsonA JSON file stores the required information needed to run the next YACHT algorithm
_manifest.tsvA TSV file contains organisms and their relevant info after removing the similar ones
_removed_orgs_to_corr_orgas_mapping.tsvA TSV file with two columns: removed organism names ('removed_org') and their similar genomes ('corr_orgs')

Run the YACHT algorithm

After this, you are ready to perform the hypothesis test for each organism in your reference database. This can be accomplished with something like:

python run_YACHT.py --json 'gtdb_ani_thresh_0.95_config.json' --sample_file 'sample.sig.zip' --num_threads 32 --keep_raw --significance 0.99 --min_coverage_list 1 0.5 0.1 0.05 0.01 --out ./result.xlsx

Parameter

The --significance parameter is basically akin to your confidence level: how sure do you want to be that the organism is present? Higher leads to more false negatives, lower leads to more false positives.

The --min_coverage_list parameter dictates a list of min_coverage which indicates what percentage (value in [0,1]) of the distinct k-mers (think: whole genome) must have been sequenced and present in my sample to qualify as that organism as being "present." Setting this to 1 is usually safe, but if you have a very low coverage sample, you may want to lower this value. Setting it higher will lead to more false negatives, setting it lower will lead to more false positives (pretty rapidly).

ParameterExplanation
--jsonthe path to a json file generated by the make_training_data_from_sketches.py script (see above)
--significanceminimum probability of individual true negative (default: 0.99)
--num_threadsthe number of threads to use for parallelization (default: 16)
--keep_rawkeep the raw result (i.e. min_coverage=1) no matter if the user specifies it
--show_allShow all organisms (no matter if present)
--min_coverage_lista list of min_coverage values, see more detailed description above (default: 1, 0.5, 0.1, 0.05, 0.01)
--outpath to output excel result (default: './result.xlsx')

Output

The output file will be an EXCEL file; column descriptions can be found here. The most important are the following:

  • organism_name: The name of the organism
  • in_sample_est: A boolean value either False or True: if False, there was not enough evidence to claim this organism is present in the sample.
  • p_vals: Probability of observing this or more extreme result at the given ANI threshold, assuming the null hypothesis.

Other interesting columns include:

  • num_exclusive_kmers_to_genome: How many k-mers were found in this organism and no others
  • num_matches: How many k-mers were found in this organism and the sample
  • acceptance_threshold_*: How many k-mers must be found in this organism to be considered "present" at the given ANI threshold. Hence, in_sample_est is True if num_matches >= acceptance_threshold_* (adjusting by coverage if desired).
  • alt_confidence_mut_rate_*: What the mutation rate (1-ANI) would need to be to get your false positive to match the false negative rate of 1-significance (adjusting by coverage if desired).

Convert YACHT result to other popular output formats (e.g., CAMI profiling format, BIOM format, GraphPlAn)

When we get the EXCEL result file from run_YACHT.py, you can run standardize_yacht_output.py under srcs folder to covert the YACHT result to other popular output formats (Currently, only cami, biom, graphplan are supported).

Note: Before you run srcs/standardize_yacht_output.py, you need to prepare a TSV file genome_to_taxid.tsv containing two columns: genome ID (genome_id) and its corresponding taxid (taxid). An example can be found here. You need to prepare it according to the reference database genomes you used.

Then you are ready to run standardize_yacht_output.py with something like:

python srcs/standardize_yacht_output.py --yacht_output 'result.xlsx' --sheet_name 'min_coverage0.01' --genome_to_taxid 'genome_to_taxid.tsv' --mode 'cami' --sample_name 'MySample' --outfile_prefix 'cami_result' --outdir ./
ParameterExplanation
--yacht_outputthe path to the output excel file generated by run_YACHT.py
--sheet_namespecify which spreadsheet result you want to covert from
--genome_to_taxidthe path to the location of genome_to_taxid.tsv you prepared
--modespecify to which output format you want to convert (e.g., 'cami', 'biom', 'graphplan')
--sample_nameA random name you would like to show in header of the cami file. Default: Sample1.'
--outfile_prefixthe prefix of the output file. Default: result
--outdirthe path to output directory where the results will be genreated

About

A mathematically characterized hypothesis test for organism presence/absence in a metagenome

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - mfl15/YACHT: A mathematically characterized hypothesis test for organism presence/absence in a metagenome · GitHub
Skip to content

Repository files navigation

YACHT

GitHub Workflow StatuscodecovQuality Gate StatusCodeQLLicense: MIT

YACHT is a mathematically rigorous hypothesis test for the presence or absence of organisms in a metagenomic sample, based on average nucleotide identity (ANI).

The associated preprint can be found at: https://doi.org/10.1101/2023.04.18.537298. Please cite via:

Koslicki, D., White, S., Ma, C., & Novikov, A. (2023). YACHT: an ANI-based statistical test to detect microbial presence/absence in a metagenomic sample. bioRxiv, 2023-04.


Quick start

We provide a demo to show how to use YACHT. Please follow the command lines below to try it out:

NUM_THREADS=64 # if your machine doesn't have so many CPU cores, feel free to reduce this value.cd demo
# build k-mer sketches for the query sample and ref genomes
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip query_data/query_data.fq
sourmash sketch fromfile ref_paths.csv -p dna,k=31,scaled=1000,abund -o ref.sig.zip --force-output-already-exists
# preprocess the reference genomes (training step)
python ../make_training_data_from_sketches.py --ref_file ref.sig.zip --ksize 31 --num_threads ${NUM_THREADS} --ani_thresh 0.95 --prefix 'demo_ani_thresh_0.95' --outdir ./ --force
# run YACHT algorithm to check the presence of reference genomes in the query sample (inference step)
python ../run_YACHT.py --json demo_ani_thresh_0.95_config.json --sample_file sample.sig.zip --significance 0.99 --num_threads ${NUM_THREADS} --min_coverage_list 1 0.6 0.2 0.1 --out ./result.xlsx
# convert result to CAMI profile format (Optional)
python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./

There will be an output EXCEL file result.xlsx recoding the presence of reference genomes with different spreadsheets given the minimum coverage of 1 0.6 0.2 0.1.


Contents

Installation

Conda

A conda release will be coming soon. In the meantime, please install manually.

Manual installation

YACHT requires Python 3 or higher. We recommend using a virtual environment (such as conda) to run YACHT. To create a virtual environment, run:

# Clone the repo
git clone https://github.com/KoslickiLab/YACHT.git
cd YACHT
# Set up an environment for YACHT
bash setup.sh
# Activiate YACHT environment
conda activate yacht_env

Usage

The workflow for YACHT is as follows:

  1. Create sketches of your reference database genomes and of your sample
  2. Preprocess the reference genomes by removing the "too similar" genomes based on ANI using the ani_thresh parameter
  3. Run YACHT to detect the presence of reference genomes in your sample

Creating sketches of your reference database genomes

You will need a reference database in the form of Sourmash sketches of a collection of microbial genomes. There are a variety of pre-created databases available at: https://sourmash.readthedocs.io/en/latest/databases.html. Our code uses the "Zipfile collection" format, and we suggest using the GTDB genomic representatives database:

wget https://farm.cse.ucdavis.edu/~ctbrown/sourmash-db/gtdb-rs214/gtdb-rs214-reps.k31.zip

If you want to use a custom database, you will need to create a Sourmash sketch Zipfile collection from the FASTA/FASTQ files of your reference database genomes (see Sourmash documentation for details). In brief, this can be accomplished via the following:

If you have a single FASTA file with one genome per record:

sourmash sketch dna -f -p k=31,scaled=1000,abund --singleton <your multi-FASTA file> -o training_database.sig.zip

If you have a directory of FASTA files, one per genome:

## Method 1 (suggested)# put all full paths of FASTA/FASTQ file into a file, one path per line
find <path of foler containg FASTA/FASTQ files>> dataset.csv
sourmash sketch fromfile dataset.csv -p dna,k=31,scaled=1000,abund -o ../training_database.sig.zip
# cd back to YACHT## Method 2# cd into the relevant directory
sourmash sketch dna -f -p k=31,scaled=1000,abund *.fasta -o ../training_database.sig.zip
# cd back to YACHT

Creating sketches of your sample

You will then create a sketch of your sample metagenome, using the same k-mer size and scale factor

# For a single-end FASTA/Q file
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip <input FASTA/Q file># For pair-end FASTA/Q files, you need to combine them into a single file first
cat <FASTA/Q file 1><FASTA/Q file 2>> combine.fastq (or combine.fasta)
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip combine.fastq (or combine.fasta)

Parameters

Sourmash database offers three available k values (21, 31, and 51), allowing you to select the one that best suits your particular analytical needs. The scale factor serves as an indicator of data compression, and if your dataset is small, you might consider using a smaller value (corresponding to a higher portion of genomes retained in the sketch).

ParameterExplanation
k=31the length of k-mer
scaled=1000fraction of k-mers to be kept in the sketch
-o sample.sig.ziparbitrary output name for sketch files (must be in zip format)

Output

In the two preceding steps, you will obtain a k-mer sketch file in zip format (in each step) for the reference data and the input sample.

FileContent
gtdb-rs214-reps.k31.zipPre-built k-mer sketch file for GTDB representative genomes
training_database.sig.zipK-mer sketch file for your selected reference genomes
sample.sig.zipK-mer sketch file for your input sample

Preprocess the reference genomes (Training Step)

Warning: the training process is time-consuming on large database

In our benchmark with GTDB representive genomes, it takes 15 minutes using 16 threads, 50GB of MEM on a system equipped with a 3.5GHz AMD EPYC 7763 64-Core Processor. The processing time can be significant when executed on GTDB all genomes OR with limited resources. If only part of genomes are needed, one may use sourmash sig command to extract signatures of interests only.


The script make_training_data_from_sketches.py extracts the sketches from the Zipfile-format reference database, and then turns them into a form usable by YACHT. In particular, it removes one of any two organisms that have ANI greater than the user-specified threshold as these two organisms are too close to be "distinguishable".

python make_training_data_from_sketches.py --ref_file gtdb-rs214-reps.k31.zip --ksize 31 --num_threads 32 --ani_thresh 0.95 --prefix 'gtdb_ani_thresh_0.95' --outdir ./

Parameter

The most important parameter of this script is --ani_thresh: this is average nucleotide identity (ANI) value equal to or below which two organisms are considered distinct. For example, if --ani_thresh is set to 0.95, then two organisms with ANI > 0.95 will be considered indistinguishable. For the organisms with ANI > 0.95, only the one with the largest number of unique kmers will be kept. If there is a tie in the number of unique kmers, one organism will be randomly selected. The default value of --ani_thresh is 0.95. The --ani_thresh value chosen here must match the one chosen for the YACHT algorithm (see below).

ParameterExplanation
--ref_filethe path to the sourmash signature database zip file
--ksizethe length of k-mer, must match the k size used in previous sketching steps (default: 31)
--num_threadsthe number of threads to use for parallelization (default: 16)
--ani_threshthe cutoff by which two organisms are considered indistinguishable (default: 0.95)
--prefixthe prefix for output folders and files (see details below)
--outdirthe path to output directory where the results and intermediate files will be genreated

Output

File (names starting with prefix)Content
_config.jsonA JSON file stores the required information needed to run the next YACHT algorithm
_manifest.tsvA TSV file contains organisms and their relevant info after removing the similar ones
_removed_orgs_to_corr_orgas_mapping.tsvA TSV file with two columns: removed organism names ('removed_org') and their similar genomes ('corr_orgs')

Run the YACHT algorithm

After this, you are ready to perform the hypothesis test for each organism in your reference database. This can be accomplished with something like:

python run_YACHT.py --json 'gtdb_ani_thresh_0.95_config.json' --sample_file 'sample.sig.zip' --num_threads 32 --keep_raw --significance 0.99 --min_coverage_list 1 0.5 0.1 0.05 0.01 --out ./result.xlsx

Parameter

The --significance parameter is basically akin to your confidence level: how sure do you want to be that the organism is present? Higher leads to more false negatives, lower leads to more false positives.

The --min_coverage_list parameter dictates a list of min_coverage which indicates what percentage (value in [0,1]) of the distinct k-mers (think: whole genome) must have been sequenced and present in my sample to qualify as that organism as being "present." Setting this to 1 is usually safe, but if you have a very low coverage sample, you may want to lower this value. Setting it higher will lead to more false negatives, setting it lower will lead to more false positives (pretty rapidly).

ParameterExplanation
--jsonthe path to a json file generated by the make_training_data_from_sketches.py script (see above)
--significanceminimum probability of individual true negative (default: 0.99)
--num_threadsthe number of threads to use for parallelization (default: 16)
--keep_rawkeep the raw result (i.e. min_coverage=1) no matter if the user specifies it
--show_allShow all organisms (no matter if present)
--min_coverage_lista list of min_coverage values, see more detailed description above (default: 1, 0.5, 0.1, 0.05, 0.01)
--outpath to output excel result (default: './result.xlsx')

Output

The output file will be an EXCEL file; column descriptions can be found here. The most important are the following:

  • organism_name: The name of the organism
  • in_sample_est: A boolean value either False or True: if False, there was not enough evidence to claim this organism is present in the sample.
  • p_vals: Probability of observing this or more extreme result at the given ANI threshold, assuming the null hypothesis.

Other interesting columns include:

  • num_exclusive_kmers_to_genome: How many k-mers were found in this organism and no others
  • num_matches: How many k-mers were found in this organism and the sample
  • acceptance_threshold_*: How many k-mers must be found in this organism to be considered "present" at the given ANI threshold. Hence, in_sample_est is True if num_matches >= acceptance_threshold_* (adjusting by coverage if desired).
  • alt_confidence_mut_rate_*: What the mutation rate (1-ANI) would need to be to get your false positive to match the false negative rate of 1-significance (adjusting by coverage if desired).

Convert YACHT result to other popular output formats (e.g., CAMI profiling format, BIOM format, GraphPlAn)

When we get the EXCEL result file from run_YACHT.py, you can run standardize_yacht_output.py under srcs folder to covert the YACHT result to other popular output formats (Currently, only cami, biom, graphplan are supported).

Note: Before you run srcs/standardize_yacht_output.py, you need to prepare a TSV file genome_to_taxid.tsv containing two columns: genome ID (genome_id) and its corresponding taxid (taxid). An example can be found here. You need to prepare it according to the reference database genomes you used.

Then you are ready to run standardize_yacht_output.py with something like:

python srcs/standardize_yacht_output.py --yacht_output 'result.xlsx' --sheet_name 'min_coverage0.01' --genome_to_taxid 'genome_to_taxid.tsv' --mode 'cami' --sample_name 'MySample' --outfile_prefix 'cami_result' --outdir ./
ParameterExplanation
--yacht_outputthe path to the output excel file generated by run_YACHT.py
--sheet_namespecify which spreadsheet result you want to covert from
--genome_to_taxidthe path to the location of genome_to_taxid.tsv you prepared
--modespecify to which output format you want to convert (e.g., 'cami', 'biom', 'graphplan')
--sample_nameA random name you would like to show in header of the cami file. Default: Sample1.'
--outfile_prefixthe prefix of the output file. Default: result
--outdirthe path to output directory where the results will be genreated

About

A mathematically characterized hypothesis test for organism presence/absence in a metagenome

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - mfl15/YACHT: A mathematically characterized hypothesis test for organism presence/absence in a metagenome · GitHub
Skip to content

Repository files navigation

YACHT

GitHub Workflow StatuscodecovQuality Gate StatusCodeQLLicense: MIT

YACHT is a mathematically rigorous hypothesis test for the presence or absence of organisms in a metagenomic sample, based on average nucleotide identity (ANI).

The associated preprint can be found at: https://doi.org/10.1101/2023.04.18.537298. Please cite via:

Koslicki, D., White, S., Ma, C., & Novikov, A. (2023). YACHT: an ANI-based statistical test to detect microbial presence/absence in a metagenomic sample. bioRxiv, 2023-04.


Quick start

We provide a demo to show how to use YACHT. Please follow the command lines below to try it out:

NUM_THREADS=64 # if your machine doesn't have so many CPU cores, feel free to reduce this value.cd demo
# build k-mer sketches for the query sample and ref genomes
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip query_data/query_data.fq
sourmash sketch fromfile ref_paths.csv -p dna,k=31,scaled=1000,abund -o ref.sig.zip --force-output-already-exists
# preprocess the reference genomes (training step)
python ../make_training_data_from_sketches.py --ref_file ref.sig.zip --ksize 31 --num_threads ${NUM_THREADS} --ani_thresh 0.95 --prefix 'demo_ani_thresh_0.95' --outdir ./ --force
# run YACHT algorithm to check the presence of reference genomes in the query sample (inference step)
python ../run_YACHT.py --json demo_ani_thresh_0.95_config.json --sample_file sample.sig.zip --significance 0.99 --num_threads ${NUM_THREADS} --min_coverage_list 1 0.6 0.2 0.1 --out ./result.xlsx
# convert result to CAMI profile format (Optional)
python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./

There will be an output EXCEL file result.xlsx recoding the presence of reference genomes with different spreadsheets given the minimum coverage of 1 0.6 0.2 0.1.


Contents

Installation

Conda

A conda release will be coming soon. In the meantime, please install manually.

Manual installation

YACHT requires Python 3 or higher. We recommend using a virtual environment (such as conda) to run YACHT. To create a virtual environment, run:

# Clone the repo
git clone https://github.com/KoslickiLab/YACHT.git
cd YACHT
# Set up an environment for YACHT
bash setup.sh
# Activiate YACHT environment
conda activate yacht_env

Usage

The workflow for YACHT is as follows:

  1. Create sketches of your reference database genomes and of your sample
  2. Preprocess the reference genomes by removing the "too similar" genomes based on ANI using the ani_thresh parameter
  3. Run YACHT to detect the presence of reference genomes in your sample

Creating sketches of your reference database genomes

You will need a reference database in the form of Sourmash sketches of a collection of microbial genomes. There are a variety of pre-created databases available at: https://sourmash.readthedocs.io/en/latest/databases.html. Our code uses the "Zipfile collection" format, and we suggest using the GTDB genomic representatives database:

wget https://farm.cse.ucdavis.edu/~ctbrown/sourmash-db/gtdb-rs214/gtdb-rs214-reps.k31.zip

If you want to use a custom database, you will need to create a Sourmash sketch Zipfile collection from the FASTA/FASTQ files of your reference database genomes (see Sourmash documentation for details). In brief, this can be accomplished via the following:

If you have a single FASTA file with one genome per record:

sourmash sketch dna -f -p k=31,scaled=1000,abund --singleton <your multi-FASTA file> -o training_database.sig.zip

If you have a directory of FASTA files, one per genome:

## Method 1 (suggested)# put all full paths of FASTA/FASTQ file into a file, one path per line
find <path of foler containg FASTA/FASTQ files>> dataset.csv
sourmash sketch fromfile dataset.csv -p dna,k=31,scaled=1000,abund -o ../training_database.sig.zip
# cd back to YACHT## Method 2# cd into the relevant directory
sourmash sketch dna -f -p k=31,scaled=1000,abund *.fasta -o ../training_database.sig.zip
# cd back to YACHT

Creating sketches of your sample

You will then create a sketch of your sample metagenome, using the same k-mer size and scale factor

# For a single-end FASTA/Q file
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip <input FASTA/Q file># For pair-end FASTA/Q files, you need to combine them into a single file first
cat <FASTA/Q file 1><FASTA/Q file 2>> combine.fastq (or combine.fasta)
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip combine.fastq (or combine.fasta)

Parameters

Sourmash database offers three available k values (21, 31, and 51), allowing you to select the one that best suits your particular analytical needs. The scale factor serves as an indicator of data compression, and if your dataset is small, you might consider using a smaller value (corresponding to a higher portion of genomes retained in the sketch).

ParameterExplanation
k=31the length of k-mer
scaled=1000fraction of k-mers to be kept in the sketch
-o sample.sig.ziparbitrary output name for sketch files (must be in zip format)

Output

In the two preceding steps, you will obtain a k-mer sketch file in zip format (in each step) for the reference data and the input sample.

FileContent
gtdb-rs214-reps.k31.zipPre-built k-mer sketch file for GTDB representative genomes
training_database.sig.zipK-mer sketch file for your selected reference genomes
sample.sig.zipK-mer sketch file for your input sample

Preprocess the reference genomes (Training Step)

Warning: the training process is time-consuming on large database

In our benchmark with GTDB representive genomes, it takes 15 minutes using 16 threads, 50GB of MEM on a system equipped with a 3.5GHz AMD EPYC 7763 64-Core Processor. The processing time can be significant when executed on GTDB all genomes OR with limited resources. If only part of genomes are needed, one may use sourmash sig command to extract signatures of interests only.


The script make_training_data_from_sketches.py extracts the sketches from the Zipfile-format reference database, and then turns them into a form usable by YACHT. In particular, it removes one of any two organisms that have ANI greater than the user-specified threshold as these two organisms are too close to be "distinguishable".

python make_training_data_from_sketches.py --ref_file gtdb-rs214-reps.k31.zip --ksize 31 --num_threads 32 --ani_thresh 0.95 --prefix 'gtdb_ani_thresh_0.95' --outdir ./

Parameter

The most important parameter of this script is --ani_thresh: this is average nucleotide identity (ANI) value equal to or below which two organisms are considered distinct. For example, if --ani_thresh is set to 0.95, then two organisms with ANI > 0.95 will be considered indistinguishable. For the organisms with ANI > 0.95, only the one with the largest number of unique kmers will be kept. If there is a tie in the number of unique kmers, one organism will be randomly selected. The default value of --ani_thresh is 0.95. The --ani_thresh value chosen here must match the one chosen for the YACHT algorithm (see below).

ParameterExplanation
--ref_filethe path to the sourmash signature database zip file
--ksizethe length of k-mer, must match the k size used in previous sketching steps (default: 31)
--num_threadsthe number of threads to use for parallelization (default: 16)
--ani_threshthe cutoff by which two organisms are considered indistinguishable (default: 0.95)
--prefixthe prefix for output folders and files (see details below)
--outdirthe path to output directory where the results and intermediate files will be genreated

Output

File (names starting with prefix)Content
_config.jsonA JSON file stores the required information needed to run the next YACHT algorithm
_manifest.tsvA TSV file contains organisms and their relevant info after removing the similar ones
_removed_orgs_to_corr_orgas_mapping.tsvA TSV file with two columns: removed organism names ('removed_org') and their similar genomes ('corr_orgs')

Run the YACHT algorithm

After this, you are ready to perform the hypothesis test for each organism in your reference database. This can be accomplished with something like:

python run_YACHT.py --json 'gtdb_ani_thresh_0.95_config.json' --sample_file 'sample.sig.zip' --num_threads 32 --keep_raw --significance 0.99 --min_coverage_list 1 0.5 0.1 0.05 0.01 --out ./result.xlsx

Parameter

The --significance parameter is basically akin to your confidence level: how sure do you want to be that the organism is present? Higher leads to more false negatives, lower leads to more false positives.

The --min_coverage_list parameter dictates a list of min_coverage which indicates what percentage (value in [0,1]) of the distinct k-mers (think: whole genome) must have been sequenced and present in my sample to qualify as that organism as being "present." Setting this to 1 is usually safe, but if you have a very low coverage sample, you may want to lower this value. Setting it higher will lead to more false negatives, setting it lower will lead to more false positives (pretty rapidly).

ParameterExplanation
--jsonthe path to a json file generated by the make_training_data_from_sketches.py script (see above)
--significanceminimum probability of individual true negative (default: 0.99)
--num_threadsthe number of threads to use for parallelization (default: 16)
--keep_rawkeep the raw result (i.e. min_coverage=1) no matter if the user specifies it
--show_allShow all organisms (no matter if present)
--min_coverage_lista list of min_coverage values, see more detailed description above (default: 1, 0.5, 0.1, 0.05, 0.01)
--outpath to output excel result (default: './result.xlsx')

Output

The output file will be an EXCEL file; column descriptions can be found here. The most important are the following:

  • organism_name: The name of the organism
  • in_sample_est: A boolean value either False or True: if False, there was not enough evidence to claim this organism is present in the sample.
  • p_vals: Probability of observing this or more extreme result at the given ANI threshold, assuming the null hypothesis.

Other interesting columns include:

  • num_exclusive_kmers_to_genome: How many k-mers were found in this organism and no others
  • num_matches: How many k-mers were found in this organism and the sample
  • acceptance_threshold_*: How many k-mers must be found in this organism to be considered "present" at the given ANI threshold. Hence, in_sample_est is True if num_matches >= acceptance_threshold_* (adjusting by coverage if desired).
  • alt_confidence_mut_rate_*: What the mutation rate (1-ANI) would need to be to get your false positive to match the false negative rate of 1-significance (adjusting by coverage if desired).

Convert YACHT result to other popular output formats (e.g., CAMI profiling format, BIOM format, GraphPlAn)

When we get the EXCEL result file from run_YACHT.py, you can run standardize_yacht_output.py under srcs folder to covert the YACHT result to other popular output formats (Currently, only cami, biom, graphplan are supported).

Note: Before you run srcs/standardize_yacht_output.py, you need to prepare a TSV file genome_to_taxid.tsv containing two columns: genome ID (genome_id) and its corresponding taxid (taxid). An example can be found here. You need to prepare it according to the reference database genomes you used.

Then you are ready to run standardize_yacht_output.py with something like:

python srcs/standardize_yacht_output.py --yacht_output 'result.xlsx' --sheet_name 'min_coverage0.01' --genome_to_taxid 'genome_to_taxid.tsv' --mode 'cami' --sample_name 'MySample' --outfile_prefix 'cami_result' --outdir ./
ParameterExplanation
--yacht_outputthe path to the output excel file generated by run_YACHT.py
--sheet_namespecify which spreadsheet result you want to covert from
--genome_to_taxidthe path to the location of genome_to_taxid.tsv you prepared
--modespecify to which output format you want to convert (e.g., 'cami', 'biom', 'graphplan')
--sample_nameA random name you would like to show in header of the cami file. Default: Sample1.'
--outfile_prefixthe prefix of the output file. Default: result
--outdirthe path to output directory where the results will be genreated

About

A mathematically characterized hypothesis test for organism presence/absence in a metagenome

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - mfl15/YACHT: A mathematically characterized hypothesis test for organism presence/absence in a metagenome · GitHub
Skip to content

Repository files navigation

YACHT

GitHub Workflow StatuscodecovQuality Gate StatusCodeQLLicense: MIT

YACHT is a mathematically rigorous hypothesis test for the presence or absence of organisms in a metagenomic sample, based on average nucleotide identity (ANI).

The associated preprint can be found at: https://doi.org/10.1101/2023.04.18.537298. Please cite via:

Koslicki, D., White, S., Ma, C., & Novikov, A. (2023). YACHT: an ANI-based statistical test to detect microbial presence/absence in a metagenomic sample. bioRxiv, 2023-04.


Quick start

We provide a demo to show how to use YACHT. Please follow the command lines below to try it out:

NUM_THREADS=64 # if your machine doesn't have so many CPU cores, feel free to reduce this value.cd demo
# build k-mer sketches for the query sample and ref genomes
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip query_data/query_data.fq
sourmash sketch fromfile ref_paths.csv -p dna,k=31,scaled=1000,abund -o ref.sig.zip --force-output-already-exists
# preprocess the reference genomes (training step)
python ../make_training_data_from_sketches.py --ref_file ref.sig.zip --ksize 31 --num_threads ${NUM_THREADS} --ani_thresh 0.95 --prefix 'demo_ani_thresh_0.95' --outdir ./ --force
# run YACHT algorithm to check the presence of reference genomes in the query sample (inference step)
python ../run_YACHT.py --json demo_ani_thresh_0.95_config.json --sample_file sample.sig.zip --significance 0.99 --num_threads ${NUM_THREADS} --min_coverage_list 1 0.6 0.2 0.1 --out ./result.xlsx
# convert result to CAMI profile format (Optional)
python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./

There will be an output EXCEL file result.xlsx recoding the presence of reference genomes with different spreadsheets given the minimum coverage of 1 0.6 0.2 0.1.


Contents

Installation

Conda

A conda release will be coming soon. In the meantime, please install manually.

Manual installation

YACHT requires Python 3 or higher. We recommend using a virtual environment (such as conda) to run YACHT. To create a virtual environment, run:

# Clone the repo
git clone https://github.com/KoslickiLab/YACHT.git
cd YACHT
# Set up an environment for YACHT
bash setup.sh
# Activiate YACHT environment
conda activate yacht_env

Usage

The workflow for YACHT is as follows:

  1. Create sketches of your reference database genomes and of your sample
  2. Preprocess the reference genomes by removing the "too similar" genomes based on ANI using the ani_thresh parameter
  3. Run YACHT to detect the presence of reference genomes in your sample

Creating sketches of your reference database genomes

You will need a reference database in the form of Sourmash sketches of a collection of microbial genomes. There are a variety of pre-created databases available at: https://sourmash.readthedocs.io/en/latest/databases.html. Our code uses the "Zipfile collection" format, and we suggest using the GTDB genomic representatives database:

wget https://farm.cse.ucdavis.edu/~ctbrown/sourmash-db/gtdb-rs214/gtdb-rs214-reps.k31.zip

If you want to use a custom database, you will need to create a Sourmash sketch Zipfile collection from the FASTA/FASTQ files of your reference database genomes (see Sourmash documentation for details). In brief, this can be accomplished via the following:

If you have a single FASTA file with one genome per record:

sourmash sketch dna -f -p k=31,scaled=1000,abund --singleton <your multi-FASTA file> -o training_database.sig.zip

If you have a directory of FASTA files, one per genome:

## Method 1 (suggested)# put all full paths of FASTA/FASTQ file into a file, one path per line
find <path of foler containg FASTA/FASTQ files>> dataset.csv
sourmash sketch fromfile dataset.csv -p dna,k=31,scaled=1000,abund -o ../training_database.sig.zip
# cd back to YACHT## Method 2# cd into the relevant directory
sourmash sketch dna -f -p k=31,scaled=1000,abund *.fasta -o ../training_database.sig.zip
# cd back to YACHT

Creating sketches of your sample

You will then create a sketch of your sample metagenome, using the same k-mer size and scale factor

# For a single-end FASTA/Q file
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip <input FASTA/Q file># For pair-end FASTA/Q files, you need to combine them into a single file first
cat <FASTA/Q file 1><FASTA/Q file 2>> combine.fastq (or combine.fasta)
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip combine.fastq (or combine.fasta)

Parameters

Sourmash database offers three available k values (21, 31, and 51), allowing you to select the one that best suits your particular analytical needs. The scale factor serves as an indicator of data compression, and if your dataset is small, you might consider using a smaller value (corresponding to a higher portion of genomes retained in the sketch).

ParameterExplanation
k=31the length of k-mer
scaled=1000fraction of k-mers to be kept in the sketch
-o sample.sig.ziparbitrary output name for sketch files (must be in zip format)

Output

In the two preceding steps, you will obtain a k-mer sketch file in zip format (in each step) for the reference data and the input sample.

FileContent
gtdb-rs214-reps.k31.zipPre-built k-mer sketch file for GTDB representative genomes
training_database.sig.zipK-mer sketch file for your selected reference genomes
sample.sig.zipK-mer sketch file for your input sample

Preprocess the reference genomes (Training Step)

Warning: the training process is time-consuming on large database

In our benchmark with GTDB representive genomes, it takes 15 minutes using 16 threads, 50GB of MEM on a system equipped with a 3.5GHz AMD EPYC 7763 64-Core Processor. The processing time can be significant when executed on GTDB all genomes OR with limited resources. If only part of genomes are needed, one may use sourmash sig command to extract signatures of interests only.


The script make_training_data_from_sketches.py extracts the sketches from the Zipfile-format reference database, and then turns them into a form usable by YACHT. In particular, it removes one of any two organisms that have ANI greater than the user-specified threshold as these two organisms are too close to be "distinguishable".

python make_training_data_from_sketches.py --ref_file gtdb-rs214-reps.k31.zip --ksize 31 --num_threads 32 --ani_thresh 0.95 --prefix 'gtdb_ani_thresh_0.95' --outdir ./

Parameter

The most important parameter of this script is --ani_thresh: this is average nucleotide identity (ANI) value equal to or below which two organisms are considered distinct. For example, if --ani_thresh is set to 0.95, then two organisms with ANI > 0.95 will be considered indistinguishable. For the organisms with ANI > 0.95, only the one with the largest number of unique kmers will be kept. If there is a tie in the number of unique kmers, one organism will be randomly selected. The default value of --ani_thresh is 0.95. The --ani_thresh value chosen here must match the one chosen for the YACHT algorithm (see below).

ParameterExplanation
--ref_filethe path to the sourmash signature database zip file
--ksizethe length of k-mer, must match the k size used in previous sketching steps (default: 31)
--num_threadsthe number of threads to use for parallelization (default: 16)
--ani_threshthe cutoff by which two organisms are considered indistinguishable (default: 0.95)
--prefixthe prefix for output folders and files (see details below)
--outdirthe path to output directory where the results and intermediate files will be genreated

Output

File (names starting with prefix)Content
_config.jsonA JSON file stores the required information needed to run the next YACHT algorithm
_manifest.tsvA TSV file contains organisms and their relevant info after removing the similar ones
_removed_orgs_to_corr_orgas_mapping.tsvA TSV file with two columns: removed organism names ('removed_org') and their similar genomes ('corr_orgs')

Run the YACHT algorithm

After this, you are ready to perform the hypothesis test for each organism in your reference database. This can be accomplished with something like:

python run_YACHT.py --json 'gtdb_ani_thresh_0.95_config.json' --sample_file 'sample.sig.zip' --num_threads 32 --keep_raw --significance 0.99 --min_coverage_list 1 0.5 0.1 0.05 0.01 --out ./result.xlsx

Parameter

The --significance parameter is basically akin to your confidence level: how sure do you want to be that the organism is present? Higher leads to more false negatives, lower leads to more false positives.

The --min_coverage_list parameter dictates a list of min_coverage which indicates what percentage (value in [0,1]) of the distinct k-mers (think: whole genome) must have been sequenced and present in my sample to qualify as that organism as being "present." Setting this to 1 is usually safe, but if you have a very low coverage sample, you may want to lower this value. Setting it higher will lead to more false negatives, setting it lower will lead to more false positives (pretty rapidly).

ParameterExplanation
--jsonthe path to a json file generated by the make_training_data_from_sketches.py script (see above)
--significanceminimum probability of individual true negative (default: 0.99)
--num_threadsthe number of threads to use for parallelization (default: 16)
--keep_rawkeep the raw result (i.e. min_coverage=1) no matter if the user specifies it
--show_allShow all organisms (no matter if present)
--min_coverage_lista list of min_coverage values, see more detailed description above (default: 1, 0.5, 0.1, 0.05, 0.01)
--outpath to output excel result (default: './result.xlsx')

Output

The output file will be an EXCEL file; column descriptions can be found here. The most important are the following:

  • organism_name: The name of the organism
  • in_sample_est: A boolean value either False or True: if False, there was not enough evidence to claim this organism is present in the sample.
  • p_vals: Probability of observing this or more extreme result at the given ANI threshold, assuming the null hypothesis.

Other interesting columns include:

  • num_exclusive_kmers_to_genome: How many k-mers were found in this organism and no others
  • num_matches: How many k-mers were found in this organism and the sample
  • acceptance_threshold_*: How many k-mers must be found in this organism to be considered "present" at the given ANI threshold. Hence, in_sample_est is True if num_matches >= acceptance_threshold_* (adjusting by coverage if desired).
  • alt_confidence_mut_rate_*: What the mutation rate (1-ANI) would need to be to get your false positive to match the false negative rate of 1-significance (adjusting by coverage if desired).

Convert YACHT result to other popular output formats (e.g., CAMI profiling format, BIOM format, GraphPlAn)

When we get the EXCEL result file from run_YACHT.py, you can run standardize_yacht_output.py under srcs folder to covert the YACHT result to other popular output formats (Currently, only cami, biom, graphplan are supported).

Note: Before you run srcs/standardize_yacht_output.py, you need to prepare a TSV file genome_to_taxid.tsv containing two columns: genome ID (genome_id) and its corresponding taxid (taxid). An example can be found here. You need to prepare it according to the reference database genomes you used.

Then you are ready to run standardize_yacht_output.py with something like:

python srcs/standardize_yacht_output.py --yacht_output 'result.xlsx' --sheet_name 'min_coverage0.01' --genome_to_taxid 'genome_to_taxid.tsv' --mode 'cami' --sample_name 'MySample' --outfile_prefix 'cami_result' --outdir ./
ParameterExplanation
--yacht_outputthe path to the output excel file generated by run_YACHT.py
--sheet_namespecify which spreadsheet result you want to covert from
--genome_to_taxidthe path to the location of genome_to_taxid.tsv you prepared
--modespecify to which output format you want to convert (e.g., 'cami', 'biom', 'graphplan')
--sample_nameA random name you would like to show in header of the cami file. Default: Sample1.'
--outfile_prefixthe prefix of the output file. Default: result
--outdirthe path to output directory where the results will be genreated

About

A mathematically characterized hypothesis test for organism presence/absence in a metagenome

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - mfl15/YACHT: A mathematically characterized hypothesis test for organism presence/absence in a metagenome · GitHub
Skip to content

Repository files navigation

YACHT

GitHub Workflow StatuscodecovQuality Gate StatusCodeQLLicense: MIT

YACHT is a mathematically rigorous hypothesis test for the presence or absence of organisms in a metagenomic sample, based on average nucleotide identity (ANI).

The associated preprint can be found at: https://doi.org/10.1101/2023.04.18.537298. Please cite via:

Koslicki, D., White, S., Ma, C., & Novikov, A. (2023). YACHT: an ANI-based statistical test to detect microbial presence/absence in a metagenomic sample. bioRxiv, 2023-04.


Quick start

We provide a demo to show how to use YACHT. Please follow the command lines below to try it out:

NUM_THREADS=64 # if your machine doesn't have so many CPU cores, feel free to reduce this value.cd demo
# build k-mer sketches for the query sample and ref genomes
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip query_data/query_data.fq
sourmash sketch fromfile ref_paths.csv -p dna,k=31,scaled=1000,abund -o ref.sig.zip --force-output-already-exists
# preprocess the reference genomes (training step)
python ../make_training_data_from_sketches.py --ref_file ref.sig.zip --ksize 31 --num_threads ${NUM_THREADS} --ani_thresh 0.95 --prefix 'demo_ani_thresh_0.95' --outdir ./ --force
# run YACHT algorithm to check the presence of reference genomes in the query sample (inference step)
python ../run_YACHT.py --json demo_ani_thresh_0.95_config.json --sample_file sample.sig.zip --significance 0.99 --num_threads ${NUM_THREADS} --min_coverage_list 1 0.6 0.2 0.1 --out ./result.xlsx
# convert result to CAMI profile format (Optional)
python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./

There will be an output EXCEL file result.xlsx recoding the presence of reference genomes with different spreadsheets given the minimum coverage of 1 0.6 0.2 0.1.


Contents

Installation

Conda

A conda release will be coming soon. In the meantime, please install manually.

Manual installation

YACHT requires Python 3 or higher. We recommend using a virtual environment (such as conda) to run YACHT. To create a virtual environment, run:

# Clone the repo
git clone https://github.com/KoslickiLab/YACHT.git
cd YACHT
# Set up an environment for YACHT
bash setup.sh
# Activiate YACHT environment
conda activate yacht_env

Usage

The workflow for YACHT is as follows:

  1. Create sketches of your reference database genomes and of your sample
  2. Preprocess the reference genomes by removing the "too similar" genomes based on ANI using the ani_thresh parameter
  3. Run YACHT to detect the presence of reference genomes in your sample

Creating sketches of your reference database genomes

You will need a reference database in the form of Sourmash sketches of a collection of microbial genomes. There are a variety of pre-created databases available at: https://sourmash.readthedocs.io/en/latest/databases.html. Our code uses the "Zipfile collection" format, and we suggest using the GTDB genomic representatives database:

wget https://farm.cse.ucdavis.edu/~ctbrown/sourmash-db/gtdb-rs214/gtdb-rs214-reps.k31.zip

If you want to use a custom database, you will need to create a Sourmash sketch Zipfile collection from the FASTA/FASTQ files of your reference database genomes (see Sourmash documentation for details). In brief, this can be accomplished via the following:

If you have a single FASTA file with one genome per record:

sourmash sketch dna -f -p k=31,scaled=1000,abund --singleton <your multi-FASTA file> -o training_database.sig.zip

If you have a directory of FASTA files, one per genome:

## Method 1 (suggested)# put all full paths of FASTA/FASTQ file into a file, one path per line
find <path of foler containg FASTA/FASTQ files>> dataset.csv
sourmash sketch fromfile dataset.csv -p dna,k=31,scaled=1000,abund -o ../training_database.sig.zip
# cd back to YACHT## Method 2# cd into the relevant directory
sourmash sketch dna -f -p k=31,scaled=1000,abund *.fasta -o ../training_database.sig.zip
# cd back to YACHT

Creating sketches of your sample

You will then create a sketch of your sample metagenome, using the same k-mer size and scale factor

# For a single-end FASTA/Q file
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip <input FASTA/Q file># For pair-end FASTA/Q files, you need to combine them into a single file first
cat <FASTA/Q file 1><FASTA/Q file 2>> combine.fastq (or combine.fasta)
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip combine.fastq (or combine.fasta)

Parameters

Sourmash database offers three available k values (21, 31, and 51), allowing you to select the one that best suits your particular analytical needs. The scale factor serves as an indicator of data compression, and if your dataset is small, you might consider using a smaller value (corresponding to a higher portion of genomes retained in the sketch).

ParameterExplanation
k=31the length of k-mer
scaled=1000fraction of k-mers to be kept in the sketch
-o sample.sig.ziparbitrary output name for sketch files (must be in zip format)

Output

In the two preceding steps, you will obtain a k-mer sketch file in zip format (in each step) for the reference data and the input sample.

FileContent
gtdb-rs214-reps.k31.zipPre-built k-mer sketch file for GTDB representative genomes
training_database.sig.zipK-mer sketch file for your selected reference genomes
sample.sig.zipK-mer sketch file for your input sample

Preprocess the reference genomes (Training Step)

Warning: the training process is time-consuming on large database

In our benchmark with GTDB representive genomes, it takes 15 minutes using 16 threads, 50GB of MEM on a system equipped with a 3.5GHz AMD EPYC 7763 64-Core Processor. The processing time can be significant when executed on GTDB all genomes OR with limited resources. If only part of genomes are needed, one may use sourmash sig command to extract signatures of interests only.


The script make_training_data_from_sketches.py extracts the sketches from the Zipfile-format reference database, and then turns them into a form usable by YACHT. In particular, it removes one of any two organisms that have ANI greater than the user-specified threshold as these two organisms are too close to be "distinguishable".

python make_training_data_from_sketches.py --ref_file gtdb-rs214-reps.k31.zip --ksize 31 --num_threads 32 --ani_thresh 0.95 --prefix 'gtdb_ani_thresh_0.95' --outdir ./

Parameter

The most important parameter of this script is --ani_thresh: this is average nucleotide identity (ANI) value equal to or below which two organisms are considered distinct. For example, if --ani_thresh is set to 0.95, then two organisms with ANI > 0.95 will be considered indistinguishable. For the organisms with ANI > 0.95, only the one with the largest number of unique kmers will be kept. If there is a tie in the number of unique kmers, one organism will be randomly selected. The default value of --ani_thresh is 0.95. The --ani_thresh value chosen here must match the one chosen for the YACHT algorithm (see below).

ParameterExplanation
--ref_filethe path to the sourmash signature database zip file
--ksizethe length of k-mer, must match the k size used in previous sketching steps (default: 31)
--num_threadsthe number of threads to use for parallelization (default: 16)
--ani_threshthe cutoff by which two organisms are considered indistinguishable (default: 0.95)
--prefixthe prefix for output folders and files (see details below)
--outdirthe path to output directory where the results and intermediate files will be genreated

Output

File (names starting with prefix)Content
_config.jsonA JSON file stores the required information needed to run the next YACHT algorithm
_manifest.tsvA TSV file contains organisms and their relevant info after removing the similar ones
_removed_orgs_to_corr_orgas_mapping.tsvA TSV file with two columns: removed organism names ('removed_org') and their similar genomes ('corr_orgs')

Run the YACHT algorithm

After this, you are ready to perform the hypothesis test for each organism in your reference database. This can be accomplished with something like:

python run_YACHT.py --json 'gtdb_ani_thresh_0.95_config.json' --sample_file 'sample.sig.zip' --num_threads 32 --keep_raw --significance 0.99 --min_coverage_list 1 0.5 0.1 0.05 0.01 --out ./result.xlsx

Parameter

The --significance parameter is basically akin to your confidence level: how sure do you want to be that the organism is present? Higher leads to more false negatives, lower leads to more false positives.

The --min_coverage_list parameter dictates a list of min_coverage which indicates what percentage (value in [0,1]) of the distinct k-mers (think: whole genome) must have been sequenced and present in my sample to qualify as that organism as being "present." Setting this to 1 is usually safe, but if you have a very low coverage sample, you may want to lower this value. Setting it higher will lead to more false negatives, setting it lower will lead to more false positives (pretty rapidly).

ParameterExplanation
--jsonthe path to a json file generated by the make_training_data_from_sketches.py script (see above)
--significanceminimum probability of individual true negative (default: 0.99)
--num_threadsthe number of threads to use for parallelization (default: 16)
--keep_rawkeep the raw result (i.e. min_coverage=1) no matter if the user specifies it
--show_allShow all organisms (no matter if present)
--min_coverage_lista list of min_coverage values, see more detailed description above (default: 1, 0.5, 0.1, 0.05, 0.01)
--outpath to output excel result (default: './result.xlsx')

Output

The output file will be an EXCEL file; column descriptions can be found here. The most important are the following:

  • organism_name: The name of the organism
  • in_sample_est: A boolean value either False or True: if False, there was not enough evidence to claim this organism is present in the sample.
  • p_vals: Probability of observing this or more extreme result at the given ANI threshold, assuming the null hypothesis.

Other interesting columns include:

  • num_exclusive_kmers_to_genome: How many k-mers were found in this organism and no others
  • num_matches: How many k-mers were found in this organism and the sample
  • acceptance_threshold_*: How many k-mers must be found in this organism to be considered "present" at the given ANI threshold. Hence, in_sample_est is True if num_matches >= acceptance_threshold_* (adjusting by coverage if desired).
  • alt_confidence_mut_rate_*: What the mutation rate (1-ANI) would need to be to get your false positive to match the false negative rate of 1-significance (adjusting by coverage if desired).

Convert YACHT result to other popular output formats (e.g., CAMI profiling format, BIOM format, GraphPlAn)

When we get the EXCEL result file from run_YACHT.py, you can run standardize_yacht_output.py under srcs folder to covert the YACHT result to other popular output formats (Currently, only cami, biom, graphplan are supported).

Note: Before you run srcs/standardize_yacht_output.py, you need to prepare a TSV file genome_to_taxid.tsv containing two columns: genome ID (genome_id) and its corresponding taxid (taxid). An example can be found here. You need to prepare it according to the reference database genomes you used.

Then you are ready to run standardize_yacht_output.py with something like:

python srcs/standardize_yacht_output.py --yacht_output 'result.xlsx' --sheet_name 'min_coverage0.01' --genome_to_taxid 'genome_to_taxid.tsv' --mode 'cami' --sample_name 'MySample' --outfile_prefix 'cami_result' --outdir ./
ParameterExplanation
--yacht_outputthe path to the output excel file generated by run_YACHT.py
--sheet_namespecify which spreadsheet result you want to covert from
--genome_to_taxidthe path to the location of genome_to_taxid.tsv you prepared
--modespecify to which output format you want to convert (e.g., 'cami', 'biom', 'graphplan')
--sample_nameA random name you would like to show in header of the cami file. Default: Sample1.'
--outfile_prefixthe prefix of the output file. Default: result
--outdirthe path to output directory where the results will be genreated

About

A mathematically characterized hypothesis test for organism presence/absence in a metagenome

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - mfl15/YACHT: A mathematically characterized hypothesis test for organism presence/absence in a metagenome · GitHub
Skip to content

Repository files navigation

YACHT

GitHub Workflow StatuscodecovQuality Gate StatusCodeQLLicense: MIT

YACHT is a mathematically rigorous hypothesis test for the presence or absence of organisms in a metagenomic sample, based on average nucleotide identity (ANI).

The associated preprint can be found at: https://doi.org/10.1101/2023.04.18.537298. Please cite via:

Koslicki, D., White, S., Ma, C., & Novikov, A. (2023). YACHT: an ANI-based statistical test to detect microbial presence/absence in a metagenomic sample. bioRxiv, 2023-04.


Quick start

We provide a demo to show how to use YACHT. Please follow the command lines below to try it out:

NUM_THREADS=64 # if your machine doesn't have so many CPU cores, feel free to reduce this value.cd demo
# build k-mer sketches for the query sample and ref genomes
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip query_data/query_data.fq
sourmash sketch fromfile ref_paths.csv -p dna,k=31,scaled=1000,abund -o ref.sig.zip --force-output-already-exists
# preprocess the reference genomes (training step)
python ../make_training_data_from_sketches.py --ref_file ref.sig.zip --ksize 31 --num_threads ${NUM_THREADS} --ani_thresh 0.95 --prefix 'demo_ani_thresh_0.95' --outdir ./ --force
# run YACHT algorithm to check the presence of reference genomes in the query sample (inference step)
python ../run_YACHT.py --json demo_ani_thresh_0.95_config.json --sample_file sample.sig.zip --significance 0.99 --num_threads ${NUM_THREADS} --min_coverage_list 1 0.6 0.2 0.1 --out ./result.xlsx
# convert result to CAMI profile format (Optional)
python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./

There will be an output EXCEL file result.xlsx recoding the presence of reference genomes with different spreadsheets given the minimum coverage of 1 0.6 0.2 0.1.


Contents

Installation

Conda

A conda release will be coming soon. In the meantime, please install manually.

Manual installation

YACHT requires Python 3 or higher. We recommend using a virtual environment (such as conda) to run YACHT. To create a virtual environment, run:

# Clone the repo
git clone https://github.com/KoslickiLab/YACHT.git
cd YACHT
# Set up an environment for YACHT
bash setup.sh
# Activiate YACHT environment
conda activate yacht_env

Usage

The workflow for YACHT is as follows:

  1. Create sketches of your reference database genomes and of your sample
  2. Preprocess the reference genomes by removing the "too similar" genomes based on ANI using the ani_thresh parameter
  3. Run YACHT to detect the presence of reference genomes in your sample

Creating sketches of your reference database genomes

You will need a reference database in the form of Sourmash sketches of a collection of microbial genomes. There are a variety of pre-created databases available at: https://sourmash.readthedocs.io/en/latest/databases.html. Our code uses the "Zipfile collection" format, and we suggest using the GTDB genomic representatives database:

wget https://farm.cse.ucdavis.edu/~ctbrown/sourmash-db/gtdb-rs214/gtdb-rs214-reps.k31.zip

If you want to use a custom database, you will need to create a Sourmash sketch Zipfile collection from the FASTA/FASTQ files of your reference database genomes (see Sourmash documentation for details). In brief, this can be accomplished via the following:

If you have a single FASTA file with one genome per record:

sourmash sketch dna -f -p k=31,scaled=1000,abund --singleton <your multi-FASTA file> -o training_database.sig.zip

If you have a directory of FASTA files, one per genome:

## Method 1 (suggested)# put all full paths of FASTA/FASTQ file into a file, one path per line
find <path of foler containg FASTA/FASTQ files>> dataset.csv
sourmash sketch fromfile dataset.csv -p dna,k=31,scaled=1000,abund -o ../training_database.sig.zip
# cd back to YACHT## Method 2# cd into the relevant directory
sourmash sketch dna -f -p k=31,scaled=1000,abund *.fasta -o ../training_database.sig.zip
# cd back to YACHT

Creating sketches of your sample

You will then create a sketch of your sample metagenome, using the same k-mer size and scale factor

# For a single-end FASTA/Q file
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip <input FASTA/Q file># For pair-end FASTA/Q files, you need to combine them into a single file first
cat <FASTA/Q file 1><FASTA/Q file 2>> combine.fastq (or combine.fasta)
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip combine.fastq (or combine.fasta)

Parameters

Sourmash database offers three available k values (21, 31, and 51), allowing you to select the one that best suits your particular analytical needs. The scale factor serves as an indicator of data compression, and if your dataset is small, you might consider using a smaller value (corresponding to a higher portion of genomes retained in the sketch).

ParameterExplanation
k=31the length of k-mer
scaled=1000fraction of k-mers to be kept in the sketch
-o sample.sig.ziparbitrary output name for sketch files (must be in zip format)

Output

In the two preceding steps, you will obtain a k-mer sketch file in zip format (in each step) for the reference data and the input sample.

FileContent
gtdb-rs214-reps.k31.zipPre-built k-mer sketch file for GTDB representative genomes
training_database.sig.zipK-mer sketch file for your selected reference genomes
sample.sig.zipK-mer sketch file for your input sample

Preprocess the reference genomes (Training Step)

Warning: the training process is time-consuming on large database

In our benchmark with GTDB representive genomes, it takes 15 minutes using 16 threads, 50GB of MEM on a system equipped with a 3.5GHz AMD EPYC 7763 64-Core Processor. The processing time can be significant when executed on GTDB all genomes OR with limited resources. If only part of genomes are needed, one may use sourmash sig command to extract signatures of interests only.


The script make_training_data_from_sketches.py extracts the sketches from the Zipfile-format reference database, and then turns them into a form usable by YACHT. In particular, it removes one of any two organisms that have ANI greater than the user-specified threshold as these two organisms are too close to be "distinguishable".

python make_training_data_from_sketches.py --ref_file gtdb-rs214-reps.k31.zip --ksize 31 --num_threads 32 --ani_thresh 0.95 --prefix 'gtdb_ani_thresh_0.95' --outdir ./

Parameter

The most important parameter of this script is --ani_thresh: this is average nucleotide identity (ANI) value equal to or below which two organisms are considered distinct. For example, if --ani_thresh is set to 0.95, then two organisms with ANI > 0.95 will be considered indistinguishable. For the organisms with ANI > 0.95, only the one with the largest number of unique kmers will be kept. If there is a tie in the number of unique kmers, one organism will be randomly selected. The default value of --ani_thresh is 0.95. The --ani_thresh value chosen here must match the one chosen for the YACHT algorithm (see below).

ParameterExplanation
--ref_filethe path to the sourmash signature database zip file
--ksizethe length of k-mer, must match the k size used in previous sketching steps (default: 31)
--num_threadsthe number of threads to use for parallelization (default: 16)
--ani_threshthe cutoff by which two organisms are considered indistinguishable (default: 0.95)
--prefixthe prefix for output folders and files (see details below)
--outdirthe path to output directory where the results and intermediate files will be genreated

Output

File (names starting with prefix)Content
_config.jsonA JSON file stores the required information needed to run the next YACHT algorithm
_manifest.tsvA TSV file contains organisms and their relevant info after removing the similar ones
_removed_orgs_to_corr_orgas_mapping.tsvA TSV file with two columns: removed organism names ('removed_org') and their similar genomes ('corr_orgs')

Run the YACHT algorithm

After this, you are ready to perform the hypothesis test for each organism in your reference database. This can be accomplished with something like:

python run_YACHT.py --json 'gtdb_ani_thresh_0.95_config.json' --sample_file 'sample.sig.zip' --num_threads 32 --keep_raw --significance 0.99 --min_coverage_list 1 0.5 0.1 0.05 0.01 --out ./result.xlsx

Parameter

The --significance parameter is basically akin to your confidence level: how sure do you want to be that the organism is present? Higher leads to more false negatives, lower leads to more false positives.

The --min_coverage_list parameter dictates a list of min_coverage which indicates what percentage (value in [0,1]) of the distinct k-mers (think: whole genome) must have been sequenced and present in my sample to qualify as that organism as being "present." Setting this to 1 is usually safe, but if you have a very low coverage sample, you may want to lower this value. Setting it higher will lead to more false negatives, setting it lower will lead to more false positives (pretty rapidly).

ParameterExplanation
--jsonthe path to a json file generated by the make_training_data_from_sketches.py script (see above)
--significanceminimum probability of individual true negative (default: 0.99)
--num_threadsthe number of threads to use for parallelization (default: 16)
--keep_rawkeep the raw result (i.e. min_coverage=1) no matter if the user specifies it
--show_allShow all organisms (no matter if present)
--min_coverage_lista list of min_coverage values, see more detailed description above (default: 1, 0.5, 0.1, 0.05, 0.01)
--outpath to output excel result (default: './result.xlsx')

Output

The output file will be an EXCEL file; column descriptions can be found here. The most important are the following:

  • organism_name: The name of the organism
  • in_sample_est: A boolean value either False or True: if False, there was not enough evidence to claim this organism is present in the sample.
  • p_vals: Probability of observing this or more extreme result at the given ANI threshold, assuming the null hypothesis.

Other interesting columns include:

  • num_exclusive_kmers_to_genome: How many k-mers were found in this organism and no others
  • num_matches: How many k-mers were found in this organism and the sample
  • acceptance_threshold_*: How many k-mers must be found in this organism to be considered "present" at the given ANI threshold. Hence, in_sample_est is True if num_matches >= acceptance_threshold_* (adjusting by coverage if desired).
  • alt_confidence_mut_rate_*: What the mutation rate (1-ANI) would need to be to get your false positive to match the false negative rate of 1-significance (adjusting by coverage if desired).

Convert YACHT result to other popular output formats (e.g., CAMI profiling format, BIOM format, GraphPlAn)

When we get the EXCEL result file from run_YACHT.py, you can run standardize_yacht_output.py under srcs folder to covert the YACHT result to other popular output formats (Currently, only cami, biom, graphplan are supported).

Note: Before you run srcs/standardize_yacht_output.py, you need to prepare a TSV file genome_to_taxid.tsv containing two columns: genome ID (genome_id) and its corresponding taxid (taxid). An example can be found here. You need to prepare it according to the reference database genomes you used.

Then you are ready to run standardize_yacht_output.py with something like:

python srcs/standardize_yacht_output.py --yacht_output 'result.xlsx' --sheet_name 'min_coverage0.01' --genome_to_taxid 'genome_to_taxid.tsv' --mode 'cami' --sample_name 'MySample' --outfile_prefix 'cami_result' --outdir ./
ParameterExplanation
--yacht_outputthe path to the output excel file generated by run_YACHT.py
--sheet_namespecify which spreadsheet result you want to covert from
--genome_to_taxidthe path to the location of genome_to_taxid.tsv you prepared
--modespecify to which output format you want to convert (e.g., 'cami', 'biom', 'graphplan')
--sample_nameA random name you would like to show in header of the cami file. Default: Sample1.'
--outfile_prefixthe prefix of the output file. Default: result
--outdirthe path to output directory where the results will be genreated

About

A mathematically characterized hypothesis test for organism presence/absence in a metagenome

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); GitHub - mfl15/YACHT: A mathematically characterized hypothesis test for organism presence/absence in a metagenome · GitHub
Skip to content

Repository files navigation

YACHT

GitHub Workflow StatuscodecovQuality Gate StatusCodeQLLicense: MIT

YACHT is a mathematically rigorous hypothesis test for the presence or absence of organisms in a metagenomic sample, based on average nucleotide identity (ANI).

The associated preprint can be found at: https://doi.org/10.1101/2023.04.18.537298. Please cite via:

Koslicki, D., White, S., Ma, C., & Novikov, A. (2023). YACHT: an ANI-based statistical test to detect microbial presence/absence in a metagenomic sample. bioRxiv, 2023-04.


Quick start

We provide a demo to show how to use YACHT. Please follow the command lines below to try it out:

NUM_THREADS=64 # if your machine doesn't have so many CPU cores, feel free to reduce this value.cd demo
# build k-mer sketches for the query sample and ref genomes
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip query_data/query_data.fq
sourmash sketch fromfile ref_paths.csv -p dna,k=31,scaled=1000,abund -o ref.sig.zip --force-output-already-exists
# preprocess the reference genomes (training step)
python ../make_training_data_from_sketches.py --ref_file ref.sig.zip --ksize 31 --num_threads ${NUM_THREADS} --ani_thresh 0.95 --prefix 'demo_ani_thresh_0.95' --outdir ./ --force
# run YACHT algorithm to check the presence of reference genomes in the query sample (inference step)
python ../run_YACHT.py --json demo_ani_thresh_0.95_config.json --sample_file sample.sig.zip --significance 0.99 --num_threads ${NUM_THREADS} --min_coverage_list 1 0.6 0.2 0.1 --out ./result.xlsx
# convert result to CAMI profile format (Optional)
python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./

There will be an output EXCEL file result.xlsx recoding the presence of reference genomes with different spreadsheets given the minimum coverage of 1 0.6 0.2 0.1.


Contents

Installation

Conda

A conda release will be coming soon. In the meantime, please install manually.

Manual installation

YACHT requires Python 3 or higher. We recommend using a virtual environment (such as conda) to run YACHT. To create a virtual environment, run:

# Clone the repo
git clone https://github.com/KoslickiLab/YACHT.git
cd YACHT
# Set up an environment for YACHT
bash setup.sh
# Activiate YACHT environment
conda activate yacht_env

Usage

The workflow for YACHT is as follows:

  1. Create sketches of your reference database genomes and of your sample
  2. Preprocess the reference genomes by removing the "too similar" genomes based on ANI using the ani_thresh parameter
  3. Run YACHT to detect the presence of reference genomes in your sample

Creating sketches of your reference database genomes

You will need a reference database in the form of Sourmash sketches of a collection of microbial genomes. There are a variety of pre-created databases available at: https://sourmash.readthedocs.io/en/latest/databases.html. Our code uses the "Zipfile collection" format, and we suggest using the GTDB genomic representatives database:

wget https://farm.cse.ucdavis.edu/~ctbrown/sourmash-db/gtdb-rs214/gtdb-rs214-reps.k31.zip

If you want to use a custom database, you will need to create a Sourmash sketch Zipfile collection from the FASTA/FASTQ files of your reference database genomes (see Sourmash documentation for details). In brief, this can be accomplished via the following:

If you have a single FASTA file with one genome per record:

sourmash sketch dna -f -p k=31,scaled=1000,abund --singleton <your multi-FASTA file> -o training_database.sig.zip

If you have a directory of FASTA files, one per genome:

## Method 1 (suggested)# put all full paths of FASTA/FASTQ file into a file, one path per line
find <path of foler containg FASTA/FASTQ files>> dataset.csv
sourmash sketch fromfile dataset.csv -p dna,k=31,scaled=1000,abund -o ../training_database.sig.zip
# cd back to YACHT## Method 2# cd into the relevant directory
sourmash sketch dna -f -p k=31,scaled=1000,abund *.fasta -o ../training_database.sig.zip
# cd back to YACHT

Creating sketches of your sample

You will then create a sketch of your sample metagenome, using the same k-mer size and scale factor

# For a single-end FASTA/Q file
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip <input FASTA/Q file># For pair-end FASTA/Q files, you need to combine them into a single file first
cat <FASTA/Q file 1><FASTA/Q file 2>> combine.fastq (or combine.fasta)
sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip combine.fastq (or combine.fasta)

Parameters

Sourmash database offers three available k values (21, 31, and 51), allowing you to select the one that best suits your particular analytical needs. The scale factor serves as an indicator of data compression, and if your dataset is small, you might consider using a smaller value (corresponding to a higher portion of genomes retained in the sketch).

ParameterExplanation
k=31the length of k-mer
scaled=1000fraction of k-mers to be kept in the sketch
-o sample.sig.ziparbitrary output name for sketch files (must be in zip format)

Output

In the two preceding steps, you will obtain a k-mer sketch file in zip format (in each step) for the reference data and the input sample.

FileContent
gtdb-rs214-reps.k31.zipPre-built k-mer sketch file for GTDB representative genomes
training_database.sig.zipK-mer sketch file for your selected reference genomes
sample.sig.zipK-mer sketch file for your input sample

Preprocess the reference genomes (Training Step)

Warning: the training process is time-consuming on large database

In our benchmark with GTDB representive genomes, it takes 15 minutes using 16 threads, 50GB of MEM on a system equipped with a 3.5GHz AMD EPYC 7763 64-Core Processor. The processing time can be significant when executed on GTDB all genomes OR with limited resources. If only part of genomes are needed, one may use sourmash sig command to extract signatures of interests only.


The script make_training_data_from_sketches.py extracts the sketches from the Zipfile-format reference database, and then turns them into a form usable by YACHT. In particular, it removes one of any two organisms that have ANI greater than the user-specified threshold as these two organisms are too close to be "distinguishable".

python make_training_data_from_sketches.py --ref_file gtdb-rs214-reps.k31.zip --ksize 31 --num_threads 32 --ani_thresh 0.95 --prefix 'gtdb_ani_thresh_0.95' --outdir ./

Parameter

The most important parameter of this script is --ani_thresh: this is average nucleotide identity (ANI) value equal to or below which two organisms are considered distinct. For example, if --ani_thresh is set to 0.95, then two organisms with ANI > 0.95 will be considered indistinguishable. For the organisms with ANI > 0.95, only the one with the largest number of unique kmers will be kept. If there is a tie in the number of unique kmers, one organism will be randomly selected. The default value of --ani_thresh is 0.95. The --ani_thresh value chosen here must match the one chosen for the YACHT algorithm (see below).

ParameterExplanation
--ref_filethe path to the sourmash signature database zip file
--ksizethe length of k-mer, must match the k size used in previous sketching steps (default: 31)
--num_threadsthe number of threads to use for parallelization (default: 16)
--ani_threshthe cutoff by which two organisms are considered indistinguishable (default: 0.95)
--prefixthe prefix for output folders and files (see details below)
--outdirthe path to output directory where the results and intermediate files will be genreated

Output

File (names starting with prefix)Content
_config.jsonA JSON file stores the required information needed to run the next YACHT algorithm
_manifest.tsvA TSV file contains organisms and their relevant info after removing the similar ones
_removed_orgs_to_corr_orgas_mapping.tsvA TSV file with two columns: removed organism names ('removed_org') and their similar genomes ('corr_orgs')

Run the YACHT algorithm

After this, you are ready to perform the hypothesis test for each organism in your reference database. This can be accomplished with something like:

python run_YACHT.py --json 'gtdb_ani_thresh_0.95_config.json' --sample_file 'sample.sig.zip' --num_threads 32 --keep_raw --significance 0.99 --min_coverage_list 1 0.5 0.1 0.05 0.01 --out ./result.xlsx

Parameter

The --significance parameter is basically akin to your confidence level: how sure do you want to be that the organism is present? Higher leads to more false negatives, lower leads to more false positives.

The --min_coverage_list parameter dictates a list of min_coverage which indicates what percentage (value in [0,1]) of the distinct k-mers (think: whole genome) must have been sequenced and present in my sample to qualify as that organism as being "present." Setting this to 1 is usually safe, but if you have a very low coverage sample, you may want to lower this value. Setting it higher will lead to more false negatives, setting it lower will lead to more false positives (pretty rapidly).

ParameterExplanation
--jsonthe path to a json file generated by the make_training_data_from_sketches.py script (see above)
--significanceminimum probability of individual true negative (default: 0.99)
--num_threadsthe number of threads to use for parallelization (default: 16)
--keep_rawkeep the raw result (i.e. min_coverage=1) no matter if the user specifies it
--show_allShow all organisms (no matter if present)
--min_coverage_lista list of min_coverage values, see more detailed description above (default: 1, 0.5, 0.1, 0.05, 0.01)
--outpath to output excel result (default: './result.xlsx')

Output

The output file will be an EXCEL file; column descriptions can be found here. The most important are the following:

  • organism_name: The name of the organism
  • in_sample_est: A boolean value either False or True: if False, there was not enough evidence to claim this organism is present in the sample.
  • p_vals: Probability of observing this or more extreme result at the given ANI threshold, assuming the null hypothesis.

Other interesting columns include:

  • num_exclusive_kmers_to_genome: How many k-mers were found in this organism and no others
  • num_matches: How many k-mers were found in this organism and the sample
  • acceptance_threshold_*: How many k-mers must be found in this organism to be considered "present" at the given ANI threshold. Hence, in_sample_est is True if num_matches >= acceptance_threshold_* (adjusting by coverage if desired).
  • alt_confidence_mut_rate_*: What the mutation rate (1-ANI) would need to be to get your false positive to match the false negative rate of 1-significance (adjusting by coverage if desired).

Convert YACHT result to other popular output formats (e.g., CAMI profiling format, BIOM format, GraphPlAn)

When we get the EXCEL result file from run_YACHT.py, you can run standardize_yacht_output.py under srcs folder to covert the YACHT result to other popular output formats (Currently, only cami, biom, graphplan are supported).

Note: Before you run srcs/standardize_yacht_output.py, you need to prepare a TSV file genome_to_taxid.tsv containing two columns: genome ID (genome_id) and its corresponding taxid (taxid). An example can be found here. You need to prepare it according to the reference database genomes you used.

Then you are ready to run standardize_yacht_output.py with something like:

python srcs/standardize_yacht_output.py --yacht_output 'result.xlsx' --sheet_name 'min_coverage0.01' --genome_to_taxid 'genome_to_taxid.tsv' --mode 'cami' --sample_name 'MySample' --outfile_prefix 'cami_result' --outdir ./
ParameterExplanation
--yacht_outputthe path to the output excel file generated by run_YACHT.py
--sheet_namespecify which spreadsheet result you want to covert from
--genome_to_taxidthe path to the location of genome_to_taxid.tsv you prepared
--modespecify to which output format you want to convert (e.g., 'cami', 'biom', 'graphplan')
--sample_nameA random name you would like to show in header of the cami file. Default: Sample1.'
--outfile_prefixthe prefix of the output file. Default: result
--outdirthe path to output directory where the results will be genreated

About

A mathematically characterized hypothesis test for organism presence/absence in a metagenome

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages