Manage custom molecular databases

Setup

[1]:
%matplotlib inline
%load_ext autoreload
%autoreload 2
[2]:
from metaspace import SMInstance

You can find an API key on your profile page

[14]:
sm = SMInstance()
[14]:
SMInstance(https://metaspace2020.eu/graphql)
[ ]:
# This will prompt you to enter your API key if needed and it will save it to a config file.
# Note that API keys should be kept secret like passwords.
sm.save_login()

Create and modify new database

Using the new custom databases feature of Metaspace, you can create your own custom database as a TSV text file with just three fields: id, name, formula. Once created it will be available on your group page, in the “Databases” tab. You will be able to use this database on the dataset upload page alongside the Metaspace public databases for annotation of datasets.

Using the new custom databases feature of Metaspace, you can create your own custom database as a TSV text file with just three fields: id, name, formula. Once created it will be available on your group page, in the “Databases” tab. You will be able to use this database on the dataset upload page alongside the Metaspace public databases for annotation of datasets.

[15]:
[db for db in sm.databases() if db.name == "hmdb_small"]
[15]:
[<43:hmdb_small:>]

Upload a new database from a local file

[46]:
custom_database_path = "/home/intsco/embl/sm/mol_databases/db_files/hmdb_small.csv"
[47]:
!head {custom_database_path}
id      name    formula
1       1-Methylhistidine       C7H11N3O2
2       13-Diaminopropane       C3H10N2
5       2-Ketobutyric acid      C4H6O3
8       2-Hydroxybutyric acid   C4H8O3
10      2-Methoxyestrone        C19H24O3
11      (R)-3-Hydroxybutyric acid       C4H8O3
12      Deoxyuridine    C9H12N2O5
14      Deoxycytidine   C9H13N3O4
15      Cortexolone     C21H30O4
[32]:
sm.create_database(local_path=custom_database_path, name="hmdb_small", version="v2")
Uploading 1 part of /home/intsco/embl/sm/mol_databases/db_files/hmdb_small.csv file...
[32]:
{'id': 48}
[33]:
[db for db in sm.databases() if db.name == "hmdb_small"]
[33]:
[<48:hmdb_small:v2>, <43:hmdb_small:>]

Archive just created database

This will make the database not available for datasets annotation.

[41]:
moldb = sm.database(name="hmdb_small", version="v2")
moldb.archived
[41]:
False
[42]:
sm.update_database(moldb.id, archived=True)
[42]:
{'id': 48}
[43]:
sm.database(id=moldb.id).archived
[43]:
True

Delete the new database

Database deletion will delete all existing datasets annotations against this database.

[44]:
sm.delete_database(moldb.id)
[44]:
True
[45]:
[db for db in sm.databases() if db.name == "hmdb_small"]
[45]:
[<43:hmdb_small:>]