Skip to content

[BUG] DeseqStats fails with AttributeError when design is a pandas DataFrame #440

@136s

Description

@136s

Describe the bug
When passing a pandas DataFrame (a precomputed design matrix) directly to the design argument of DeseqDataSet, an AttributeError is raised later when creating a DeseqStats object.
Specifically, DeseqStats fails with:

AttributeError: 'DeseqDataSet' object has no attribute 'formulaic_contrasts'

This does not occur when design is provided as a formula string.

To Reproduce

from pydeseq2.utils import load_example_data
from pydeseq2.default_inference import DefaultInference
from formulaic_contrasts import FormulaicContrasts
from pydeseq2.dds import DeseqDataSet
from pydeseq2.ds import DeseqStats


counts_df = load_example_data(
    modality="raw_counts",
    dataset="synthetic",
    debug=False,
)

metadata = load_example_data(
    modality="metadata",
    dataset="synthetic",
    debug=False,
)

inference = DefaultInference(n_cpus=8)
design = FormulaicContrasts(
    metadata, '~ C(condition, contr.treatment(base="B"))'
).design_matrix
dds = DeseqDataSet(
    counts=counts_df,
    metadata=metadata,
    design=design,
    refit_cooks=True,
    inference=inference,
)
dds.deseq2()

ds = DeseqStats(dds, contrast=["condition", "B", "A"], inference=inference)

This raises:

AttributeError: 'DeseqDataSet' object has no attribute 'formulaic_contrasts'

pydeseq2 version: 0.5.4

Expected behavior

Either:

  • Passing a design matrix directly should be fully supported, and DeseqStats should work without error, or
  • A clear and explicit error should be raised earlier, indicating that design must be a formula string (or that additional information such as contrasts is required).

Screenshots

Image

Desktop (please complete the following information):

  • OS: macOS
  • Version: 26.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions