magnusdv / ibdsim2

Simulate patterns of DNA sharing between pedigree members
https://magnusdv.github.io/pedsuite/
5 stars 2 forks source link

Feature request: karyo plot #9

Closed thoree closed 5 years ago

thoree commented 5 years ago

It would be very nice with a plot simillar to that produced by karyo_haploid but with with different colors or shading to indicate no IBD, maternal IBD, paternal IBD or paternal and maternal IBD.

magnusdv commented 5 years ago

This can already be done: The colorBy parameter is intended for exactly this purpose.

Example with full siblings:

library(ibdsim2)
#> Loading required package: pedtools

# Simulate sibs
x = nuclearPed(2)
s = ibdsim(x, sims=1, verbose = F)[[1]]

# Summarise IBD segments in a data.frame
a = as.data.frame(alleleSummary(s, 3:4))

# Logical vectors with mat/pat IBD status
pat = a$`3:p` == a$`4:p`
mat = a$`3:m` == a$`4:m`

# Add column with mat/pat IBD status
status = rep("", nrow(a)) 
status[!mat & !pat] = "No IBD"
status[mat & !pat] = "Maternal"
status[!mat & pat] = "Paternal"
status[mat & pat] = "Mat & pat"
a$status = status

# Convert to factor to enforce level ordering
a$status = factor(a$status, levels = c("No IBD", "Maternal", "Paternal", "Mat & pat"))

# Plot karyogram using "status" to control color
karyo_haploid(a, colorBy = "status", alpha = 0.8,  
              color = c("No IBD" = "white", 
                        Maternal = "brown1", 
                        Paternal = "cornflowerblue", 
                        "Mat & pat" = "darkolivegreen"))

thoree commented 5 years ago

Great, nice figure, thanks!