Skip to main content

Global-Global genetic database search.

Project description


vpsearch - Fast Vantage-Point Tree Search for Sequence Databases

This is a package for indexing and querying a sequence database for fast nearest-neighbor search by means of vantage point trees. For reasonably large databases, such as RDP, this results in sequence lookups that are typically 5-10 times faster than other alignment-based lookup methods.

Vantage-point tree search uses global-to-global alignment to compare sequences, rather than seed-and-extend approximative methods as used for example by BLAST.

Usage

Given a sequence database (in FASTA format), vpsearch build constructs an optimized vantage point search tree. Building the tree is a one-time operation and doesn't have to be done again unless the database changes. As an illustration, we build a vantage point tree for the RDP database of bacterial 16S sequences. This database contains 281261 sequences of which 39237 are duplicates. After removing these duplicates, we are left with 242024 unique sequences. Building a tree for these sequences is done with:

  $ vpsearch build rdp_download_281261seqs_dedup.fa
  Building for 242024 sequences...
  done.
  Linearizing...done.
  Database created in rdp_download_281261seqs_dedup.db

For the RDP database of full length sequences, this takes about 20 minutes on a standard machine. When only selected regions of the sequences are considered, the time needed to build a tree can be much reduced. For example, vantage point trees for the v1-v2 hypervariable region (350 base pairs) or the v3-v4 region (250 base pairs) of the RDP 16S sequencese can be built in 30 seconds to 1 minute.

Once a tree has been built, unknown sequences can be looked up using the vpsearch query command. Here we supply a query file with a single sequence

  vpsearch query rdp_download_281261seqs_dedup.fa query.fa
  query	S000143715	99.54	1529	0	0	1	1524	1	1529	0	7546
  query	S004085923	99.08	1529	0	0	1	1524	1	1526	0	7481
  query	S004085922	99.08	1529	0	0	1	1524	1	1526	0	7481
  query	S004085925	98.50	1531	0	0	1	1524	1	1527	0	7386

By default, the vpsearch query command outputs the best four matches in the database per query sequence (the number of matches can be changed with the -k parameter). Lookup is done one query sequence at a time, but multiple queries can be considered in parallel by enabling multiple threads; use the -j option to specify the number of threads.

The vpsearch query command attempts to output its results in the standard BLAST tabular format. The interpretation of the columns is as follows:

Column name Example Notes
query ID query
subject ID S000143715
% identity 99.54
alignment length 1529
mismatches 0 currently not implemented
gap openings 0 currently not implemented
query start 1
query end 1524
subject start 1
subject end 1529
E-value 0 N/A (always 0)
bit score 7546 interpreted as the alignment score

Note that the number of mismatches and gap openings are currently not displayed in the result output. This will be addressed in a future version of the package.

Installation

Using EDM

Users of the Enthought Deployment Manager(EDM) can install the necessary prerequisites (Click, Cython, Numpy, and Parasail) by importing an EDM environment from the bundle file shipped with this repository

  edm env import -f <bundle.json> vpsearch

where <bundle.json> is one of vpsearch_py3.6_osx-x86_64.json or vpsearch_py3.6_rh6-x86_64.json, depending on your platform.

When this is done, activate the environment, and install this package. From the root of this repository, run

  edm shell -e vpsearch
  pip install -e .

Using Pip, Conda, etc.

Users of other package installation tools, such as Pip or Conda, need to install the Parasail library following the instructions on the Parasail web page. Once that is done, the Python dependencies can be installed using the appropriate command for your package manager. For pip, for example, this can be done with

  pip install -r requirements.txt

Once that is done, activate your virtual environment, and install this package via

  pip install -e .

Using Docker

It is possible to build a Docker image that contains vpsearch as well as all of its dependencies. This is useful, for example, when integrating vpsearch into a workflow manager, like Snakemake, CWL, or WDL.

To build the image, run the following command from the root of this repository:

  docker build . -t vpsearch-image

