ADSL Dataset Example

Introduction

This example demonstrates how to generate an ADSL (Analysis Dataset Subject Level) dataset using the ADaM YAML specification system.

Setup

First, let’s import the necessary libraries and load our specification:

import sys
import os
sys.path.insert(0, os.path.abspath(".."))

import polars as pl
from adamyaml.adam_derivation import AdamDerivation
from adamyaml.adam_spec import AdamSpec
from reactable import Reactable, embed_css

pl.Config.set_tbl_rows(20)
embed_css()

Load and Examine the Specification

Let’s load the ADSL specification and examine its structure:

# Load the specification
spec = AdamSpec("../spec/study1/adsl_study1.yaml")

# Display basic information
print(f"Domain: {spec.domain}")
print(f"Number of columns: {len(spec.columns)}")
print(f"Key variables: {spec.key}")
Domain: ADSL
Number of columns: 11
Key variables: ['USUBJID']

View Column Specifications

Let’s create an interactive table showing the column specifications:

# Convert columns to a polars dataframe for display
columns_data = []
for col in spec.columns:
    columns_data.append({
        "Name": col.name,
        "Label": col.label,
        "Type": col.type,
        "Core": col.core if col.core else "N/A",
        "Has Derivation": "Yes" if col.derivation else "No"
    })

Reactable(
    pl.DataFrame(columns_data)
)

Generate the Dataset

Now let’s generate the actual ADSL dataset:

# Create the derivation engine
engine = AdamDerivation("../spec/study1/adsl_study1.yaml")

# Build the dataset
df = engine.build()

print(f"Dataset shape: {df.shape}")
print(f"Columns: {', '.join(df.columns)}")
Dataset shape: (306, 11)
Columns: USUBJID, DOMAIN, STUDYID, SUBJID, TRTSDT, AGE, AGEU, SEX, WEIGHT, HEIGHT, BMI

Explore the Generated Data

Let’s look at the first few records with an interactive table:

Reactable(df)

Conclusion

This example demonstrated how to use the ADaM YAML system to generate ADSL datasets with interactive exploration using reactable.