Mercurial > repos > tduigou > retrorules
comparison query.py @ 4:815748762646 draft default tip
planemo upload for repository https://github.com/brsynth/galaxytools commit d7030c1af6fe06a1d45af115756ee775721e39b5
| author | tduigou |
|---|---|
| date | Thu, 02 Oct 2025 14:27:31 +0000 |
| parents | 95b4196b4ded |
| children |
comparison
equal
deleted
inserted
replaced
| 3:95b4196b4ded | 4:815748762646 |
|---|---|
| 15 reaction_ids_str: str, | 15 reaction_ids_str: str, |
| 16 datasets_str: str, | 16 datasets_str: str, |
| 17 chemical_domain_str: str, | 17 chemical_domain_str: str, |
| 18 ec_number_str: str, | 18 ec_number_str: str, |
| 19 min_radius_int: int, | 19 min_radius_int: int, |
| 20 valid_str: str, | 20 valid_str: str, |
| 21 dedup_str: str, | 21 dedup_str: str, |
| 22 limit_int: int, | 22 limit_int: int, |
| 23 offset_int: int, | 23 offset_int: int, |
| 24 ) -> Tuple: | 24 ) -> Tuple: |
| 25 url = f"{BASE_URL}/templates" | 25 url = f"{BASE_URL}/templates" |
| 26 params = [] | 26 params = [] |
| 27 if smarts_str: | 27 if smarts_str: |
| 28 params.append(("q", smarts_str)) | 28 params.append(("q", smarts_str)) |
| 29 if template_ids_str: | 29 if template_ids_str: |
| 46 params.append(("limit", str(limit_int))) | 46 params.append(("limit", str(limit_int))) |
| 47 if offset_int: | 47 if offset_int: |
| 48 params.append(("offset", str(offset_int))) | 48 params.append(("offset", str(offset_int))) |
| 49 return url, params | 49 return url, params |
| 50 | 50 |
| 51 | |
| 51 def from_templates_summary(template_id_str: str) -> Tuple: | 52 def from_templates_summary(template_id_str: str) -> Tuple: |
| 52 url = f"{BASE_URL}/templates/{template_id_str}/summary" | 53 url = f"{BASE_URL}/templates/{template_id_str}/summary" |
| 53 params = {} | 54 params = {} |
| 54 return url, params | 55 return url, params |
| 55 | 56 |
| 57 | |
| 56 def from_templates_sources(template_id_str: str) -> Tuple: | 58 def from_templates_sources(template_id_str: str) -> Tuple: |
| 57 url = f"{BASE_URL}/templates/{template_id_str}/sources" | 59 url = f"{BASE_URL}/templates/{template_id_str}/sources" |
| 58 params = {} | 60 params = {} |
| 59 return url, params | 61 return url, params |
| 62 | |
| 60 | 63 |
| 61 def from_templates_count( | 64 def from_templates_count( |
| 62 smarts_str: str, | 65 smarts_str: str, |
| 63 template_ids_str: str, | 66 template_ids_str: str, |
| 64 reaction_ids_str: str, | 67 reaction_ids_str: str, |
| 65 datasets_str: str, | 68 datasets_str: str, |
| 66 chemical_domain_str: str, | 69 chemical_domain_str: str, |
| 67 ec_number_str: str, | 70 ec_number_str: str, |
| 68 min_radius_int: int, | 71 min_radius_int: int, |
| 69 valid_str: str, | 72 valid_str: str, |
| 70 dedup_str: str, | 73 dedup_str: str, |
| 71 ) -> Tuple: | 74 ) -> Tuple: |
| 72 url = f"{BASE_URL}/templates_count" | 75 url = f"{BASE_URL}/templates_count" |
| 73 params = [] | 76 params = [] |
| 74 if smarts_str: | 77 if smarts_str: |
| 75 params.append(("q", smarts_str)) | 78 params.append(("q", smarts_str)) |
| 76 if template_ids_str: | 79 if template_ids_str: |
| 89 params.append(("valid", valid_str)) | 92 params.append(("valid", valid_str)) |
| 90 if dedup_str and dedup_str != "any": | 93 if dedup_str and dedup_str != "any": |
| 91 params.append(("dedup", dedup_str)) | 94 params.append(("dedup", dedup_str)) |
| 92 return url, params | 95 return url, params |
| 93 | 96 |
| 97 | |
| 94 def from_templates_export( | 98 def from_templates_export( |
| 95 generation_token_str: str, | 99 generation_token_str: str, |
| 96 smarts_str: str, | 100 smarts_str: str, |
| 97 template_ids_str: str, | 101 template_ids_str: str, |
| 98 reaction_ids_str: str, | 102 reaction_ids_str: str, |
| 99 datasets_str: str, | 103 datasets_str: str, |
| 100 chemical_domain_str: str, | 104 chemical_domain_str: str, |
| 101 ec_number_str: str, | 105 ec_number_str: str, |
| 102 min_radius_int: int, | 106 min_radius_int: int, |
| 103 valid_str: str, | 107 valid_str: str, |
| 104 dedup_str: str, | 108 dedup_str: str, |
| 105 ) -> Tuple: | 109 ) -> Tuple: |
| 106 url = f"{BASE_URL}/templates_export" | 110 url = f"{BASE_URL}/templates_export" |
| 107 params = [] | 111 params = [] |
| 108 if generation_token_str: | 112 if generation_token_str: |
| 109 params.append(("gen_token", generation_token_str)) | 113 params.append(("gen_token", generation_token_str)) |
| 110 if smarts_str: | 114 if smarts_str: |
| 125 params.append(("valid", valid_str)) | 129 params.append(("valid", valid_str)) |
| 126 if dedup_str and dedup_str != "any": | 130 if dedup_str and dedup_str != "any": |
| 127 params.append(("dedup", dedup_str)) | 131 params.append(("dedup", dedup_str)) |
| 128 return url, params | 132 return url, params |
| 129 | 133 |
| 134 | |
| 130 def query(url: str, params: Dict): | 135 def query(url: str, params: Dict): |
| 131 response = requests.get(url, params=params) | 136 response = requests.get(url, params=params) |
| 132 response.raise_for_status() | 137 response.raise_for_status() |
| 133 return response | 138 return response |
| 134 | 139 |
| 140 | |
| 135 def write_json(path: str, data: Dict): | 141 def write_json(path: str, data: Dict): |
| 136 with open(path, "w") as fd: | 142 with open(path, "w") as fd: |
| 137 json.dump(data, fd, indent=4) | 143 json.dump(data, fd, indent=4) |
| 138 | 144 |
| 145 | |
| 139 def write_tab(path: str, data: str): | 146 def write_tab(path: str, data: str): |
| 140 with open(path, "w") as fd: | 147 with open(path, "w") as fd: |
| 141 fd.write(data) | 148 fd.write(data) |
| 149 | |
| 142 | 150 |
| 143 def main(): | 151 def main(): |
| 144 parser = argparse.ArgumentParser( | 152 parser = argparse.ArgumentParser( |
| 145 description="Query RetroRules API via command-line endpoints." | 153 description="Query RetroRules API via command-line endpoints." |
| 146 ) | 154 ) |
| 213 parser_tem_sum.add_argument( | 221 parser_tem_sum.add_argument( |
| 214 "--output-data-json", | 222 "--output-data-json", |
| 215 required=True, | 223 required=True, |
| 216 help="Path to output JSON file", | 224 help="Path to output JSON file", |
| 217 ) | 225 ) |
| 218 | 226 |
| 219 # Subcommand: templates-sources | 227 # Subcommand: templates-sources |
| 220 parser_tem_sou = subparsers.add_parser("templates-sources", help="From templates-sources") | 228 parser_tem_sou = subparsers.add_parser("templates-sources", help="From templates-sources") |
| 221 parser_tem_sou.add_argument("--input-template-id-str", required=True, help="Template ID") | 229 parser_tem_sou.add_argument("--input-template-id-str", required=True, help="Template ID") |
| 222 parser_tem_sou.add_argument( | 230 parser_tem_sou.add_argument( |
| 223 "--output-data-json", | 231 "--output-data-json", |
