Mercurial > repos > tduigou > retrorules
annotate query.py @ 2:58bbbff358d6 draft
planemo upload for repository https://github.com/brsynth/galaxytools commit 469ebd8616b81810ead4633c278dc4c65ab8603b
| author | tduigou |
|---|---|
| date | Mon, 15 Sep 2025 09:42:19 +0000 |
| parents | 6d20407d9a72 |
| children | 95b4196b4ded |
| rev | line source |
|---|---|
|
0
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
1 import argparse |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
2 import json |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
3 import logging |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
4 import sys |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
5 from typing import Dict, List |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
6 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
7 import requests |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
8 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
9 BASE_URL = "https://retrorules.org/api/v0.7" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
10 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
11 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
12 def from_ec_number(ec_number: str, min_diameter: int = None) -> List: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
13 url = f"{BASE_URL}/ecnumber" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
14 params = [("input", ec_number)] |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
15 if min_diameter: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
16 params.append(("minDiameter", str(min_diameter))) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
17 return url, params |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
18 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
19 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
20 def from_substrate(substrate: str, min_diameter: int = None) -> List: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
21 url = f"{BASE_URL}/substrate" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
22 params = [("input", substrate)] |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
23 if min_diameter: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
24 params.append(("minDiameter", str(min_diameter))) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
25 return url, params |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
26 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
27 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
28 def from_reaction_id( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
29 reaction_id: str, repository: str, min_diameter: int = None |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
30 ) -> List: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
31 url = f"{BASE_URL}/reactionid" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
32 params = [("input", reaction_id)] |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
33 params.append(("repo", repository)) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
34 if min_diameter: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
35 params.append(("minDiameter", str(min_diameter))) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
36 return url, params |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
37 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
38 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
39 def from_inchi(inchi: str, min_diameter: int = None) -> List: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
40 url = f"{BASE_URL}/inchi" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
41 params = [("input", inchi)] |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
42 if min_diameter: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
43 params.append(("minDiameter", str(min_diameter))) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
44 return url, params |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
45 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
46 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
47 def from_repository(repository: str, min_diameter: int = None) -> List: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
48 url = f"{BASE_URL}/repo" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
49 params = [("input", repository)] |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
50 if min_diameter: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
51 params.append(("minDiameter", str(min_diameter))) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
52 return url, params |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
53 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
54 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
55 def from_smarts_id(smarts_ids: List[str], min_diameter: int = None) -> List: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
56 url = f"{BASE_URL}/smartsid" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
57 params = [("input", smart_id) for smart_id in smarts_ids] |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
58 if min_diameter: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
59 params.append(("minDiameter", str(min_diameter))) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
60 return url, params |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
61 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
62 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
63 def query(url: str, params: Dict) -> Dict: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
64 response = requests.get(url, params=params) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
65 response.raise_for_status() |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
66 return response.json() |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
67 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
68 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
69 def write_json(path: str, data: Dict): |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
70 with open(path, "w") as fd: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
71 json.dump(data, fd, indent=4) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
72 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
73 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
74 def main(): |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
75 parser = argparse.ArgumentParser( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
76 description="Query RetroRules API via command-line endpoints." |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
77 ) |
|
2
58bbbff358d6
planemo upload for repository https://github.com/brsynth/galaxytools commit 469ebd8616b81810ead4633c278dc4c65ab8603b
tduigou
parents:
0
diff
changeset
|
78 subparsers = parser.add_subparsers(dest="command") |
|
0
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
79 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
80 # Subcommand: EC number |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
81 parser_ecn = subparsers.add_parser("ec-number", help="From EC number") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
82 parser_ecn.add_argument( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
83 "--input-ec-number-str", required=True, help="EC number such as 1.1.1.1" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
84 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
85 parser_ecn.add_argument("--input-min-diameter-int", type=int, help="Min diameter") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
86 parser_ecn.add_argument( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
87 "--output-data-json", required=True, help="Output results, JSON format" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
88 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
89 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
90 # Subcommand: Substrate |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
91 parser_sub = subparsers.add_parser("substrate", help="From substrate") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
92 parser_sub.add_argument( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
93 "--input-substrate-str", required=True, help="Substrate label" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
94 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
95 parser_sub.add_argument("--input-min-diameter-int", type=int, help="Min diameter") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
96 parser_sub.add_argument( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
97 "--output-data-json", required=True, help="Output results, JSON format" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
98 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
99 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
100 # Subcommand: Reaction ID |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
101 parser_rea = subparsers.add_parser("reaction-id", help="From Reaction ID") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
102 parser_rea.add_argument( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
103 "--input-reaction-id-str", required=True, help="Reaction ID" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
104 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
105 parser_rea.add_argument("--input-repository-str", required=True, help="Repository") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
106 parser_rea.add_argument("--input-min-diameter-int", type=int, help="Min diameter") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
107 parser_rea.add_argument( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
108 "--output-data-json", required=True, help="Output results, JSON format" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
109 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
110 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
111 # Subcommand: InChI |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
112 parser_inc = subparsers.add_parser("inchi", help="From InChI") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
113 parser_inc.add_argument("--input-inchi-str", required=True, help="InChI") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
114 parser_inc.add_argument("--input-min-diameter-int", type=int, help="Min diameter") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
115 parser_inc.add_argument( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
116 "--output-data-json", required=True, help="Output results, JSON format" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
117 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
118 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
119 # Subcommand: Repository |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
120 parser_rep = subparsers.add_parser("repository", help="From Repository") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
121 parser_rep.add_argument("--input-repository-str", required=True, help="InChI") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
122 parser_rep.add_argument("--input-min-diameter-int", type=int, help="Min diameter") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
123 parser_rep.add_argument( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
124 "--output-data-json", required=True, help="Output results, JSON format" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
125 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
126 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
127 # Subcommand: Smarts ID |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
128 parser_sma = subparsers.add_parser("smarts-id", help="From Smarts ID") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
129 parser_sma.add_argument( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
130 "--input-smarts-id-str", nargs="+", required=True, help="Smarts ID" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
131 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
132 parser_sma.add_argument("--input-min-diameter-int", type=int, help="Min diameter") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
133 parser_sma.add_argument( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
134 "--output-data-json", required=True, help="Output results, JSON format" |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
135 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
136 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
137 logging.info("Query RetroRules - start") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
138 args = parser.parse_args() |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
139 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
140 try: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
141 logging.info("Build arguments") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
142 url, params = "", {} |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
143 if args.command == "ec-number": |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
144 url, params = from_ec_number( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
145 ec_number=args.input_ec_number_str, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
146 min_diameter=args.input_min_diameter_int, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
147 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
148 elif args.command == "substrate": |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
149 url, params = from_substrate( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
150 substrate=args.input_substrate_str, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
151 min_diameter=args.input_min_diameter_int, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
152 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
153 elif args.command == "reaction-id": |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
154 url, params = from_reaction_id( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
155 reaction_id=args.input_reaction_id_str, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
156 repository=args.input_repository_str, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
157 min_diameter=args.input_min_diameter_int, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
158 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
159 elif args.command == "inchi": |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
160 url, params = from_inchi( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
161 inchi=args.input_inchi_str, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
162 min_diameter=args.input_min_diameter_int, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
163 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
164 elif args.command == "repository": |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
165 url, params = from_repository( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
166 repository=args.input_repository_str, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
167 min_diameter=args.input_min_diameter_int, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
168 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
169 elif args.command == "smarts-id": |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
170 url, params = from_smarts_id( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
171 smarts_ids=args.input_smarts_id_str, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
172 min_diameter=args.input_min_diameter_int, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
173 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
174 else: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
175 parser.print_help() |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
176 sys.exit(1) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
177 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
178 logging.info("Query API") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
179 data = query(url=url, params=params) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
180 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
181 logging.info("Write data") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
182 write_json(path=args.output_data_json, data=data) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
183 except requests.HTTPError as e: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
184 logging.error(f"HTTP error: {e.response.status_code} - {e.response.text}") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
185 sys.exit(1) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
186 except Exception as e: |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
187 logging.error(f"Error: {e}") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
188 sys.exit(1) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
189 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
190 logging.info("Query RetroRules - end") |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
191 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
192 |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
193 if __name__ == "__main__": |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
194 logging.basicConfig( |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
195 level=logging.INFO, |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
196 format="%(asctime)s - %(levelname)s - %(message)s", |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
197 datefmt="%d-%m-%Y %H:%M", |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
198 ) |
|
6d20407d9a72
planemo upload for repository https://github.com/brsynth/galaxytools commit ccd77691de09b70e3048dca6be832dd93964c635-dirty
tduigou
parents:
diff
changeset
|
199 main() |
