Skip to content

Commit

Permalink
add reps to x_DH
Browse files Browse the repository at this point in the history
  • Loading branch information
cjGO committed Jun 12, 2024
1 parent 80c50d0 commit c0af82e
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 186 deletions.
51 changes: 17 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,55 +34,38 @@ First, define the genome of your crop

``` python
import torch
```

ploidy = 2
n_chr = 10
n_loci = 100
n_Ind = 3330
g = Genome(ploidy, n_chr, n_loci)
population = Population()
population.create_random_founder_population(g, n_founders=n_Ind)
init_pop = population.get_dosages().float() # gets allele dosage for calculating trait values

``` python
g = Genome()
founder_pop = Population()
founder_pop.create_random_founder_population(g, 30)
# multi_traits


target_means = torch.tensor([0, 5])
target_vars = torch.tensor([1, 1]) # Note: I'm assuming you want a variance of 1 for the second trait
target_means = torch.tensor([0, 5, 20])
target_vars = torch.tensor([1, 1, 0.5]) # Note: I'm assuming you want a variance of 1 for the second trait
correlation_values = [
[1.0, 0.8],
[0.8, 1.0],
[1.0, 0.2, 0.58],
[0.2, 1.0, -0.37],
[0.58, -0.37, 1.0],
]


correlated_traits = corr_traits(g, init_pop, target_means, target_vars, correlation_values)
traits = corr_traits(g, founder_pop.get_dosages().float(), target_means, target_vars, correlation_values)
```

Created genetic map

``` python
current_pop = init_pop
f1 = x_random(g, founder_pop.get_genotypes().float(), 50)
f1.shape
```

``` python
new_parents = population.get_genotypes().float()
means = []
for i in range(10):
curr_pop = random_crosses(g, new_parents, 200)
new_pheno = correlated_traits[0](curr_pop.sum(dim=1))
means.append(new_pheno.mean())
topk = torch.topk(new_pheno,10) # select top 50 parents
new_parents = curr_pop.float()[topk.indices]
```
torch.Size([50, 2, 10, 5])

``` python
plt.scatter(range(len(means)),means)
DH = x_DH(g,f1)
```

![](index_files/figure-commonmark/cell-6-output-1.png)

``` python
plt.scatter(correlated_traits[0](init_pop,h2=.5),correlated_traits[1](init_pop,h2=1))
DH.shape
```

![](index_files/figure-commonmark/cell-8-output-1.png)
torch.Size([50, 2, 10, 5])
2 changes: 1 addition & 1 deletion chewc/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.5"
__version__ = "0.0.6"
4 changes: 2 additions & 2 deletions chewc/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
'chewc.core.PopulationDataset.__init__': ('core.html#populationdataset.__init__', 'chewc/core.py'),
'chewc.core.PopulationDataset.__len__': ('core.html#populationdataset.__len__', 'chewc/core.py'),
'chewc.core.create_population_dataloader': ('core.html#create_population_dataloader', 'chewc/core.py')},
'chewc.cross': { 'chewc.cross.double_haploid': ('cross.html#double_haploid', 'chewc/cross.py'),
'chewc.cross.random_crosses': ('cross.html#random_crosses', 'chewc/cross.py')},
'chewc.cross': { 'chewc.cross.x_DH': ('cross.html#x_dh', 'chewc/cross.py'),
'chewc.cross.x_random': ('cross.html#x_random', 'chewc/cross.py')},
'chewc.crossing': { 'chewc.crossing.double_haploid': ('crossing.html#double_haploid', 'chewc/crossing.py'),
'chewc.crossing.random_crosses': ('crossing.html#random_crosses', 'chewc/crossing.py')},
'chewc.meiosis': { 'chewc.meiosis.poisson_crossing_over': ('meiosis.html#poisson_crossing_over', 'chewc/meiosis.py'),
Expand Down
8 changes: 4 additions & 4 deletions chewc/cross.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/04_cross.ipynb.

# %% auto 0
__all__ = ['random_crosses', 'double_haploid']
__all__ = ['x_random', 'x_DH']

# %% ../nbs/04_cross.ipynb 3
from .core import *
Expand All @@ -11,7 +11,7 @@
import torch

# %% ../nbs/04_cross.ipynb 4
def random_crosses( genome: Genome, parent_haplotypes: torch.Tensor, n_crosses: int) -> torch.Tensor:
def x_random( genome: Genome, parent_haplotypes: torch.Tensor, n_crosses: int) -> torch.Tensor:
"""
Generate random crosses from a set of parent haplotypes.
Expand Down Expand Up @@ -49,8 +49,8 @@ def random_crosses( genome: Genome, parent_haplotypes: torch.Tensor, n_crosses:

return progeny_haplotypes

# %% ../nbs/04_cross.ipynb 8
def double_haploid(genome: Genome, parent_haplotypes: torch.Tensor) -> torch.Tensor:
# %% ../nbs/04_cross.ipynb 7
def x_DH(genome: Genome, parent_haplotypes: torch.Tensor) -> torch.Tensor:
"""
Generate doubled haploid individuals from a set of parent haplotypes.
Expand Down
20 changes: 10 additions & 10 deletions nbs/01_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,16 @@
{
"data": {
"text/plain": [
"tensor([[0.0000e+00, 4.4549e+00, 9.7864e+00, 3.2619e+01, 8.7588e+01],\n",
" [0.0000e+00, 1.4553e+01, 4.2347e+01, 6.4445e+01, 8.7742e+01],\n",
" [0.0000e+00, 4.3246e+01, 6.5383e+01, 7.5921e+01, 8.8695e+01],\n",
" [0.0000e+00, 5.7855e+00, 2.0517e+01, 4.6006e+01, 6.2638e+01],\n",
" [0.0000e+00, 3.1555e-02, 2.5189e+01, 7.0929e+01, 9.8765e+01],\n",
" [0.0000e+00, 8.9019e+00, 2.7753e+01, 4.0029e+01, 9.0203e+01],\n",
" [0.0000e+00, 4.3217e+00, 2.2171e+01, 3.2822e+01, 4.1771e+01],\n",
" [0.0000e+00, 1.4086e+01, 4.6586e+01, 8.6157e+01, 9.6368e+01],\n",
" [0.0000e+00, 4.3982e+01, 5.5968e+01, 5.8194e+01, 6.7353e+01],\n",
" [0.0000e+00, 1.4841e+01, 2.9923e+01, 6.3333e+01, 7.7275e+01]])"
"tensor([[ 0.0000, 0.2113, 5.1624, 26.2153, 29.5955],\n",
" [ 0.0000, 0.5898, 34.2930, 35.4808, 50.0303],\n",
" [ 0.0000, 35.2943, 39.6551, 44.4670, 99.3925],\n",
" [ 0.0000, 12.7377, 64.0160, 84.8742, 90.3918],\n",
" [ 0.0000, 21.9701, 29.2368, 43.9047, 52.4668],\n",
" [ 0.0000, 31.6351, 31.7786, 40.3927, 42.7500],\n",
" [ 0.0000, 3.6074, 39.6339, 55.3322, 73.2535],\n",
" [ 0.0000, 23.3346, 40.6038, 79.3619, 90.6116],\n",
" [ 0.0000, 7.7061, 46.0459, 69.5689, 72.6099],\n",
" [ 0.0000, 66.2367, 72.1667, 90.1024, 94.9115]])"
]
},
"execution_count": null,
Expand Down
2 changes: 0 additions & 2 deletions nbs/02_trait.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@
"init_pop = population.get_dosages().float() # gets allele dosage for calculating trait values\n",
"\n",
"# multi_traits\n",
"\n",
"\n",
"target_means = torch.tensor([0, 5, 20])\n",
"target_vars = torch.tensor([1, 1, 0.5]) # Note: I'm assuming you want a variance of 1 for the second trait\n",
"correlation_values = [\n",
Expand Down
50 changes: 0 additions & 50 deletions nbs/03_meiosis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -144,56 +144,6 @@
" # import pdb; pdb.set_trace() # Set the breakpoint"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc5fbd18",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Created genetic map\n"
]
},
{
"ename": "NameError",
"evalue": "name 'random_crosses' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[6], line 23\u001b[0m\n\u001b[1;32m 16\u001b[0m correlation_values \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 17\u001b[0m [\u001b[38;5;241m1.0\u001b[39m, \u001b[38;5;241m0.8\u001b[39m],\n\u001b[1;32m 18\u001b[0m [\u001b[38;5;241m0.8\u001b[39m, \u001b[38;5;241m1.0\u001b[39m],\n\u001b[1;32m 19\u001b[0m ]\n\u001b[1;32m 22\u001b[0m correlated_traits \u001b[38;5;241m=\u001b[39m corr_traits(g, init_pop, target_means, target_vars, correlation_values)\n\u001b[0;32m---> 23\u001b[0m \u001b[43mrandom_crosses\u001b[49m(g, init_pop, \u001b[38;5;241m50\u001b[39m)\n",
"\u001b[0;31mNameError\u001b[0m: name 'random_crosses' is not defined"
]
}
],
"source": [
"import torch\n",
"ploidy = 2\n",
"n_chr = 10\n",
"n_loci = 100\n",
"n_Ind = 3330\n",
"g = Genome(ploidy, n_chr, n_loci)\n",
"population = Population()\n",
"population.create_random_founder_population(g, n_founders=n_Ind)\n",
"init_pop = population.get_dosages().float() # gets allele dosage for calculating trait values\n",
"\n",
"# multi_traits\n",
"\n",
"\n",
"target_means = torch.tensor([0, 5])\n",
"target_vars = torch.tensor([1, 1]) # Note: I'm assuming you want a variance of 1 for the second trait\n",
"correlation_values = [\n",
" [1.0, 0.8],\n",
" [0.8, 1.0],\n",
" ]\n",
"\n",
"\n",
"correlated_traits = corr_traits(g, init_pop, target_means, target_vars, correlation_values)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
14 changes: 3 additions & 11 deletions nbs/04_cross.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"outputs": [],
"source": [
"#| export\n",
"def random_crosses( genome: Genome, parent_haplotypes: torch.Tensor, n_crosses: int) -> torch.Tensor:\n",
"def x_random( genome: Genome, parent_haplotypes: torch.Tensor, n_crosses: int) -> torch.Tensor:\n",
" \"\"\"\n",
" Generate random crosses from a set of parent haplotypes.\n",
"\n",
Expand Down Expand Up @@ -93,14 +93,6 @@
" return progeny_haplotypes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "49898066",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -126,7 +118,7 @@
"init_pop = population.get_genotypes().float() # gets allele dosage for calculating trait values\n",
"\n",
"# Convert to numpy array\n",
"boolean_array = random_crosses(g, init_pop, 10)"
"boolean_array = x_random(g, init_pop, 10)"
]
},
{
Expand All @@ -148,7 +140,7 @@
"outputs": [],
"source": [
"#|export\n",
"def double_haploid(genome: Genome, parent_haplotypes: torch.Tensor) -> torch.Tensor:\n",
"def x_DH(genome: Genome, parent_haplotypes: torch.Tensor) -> torch.Tensor:\n",
" \"\"\"\n",
" Generate doubled haploid individuals from a set of parent haplotypes.\n",
"\n",
Expand Down
4 changes: 3 additions & 1 deletion nbs/exp1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"id": "98eed592",
"metadata": {},
"source": [
"use an agent to decide which QTL to gene edit in a given line... plus budget etc... idea is that it will pick clever QTL based not on estimated additive value but also factor in haplotype diversity"
"use an agent to decide which QTL to gene edit in a given line... plus budget etc... idea is that it will pick clever QTL based not on estimated additive value but also factor in haplotype diversity\n",
"\n",
"may be interesting to see if it waits later in the breeding program to select/use budget for gene edits e.g. it waits til later stages of breeding program once the haplotype population structure plays out after generations of mendelian sampling."
]
},
{
Expand Down
Loading

0 comments on commit c0af82e

Please sign in to comment.