diff get_feature_info.py @ 7:c79ce2342f1e draft default tip

planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/Ensembl-REST commit 8f8808de862973aedbf87abd4dfa9d2dc7219322
author earlhaminst
date Mon, 17 Feb 2025 14:49:24 +0000
parents 7af66c2b3831
children
line wrap: on
line diff
--- a/get_feature_info.py	Tue Oct 20 15:07:23 2020 +0000
+++ b/get_feature_info.py	Mon Feb 17 14:49:24 2025 +0000
@@ -1,37 +1,45 @@
 # A simple tool to connect to the Ensembl server and retrieve feature
 # information using the Ensembl REST API.
-from __future__ import print_function
-
 import json
 import optparse
 from itertools import islice
+from urllib.parse import urljoin
 
 import requests
-from six.moves.urllib.parse import urljoin
 
 parser = optparse.OptionParser()
-parser.add_option('-i', '--input', help='List of Ensembl IDs')
-parser.add_option('-e', '--expand', type='choice', choices=['0', '1'],
-                  default='0',
-                  help='Expands the search to include any connected features. e.g. If the object is a gene, its transcripts, translations and exons will be returned as well.')
+parser.add_option("-i", "--input", help="List of Ensembl IDs")
+parser.add_option(
+    "-e",
+    "--expand",
+    type="choice",
+    choices=["0", "1"],
+    default="0",
+    help="Expands the search to include any connected features. e.g. If the object is a gene, its transcripts, translations and exons will be returned as well.",
+)
 
-parser.add_option('-f', '--format', type='choice',
-                  choices=['full', 'condensed'], default='full',
-                  help='Specify the formats to emit from this endpoint')
+parser.add_option(
+    "-f",
+    "--format",
+    type="choice",
+    choices=["full", "condensed"],
+    default="full",
+    help="Specify the formats to emit from this endpoint",
+)
 options, args = parser.parse_args()
 if options.input is None:
-    raise Exception('-i option must be specified')
+    raise Exception("-i option must be specified")
 
 
-server = 'https://rest.ensembl.org'
-ext = 'lookup/id'
+server = "https://rest.ensembl.org"
+ext = "lookup/id"
 
-headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
-params = dict((k, getattr(options, k)) for k in ['format', 'expand'])
+headers = {"Content-Type": "application/json", "Accept": "application/json"}
+params = {k: getattr(options, k) for k in ("format", "expand")}
 
 first = True
 
-print('{')
+print("{")
 
 with open(options.input) as f:
     while True:
@@ -40,9 +48,14 @@
             break
         if not first:
             print(",")
-        data = {'ids': ids}
-        r = requests.post(urljoin(server, ext), params=params, headers=headers,
-                          data=json.dumps(data), allow_redirects=False)
+        data = {"ids": ids}
+        r = requests.post(
+            urljoin(server, ext),
+            params=params,
+            headers=headers,
+            data=json.dumps(data),
+            allow_redirects=False,
+        )
 
         if not r.ok:
             r.raise_for_status()
@@ -51,4 +64,4 @@
 
         first = False
 
-print('}')
+print("}")