Skip to content

Commit 9fcc9d6

Browse files
committed
WIP: To be continued when David and I will work on this
1 parent 8480971 commit 9fcc9d6

2 files changed

Lines changed: 204 additions & 0 deletions

File tree

Notes_for_imprinting_work.txt

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
Imprinting Work Restart Notes
2+
=============================
3+
4+
Date: 2026-04-18
5+
6+
Current setup
7+
-------------
8+
9+
- Clean restart worktree:
10+
`/Users/ggorjanc/Storages/GitBox/AlphaSimR/AlphaSimR-wt-imprinting`
11+
- Branch in that worktree:
12+
`imprinting`
13+
- Base commit:
14+
current `upstream/devel` at the time the worktree was created
15+
16+
What was reviewed
17+
-----------------
18+
19+
- David's old branch:
20+
`https://github.com/david20011999/AlphaSimR/commits/imprinting/`
21+
- David -> Gregor PR:
22+
`https://github.com/gregorgorjanc/AlphaSimR/pull/4`
23+
- Gregor fork branch:
24+
`https://github.com/gregorgorjanc/AlphaSimR/tree/imprinting`
25+
- Upstream branch:
26+
`https://github.com/gaynorr/AlphaSimR/tree/imprinting`
27+
- Upstream discussion and design record:
28+
`https://github.com/gaynorr/AlphaSimR/pull/167`
29+
30+
Main conclusions
31+
----------------
32+
33+
- The old `imprinting` branches are not a clean place to continue work.
34+
- `upstream/imprinting` is far behind current `upstream/devel` and should be treated as historical reference, not as the active implementation branch.
35+
- `origin/imprinting` is effectively the same old line of work and also should be treated as reference only.
36+
- David's PR to Gregor contains later experiments such as `TraitADI`, `calcGenParamS()`, and `getGvS()`, but it still sits on the stale branch history.
37+
- The real unresolved technical problem is not the basic API surface for imprinting. It is the variance-component definition and orthogonal decomposition of additive, dominance, and imprinting effects.
38+
- The upstream discussion in PR #167 is the key design record. The important guidance there was:
39+
- move toward regression-based orthogonalization of `bv`, `dd`, and imprinting deviation
40+
- do not lock in male/female breeding-value semantics too early
41+
- keep F1 / cross-mean prediction outside AlphaSimR for now
42+
- keep the first renewed implementation narrow and avoid dragging in polyploids or epistasis immediately
43+
44+
Recommended restart strategy
45+
----------------------------
46+
47+
- Use the new `imprinting` worktree as the active restart.
48+
- Treat old code only as a quarry for selective porting.
49+
- Use `/Users/ggorjanc/Downloads/__TODO_AlphaSimR_ImprintingVarianceComponents.R`
50+
as the mathematical scratchpad / oracle for the regression decomposition.
51+
- First implementation pass should focus on:
52+
- tests for orthogonal regressors under arbitrary genotype frequencies
53+
- `TraitAI`
54+
- updated `calcGenParam()` logic for orthogonal decomposition
55+
- matching `getGv()` behavior
56+
- only then extend to `TraitADI`
57+
- Leave out, for now:
58+
- polyploids
59+
- epistasis-related imprinting combinations
60+
- polished vignette work
61+
- a final public interpretation of sex-specific breeding values
62+
63+
Useful branch facts
64+
-------------------
65+
66+
- Local working branch now is `imprinting`.
67+
- Remote branch status checked on 2026-04-18:
68+
- `highlanderlab/imprinting`: does not currently exist
69+
- `origin/imprinting`: already exists and points to the old imprinting history
70+
71+
Commands to push this branch
72+
----------------------------
73+
74+
Work from the imprinting worktree:
75+
76+
```bash
77+
cd /Users/ggorjanc/Storages/GitBox/AlphaSimR/AlphaSimR-wt-imprinting
78+
git status --short --branch
79+
git log --oneline --max-count=5
80+
```
81+
82+
Push to HighlanderLab for the first time:
83+
84+
```bash
85+
git push highlanderlab imprinting:imprinting
86+
```
87+
88+
Push to Gregor's fork under the same branch name:
89+
90+
```bash
91+
git push origin imprinting:imprinting
92+
```
93+
94+
Important note about Gregor's fork
95+
----------------------------------
96+
97+
- `origin/imprinting` already exists on the old history.
98+
- Because this new local `imprinting` branch is a clean restart from `upstream/devel`, the plain push above will most likely be rejected as non-fast-forward.
99+
- If the intention is to replace the old `origin/imprinting` branch with this new restart branch, use:
100+
101+
```bash
102+
git push --force-with-lease origin imprinting:imprinting
103+
```
104+
105+
Safer alternative for Gregor's fork
106+
-----------------------------------
107+
108+
If you want to keep the old `origin/imprinting` branch around for archaeology, push this restart under a new branch name instead:
109+
110+
```bash
111+
git push origin imprinting:imprinting-restart
112+
```
113+
114+
Suggested practical sequence
115+
----------------------------
116+
117+
If the goal is to share the restart without losing the old branch immediately:
118+
119+
```bash
120+
cd /Users/ggorjanc/Storages/GitBox/AlphaSimR/AlphaSimR-wt-imprinting
121+
git push highlanderlab imprinting:imprinting
122+
git push origin imprinting:imprinting-restart
123+
```
124+
125+
If later you decide that `origin/imprinting` should be replaced:
126+
127+
```bash
128+
git push --force-with-lease origin imprinting:imprinting
129+
```
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Simulate genotype frequencies for 00, 01, 10, and 11 (maternal-paternal)
2+
freq = runif(4)
3+
freq = freq/sum(freq)
4+
# freq = c(0.25, 0.25, 0.25, 0.25)
5+
6+
# Genotypic effects
7+
a = 1
8+
d = 0
9+
i = 0.5
10+
11+
# Vector of genetic values
12+
g = c(-a, d+i, d-i, a)
13+
g = g - sum(freq*g) # Center
14+
15+
## Genotype dosage
16+
x = c(0, 1, 1, 2)
17+
x = x - sum(freq*x) # Center
18+
19+
## Breeding value regressor
20+
# Genetic contribution of "a"
21+
x_a = c(-1, 0, 0, 1)
22+
x_a = x_a - sum(freq*x_a) # Center
23+
24+
## Dominance deviation regressor
25+
# Genetic contribution of "d"
26+
x_d = c(0, 1, 1, 0)
27+
x_d = x_d - sum(freq*x_d) # Center
28+
29+
# Regression coefficient from regressing x_d on x_a
30+
m = sum(freq*x_a*x_d) / sum(freq*x_a^2)
31+
32+
# Construct orthogonal regressor using lack-of-fit from regression of x_d on x_a
33+
x_d = x_d - x_a*m
34+
35+
# Check orthogonality (should be zero within numeric precision)
36+
sum(freq*x_a*x_d)
37+
38+
## Imprinting regressor
39+
# Genetic contribution of "i"
40+
x_i = c(0, 1, -1, 0)
41+
x_i = x_i - sum(freq*x_i) # Center
42+
43+
# Regression coefficient from regressing x_i on x_a
44+
m_a = sum(freq*x_a*x_i) / sum(freq*x_a^2)
45+
46+
# Regression coefficient from regressing x_i on x_d
47+
m_d = sum(freq*x_d*x_i) / sum(freq*x_d^2)
48+
49+
# Construct orthogonal regressor using lack-of-fit
50+
x_i = x_i - x_a*m_a - x_d*m_d
51+
52+
# Check orthogonality (all should be zero within numeric precision)
53+
sum(freq*x_i*x_a)
54+
sum(freq*x_i*x_d)
55+
56+
## Calculate variances
57+
58+
# Additive genetic variance
59+
alpha = sum(freq*x_a*g) / sum(freq*x_a^2)
60+
bv = x_a*alpha
61+
sum(freq*bv^2)
62+
63+
# Dominance genetic variance
64+
beta = sum(freq*x_d*g) / sum(freq*x_d^2)
65+
dd = x_d*beta
66+
sum(freq*dd^2)
67+
68+
# Imprinting genetic variance
69+
gamma = sum(freq*x_i*g) / sum(freq*x_i^2)
70+
id = x_i*gamma
71+
sum(freq*id^2)
72+
73+
74+
75+

0 commit comments

Comments
 (0)