Motif families
In the basic model, the activities of different motifs are independent. Real motifs often are not: the motifs of one transcription factor, the motifs of factors of one structural class, or the occupancies of one motif in several windows around the TSS tend to change together. The --motif-families option of fit tells MARADONER which motifs form a family, and the activities of the motifs of a family then get a common part. The --motif-lowrank option adds a covariance between the families. The mean activities are left to the next section.
What is a family?
A family is a set of motifs. The deviation of the activity of a motif from its mean becomes a sum of 2 parts:
The individual part has the variance $τ$ of the motif, as in the basic model. The family part (the highlighted box) is the same for all motifs of the family in a group, and its variance $ω$ is one per family. The covariance matrix between motifs turns from the diagonal $Σ$ of the $τ$ into $$Σ + F Ω F^T.$$ Here, $F$ has a row per motif and a column per family, with a one where the motif belongs to the family and zeros elsewhere, and $Ω$ is the diagonal matrix of the $ω$. As before, the whole matrix is multiplied by the $ν$ of a group.
A motif may belong to several families, and it then gets the family part of each. A motif of no family has the individual part only. A family of one motif has no $ω$, as its family part could not be told apart from the individual part of the motif.
The file of families
The file is a JSON dictionary or a text file:
- A JSON dictionary maps a family to its motifs, as in
{"family_1": ["motif_39", "motif_195"]}, or a motif to its family, as in{"motif_39": "family_1"}; - A text file has a family per line, the name of the family followed by the names of its motifs;
- Alternatively, a text file has a motif per line, followed by the name of its family. MARADONER recognizes this layout by the first column holding names of motifs.
In a text file the names are separated by spaces or tabs. Motifs absent from the project are ignored, families left without motifs are dropped, and families with the same motifs are merged into one.
A member of a family may also be another family, and it then stands for all motifs of that family. The file
tfA motif_39 motif_195 tfB motif_240 motif_262 class_1 tfA tfB motif_315
gives class_1 the 5 motifs of its line and of the families tfA and tfB. A family may be listed before its definition, and families of families may be nested to any depth. A name of a motif of the project always means the motif: if a family has the same name, MARADONER warns about it. A family containing itself, directly or through other families, is an error. The Motif families and windows page uses families of families for the windows of motifs.
Example
The generator of synthetic data can split the active motifs into families. First, we generate a dataset with 40 families and create a project from it:
> maradoner generate demo --families 40 > maradoner create Families demo/expression.tsv demo/loadings.tsv --sample-groups demo/groups.json --loading-transform none
Here, the 400 active motifs of the dataset are split at random into 40 families. The demo folder gets the file families.txt with a family per line, and the true variances of the families go to family_variances_gt.tsv. The first lines of families.txt are
family_1 motif_39 motif_195 motif_240 motif_262 motif_315 motif_327 motif_352 motif_394 motif_406 motif_486 motif_500 family_2 motif_59 motif_84 motif_106 motif_117 motif_142 motif_172 motif_191 motif_217 motif_244 motif_253 motif_258 motif_276 motif_317 motif_382 motif_413 motif_415 motif_417 motif_481 family_3 motif_99 motif_112 motif_144 motif_187 motif_212 motif_274 motif_345
Then we fit the model with the families:
> maradoner fit Families --motif-families demo/families.txt
The output starts with a line about the file:
Motif families: 40 families (40 of them with more than one motif) cover 400 of 500 motifs.
After the usual block of the variances of motif activities come these lines:
[motif covariance] Fisher scoring: 9 steps, 10 evaluations, deviance -203233.532 -> -208842.885 [motif covariance] 9 iterations, 10 evaluations of the deviance (converged=True) [motif covariance] Sigma/G REML deviance -197070.653 -> -208842.885 (gain +11772.232) Smallest eigenvalue of the Fisher information of the variances (scaled to a unit diagonal): 0.04685838893530208 covariance between motifs: diagonal Sigma + 40 of 40 family variances above zero (REML deviance -208842.89).
The model with independent motifs is fitted first, and its estimates are the start of the model with families. The first 2 lines count the steps of that second optimization. The third one compares the 2 models: the 40 variances of the families lowered the deviance by 11772. The last line says that every family has a variance above zero.
Next, the usual commands:
> maradoner predict Families > maradoner export Families families_results
The families_results/params/family_variances.tsv table has a row per family with the variance $ω$, its standard error and the number of motifs:
family omega std motifs family_1 4.7053241495732685 0.9641532210699656 11 family_2 2.9355039950081205 0.6000799042236812 18 family_3 3.9489480420127903 0.8334671103365756 7
The true $ω$ of family_1 is 0.62, and the estimate is 4.71. That is fine: the scale of the variances is set by the $ν$ of one group, and the generator uses a different one. Relative to the mean $τ$ of the motifs, the estimated $ω$ are 1.13 on average and the true ones 1.28, with a correlation of 0.77 between them.
The tests/asymptotics_based/family_anova.tsv table tests $ω = 0$ for each family with a likelihood ratio:
family stat p-value FDR family_1 326.9672978884076 2.1993433993055434e-73 5.498358498263858e-73 family_2 433.00425499467195 1.802965587492313e-96 8.013180388854724e-96 family_3 192.52328841334426 4.472396497332097e-44 5.770834190105931e-44
Under the hypothesis, the $τ$ of the motifs of the family take over $ω$. The variance of each motif stays, and only the covariance within the family goes. All 40 families have p-values below $3 × 10^{-7}$.
With families in the model, the $τ$ of a motif is the variance of its individual part. Hence the test of $τ = 0$ in anova.tsv asks whether a motif varies beyond its family. It finds 348 motifs at an FDR of 0.05, against 407 in the fit without families.
Do the families help to predict activities? In this example they do. Without families, the deviations predicted for single samples have a squared error of 10.6% of the variance of the true deviations, and with them 8.4%. A motif borrows strength from the other motifs of its family. The params/activity_correlations.tsv table has the correlations between the activities of motifs implied by the fitted covariance.
Which families differ between groups?
The export command splits the predicted deviation of each motif in each group into the family part and the individual part. Both are posterior means given the activities of all motifs, with posterior standard deviations. The group test of anova.tsv is then applied to each part:
| Question | Where |
|---|---|
| What is the family part of a family in each group? | activities/family_activity_group_raw.tsv, with the standard deviations in family_activity_group_raw_std.tsv and the z-scores in family_activity.tsv |
| What is the individual part of a motif in each group? | The same files with individual in place of family |
| Does the family part differ between groups? | tests/prediction_based/family_anova.tsv |
| Does a motif differ between groups beyond its families? | tests/prediction_based/individual_anova.tsv |
| All of the above for a family in one row | tests/families.tsv |
In the example, the family parts of 32 of the 40 families differ between groups at an FDR of 0.05. The z-scores of family_1 range from -5.29 in group_6 to 2.47 in group_2. Of the 449 motifs, 383 differ between groups in anova.tsv, and 138 in their individual parts. For 246 of the 383, the test finds no difference beyond their families.
The tests/families.tsv table joins the tests of a family and of its motifs. The row of family_3 is
family motifs class family_FDR family_groups_FDR individual individual_groups members family_3 7 family+individual 5.770834190105931e-44 2.9590055972384587e-05 motif_112,motif_144,motif_187,motif_212,motif_274 motif_112,motif_212 motif_99,motif_112,motif_144,motif_187,motif_212,motif_274,motif_345
The 7 motifs of the family share a variation (family_FDR, the test of $ω = 0$), and the family part differs between groups (family_groups_FDR). Of them, 5 vary beyond the family (individual, the test of $τ = 0$), and the individual parts of 2 differ between groups (individual_groups). The class column sums up the 2 tests of variances: family, individual, family+individual or none. All 40 families of the example are of class family+individual, as the generator gives every motif an individual variance. The lists and the classes use the FDR level of the --alpha option of export, 0.05 by default.
For a family of the core, upstream and downstream windows of a motif X, a row is a statement about the windows. Class individual with only X_core in the individual column means that the windows share no variation and only the core varies: X acts in the core. Class family means that X acts through all windows together. A window left out of a list lacks evidence of the property. That is no evidence of its absence. With families of 2 levels, e.g. clusters of related factors over the families of windows, every family has a row, and the individual part of a motif is the part shared with neither of its families.
The Motif families and windows page goes through such a project from the input files to the conclusions.
Covariance between families
Families may change together as well. With the --motif-lowrank option, $Ω$ becomes
$$Ω + L L^T.$$
Here, $L$ has a row per family and a column per factor. As with the hidden covariates, the number of factors $k$ is small next to the number of families, hence the name of the option. A factor is a direction along which families move together, some of them up and others down.
The generator can add such a covariance. Let's generate a dataset with 1 factor and fit it with the families and 1 factor:
> maradoner generate demo --families 40 --motif-lowrank 1 > maradoner create Covariance demo/expression.tsv demo/loadings.tsv --sample-groups demo/groups.json --loading-transform none > maradoner fit Covariance --motif-families demo/families.txt --motif-lowrank 1
The true factor is saved to demo/L_motif_gt.tsv. The output of fit has these lines:
[motif covariance] Fisher scoring: 10 steps, 11 evaluations, deviance -350976.215 -> -351422.338 [motif covariance] 19 iterations, 21 evaluations of the deviance (converged=True) [motif covariance] Sigma/G REML deviance -332921.551 -> -351422.338 (gain +18500.787) Smallest eigenvalue of the Fisher information of the variances (scaled to a unit diagonal): 0.04786604990828177 covariance between motifs: diagonal Sigma + 40 of 40 family variances above zero + rank-1 covariance between families (REML deviance -351422.34).
Here, the gain is counted from the model with independent motifs. The families alone reach a deviance of -350592.269 on these data, so the factor adds 830. Fisher scoring covers the factor as well as the variances. It starts from the fit with families alone, and the first line counts its 10 steps. The second line counts the steps of both models, 9 of them for the families alone.
The params/family_factors.tsv table of the exported folder has a row per family and a column per factor:
family factor_1 family_1 3.8053847574250192 family_2 -1.7553280784059162
The factor has a correlation of -0.986 with the true one. The minus is no error: $L L^T$ is the same for $L$ and $-L$, so the sign of a factor is arbitrary. The params/family_correlations.tsv table has the correlations between families implied by $Ω + L L^T$. In this example the factor leaves the predicted activities as accurate as they are with the families alone, with a squared error of 5.3% in both fits.
How many factors? The select-rank command does not cover --motif-lowrank, and it says so. The number is judged from the gains. A factor adds a parameter per family, and it lowers the deviance even when there is nothing to find. On the data of the previous example, with no covariance between families, a factor gained 69. A gain many times larger, as 830 above, speaks for the factor. We have no calibrated test for it.
Without families
With --motif-lowrank and no file of families, each motif forms a family of one, and the covariance between motifs becomes $Σ + L L^T$ with a row of $L$ per motif. The factors go to params/motif_factors.tsv. A factor then has a parameter per motif. On the data of the first example, a factor without the file of families lowered the deviance by 1150, against 11772 for the 40 families.
What does it cost?
- Time. On the data of the first example,
fittakes 2.9 seconds without families, 3.7 with them and 5.8 with a factor and no families. On the data of the second example it takes 3.8 seconds with the families and 5.1 with the families and a factor; - Families that fit the data well do not have to improve prediction. In fact, on a real data you may observe the converse - a marginal worsening of FOV on held out promoters, if used with low-rank structure. Thats' it, the low-rank structure should be used as a tool to study the structure, but not as a way to improve predictions quality;
- The options need motif variances. With
--no-motif-variancethey are ignored with a warning; - They cannot be combined with
--clustering, as the latter replaces motifs by clusters.
