Skip to main content

Python package interface for the RCSB PDB search API service

Project description

PyPi Release Build Status Documentation Status Open In Colab

rcsbsearchapi

Python interface for the RCSB PDB Search API.

This package requires Python 3.7 or later.

Quickstart

Quickstart

Installation

Get it from PyPI:

pip install rcsbsearchapi

Or, download from GitHub

Getting Started

Full documentation available at readthedocs

Basic Query Construction

Full-text search

To perform a "full-text" search for structures associated with the term "Hemoglobin", you can create a TextQuery:

from rcsbsearchapi import TextQuery

# Search for structures associated with the phrase "Hemoglobin"
query = TextQuery(value="Hemoglobin")

# Execute the query by running it as a function
results = query()

# Results are returned as an iterator of result identifiers.
for rid in results:
    print(rid)

Attribute search

To perform a search for specific structure or chemical attributes, you can create an AttributeQuery.

from rcsbsearchapi import AttributeQuery

# Construct a query searching for structures from humans
query = AttributeQuery(
    attribute="rcsb_entity_source_organism.scientific_name",
    operator="exact_match",  # Other operators include "contains_phrase", "exists", and more
    value="Homo sapiens"
)

# Execute query and construct a list from results
results = list(query())
print(results)

Refer to the Search Attributes and Chemical Attributes documentation for a full list of attributes and applicable operators.

Alternatively, you can also construct attribute queries with comparative operators using the rcsb_attributes object (which also allows for names to be tab-completed):

from rcsbsearchapi import rcsb_attributes as attrs

# Search for structures from humans
query = attrs.rcsb_entity_source_organism.scientific_name == "Homo sapiens"

# Run query and construct a list from results
results = list(query())
print(results)

Grouping sub-queries

You can combine multiple queries using Python bitwise operators.

from rcsbsearchapi import rcsb_attributes as attrs

# Query for human epidermal growth factor receptor (EGFR) structures (UniProt ID P00533)
#  with investigational or experimental drugs bound
q1 = attrs.rcsb_polymer_entity_container_identifiers.reference_sequence_identifiers.database_accession == "P00533"
q2 = attrs.rcsb_entity_source_organism.scientific_name == "Homo sapiens"
q3 = attrs.drugbank_info.drug_groups == "investigational"
q4 = attrs.drugbank_info.drug_groups == "experimental"

# Structures matching UniProt ID P00533 AND from humans
#  AND (investigational OR experimental drug group)
query = q1 & q2 & (q3 | q4)

# Execute query and print first 10 ids
results = list(query())
print(results[:10])

These examples are in operator syntax. You can also make queries in fluent syntax. Learn more about both syntaxes and implementation details in Constructing and Executing Queries.

Supported Search Services

The list of supported search service types are listed in the table below. For more details on their usage, see Search Service Types.

Search service QueryType
Full-text TextQuery()
Attribute (structure or chemical) AttributeQuery()
Sequence similarity SequenceQuery()
Sequence motif SequenceMotifQuery()
Structure similarity StructSimilarityQuery()
Structure motif StructMotifQuery()
Chemical similarity ChemSimilarityQuery()

Learn more about available search services on the RCSB PDB Search API docs.

Jupyter Notebooks

A runnable jupyter notebook is available in notebooks/quickstart.ipynb, or can be run online using Google Colab: Open In Colab

An additional Covid-19 related example is in notebooks/covid.ipynb: Open In Colab

Supported Features

The following table lists the status of current and planned features.

  • Structure and chemical attribute search
    • Attribute Comparison operations
    • Query set operations
    • Attribute contains, in_ (fluent only)
  • Option to include computed structure models (CSMs) in search
  • Sequence search
  • Sequence motif search
  • Structure similarity search
  • Structure motif search
  • Chemical similarity search
  • Rich results using the Data API

Contributions are welcome for unchecked items!

License

Code is licensed under the BSD 3-clause license. See LICENSE for details.

Citing rcsbsearchapi

Please cite the rcsbsearchapi package by URL:

https://rcsbsearchapi.readthedocs.io

You should also cite the RCSB PDB service this package utilizes:

Yana Rose, Jose M. Duarte, Robert Lowe, Joan Segura, Chunxiao Bi, Charmi Bhikadiya, Li Chen, Alexander S. Rose, Sebastian Bittrich, Stephen K. Burley, John D. Westbrook. RCSB Protein Data Bank: Architectural Advances Towards Integrated Searching and Efficient Access to Macromolecular Structure Data from the PDB Archive, Journal of Molecular Biology, 2020. DOI: 10.1016/j.jmb.2020.11.003

Attributions

The source code for this project was originally written by Spencer Bliven and forked from sbliven/rcsbsearch. We would like to express our tremendous gratitude for his generous efforts in designing such a comprehensive public utility Python package for interacting with the RCSB PDB search API.

Developers

For information about building and developing rcsbsearchapi, see CONTRIBUTING.md

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

rcsbsearchapi-2.0.0.tar.gz (181.7 kB view details)

Uploaded Source

File details

Details for the file rcsbsearchapi-2.0.0.tar.gz.

File metadata

  • Download URL: rcsbsearchapi-2.0.0.tar.gz
  • Upload date:
  • Size: 181.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for rcsbsearchapi-2.0.0.tar.gz
Algorithm Hash digest
SHA256 de5b46d2f5b75539860ac65bd9c47ad1b834feb743048acae5a8296a073edcfe
MD5 c099fa24a25e45673c3b03755db9d563
BLAKE2b-256 8691a18789016a05d76eacc3a3352376a0684dcf11440441d70827a4597339e6

See more details on using hashes here.

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