drugforge.data.services.postera.molecule_set.MoleculeSetAPI

class drugforge.data.services.postera.molecule_set.MoleculeSetAPI(url, api_version, api_key, timeout=500, **kwargs)[source]

Bases: _BaseWebAPI

Connection and commands for PostEra Molecule Set API

__init__(url, api_version, api_key, timeout=500, **kwargs)

Methods

__init__(url, api_version, api_key[, timeout])

add_molecules(molecule_set_id, data)

Add additional molecules to the MoleculeSet.

add_molecules_from_df_with_manifold_validation(...)

create(molecule_set_name, data[, return_full])

Create a MoleculeSet from a list of Molecules.

create_molecule_set_from_df_with_manifold_validation(...)

destroy(molecule_set_id)

Delete a MoleculeSet.

exists(molecule_set_name[, by])

Check if a molecule set exists in PostEra.

from_settings(settings)

Create an interface to PostEra Molecule Set API from a Settings object.

get(molecule_set_id)

Get summary data for a given MoleculeSet.

get_id_from_name(name)

Get the unique id of a MoleculeSet from its human-readable name.

get_molecules(molecule_set_id[, return_as])

Pull the full contents of a MoleculeSet as a DataFrame.

get_molecules_from_id_or_name([id, name, ...])

Get the molecules from a molecule set by either id or name.

get_name_from_id(id)

Get the human-readable name of a MoleculeSet from its unique id.

list_available([return_full])

List available MoleculeSets.

token_name()

Return the name of the API token which should be used in the header.

update_molecules(molecule_set_id, data[, ...])

Updates the custom data associated with the Molecules in a MoleculeSet.

update_molecules_from_df_with_manifold_validation(...)

Attributes

molecule_set_url

add_molecules(molecule_set_id: id, data: MoleculeList) int[source]

Add additional molecules to the MoleculeSet.

Parameters:
  • molecule_set_id – The unique id of the MoleculeSet.

  • data – MoleculeList giving Molecules to add.

Returns:

  • Number of molecules not added due to exceeding the max number of

  • molecules allowed in a MoleculeSet.

create(molecule_set_name: str, data: MoleculeList, return_full: bool = False) str[source]

Create a MoleculeSet from a list of Molecules.

Parameters:
  • set_name – The human-readable name for the set.

  • data – MoleculeList giving Molecules to add.

  • return_full – If True, return a dict containing summary data for the created MoleculeSet; if False, return only its unique id.

destroy(molecule_set_id: str) None[source]

Delete a MoleculeSet.

Parameters:

molecule_set_id – The unique id of the MoleculeSet

exists(molecule_set_name: str, by='name') bool[source]

Check if a molecule set exists in PostEra.

Parameters:
  • molecule_set_name – The name of the molecule set to check.

  • by – The identifier type to check by. Can be either “id” or “name”.

Returns:

Whether the molecule set exists in PostEra.

Return type:

bool

classmethod from_settings(settings)[source]

Create an interface to PostEra Molecule Set API from a Settings object.

Parameters:

settings – A PosteraSettings object

Returns:

MoleculeSetAPI interface object.

Return type:

MoleculeSetAPI

get(molecule_set_id: str) dict[source]

Get summary data for a given MoleculeSet.

Parameters:

molecule_set_id – The unique id of the MoleculeSet

Return type:

Summary data as a dict.

get_id_from_name(name: str) str[source]

Get the unique id of a MoleculeSet from its human-readable name.

Parameters:

name – The human-readable name of the MoleculeSet.

Returns:

The unique id of the MoleculeSet.

Return type:

str

get_molecules(molecule_set_id: str, return_as='dataframe') DataFrame | list[source]

Pull the full contents of a MoleculeSet as a DataFrame.

Parameters:
  • molecule_set_id – The unique id of the MoleculeSet

  • return_as ({‘dataframe’, ‘list’}) – Whether to return the molecules as a DataFrame or a list.

get_molecules_from_id_or_name(id: str | None = None, name: str | None = None, return_as='dataframe') tuple[DataFrame | list, str][source]

Get the molecules from a molecule set by either id or name.

Parameters:
  • id – The unique id of the MoleculeSet.

  • name – The human-readable name of the MoleculeSet.

  • return_as ({‘dataframe’, ‘list’}) – Whether to return the molecules as a DataFrame or a list.

Returns:

The molecules in the molecule set.

Return type:

Union[pd.DataFrame, list]

get_name_from_id(id: str) str[source]

Get the human-readable name of a MoleculeSet from its unique id.

Parameters:

id – The unique id of the MoleculeSet.

Returns:

The human-readable name of the MoleculeSet.

Return type:

str

list_available(return_full: bool = False) list[dict] | dict[source]

List available MoleculeSets.

Parameters:

return_full – If True, return a list of dicts containing summary data for each MoleculeSet; if False, return a dict with the unique id for each MoleculeSet as keys, human-readable name as values.

classmethod token_name() str[source]

Return the name of the API token which should be used in the header.

update_molecules(molecule_set_id: str, data: MoleculeUpdateList, overwrite=False) list[str][source]

Updates the custom data associated with the Molecules in a MoleculeSet.

Parameters:
  • molecule_set_id – The unique id of the MoleculeSet.

  • data – MoleculeUpdateList giving MoleculeUpdates with update data for existing Molecules.

  • overwrite – If True, then customData will be entirely replaced with new data submitted; if False, then old and new customData will be combined, overwriting keys existing in both.

Return type:

List of Molecule ids that were updated.