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:
- Open an issue in our GitHub repository for discussion
- Submit a pull request with your proposed changes
- 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
Currently, search ncbi is not available on PyPI. You can install it using one of the following methods:
Option 1: Install directly from GitHub
You can install the latest version directly from the GitHub repository using pip:
pip install git+https://github.com/Bluetea577/search_ncbi.git
Option 2: Install from source
To install search ncbi from source, follow these steps:
-
Clone the repository:
git clone https://github.com/Bluetea577/search_ncbi.git
-
Navigate to the project directory:
cd search_ncbi
-
Install the package:
pip install .
If you want to install in editable mode for development:
pip install -e .
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.
Verifying the Installation
After installation, you can verify that search ncbi is installed correctly by running:
python -c "import search_ncbi; print(search_ncbi.__version__)"
This should print the version number of search ncbi.
Note: Once search ncbi is available on PyPI, you will be able to install it using pip install search-ncbi.
Supported NCBI Libraries
This project supports the following NCBI libraries:
- 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
metadata: Process and save all metadata (default)custom: Process and save custom filtered metadataraw: Retrieve and save raw datacount: Get the total count of search resultsid_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
-
Search BioProject and save all metadata:
searchncbi --email user@example.com --api-key ABCDEF123456 -d bioproject -t "cancer" -o bioproject_results.csv -
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 -
Get raw data from Protein database:
searchncbi --email user@example.com -d protein -t "insulin" -a raw -m 100 -o insulin_raw.csv -
Get total count of results for a Gene search:
searchncbi --email user@example.com -d gene -t "human[organism] AND cancer" -a count -
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file search_ncbi-0.1.1.tar.gz.
File metadata
- Download URL: search_ncbi-0.1.1.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78bef363451506dd36e29d3cd126840bf67eb6b3eafa6b541076da632c2a43dc
|
|
| MD5 |
983a30b4676b297a410efda497a12b29
|
|
| BLAKE2b-256 |
e7104aceb87238604c20c78d34d47c0a826e37cab3fbcfe8a2d71b8c1a933861
|
File details
Details for the file search_ncbi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: search_ncbi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce5e8285e2c66ddef1e850f749f99ec800eb3422ed92524a00b538c7f7bd01d8
|
|
| MD5 |
9f7157a2205d5352b2aa164f58ae8a35
|
|
| BLAKE2b-256 |
30611595a9ccc0ba3619247249cb90d404be993e2d1cbc0c00bfff0512c30621
|