#!/usr/bin/env python# -*- coding: utf-8 -*-## This file is part of the `pypath` python module## Copyright 2014-2023# EMBL, EMBL-EBI, Uniklinik RWTH Aachen, Heidelberg University## Authors: see the file `README.rst`# Contact: Dénes Türei (turei.denes@gmail.com)## Distributed under the GPLv3 License.# See accompanying file LICENSE.txt or copy at# https://www.gnu.org/licenses/gpl-3.0.html## Website: https://pypath.omnipathdb.org/#from__future__importannotations"""Visualisation services from the Human Metabolome Database (HMDB)."""importwebbrowserimportpypath.resources.urlsasurlsimportpypath.share.curlascurldef_svg_url(hmdb_id:str)->str:""" Returns the SVG URL for the given HMDB ID. """returnurls.urls['hmdb']['svg']%hmdb_id
[docs]defshow_structure(hmdb_id:str)->None:""" Show the 2D structure of the given HMDB ID in a web browser. Args: hmdb_id: Identifier of a metabolite. """url=_svg_url(hmdb_id)webbrowser.open(url)
[docs]defstructure_svg(hmdb_id:str,path:str|None=None)->str:""" Retrieve the picture of the 2D structure of a metabolite in SVG format. Args: hmdb_id: Identifier of a metabolite. path: Save the SVG file to this path (optional). Returns: The SVG file as a string. """url=_svg_url(hmdb_id)c=curl.Curl(url,large=False,silent=True)ifpath:withopen(path,'w')asfp:fp.write(c.result)returnc.result