Once the image has been built, vpsearch can then be run from within a container. Assuming you have a FASTA file of target sequences in the file database.fasta in the current directory, run the following to build a vpsearch index:

  docker run -it -v $PWD:/data -t vpsearch-image vpsearch build /data/database.fasta

To query the index for a given FASTA file query.fasta of query sequences, run:

  docker run -it -v $PWD:/data -t vpsearch-image vpsearch query /data/database.db /data/query.fasta

Troubleshooting

The vpsearch package relies on the Parasail C library for alignment. If building the package fails because the Parasail library cannot be found, you can manually specify the location of the Parasail include files and shared object libraries by setting the PARASAIL_INCLUDE_DIR and PARASAIL_LIB_DIR environment variables before building the package:

  export PARASAIL_INCLUDE_DIR=/location/of/parasail/include/files
  export PARASAIL_LIB_DIR=/location/of/parasail/lib/files
  pip install -e .

Note that if Parasail is installed in a non-standard location, you may have to set the LD_LIBRARY_PATH variable at runtime.

Implementation notes

The tree construction operates in two phases. We first build the tree as a tree of Python object nodes because it's easier to build with a dynamic data structure. Then it linearizes the topology of the nodes into a few integer arrays that are easy to serialize and fast to look up. The object that represents the linearized tree can only query the database, not build the tree. The slower tree-of-nodes implementation can build and query (albeit with more overhead).

Building wheels

Wheels for this package can be built in a platform-independent way using cibuildwheel, running under GitHub actions. As an administrator, you can start a workflow to build wheels by selecting the "Build wheels" action from the GitHub actions menu, and clicking the "Run workflow" button. When the workflow completes, wheels for Linux and macOS will be available as a zipped artifact.

It is possible to run cibuildwheels locally, but only to build wheels for Linux. In a clean Python environment, run pip install cibuildwheel to install the tool, followed by e.g.

  CIBW_BUILD_VERBOSITY=1 \
  CIBW_BUILD=cp38-manylinux_x86_64 \
  CIBW_BEFORE_BUILD="./ci/build-parasail.sh" \
  python -m cibuildwheel --output-dir wheelhouse --platform linux

to build Python 3.8 wheels for Linux. By varying the build tag, wheels for other Python versions can be built.

License

This package is licensed under the BSD license.

References

Vantage point trees were introduced in

Uhlmann, Jeffrey (1991). "Satisfying General Proximity/Similarity Queries with Metric Trees". Information Processing Letters. 40 (4): 175–179. doi:10.1016/0020-0190(91)90074-r.

Yianilos (1993). Data structures and algorithms for nearest neighbor search in general metric spaces (PDF). Fourth annual ACM-SIAM symposium on Discrete algorithms. Society for Industrial and Applied Mathematics Philadelphia, PA, USA. pp. 311–321. pny93.

The Parasail library is described in

Daily, Jeff. (2016). Parasail: SIMD C library for global, semi-global, and local pairwise sequence alignments. BMC Bioinformatics, 17(1), 1-11. doi:10.1186/s12859-016-0930-z

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vpsearch-0.1.2.tar.gz (218.2 kB view hashes)

Uploaded Source

Built Distributions

vpsearch-0.1.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64

vpsearch-0.1.2-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl (13.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686

vpsearch-0.1.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

vpsearch-0.1.2-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl (13.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

vpsearch-0.1.2-cp39-cp39-macosx_10_9_x86_64.whl (2.7 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

vpsearch-0.1.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

vpsearch-0.1.2-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl (13.5 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

vpsearch-0.1.2-cp38-cp38-macosx_10_9_x86_64.whl (2.7 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

vpsearch-0.1.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (14.9 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

vpsearch-0.1.2-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl (13.4 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

vpsearch-0.1.2-cp37-cp37m-macosx_10_9_x86_64.whl (2.7 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

vpsearch-0.1.2-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (14.9 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

vpsearch-0.1.2-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.whl (13.4 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

vpsearch-0.1.2-cp36-cp36m-macosx_10_9_x86_64.whl (2.7 MB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page