hdmf.common.resources module¶
- class hdmf.common.resources.KeyTable(name='keys', data=[])¶
Bases:
TableA table for storing keys used to reference external resources.
- Parameters
name (
str) – the name of this tabledata (
ndarrayorlistortupleorDatasetorStrDatasetorHDMFDatasetorAbstractDataChunkIteratororDataIO) – the data in this table
- class hdmf.common.resources.Key(key, table=None, idx=None)¶
Bases:
RowA Row class for representing rows in the KeyTable.
- Parameters
- todict()¶
- class hdmf.common.resources.ResourceTable(name='resources', data=[])¶
Bases:
TableA table for storing names and URIs of ontology sources.
- Parameters
name (
str) – the name of this tabledata (
ndarrayorlistortupleorDatasetorStrDatasetorHDMFDatasetorAbstractDataChunkIteratororDataIO) – the data in this table
- class hdmf.common.resources.Resource(resource, resource_uri, table=None, idx=None)¶
Bases:
RowA Row class for representing rows in the ResourceTable.
- Parameters
- todict()¶
- class hdmf.common.resources.EntityTable(name='entities', data=[])¶
Bases:
TableA table for storing the external resources a key refers to.
- Parameters
name (
str) – the name of this tabledata (
ndarrayorlistortupleorDatasetorStrDatasetorHDMFDatasetorAbstractDataChunkIteratororDataIO) – the data in this table
- add_row(keys_idx, resources_idx, entity_id, entity_uri)¶
- Parameters
keys_idx (
intorKey) – The index into the keys table for the user key that maps to the resource term / registry symbol.resources_idx (
intorResource) – The index into the ResourceTable.entity_id (
str) – The unique ID for the resource term / registry symbol.entity_uri (
str) – The URI for the resource term / registry symbol.
- class hdmf.common.resources.Entity(keys_idx, resources_idx, entity_id, entity_uri, table=None, idx=None)¶
Bases:
RowA Row class for representing rows in the EntityTable.
- Parameters
keys_idx (
intorKey) – The index into the keys table for the user key that maps to the resource term / registry symbol.resources_idx (
intorResource) – The index into the ResourceTable.entity_id (
str) – The unique ID for the resource term / registry symbol.entity_uri (
str) – The URI for the resource term / registry symbol.table (
Table) – Noneidx (
int) – None
- todict()¶
- class hdmf.common.resources.ObjectTable(name='objects', data=[])¶
Bases:
TableA table for storing objects (i.e. Containers) that contain keys that refer to external resources.
- Parameters
name (
str) – the name of this tabledata (
ndarrayorlistortupleorDatasetorStrDatasetorHDMFDatasetorAbstractDataChunkIteratororDataIO) – the data in this table
- add_row(object_id, relative_path, field)¶
- Parameters
object_id (
str) – The object ID for the Container/Data.relative_path (
str) – (‘The relative_path of the attribute of the object that uses ‘, ‘an external resource reference key. Use an empty string if not applicable.’)field (
str) – The field of the compound data type using an external resource. Use an empty string if not applicable.
- class hdmf.common.resources.Object(object_id, relative_path, field, table=None, idx=None)¶
Bases:
RowA Row class for representing rows in the ObjectTable.
- Parameters
object_id (
str) – The object ID for the Container/Data.relative_path (
str) – (‘The relative_path of the attribute of the object that uses ‘, ‘an external resource reference key. Use an empty string if not applicable.’)field (
str) – The field of the compound data type using an external resource. Use an empty string if not applicable.table (
Table) – Noneidx (
int) – None
- todict()¶
- class hdmf.common.resources.ObjectKeyTable(name='object_keys', data=[])¶
Bases:
TableA table for identifying which keys are used by which objects for referring to external resources.
- Parameters
name (
str) – the name of this tabledata (
ndarrayorlistortupleorDatasetorStrDatasetorHDMFDatasetorAbstractDataChunkIteratororDataIO) – the data in this table
- class hdmf.common.resources.ObjectKey(objects_idx, keys_idx, table=None, idx=None)¶
Bases:
RowA Row class for representing rows in the ObjectKeyTable.
- Parameters
- todict()¶
- class hdmf.common.resources.ExternalResources(name, keys=None, resources=None, entities=None, objects=None, object_keys=None, type_map=None)¶
Bases:
ContainerA table for mapping user terms (i.e. keys) to resource entities.
- Parameters
name (
str) – The name of this ExternalResources container.keys (
KeyTable) – The table storing user keys for referencing resources.resources (
ResourceTable) – The table for storing names and URIs of resources.entities (
EntityTable) – The table storing entity information.objects (
ObjectTable) – The table storing object information.object_keys (
ObjectKeyTable) – The table storing object-resource relationships.type_map (
TypeMap) – The type map. If None is provided, the HDMF-common type map will be used.
- property keys¶
The table storing user keys for referencing resources.
- property resources¶
The table for storing names and URIs of resources.
- property entities¶
The table storing entity information.
- property objects¶
The table storing object information.
- property object_keys¶
The table storing object-resource relationships.
- get_key(key_name, container=None, relative_path='', field='')¶
Return a Key or a list of Key objects that correspond to the given key.
If container, relative_path, and field are provided, the Key that corresponds to the given name of the key for the given container, relative_path, and field is returned.
- Parameters
key_name (
str) – The name of the Key to get.container (
strorAbstractContainer) – The Container/Data object that uses the key or the object id for the Container/Data object that uses the key.relative_path (
str) – (‘The relative_path of the attribute of the object that uses ‘, ‘an external resource reference key. Use an empty string if not applicable.’)field (
str) – The field of the compound data type using an external resource.
- get_resource(resource_name)¶
Retrieve resource object with the given resource_name.
- Parameters
resource_name (
str) – The name of the resource.
- add_ref(container=None, attribute=None, field='', key=None, resources_idx=None, resource_name=None, resource_uri=None, entity_id=None, entity_uri=None)¶
Add information about an external reference used in this file.
It is possible to use the same name of the key to refer to different resources so long as the name of the key is not used within the same object, relative_path, and field combination. This method does not support such functionality by default.
- Parameters
container (
strorAbstractContainer) – The Container/Data object that uses the key or the object_id for the Container/Data object that uses the key.attribute (
str) – The attribute of the container for the external reference.field (
str) – The field of the compound data type using an external resource.key (
strorKey) – The name of the key or the Key object from the KeyTable for the key to add a resource for.resources_idx (
Resource) – The Resource from the ResourceTable.resource_name (
str) – The name of the resource to be created.resource_uri (
str) – The URI of the resource to be created.entity_id (
str) – The identifier for the entity at the resource.entity_uri (
str) – The URI for the identifier at the resource.
- get_object_resources(container, relative_path='', field='')¶
Get all entities/resources associated with an object.
- Parameters
container (
strorAbstractContainer) – The Container/data object that is linked to resources/entities.relative_path (
str) – (‘The relative_path of the attribute of the object that uses ‘, ‘an external resource reference key. Use an empty string if not applicable.’)field (
str) – The field of the compound data type using an external resource.
- get_keys(keys=None)¶
- Return a DataFrame with information about keys used to make references to external resources.
- The DataFrame will contain the following columns:
key_name: the key that will be used for referencing an external resource
resources_idx: the index for the resourcetable
entity_id: the index for the entity at the external resource
entity_uri: the URI for the entity at the external resource
It is possible to use the same key_name to refer to different resources so long as the key_name is not used within the same object, relative_path, field. This method doesn’t support such functionality by default. To select specific keys, use the keys argument to pass in the Key object(s) representing the desired keys. Note, if the same key_name is used more than once, multiple calls to this method with different Key objects will be required to keep the different instances separate. If a single call is made, it is left up to the caller to distinguish the different instances.
- to_dataframe(use_categories=False)¶
- Convert the data from the keys, resources, entities, objects, and object_keys tables
to a single joint dataframe. I.e., here data is being denormalized, e.g., keys that are used across multiple enities or objects will duplicated across the corresponding rows.
Returns:
DataFramewith all data merged into a single, flat, denormalized table.
- Parameters
use_categories (
bool) – Use a multi-index on the columns to indicate which category each column belongs to.- Returns
A DataFrame with all data merged into a flat, denormalized table.
- Return type
DataFrame
- export_to_sqlite(db_file)¶
Save the keys, resources, entities, objects, and object_keys tables using sqlite3 to the given db_file.
The function will first create the tables (if they do not already exist) and then add the data from this ExternalResource object to the database. If the database file already exists, then the data will be appended as rows to the existing database tables.
Note, the index values of foreign keys (e.g., keys_idx, objects_idx, resources_idx) in the tables will not match between the ExternalResources here and the exported database, but they are adjusted automatically here, to ensure the foreign keys point to the correct rows in the exported database. This is because: 1) ExternalResources uses 0-based indexing for foreign keys, whereas SQLite uses 1-based indexing and 2) if data is appended to existing tables then a corresponding additional offset must be applied to the relevant foreign keys.
- raises
The function will raise errors if connection to the database fails. If the given db_file already exists, then there is also the possibility that certain updates may result in errors if there are collisions between the new and existing data.
- Parameters
db_file (
str) – Name of the SQLite database file- Returns
A DataFrame with all data merged into a flat, denormalized table.
- Return type
DataFrame
- data_type = 'ExternalResources'¶
- namespace = 'hdmf-experimental'¶