Skip to content

Commit

Permalink
Merge pull request #125 from McTavishLab/api-key
Browse files Browse the repository at this point in the history
Api key
  • Loading branch information
snacktavish committed Jul 1, 2020
2 parents 6400df5 + b08fb10 commit c097108
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
7 changes: 6 additions & 1 deletion bin/physcraper_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
parser.add_argument("-db", "--blast_db", help="local download of blast database")
parser.add_argument("-u", "--blast_url", help="a URL for your own mirrored blast database")
parser.add_argument("-e","--email", help="email address for ncbi blast searches")
parser.add_argument("-ak","--api_key", help="ncbi api key")

parser.add_argument("-ev","--eval", help="blast evalue cutoff")
parser.add_argument("-hl","--hitlist_len", help="number of blast searches to save per taxon")

Expand All @@ -46,7 +48,7 @@

parser.add_argument("-tx","--taxonomy", help="path to taxonomy")

parser.add_argument("-v","--verbose", help="OpenTree study id")
parser.add_argument("-v","--verbose", action="store_true", help="OpenTree study id")



Expand Down Expand Up @@ -130,6 +132,9 @@
if args.email:
conf.email = args.email

if args.api_key:
conf.api_key = args.api_key

sys.stdout.write("Configuration Settings\n")
sys.stdout.write(conf.config_str()+"\n")

Expand Down
9 changes: 9 additions & 0 deletions docs/LocalDB.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ Blast Utilities

## Create an NCBI API key

Generating an NCBI API key will speed up downloading full sequences following blast searches.
See (NCBI API keys for details)[https://ncbiinsights.ncbi.nlm.nih.gov/2017/11/02/new-api-keys-for-the-e-utilities/]

You can add your api key to your config using

Entrez.api_key = <apikey>

or as a flag in your physcraper_run script --api_key



### To Update or download blast DB:
Expand Down
5 changes: 4 additions & 1 deletion docs/examples/example.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

[blast]
#Use your email address, please, this is just for NCBI records
Entrez.email = ejmctavish@gmail.com
Entrez.email = None

#You can speed up the NCBI calls by generating a personal API key
Entrez.api_key = None

#The statistcal cutoff for matches
e_value_thresh = 0.001
Expand Down
10 changes: 8 additions & 2 deletions physcraper/configobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def set_defaults(self):
self.delay = 90
self.spp_threshold = 5
self.minlen = 0.8
self.api_key = None
self.maxlen = 1.2
self.taxonomy_dir = "{}/taxonomy".format(physcraper_dir)
self.ott_ncbi = "{}/ott_ncbi".format(self.taxonomy_dir)
Expand Down Expand Up @@ -127,10 +128,15 @@ def read_config(self, configfi, interactive):
config.read_file(open(configfi))

# read in blast settings
self.email = config["blast"]["Entrez.email"]
self.email = config["blast"].get("Entrez.email")
if not "@" in self.email:
sys.stderr.write("your email `%s` does not have an @ sign. NCBI blast requests an email address.\n" % self.email)

if config["blast"].get("Entrez.api_key"):
self.api_key = config["blast"]["Entrez.api_key"]
if self.api_key == 'None':
self.api_key = None
else:
self.api_key = None
self.e_value_thresh = config["blast"]["e_value_thresh"]
assert is_number(self.e_value_thresh), (
"value `%s` does not exists" % self.e_value_thresh
Expand Down
2 changes: 2 additions & 0 deletions physcraper/ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def entrez_efetch(self, gb_id):
"""
tries = 10
Entrez.email = self.config.email
if self.config.api_key:
Entrez.api_key = self.config.apikey
handle = None

# method needs delay because of ncbi settings
Expand Down

0 comments on commit c097108

Please sign in to comment.