Open In App

Biopython – Entrez Database Search Operation

The NCBI provides an online search system named Entrez. This provides access to a wide range of databases of the molecular biology and it also provides an integrated global query system which supports the boolean operators and the field search. The results are returned from all databases containing information like number of hits, links to originating database, etc from each database.

Functions used

Biopython Entrez comes equipped with 2 methods to perform search operation on databases:



Syntax:

Bio.Entrez.esearch(database, term)



Syntax:

Bio.Entrez.egquery(term)

Approach

Implementation using both methods is given below:

Example 1: Using esearch()




# Import libraries
from Bio import Entrez
  
# Setting email
Entrez.email = 'jeetesh1@yopmail.com'
  
# Setting Entrez tool parameter
Entrez.tool = 'Demoscript'
  
# Searching for database
info = Entrez.esearch(db="nucleotide", term="genome")
  
# reading records
record = Entrez.read(info)
  
# Showing records
print(record)

Output:

Example 2: Using egquery()




# Import libraries
from Bio import Entrez
  
# Setting email
Entrez.email = 'jeetesh1@yopmail.com'
  
# Setting Entrez tool parameter
Entrez.tool = 'Demoscript'
  
# Searching for database
info = Entrez.egquery(term="genome")
  
record = Entrez.read(info)
for row in record["eGQueryResult"]:
    print(row["DbName"], row["Count"])

Output :


Article Tags :