Building a Chromosome for shadie
¶
There are many ways to build a chromosome in shadie. This tutorial assumes a basic understanding of how chromosomes work in SLiM - please refer to the SLiM manual for specifics.
import shadie
Default chromsome¶
The default chromosome in shadie
is 10,000 bp long and has a single gene. There is a 2,000bp coding region flanked by two 2,000bp non-coing regions. You can access this chromosome using shadie.chromosome.default()
default_chrom = shadie.chromosome.default()
default_chrom.draw(); #note: semicolon tells toyplot to omit printing object data
Random Chromosome¶
The random chromosome function in shadie
is designed to generate a random chromosome with somewhat 'realistic' structure by ensuring that all coding regions fall between non-coding regions and exons alternate with introns.
#re-run this code block to see different chromosome
#structures generated by the random chromosome function
shadie.chromosome.random().draw();
You can specify the length (in base pairs) of the chromosome using the genome_size
argument. The length of non-coding (noncds), introns, and exons (cds) is controlled by the noncds_scale
, intron_scale
, and cds_scale
arguments. Remember to use a seed if you want to be able to regenerate your exact chromosome again.
shadie.chromosome.random(
genome_size=50001,
noncds_scale=3000,
cds_scale=2000,
intron_scale=2000,
seed=123456,
).draw();
Custom Chromosome¶
Finally, you can define each part of your chromosome using the custom
function. You will need to define the genomic elements that you will use to build your chromosome, and then specify where they occur along the chromosome. Remember to define your mutations first:
# "f" is fixed fitness effect (no distribution), so takes a single argument = fitness effect
mut1 = shadie.mtype(0.5, "f", 0.1)
# "g" is a gamma distribution and takes 2 arguments: alpha, beta
mut2 = shadie.mtype(0.1, "g", [0.3, 0.2])
# "n" is a normal distribution and takes 2 arguments: mean, standard deviation
mut3 = shadie.mtype(0.5, "n", [0.05, 0.1])
# "e" is a exponential distribution and takes 2 arguments: rate
mut4 = shadie.mtype(0.5, "e", -0.1)
This example uses a combination of custom mutations and default mutation types from shadie in the genomic elements:
e1 = shadie.etype([shadie.NEUT, shadie.DEL, shadie.BEN], (5,1,2), altname = "exon1")
e2 = shadie.etype([mut1, mut2, mut3], (5,1,2), altname = "exon2")
e3 = shadie.etype([mut1], (1,), altname = "exon3")
i1 = shadie.etype([mut4], (1,), altname = "intron1")
i2 = shadie.etype([mut4, shadie.DEL], (1,2), altname = "intron2")
custom = shadie.chromosome.explicit({
(0, 1_200_000): shadie.NONCDS,
(1_200_001, 1_400_000): i1,
(1_400_001, 1_600_000): e1,
(1_600_001, 1_800_000): i1,
(1_800_001, 2_500_000): shadie.NONCDS,
(2_500_001, 2_700_000): i1,
(2_700_001, 2_900_000): e3,
(2_900_001, 3_000_000): i1,
(3_000_001, 3_700_000): e2,
(3_700_001, 3_800_000): i1,
(3_800_001, 5_000_000): shadie.NONCDS,
})
#exons will show up as different colors,
#but all introns will show up green on the plot
custom.draw();
You can also specify custom genomic elements using the random generator. The intron
, exon
, and noncds
arguments will all accept a genomic element type object, or a list of multiple objects:
# set up a chrom by random sampling
my_random_chrom = shadie.chromosome.random(
genome_size=100001,
intron=[i1, i2],
exon=[e1, e2, e3],
noncds_scale=7000,
cds_scale=3000,
intron_scale=4000,
seed=345,
)
# draw the chrom
my_random_chrom.draw();
Interactive Plot¶
You can visualize complex chromosomes using an interactive altair plot instead of the static toyplot by using the inspect
function. For this feature to function properly, you must assign each of your genomic elements a unique altname
. The altnames should contain ex
and int
to allow shadie to recognize them as either exons or introns. Otherwise, shadie will try to assign any non-neutral regions as exons and all neutral regions will be non-coding.
Highlight areas on the lower plot to zoom in on the upper plot. Click anywhere on the lower plot to re-set the zoom. Hover over either plot for more information about each genomic element.
Note: this feature can be a little glitchy between altair updates.
#the plot may not display in certain web browsers, like Safari
my_random_chrom.inspect()