text: user16316: I'm trying to get genome coordinate information programmatically for multiple genes.
  As an example, I'd like to get the annotation (list of exons and their chromosomes, starts, and ends) for this UniProt entry: https://www.uniprot.org/uniprotkb/B6TU39/entry.
  There is a corresponding GenBank entry, which gives the CDS (https://www.ncbi.nlm.nih.gov/nuccore/EU968504) but I can't see anywhere how to extract the genome coordinates. How can I do this?
  Thanks!
  
  user298: You don't want the EU968504, that's the mRNA not the genome sequence. You want https://www.ncbi.nlm.nih.gov/nuccore/CM007647, also linked to from the UniProt page, just under the link to EU968504:
  
  You also need the gene name, ZEAMMB73_Zm00001d029604 in this case, available further up on the page in the "Names & Taxonomy" section:
  
  Next, we can download the GenBank file for the relevant chromosomal contig  using NCBI's entrez API:
  curl "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&id=CM007647&rettype=gbwithparts&retmode=text" > CM007647
  
  This will take a few minutes. Once that is done, you can parse the file and extract the start and end coordinates using something like this:
  #!/usr/bin/env python3
  from Bio import SeqIO
  import sys
  
  gb_record=SeqIO.read(open(sys.argv[1],"r"), "genbank")
  
  for feature in gb_record.features:
      if feature.type == "gene" and sys.argv[2] in feature.qualifiers['locus_tag']:
          if feature.location.strand == 1:
              strand = "+"
          elif feature.location.strand == -1:
              strand = "-"
          else:
              print("Unknown strand: ", feature.location.strand)
              sys.exit(1)
              
          print("%s\t%s\t%s\t%s\t%s\t%s\t%s\t.\t." % (gb_record.id, "GenBank",
                                                      feature.type, feature.location.start,
                                                      feature.location.end, ".", strand))
  
  You pass the GenBank file and gene name as arguments, and this is the result:
  $ foo.py CM007647  ZEAMMB73_Zm00001d029604
  CM007647.1  GenBank gene    78770080    78773320    .   +   .   .
  
  
original_text: 16316: <p>I'm trying to get genome coordinate information programmatically for multiple genes.</p>
  <p>As an example, I'd like to get the annotation (list of exons and their chromosomes, starts, and ends) for this UniProt entry: <a href="https://www.uniprot.org/uniprotkb/B6TU39/entry" rel="nofollow noreferrer">https://www.uniprot.org/uniprotkb/B6TU39/entry</a>.</p>
  <p>There is a corresponding GenBank entry, which gives the CDS (<a href="https://www.ncbi.nlm.nih.gov/nuccore/EU968504" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/nuccore/EU968504</a>) but I can't see anywhere how to extract the genome coordinates. How can I do this?</p>
  <p>Thanks!</p>
   298: <p>You don't want the EU968504, that's the mRNA not the genome sequence. You want <a href="https://www.ncbi.nlm.nih.gov/nuccore/CM007647" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/nuccore/CM007647</a>, also linked to from the UniProt page, just under the link to EU968504:</p>
  <p><a href="https://i.stack.imgur.com/WFaDX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WFaDX.png" alt="Screenshot of the UniProt page with the link" /></a></p>
  <p>You also need the gene name, <code>ZEAMMB73_Zm00001d029604</code> in this case, available further up on the page in the &quot;Names &amp; Taxonomy&quot; section:</p>
  <p><a href="https://i.stack.imgur.com/7NOIt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7NOIt.png" alt="Screenshot of UniProt page showing the relevant section" /></a></p>
  <p>Next, we can download the GenBank file for the relevant chromosomal contig  using NCBI's entrez API:</p>
  <pre><code>curl &quot;https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&amp;id=CM007647&amp;rettype=gbwithparts&amp;retmode=text&quot; &gt; CM007647
  </code></pre>
  <p>This will take a few minutes. Once that is done, you can parse the file and extract the start and end coordinates using something like this:</p>
  <pre class="lang-py prettyprint-override"><code>#!/usr/bin/env python3
  from Bio import SeqIO
  import sys
  
  gb_record=SeqIO.read(open(sys.argv[1],&quot;r&quot;), &quot;genbank&quot;)
  
  for feature in gb_record.features:
      if feature.type == &quot;gene&quot; and sys.argv[2] in feature.qualifiers['locus_tag']:
          if feature.location.strand == 1:
              strand = &quot;+&quot;
          elif feature.location.strand == -1:
              strand = &quot;-&quot;
          else:
              print(&quot;Unknown strand: &quot;, feature.location.strand)
              sys.exit(1)
              
          print(&quot;%s\t%s\t%s\t%s\t%s\t%s\t%s\t.\t.&quot; % (gb_record.id, &quot;GenBank&quot;,
                                                      feature.type, feature.location.start,
                                                      feature.location.end, &quot;.&quot;, strand))
  </code></pre>
  <p>You pass the GenBank file and gene name as arguments, and this is the result:</p>
  <pre><code>$ foo.py CM007647  ZEAMMB73_Zm00001d029604
  CM007647.1  GenBank gene    78770080    78773320    .   +   .   .
  </code></pre>
  