How to build pie charts in haploNet Haplotype Networks {pegas}

I am trying to use the haploNet {pegas} function to build a haplotype network, but I am having trouble setting equal haplotypes from different populations on the same pie. I can build a haplotype network with the following script:

x <- read.dna(file="x.fas",format="fasta")
h <- haplotype(x)
net <- haploNet(h)
plot(net)

      

I would like to set in the dnabin data the label of the original population of each taxon, so in the resulting network I could have pivot plots of different colors (from haplotypes from different populations). I would also like to remove the overlapping circles in the resulting haplotype network.

Thanks for any help!

Example:

> data(woodmouse)
> x <- woodmouse[sample(15, size = 110, replace = TRUE), ]
> h <- haplotype(x)
> net <- haploNet(h)
> plot(net, size=attr(net, "freq"), scale.ratio = 2, cex = 0.8)

      

This script is used to create a haplotype network using {pegas}. Large circles represent many more haplotypes of some kind. I would like to know how I could set the start of the haplotypes in the dnabin matrix so that they appear with different colors on the net.

+3


source to share


1 answer


Ok, trying to understand the meaning of your example. It looks like you have a population of 15 people with 3 to 13 samples per population.

table(rownames(x))

# No0906S No0908S No0909S No0910S No0912S No0913S No1007S 
#      10       8       6       3       3       7       6 
# No1103S No1114S No1202S No1206S No1208S   No304   No305 
#       4      13       9       6       9      13       7 
#   No306 
#       6

      

When you run haplotype(x)

, you get (unsurprisingly) 15 haplotypes, representing a 1: 1 mapping from population to haplotype. We can create a table showing the relationship between populations and haplotypes using

ind.hap<-with(
    stack(setNames(attr(h, "index"), rownames(h))), 
    table(hap=ind, pop=rownames(x)[values])
)
ind.hap[1:10, 1:9]  #print just a chunk

#       pop
# hap    No0906S No0908S No0909S No0910S No0912S No0913S No1007S No1103S No1114S
#   I          0       0       0       0       0       0       0       0       0
#   II         0       0       0       0       0       0       6       0       0
#   III        0       0       0       0       0       0       0       4       0
#   IV        10       0       0       0       0       0       0       0       0
#   IX         0       0       0       0       0       0       0       0       0
#   V          0       0       6       0       0       0       0       0       0
#   VI         0       0       0       0       0       0       0       0       0
#   VII        0       0       0       0       0       7       0       0       0
#   VIII       0       0       0       0       0       0       0       0      13
#   X          0       0       0       0       0       0       0       0       0

      

We can use this table while plotting to draw pic symbols on each of the nodes.

plot(net, size=attr(net, "freq"), scale.ratio = 2, cex = 0.8, pie=ind.hap)
legend(50,50, colnames(ind.hap), col=rainbow(ncol(ind.hap)), pch=20)

      



enter image description here

To show pie charts better, we can assign incorrect populations to each of the samples

wrong.pop<-rep(letters[1:5], each=22)
ind.hap2<-with(
    stack(setNames(attr(h, "index"), rownames(h))), 
    table(hap=ind, pop=wrong.pop[values])
)

plot(net, size=attr(net, "freq"), scale.ratio = 2, cex = 0.8, pie=ind.hap2)
legend(50,50, colnames(ind.hap2), col=rainbow(ncol(ind.hap2)), pch=20)

      

enter image description here

Here you can see that we have more variety in each haplotype because we are mislabeled by the population with artificial names so they don't shrink so well.

+5


source







All Articles