Skip to main content

A package for searching and processing NCBI data

Project description

search_ncbi

This tool provides a simple and efficient way to search NCBI databases using the Entrez Programming Utilities (E-utilities)

Notice

This module is still in the development stage. If you encounter any issues or have suggestions, please:

  1. Open an issue in our GitHub repository for discussion
  2. Submit a pull request with your proposed changes
  3. Contact the maintainer directly at limingyang577@163.com

We welcome all forms of contribution and feedback to improve this project.


Note: As this is an open-source project, please ensure that any communication or contribution adheres to our code of conduct and contribution guidelines.

Features

  • Search NCBI databases (e.g., PubMed, Nucleotide, Protein)
  • Retrieve and process search results
  • Analyze and visualize NCBI data
  • Command-line interface for quick searches
  • Python API for integration into your own scripts and workflows

Installation

You can install it using one of the following methods:

Option 1: Install from Conda (Recommended)

You can install it from bioconda:

conda create -n search_ncbi -c bioconda search_ncbi

Option 2: Install from source

To install search ncbi from source, follow these steps:

  1. Clone the repository:

    git clone https://github.com/Bluetea577/search_ncbi.git
    
  2. Navigate to the project directory:

    cd search_ncbi
    
  3. Install the package:

    pip install .
    

Dependencies

search ncbi requires Python 3.6 or later. Other dependencies will be automatically installed when you install the package using one of the methods above.

Supported NCBI Libraries

This project supports the following NCBI libraries:

  • pubmed
  • protein
  • nuccore
  • nucleotide
  • assembly
  • blastdbinfo
  • books
  • cdd
  • clinvar
  • gap
  • gene
  • geoprofiles
  • medgen
  • omim
  • orgtrack
  • popset
  • pcassay
  • protfam
  • pccompound
  • pcsubstance
  • seqannot
  • biocollections
  • taxonomy
  • bioproject
  • biosample
  • sra

search_ncbi Command Line Interface Usage

After installation, you can use the searchncbi command to interact with NCBI databases.

Basic Usage

searchncbi --email <your_email> --api-key <your_api_key> -d <database> -t <search_term> [options]

Required Arguments

  • --email: Your email address for NCBI queries (required)
  • -d, --db: NCBI database to search (required)
  • -t, --term: Search term (required)

Optional Arguments

  • --api-key: Your NCBI API key (optional, but recommended for higher request limits)
  • -m, --max-results: Maximum number of results to return (default: all available results)
  • -b, --batch-size: Number of results to process in each batch (default: 500)
  • -o, --output: Output file name (default: "output.csv")
  • -a, --action: Action to perform (default: "metadata")

Actions

  1. metadata: Process and save all metadata (default)
  2. custom: Process and save custom filtered metadata
  3. raw: Retrieve and save raw data
  4. count: Get the total count of search results
  5. id_list: Retrieve and save a list of IDs

Custom Filtering Options (for custom action)

  • --include: List of column names to include
  • --exclude: List of column names to exclude
  • --contains: List of strings that column names should contain
  • --regex: Regular expression for filtering column names

Examples

  1. Search BioProject and save all metadata:

    searchncbi --email user@example.com --api-key ABCDEF123456 -d bioproject -t "cancer" -o bioproject_results.csv
    
  2. Search Nucleotide database with custom filtering:

    searchncbi --email user@example.com -d nucleotide -t "BRCA1" -a custom --include "GBSeq_locus" "GBSeq_length" -o brca1_custom.csv
    
  3. Get raw data from Protein database:

    searchncbi --email user@example.com -d protein -t "insulin" -a raw -m 100 -o insulin_raw.csv
    
  4. Get total count of results for a Gene search:

    searchncbi --email user@example.com -d gene -t "human[organism] AND cancer" -a count
    
  5. Get ID list for SRA database:

    searchncbi --email user@example.com -d sra -t "RNA-Seq" -a id_list -m 1000 -o sra_ids.txt
    

Python Module

Import

First, ensure that the search_ncbi package is installed. Then, import the NCBITools class in your Python script:

from search_ncbi import NCBITools

Initialization

Create an instance of NCBITools by providing your email address and an optional API key:

searcher = NCBITools("your_email@example.com", api_key="your_api_key")

Note: The API key is optional but recommended for higher request limits.

Main Methods

1. Search and Process Data

results = searcher.search_and_process(
    db="nucleotide",
    term="SARS-CoV-2[Organism] AND complete genome[Title]",
    max_results=10,
    batch_size=500,
    process_method='all'
)

Parameters:

  • db: NCBI database name (string)
  • term: Search term (string)
  • max_results: Maximum number of results (integer, optional)
  • batch_size: Batch size for processing (integer, default 500)
  • process_method: Processing method, 'all' or 'custom' (string, default 'all')

For 'custom' processing method, additional filtering parameters can be used: include, exclude, contains, regex.

2. Get Raw Data

raw_data = searcher.get_raw_data(
    db="nucleotide",
    term="SARS-CoV-2[Organism] AND complete genome[Title]",
    max_results=10,
    batch_size=500
)

3. Get Search Result Count

count = searcher.search_count(
    db="nucleotide",
    term="SARS-CoV-2[Organism] AND complete genome[Title]"
)

4. Get ID List

id_list = searcher.get_id_list(
    db="nucleotide",
    term="SARS-CoV-2[Organism] AND complete genome[Title]",
    max_results=100,
    batch_size=500
)

5. Search and Save Metadata

searcher.search_and_save_metadata(
    db="nucleotide",
    term="SARS-CoV-2[Organism] AND complete genome[Title]",
    output_file="metadata.csv",
    max_results=100,
    batch_size=500
)

6. Filter Metadata

filtered_data = searcher.filter_metadata(
    input_file="metadata.csv",
    output_file="filtered_metadata.csv",
    filter_term="specific_term"
)

7. Search, Save, and Filter Metadata (Complete Workflow)

filtered_data = searcher.search_and_filter_metadata(
    db="nucleotide",
    term="SARS-CoV-2[Organism] AND complete genome[Title]",
    filter_term="specific_term",
    metadata_file="metadata.csv",
    filter_file="filtered_metadata.csv",
    max_results=100,
    batch_size=500
)

Note: All methods return pandas DataFrames or appropriate data structures unless otherwise specified. Ensure proper handling of the returned data.

Contributing

Contributions to NCBI Tools are welcome! Please refer to our Contributing Guidelines for more information.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

If you have any questions or feedback, please open an issue on our GitHub repository.

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

search_ncbi-0.1.2.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

search_ncbi-0.1.2-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file search_ncbi-0.1.2.tar.gz.

File metadata

  • Download URL: search_ncbi-0.1.2.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for search_ncbi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b48eb8c2fdac06728ae27e1d0173788e4d1b63ad5dfd20be14f71d8a94448c77
MD5 1ce83f296ee73717da334c2bc9deb85c
BLAKE2b-256 5d790c0acbecac5354cbd1bd08d5b66ca944e8aa5c23771b237fe19a5215ef7b

See more details on using hashes here.

File details

Details for the file search_ncbi-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: search_ncbi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for search_ncbi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3ed8b0908bf9e46b01816368bb6d3766334e01414a50756844a5a323198e75ad
MD5 76652e50560df269ebd5dd5317b6c336
BLAKE2b-256 c223dd1255f2bd6fa431f157064084de4391ccc8a9e3e2f4a4f4893a367a4166

See more details on using hashes here.

Supported by

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