Spaces:
No application file
No application file
Merge pull request #9 from caraiz2001/add-bio-tools-ontology
Browse files- tools/meta_yml_tools.py +55 -2
tools/meta_yml_tools.py
CHANGED
|
@@ -105,7 +105,6 @@ def extract_information_from_meta_json(meta_file: dict, tool_name: str) -> dict:
|
|
| 105 |
print("Extracted metadata information from nf-core module meta.yml")
|
| 106 |
return {"inputs": inputs, "outputs": outputs, "homepage": homepage_url, "documentation": documentation_rul, "bio_tools_id": bio_tools_id}
|
| 107 |
|
| 108 |
-
|
| 109 |
def get_biotools_response(tool_name: str) -> list:
|
| 110 |
"""
|
| 111 |
Try to get bio.tools information for a tool.
|
|
@@ -135,4 +134,58 @@ def get_biotools_response(tool_name: str) -> list:
|
|
| 135 |
|
| 136 |
except requests.exceptions.RequestException as e:
|
| 137 |
print(f"Could not find bio.tools information for '{tool_name}': {e}")
|
| 138 |
-
return f"Could not find bio.tools information for '{tool_name}': {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
print("Extracted metadata information from nf-core module meta.yml")
|
| 106 |
return {"inputs": inputs, "outputs": outputs, "homepage": homepage_url, "documentation": documentation_rul, "bio_tools_id": bio_tools_id}
|
| 107 |
|
|
|
|
| 108 |
def get_biotools_response(tool_name: str) -> list:
|
| 109 |
"""
|
| 110 |
Try to get bio.tools information for a tool.
|
|
|
|
| 134 |
|
| 135 |
except requests.exceptions.RequestException as e:
|
| 136 |
print(f"Could not find bio.tools information for '{tool_name}': {e}")
|
| 137 |
+
return f"Could not find bio.tools information for '{tool_name}': {e}"
|
| 138 |
+
|
| 139 |
+
def get_biotools_ontology(tool_name, entry_id:str) -> str:
|
| 140 |
+
"""
|
| 141 |
+
Given a specific entry of the tools list associated to the module, return the biotools input ontology ID.
|
| 142 |
+
|
| 143 |
+
Args:
|
| 144 |
+
biotools_id (str): The biotools ID to get the ontology ID for (selected by the agent from the list of tools)
|
| 145 |
+
|
| 146 |
+
Returns:
|
| 147 |
+
str: The biotools ontology ID in the format "biotools:<tool_name>".
|
| 148 |
+
"""
|
| 149 |
+
|
| 150 |
+
url = f"https://bio.tools/api/t/?q={tool_name}&format=json"
|
| 151 |
+
try:
|
| 152 |
+
# Send a GET request to the API
|
| 153 |
+
response = requests.get(url)
|
| 154 |
+
response.raise_for_status() # Raise an error for bad status codes
|
| 155 |
+
# Parse the JSON response
|
| 156 |
+
data = response.text
|
| 157 |
+
data = json.loads(data)
|
| 158 |
+
data_list = data.get("list", [])
|
| 159 |
+
|
| 160 |
+
found = False
|
| 161 |
+
|
| 162 |
+
for tool in data_list:
|
| 163 |
+
# Select the tool with the given entry_id
|
| 164 |
+
if tool.get("name") == entry_id:
|
| 165 |
+
found = True
|
| 166 |
+
tool_function = tool.get("function")
|
| 167 |
+
|
| 168 |
+
format_terms = []
|
| 169 |
+
|
| 170 |
+
for fn in tool_function:
|
| 171 |
+
for inp in fn.get("input", []):
|
| 172 |
+
for fmt in inp.get("format", []):
|
| 173 |
+
term = fmt.get("term", "Unknown")
|
| 174 |
+
uri = fmt.get("uri", "No URI")
|
| 175 |
+
format_terms.append((term, uri))
|
| 176 |
+
text_block = "List of EDAM formats used:\n"
|
| 177 |
+
|
| 178 |
+
for i, (term, uri) in enumerate(format_terms, start=1):
|
| 179 |
+
text_block += f"{i}. {term} ({uri})\n"
|
| 180 |
+
|
| 181 |
+
print(text_block)
|
| 182 |
+
return format_terms
|
| 183 |
+
|
| 184 |
+
if not found:
|
| 185 |
+
print(f"Could not find the entry '{entry_id}' for the tool {tool_name}")
|
| 186 |
+
return f"Could not find the entry '{entry_id}' for the tool {tool_name}"
|
| 187 |
+
|
| 188 |
+
except requests.exceptions.RequestException as e:
|
| 189 |
+
print(f"Could not find the entry '{entry_id}' for the tool {tool_name}")
|
| 190 |
+
return f"Could not find bio.tools information for '{tool_name}': {e}"
|
| 191 |
+
|