Skip to content

Instantly share code, notes, and snippets.

@brantfaircloth
Created December 17, 2025 21:31
Show Gist options
  • Select an option

  • Save brantfaircloth/3c9ef2cb184c493254ec7e1401db4a56 to your computer and use it in GitHub Desktop.

Select an option

Save brantfaircloth/3c9ef2cb184c493254ec7e1401db4a56 to your computer and use it in GitHub Desktop.
ncbi_get_geo_loc.py
#!/usr/bin/env python
# encoding: utf-8
"""
Created by Brant Faircloth on December 17, 2025 at 14:09:15 CST
Copyright (c) 2025 Brant C. Faircloth. All rights reserved.
Description:
"""
from Bio import Entrez
import time
Entrez.email = "you@somewhere.whatever"
seq = ["JQ688273.1","JQ688272.1","JQ688271.1"]
for iden in seq:
handle = Entrez.efetch(db="nucleotide", id=iden, rettype="gb", retmode="XML")
record = Entrez.read(handle)
name = record[0]["GBSeq_accession-version"]
location = ""
isolate = ""
for item in record[0]['GBSeq_feature-table'][0]['GBFeature_quals']:
if item["GBQualifier_name"]=="geo_loc_name":
location = (item["GBQualifier_value"])
if item["GBQualifier_name"]=="isolate":
isolate = (item["GBQualifier_value"])
print(f"{name},{location},{isolate}")
handle.close()
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment