-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_ncbi_gi_by_term.py
executable file
·61 lines (44 loc) · 1.1 KB
/
search_ncbi_gi_by_term.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python3
'''
File name: search_ncbi_gi_by_term.py
Author: Jose G. Macia-Vicente
Date created: 2016-06-29
Date last modified: 2020-08-27
Python Version: 3.8
'''
__author__ = "Jose G. Macia-Vicente"
from Bio import Entrez
import sys
import argparse
# input arguments parameters
parser = argparse.ArgumentParser(
description='Retrieve GI list from NCBI from Entrez terms.')
parser.add_argument(
"query",
help = 'input string with Entrez query (with quotations)',
type=str)
parser.add_argument(
"-o", help = 'output file',
type=str,
default='giList.txt')
parser.add_argument(
"-email", help = 'tell NCBI who you are!',
type=str,
default = 'your@email')
args = parser.parse_args()
query = args.query
of = args.o
# process query
Entrez.email = args.email
handle = Entrez.esearch(
db="nucleotide",
term=query,
retmax=2000000)
record = Entrez.read(handle)
# save results to output file
giOut = open(of, "w")
for i in record["IdList"]:
giOut.write(i+"\n")
print(record["Count"] + " records extracted.")
giOut.close()
handle.close()