ToxRefDBObservation API Reference¶
pycomptox.hazard.toxrefdbobservation.ToxRefDBObservation
¶
Bases: CachedAPIClient
Client for accessing ToxRefDB observation and endpoint status data from EPA CompTox Dashboard.
This class provides access to all observations and endpoint observation status according to relevant guideline profiles for chemicals, studies, or study types.
ToxRefDB curations are guideline studies with specific testing requirements. Guideline profiles are used to populate a list of observations that should be reported and tested within each study - the endpoint observation status.
Endpoint Observation Status enables: - Automated distinction of true negatives (tested with no effect observed) - Better understanding of false negatives (missing/untested effects) - Identification of which endpoints were actually evaluated - Assessment of study completeness against guideline requirements
This is critical for proper interpretation of toxicology data, as the absence of an effect report could mean either: 1. The endpoint was tested and no effect was observed (true negative) 2. The endpoint was not tested or not reported (false negative/missing data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
CompTox API key. If not provided, will attempt to load from saved configuration or COMPTOX_API_KEY environment variable. |
None
|
base_url
|
str
|
Base URL for the CompTox API. Defaults to EPA's endpoint. |
'https://comptox.epa.gov/ctx-api/'
|
time_delay_between_calls
|
float
|
Delay in seconds between API calls for rate limiting. Default is 0.0 (no delay). |
0.0
|
use_cache
|
bool
|
Whether to use caching by default. Default is True. |
required |
Example
from pycomptox.hazard import ToxRefDBObservation obs = ToxRefDBObservation()
Get observations for a study¶
study_obs = obs.get_observations_by_study_id(63)
Check endpoint observation status¶
for observation in study_obs: ... endpoint = observation.get('endpoint', 'Unknown') ... status = observation.get('observationStatus', 'Unknown') ... print(f"{endpoint}: {status}")
Source code in src/pycomptox/hazard/toxrefdbobservation.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
__init__(api_key=None, base_url='https://comptox.epa.gov/ctx-api/', time_delay_between_calls=0.0, **kwargs)
¶
Initialize the ToxRefDBObservation client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
Optional[str]
|
CompTox API key (optional, will be loaded from config if not provided) |
None
|
base_url
|
str
|
Base URL for the CompTox API |
'https://comptox.epa.gov/ctx-api/'
|
time_delay_between_calls
|
float
|
Delay between API calls in seconds |
0.0
|
kwargs
|
Any
|
Additional arguments for CachedAPIClient (cache_manager, use_cache) |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no API key is provided or found in configuration |
Source code in src/pycomptox/hazard/toxrefdbobservation.py
get_observations_by_dtxsid(dtxsid, use_cache=None)
¶
Get ToxRefDB observations by DTXSID.
Retrieves all observations and endpoint observation status for a chemical
across all studies in ToxRefDB. This provides a comprehensive view of
toxicological observations across different study types and conditions.
Args:
dtxsid: DSSTox Substance Identifier (e.g., 'DTXSID1037806')
use_cache: Whether to use cache for this request. If None, uses
the instance default setting.
Returns:
List of dictionaries containing observation data across all studies
for the chemical. Each entry includes fields such as:
- dtxsid (str): Chemical identifier
- studyId (int): Study identifier
- studyType (str): Type of study
- endpoint (str): Toxicological endpoint
- observationStatus (str): Status of observation
- effect (str): Observed effect (if any)
- target (str): Target organ or system
- finding (str): Detailed finding
- sex (str): Sex of test animals
- species (str): Test species
- ageAtObservation (str): Age at observation
- generation (str): Generation (for reproductive studies)
- exposureDuration (str): Duration of exposure
- doseGroup (str): Dose group information
- guidelineRequired (bool): Guideline requirement status
- reference (str): Study reference
- Notes: Exact fields vary by study
Raises:
ValueError: If dtxsid is not a valid non-empty string
PermissionError: If API key is invalid
RuntimeError: For other API errors
Example:
>>> from pycomptox.hazard import ToxRefDBObservation
>>> obs = ToxRefDBObservation()
>>>
>>> # Get all observations for a chemical
>>> chem_obs = obs.get_observations_by_dtxsid("DTXSID1037806")
>>>
>>> if chem_obs:
... print(f"Found {len(chem_obs)} observations")
...
... # Group by study type
... by_type = {}
... for record in chem_obs:
... stype = record.get('studyType', 'Unknown')
... if stype not in by_type:
... by_type[stype] = []
... by_type[stype].append(record)
...
... print(f"
Observations by study type:")
... for stype, records in sorted(by_type.items()):
... print(f" {stype}: {len(records)} observation(s)")
...
... # Identify all endpoints tested
... endpoints = set(r.get('endpoint') for r in chem_obs if r.get('endpoint'))
... print(f"
Unique endpoints tested: {len(endpoints)}")
...
... # Find all target organs/systems
... targets = set(r.get('target') for r in chem_obs if r.get('target'))
... print(f"Target organs/systems: {', '.join(sorted(targets))}")
...
... # Analyze observation status across all studies
... status_counts = {}
... for record in chem_obs:
... status = record.get('observationStatus', 'Unknown')
... status_counts[status] = status_counts.get(status, 0) + 1
...
... print(f"
Observation status across all studies:")
... for status, count in sorted(status_counts.items()):
... print(f" {status}: {count}")
...
... # Find consistent effects across studies
... effects_by_endpoint = {}
... for record in chem_obs:
... endpoint = record.get('endpoint')
... effect = record.get('effect')
... if endpoint and effect:
... if endpoint not in effects_by_endpoint:
... effects_by_endpoint[endpoint] = []
... effects_by_endpoint[endpoint].append(effect)
...
... print(f"
Endpoints with effects in multiple studies:")
... for endpoint, effects in effects_by_endpoint.items():
... if len(effects) > 1:
... print(f" {endpoint}: {len(effects)} observation(s)")
...
... # Compare across study types
... dev_obs = [r for r in chem_obs if r.get('studyType') == 'DEV']
... rep_obs = [r for r in chem_obs if r.get('studyType') == 'REP']
...
... if dev_obs:
... dev_effects = [r for r in dev_obs if r.get('effect')]
... print(f"
Developmental studies: {len(dev_obs)} obs, {len(dev_effects)} with effects")
...
... if rep_obs:
... rep_effects = [r for r in rep_obs if r.get('effect')]
... print(f"Reproductive studies: {len(rep_obs)} obs, {len(rep_effects)} with effects")
Note:
- Returns observations from all available studies for the chemical
- May include multiple study types and conditions
- Useful for comprehensive hazard assessment across all available data
- Observation status helps distinguish tested vs. untested endpoints
Source code in src/pycomptox/hazard/toxrefdbobservation.py
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 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
get_observations_by_study_id(study_id, use_cache=None)
¶
Get ToxRefDB observations by study ID.
Retrieves all observations and endpoint observation status for a specific
study. This provides a complete view of what endpoints were evaluated and
their observation status.
Args:
study_id: ToxRefDB study identifier (integer)
use_cache: Whether to use cache for this request. If None, uses
the instance default setting.
Returns:
List of dictionaries containing observation data with fields such as:
- dtxsid (str): Chemical identifier
- studyId (int): Study identifier
- studyType (str): Type of study
- endpoint (str): Toxicological endpoint name
- observationStatus (str): Status (observed/not observed/tested/not tested)
- effect (str): Observed effect description (if any)
- target (str): Target organ or system
- finding (str): Detailed finding description
- sex (str): Sex of test animals
- ageAtObservation (str): Age when observation was made
- generation (str): Generation studied (for reproductive studies)
- doseGroup (str): Dose group information
- guidelineRequired (bool): Whether endpoint is required by guideline
- observationMethod (str): Method used for observation
- Notes: Exact fields vary by study type
Raises:
ValueError: If study_id is not a positive integer
PermissionError: If API key is invalid
RuntimeError: For other API errors
Example:
>>> from pycomptox.hazard import ToxRefDBObservation
>>> obs = ToxRefDBObservation()
>>>
>>> # Get observations for a specific study
>>> study_obs = obs.get_observations_by_study_id(63)
>>>
>>> if study_obs:
... print(f"Found {len(study_obs)} observations")
...
... # Get study metadata from first record
... first = study_obs[0]
... print(f"
Study ID: {first.get('studyId')}")
... print(f"Chemical: {first.get('dtxsid')}")
... print(f"Study Type: {first.get('studyType')}")
...
... # Analyze observation status
... status_counts = {}
... for record in study_obs:
... status = record.get('observationStatus', 'Unknown')
... status_counts[status] = status_counts.get(status, 0) + 1
...
... print(f"
Observation status breakdown:")
... for status, count in sorted(status_counts.items()):
... print(f" {status}: {count}")
...
... # Find endpoints with effects
... with_effects = [r for r in study_obs if r.get('effect')]
... print(f"
Endpoints with effects: {len(with_effects)}")
...
... if with_effects:
... print("
Sample effects:")
... for rec in with_effects[:3]:
... endpoint = rec.get('endpoint', 'Unknown')
... effect = rec.get('effect', 'N/A')
... target = rec.get('target', 'N/A')
... print(f" {endpoint} ({target}): {effect}")
...
... # Check guideline compliance
... required = [r for r in study_obs if r.get('guidelineRequired')]
... tested = [r for r in required if 'tested' in str(r.get('observationStatus', '')).lower()]
... print(f"
Guideline compliance:")
... print(f" Required observations: {len(required)}")
... print(f" Tested: {len(tested)}")
... if required:
... compliance = (len(tested) / len(required)) * 100
... print(f" Compliance: {compliance:.1f}%")
Note:
- A single study may have many endpoint observations
- Observation status distinguishes true negatives from missing data
- Use this to assess study completeness and guideline compliance
Source code in src/pycomptox/hazard/toxrefdbobservation.py
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 | |
get_observations_by_study_type(study_type, page_number=1, use_cache=None)
¶
Get ToxRefDB observations by study type with pagination.
Retrieves all observations and endpoint observation status for studies of a specified type. Results are paginated to handle large datasets.
Observation data includes: - Endpoints that should be tested per guideline requirements - Observation status (tested/not tested, effect/no effect) - True negatives vs. missing data distinction - Guideline compliance information
Common study types include: - DEV: Developmental toxicity studies - REP/REPRO: Reproductive toxicity studies - DNT: Developmental neurotoxicity studies - CHRON: Chronic toxicity studies - SUBCHRON: Subchronic toxicity studies
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_type
|
str
|
Study type code (e.g., 'DEV', 'REP', 'DNT') |
required |
page_number
|
int
|
Page number for paginated results (default is 1) |
1
|
use_cache
|
Optional[bool]
|
Whether to use cache for this request. If None, uses the instance default setting. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing paginated results with fields: - data (list): List of observation records for this page - pageNumber (int): Current page number - recordsOnPage (int): Number of records on this page - studyType (str): The requested study type |
Dict[str, Any]
|
Each record in 'data' contains fields such as: - dtxsid (str): Chemical identifier - studyId (int): Study identifier - studyType (str): Type of study - endpoint (str): Toxicological endpoint - observationStatus (str): Status (observed/not observed/tested/etc.) - target (str): Target organ or system - effect (str): Observed effect (if any) - ageAtObservation (str): Age when observation was made - sex (str): Sex of test animals - generation (str): Generation (for reproductive studies) - guidelineRequired (bool): Whether endpoint is required by guideline - Notes: Exact fields vary by study type |
Raises:
| Type | Description |
|---|---|
ValueError
|
If study_type is not a valid non-empty string or page_number < 1 |
PermissionError
|
If API key is invalid |
RuntimeError
|
For other API errors |
Example
from pycomptox.hazard import ToxRefDBObservation obs = ToxRefDBObservation()
Get developmental study observations¶
dev_obs = obs.get_observations_by_study_type("DEV", page_number=1)
print(f"Page {dev_obs['pageNumber']}") print(f"Records on this page: {dev_obs['recordsOnPage']}")
Analyze observation status¶
if dev_obs.get('data'): ... tested = 0 ... not_tested = 0 ... effects = 0 ...
... for record in dev_obs['data']: ... status = record.get('observationStatus', '') ... if 'tested' in status.lower(): ... tested += 1 ... if 'effect' in str(record.get('effect', '')).lower(): ... effects += 1 ...
... print(f"Tested endpoints: {tested}") ... print(f"Endpoints with effects: {effects}")Check guideline compliance¶
if dev_obs.get('data'): ... required = [r for r in dev_obs['data'] if r.get('guidelineRequired')] ... print(f"Guideline-required observations: {len(required)}")
Note
- Results are paginated; use page_number to navigate
- Observation status distinguishes true negatives from missing data
- Guideline profiles define expected observations per study type
Source code in src/pycomptox/hazard/toxrefdbobservation.py
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 | |