formula
closing_paren(text)
Index of the bracket closing the one at text[0], or -1.
Source code in scdesigner/src/scdesigner/data/formula.py
116 117 118 119 120 121 122 123 124 125 126 | |
partition_formula(formula)
Modify a formula to partition observations.
We remove the intercept unless the formula has no other terms, so that "~
cell_type" is a proper indicator across cell types (and there is no
intercept-like column equal to 1 across all cells).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
A copula group formula. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The normalized formula. |
Examples:
>>> partition_formula("~ cell_type")
'~ -1 + cell_type'
Source code in scdesigner/src/scdesigner/data/formula.py
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 | |
split_random_terms(formula)
Separate lme4-style random-effect terms from a formula.
We parse random-effect terms formatted like (1 | donor), since they
aren't supported natively in formulaic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
A formula whose right-hand side may include random-effect terms. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
fixed |
str
|
The formula without random-effect terms, or |
random |
list of tuple of str
|
|
Examples:
>>> split_random_terms("~ genotype * cell_type + (1 | donor)")
('~ genotype * cell_type', [('1', 'donor')])
Source code in scdesigner/src/scdesigner/data/formula.py
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 | |
split_top_level(text, separator)
Split on separator outside of brackets
This also removes surrounding whitespace.
Source code in scdesigner/src/scdesigner/data/formula.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |