Interact with your Mantle Database
Introduction
In your Mantle Database, data is stored as entities. Each entity in your Mantle Database has a name and a data type. Each data type has a set of required properties and optional properties. You can view all of the entities of a data type as a table in your Mantle Database. Each entity is a row in a table, and the properties are columns of the table. There a multiple data types, such as rnaseq_fastq
or image_directory
.
Each value of each property is one of:
- string
- integer
- double (float)
- boolean
- file
Using the Mantle SDK, you can access information stored in your Mantle Database or create new entities in your Mantle Database.
Interacting with a single data entity
Getting an entity by its unique ID
This returns a Python object representing the data entity.
Accessing an entity’s name and unique ID
If you got an entity by its unique ID and want to know its name:
If you got an entity some other way (e.g. as an output of a Mantle Pipeline run) and want to know its unique ID:
Getting entity properties
To conveniently access the values of all of an entity’s properties, you can represent the entity as a Pandas series:
Downloading files from an entity
Files that are properties of entities are stored in Amazon S3. To use the files, you need to download them to your local working environment, whether you are in a Mantle Notebook or using a script on your own computer.
Download files from file properties using the download_s3
method,
which takes as arguments the key of the property and the local path to
which the file will be downloaded.
Querying for a group of entities and returning a DataFrame
To get a Pandas DataFrame where datasets are represented as rows, you can query for a group of datasets and turn them into a DataFrame.
This returns an iterable of entity Python objects, which can each be interacted with using the SDK. For example, you can loop through and download files from each entity into your working environment.
Additionally, you can turn this iterable into a Pandas DataFrame:
Creating a new data entity in your Mantle Database
To create a new entity in your Mantle Database, you must provide a name and a data type, and the required properties (each data type has a set of required properties and optional properties). The properties of the entity are expressed as key-value pairs.
To test this out yourself, download the PDB file here.
Note that to use a file as a property, you need to pass a nested dictionary that instructs Mantle to upload a file from a local file path to Amazon S3:
This is different from other properties, where you only need to pass the value.
local
keyword in Mantle relates to whether you’re asking the system
to create a new entity in the database via an API request.
In this version of the SDK, local
is set to True
by default to be consistent with earlier versions.
However, for most purposes, setting it to False
is appropriate.
When set to False
, the entity is automatically pushed to Mantle.