DatasetBag Class
The module implements the sqllite interface to a set of directories representing a dataset bag.
DatasetBag
DatasetBag is a class that manages a materialized bag. It is created from a locally materialized BDBag for a dataset_table, which is created either by DerivaML.create_execution, or directly by calling DerivaML.download_dataset.
A general a bag may contain multiple datasets, if the dataset is nested. The DatasetBag is used to represent only one of the datasets in the bag.
All the metadata associated with the dataset is stored in a SQLLite database that can be queried using SQL.
Attributes:
Name | Type | Description |
---|---|---|
dataset_rid |
RID
|
RID for the specified dataset |
version |
The version of the dataset |
|
model |
DatabaseModel
|
The Database model that has all the catalog metadata associated with this dataset. database: |
dbase |
Connection
|
connection to the sqlite database holding table values |
domain_schema |
str
|
Name of the domain schema |
Source code in src/deriva_ml/dataset/dataset_bag.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
__init__
__init__(
database_model: DatabaseModel,
dataset_rid: RID | None = None,
) -> None
Initialize a DatasetBag instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database_model
|
DatabaseModel
|
Database version of the bag. |
required |
dataset_rid
|
RID | None
|
Optional RID for the dataset. |
None
|
Source code in src/deriva_ml/dataset/dataset_bag.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
find_features
find_features(
table: str | Table,
) -> Iterable[Feature]
Find features for a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str | Table
|
The table to find features for. |
required |
Returns:
Type | Description |
---|---|
Iterable[Feature]
|
An iterable of Feature instances. |
Source code in src/deriva_ml/dataset/dataset_bag.py
240 241 242 243 244 245 246 247 248 249 |
|
get_table
get_table(
table: str,
) -> Generator[tuple, None, None]
Retrieve the contents of the specified table. If schema is not provided as part of the table name, the method will attempt to locate the schema for the table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
return: A generator that yields tuples of column values. |
required |
Returns:
Type | Description |
---|---|
None
|
A generator that yields tuples of column values. |
Source code in src/deriva_ml/dataset/dataset_bag.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
get_table_as_dataframe
get_table_as_dataframe(
table: str,
) -> pd.DataFrame
Retrieve the contents of the specified table as a dataframe.
If schema is not provided as part of the table name, the method will attempt to locate the schema for the table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
Table to retrieve data from. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe containing the contents of the specified table. |
Source code in src/deriva_ml/dataset/dataset_bag.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
get_table_as_dict
get_table_as_dict(
table: str,
) -> Generator[
dict[str, Any], None, None
]
Retrieve the contents of the specified table as a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
Table to retrieve data from. f schema is not provided as part of the table name, the method will attempt to locate the schema for the table. |
required |
Returns:
Type | Description |
---|---|
None
|
A generator producing dictionaries containing the contents of the specified table as name/value pairs. |
Source code in src/deriva_ml/dataset/dataset_bag.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
list_dataset_children
list_dataset_children(
recurse: bool = False,
) -> list[DatasetBag]
Get nested datasets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
recurse
|
bool
|
Whether to include children of children. |
False
|
Returns:
Type | Description |
---|---|
list[DatasetBag]
|
List of child dataset bags. |
Source code in src/deriva_ml/dataset/dataset_bag.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
list_dataset_members
list_dataset_members(
recurse: bool = False,
) -> dict[str, list[dict[str, Any]]]
Return a list of entities associated with a specific dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
recurse
|
bool
|
Whether to include nested datasets. |
False
|
Returns:
Type | Description |
---|---|
dict[str, list[dict[str, Any]]]
|
Dictionary of entities associated with the dataset. |
Source code in src/deriva_ml/dataset/dataset_bag.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
list_feature_values
list_feature_values(
table: Table | str,
feature_name: str,
) -> datapath._ResultSet
Return feature values for a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
Table | str
|
The table to get feature values for. |
required |
feature_name
|
str
|
Name of the feature. |
required |
Returns:
Type | Description |
---|---|
_ResultSet
|
Feature values. |
Source code in src/deriva_ml/dataset/dataset_bag.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
list_tables
list_tables() -> list[str]
List the names of the tables in the catalog
Returns:
Type | Description |
---|---|
list[str]
|
A list of table names. These names are all qualified with the Deriva schema name. |
Source code in src/deriva_ml/dataset/dataset_bag.py
81 82 83 84 85 86 87 |
|
lookup_term
lookup_term(
table: str | Table, term_name: str
) -> VocabularyTerm
Finds a term in a vocabulary table.
Searches for a term in the specified vocabulary table, matching either the primary name or any of its synonyms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str | Table
|
Vocabulary table to search in (name or Table object). |
required |
term_name
|
str
|
Name or synonym of the term to find. |
required |
Returns:
Name | Type | Description |
---|---|---|
VocabularyTerm |
VocabularyTerm
|
The matching vocabulary term. |
Raises:
Type | Description |
---|---|
DerivaMLVocabularyException
|
If the table is not a vocabulary table, or term is not found. |
Examples:
Look up by primary name: >>> term = ml.lookup_term("tissue_types", "epithelial") >>> print(term.description)
Look up by synonym: >>> term = ml.lookup_term("tissue_types", "epithelium")
Source code in src/deriva_ml/dataset/dataset_bag.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|