FastANI

FastANI (Jain, C., Rodriguez-R, L.M., Phillippy, A.M. et al.)

Basic usage

from chiton.fastani import fastani

result = fastani(query='query.fna', reference='reference.fna')
dict_results = result.as_dict()

# Accessing results
print(dict_results['query.fna']['reference.fna'].ani)         # 89.1234
print(dict_results['query.fna']['reference.fna'].n_frag)      # 50
print(dict_results['query.fna']['reference.fna'].total_frag)  # 100
print(dict_results['query.fna']['reference.fna'].align_frac)  # 0.5

# Writing results to disk
result.to_file('results.txt')

Models

Input

chiton.fastani.fastani(query, reference, k=None, cpus=None, frag_len=None, min_frac=None, min_frag=None, single_execution=True, bidirectional=False, exe='fastANI', tmp_root='/tmp', show_progress=True)

Run FastANI on a set of paths.

Parameters
  • query (Union[str, Collection[str]]) – Either a path to the query genome, or a collection of paths to query genomes.

  • reference (Union[str, Collection[str]]) – Either a path to the reference genome, or a collection of paths to reference genomes.

  • k (Optional[int]) – kmer size <= 16 (default: 16).

  • cpus (Optional[int]) – Number of CPUs to use (default: 1).

  • frag_len (Optional[int]) – fragment length (default: 3,000).

  • min_frac (Optional[float]) – minimum fraction of genome that must be shared for trusting ANI (default: 0.2) [version >= 1.3].

  • min_frag (Optional[int]) – minimum matched fragments for trusting ANI (default: 50) [version <= 1.2].

  • single_execution (bool) – True if –refList and –queryList should be used, otherwise a subprocess will be launched to do 1:1 comparisons.

  • bidirectional (bool) – True if the ANI should be calculated for query vs reference and vice-versa.

  • exe (str) – The path to the execution file.

  • tmp_root (str) – The root directory used to write temporary files to.

  • show_progress (bool) – True if a progress bar should be shown, False otherwise.

Return type

FastANIResults

Output

class chiton.fastani.model.FastANIResults(query, reference, executions, params)

The results from a FastANI method request.

as_dict()

Returns the results as a dictionary of query -> reference values.

Examples

>>> result = fastani(query='query.fna', reference='reference.fna')
>>> d_results = results.as_dict()
>>> d_results['query.fna']['reference.fna'].align_frac)
0.8
Return type

Dict[str, Dict[str, Optional[FastANIResult]]]

executions

The outcome of each FastANIExecution.

iter_results()

Returns an iterator of the query, reference, and results. NOTE: This will only return those which had >=80% ANI.

Return type

Iterator[Tuple[str, str, Optional[FastANIResult]]]

params

The FastANIParameters used in the execution.

query

A collection of paths to the query genomes.

reference

A collection of paths to the reference genomes.

class chiton.fastani.model.FastANIResult(ani, n_frag, total_frag)

The data associated with a FastANI output file.

align_frac

The alignment fraction

ani

The percentage of ANI

n_frag

The number of aligned fragments

total_frag

The total number of fragments

Helper classes

class chiton.fastani.model.FastANIExecution(cmd, stdout, stderr, return_code, output)

The input, output and logs of a single FastANI execution.

cmd

The command used to execute FastANI

output

The output of the execution, None if ANI <80%

return_code

The return code of the execution

stderr

The stderr of the execution

stdout

The stdout of the execution

class chiton.fastani.model.ResultFile(path)

A wrapper to the FastANI output file.

data

A map of (query path, reference path) = result

class chiton.fastani.model.FastANIParameters(version, exe, single_execution=True, bidirectional=False, k=None, cpus=None, frag_len=None, min_frac=None, min_frag=None)

An interface to the parameters selected for execution.

bidirectional

True if the ANI should be calculated for query vs reference and vice-versa.

cpus

The number of CPUs to use.

exe

The path to the FastANI executable.

frag_len

The minimum fragment length.

k

The k-mer size.

min_frac

Minimum fraction of genome that must be shared for trusting ANI [version >= 1.3].

min_frag

Minimum matched fragments for trusting ANI [version <= 1.2].

single_execution

True if –refList and –queryList should be used, otherwise a subprocess will be launched to do 1 to 1 comparisons.

version

The version of FastANI.