# Code for analysis of Chakarov et al . "Apparent vector-mediated parent-to-offspring transmission in an avian malaria-like parasite" rm(list=ls()) setwd("C:/Users/Downloads") library(lme4) library(polysat) library(ecodist) library(poppr) genotypes <- read.GeneMapper("Genotypes used by Chakarov et al. Apparent mother to offspring transmission.txt") #Calculate genetic distance between infections Usatnts(genotypes) <- c(3, 3, 3, 3, 3, 3, 3,3,3,3,4, 3, 3, 3, 3) #microsatellite repeat length for each locus genotypes1<-estimatePloidy(genotypes) #estimate number of Leucocytozoon clones per infection Ploidies (genotypes1)<-1 #fix ploidies to a unified dummy, allowing transformation into genind object PopInfo(genotypes1)<-c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126)# set population dummy = equal to individual id, allowing transfomation to genind genotypes2<-gendata.to.genind(genotypes1) ia(genotypes2, sample=10000, method=1,missing="ignore", hist=FALSE ) # estimate significance of allele association i.e. clonality genotypedismat<-meandistance.matrix(genotypes1, samples=Samples(genotypes1), all.distance=FALSE, distmetric=Bruvo.distance, progress=FALSE) #calculate genetic distance matrix between infections genotypedismatflat <- data.frame(i=rep(row.names(genotypedismat),ncol(genotypedismat)), j=rep(colnames(genotypedismat),each=nrow(genotypedismat)),score=as.vector(genotypedismat)) write.table(genotypedismatflat, file="genotypedismatflat.txt") #flatten matrix in three coloums; includes repeats and self-comparisons; use to calculate Dataset of Chakarov et al. vector-mediated parent-to-offspring transmission. #Read assembled table with data on genetic distance between infections, family relations of hosts, morph of hosts and their parents and Geographic distance) infections <- read.table("Dataset of Chakarov et al. vector-mediated parent-to-offspring transmission.csv", header=TRUE, sep=",") #read full dataset of genetic distances between infections and matching of host traits infections$similarity<-1-infections$Genetic.distance #create similarity from the calculated distance between infections infections$motherssame<- as.factor(infections$Mothers.have.same.morph) #Create factor of same or different plumage morphs of mothers infections$fatherssame<- as.factor(infections$Fathers.have.the.same.morph) #Create factor of same or different plumage morphs of fathers infections$nestlingssame<- as.factor(infections$Chicks.have.the.same.morph) #Create factor of same or different plumage morphs of chicks infections$family<- as.factor(infections$ Family..0...unrelated..1..siblings.across.years..2...nestmates) #Create factor of family with levels 0 - unrelated, 1 - sibs between years (i.e. from different broods), 2 - sibs from same brood, nestmates model1<-lmer(similarity~family+Geographic.distance.in.km+Difference.in.years.between.both.chicks+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), infections) model2<-lmer(similarity~Geographic.distance.in.km+Difference.in.years.between.both.chicks+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), infections) model3<-lmer(similarity~family+Difference.in.years.between.both.chicks+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), infections) model4<-lmer(similarity~family+Geographic.distance.in.km+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), infections) anova(model1, model2) #test significance of family mant1<-mantel(infections$similarity~infections$Family..0...unrelated..1..siblings.across.years..2...nestmates.+infections$Geographic.distance.in.km+infections$Difference.in.years.between.both.chicks+infections$Chicks.have.the.same.morph+infections$Fathers.have.the.same.morph+infections$Mothers.have.same.morph,nperm=1000000, pboot=0.9, cboot=0.95) mant1 #partial Mantel test of family significance for parasite similarity anova(model1, model3) #test significance of georaphic distance between both hosts mant2<-mantel(infections$similarity~infections$Geographic.distance.in.km+infections$Difference.in.years.between.both.chicks+infections$Chicks.have.the.same.morph+infections$Fathers.have.the.same.morph+infections$Mothers.have.same.morph+infections$Family..0...unrelated..1..siblings.across.years..2...nestmates.,nperm=1000000, pboot=0.9, cboot=0.95) mant2 #partial Mantel test of geographic distance for parasite similarity anova(model1, model4) mant3<-mantel(infections$similarity~infections$Difference.in.years.between.both.chicks+infections$Chicks.have.the.same.morph+infections$Fathers.have.the.same.morph+infections$Mothers.have.same.morph+infections$Family..0...unrelated..1..siblings.across.years..2...nestmates.+infections$Geographic.distance.in.km,nperm=1000000, pboot=0.9, cboot=0.95) mant3 #partial Mantel test of time distance for parasite similarity summary(model1) unrelatedinf<-subset(infections, Family..0...unrelated..1..siblings.across.years..2...nestmates.<1) # data subset of unrelated chicks only model11<-lmer(similarity~Geographic.distance.in.km+Difference.in.years.between.both.chicks+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), unrelatedinf) model12<-lmer(similarity~Difference.in.years.between.both.chicks+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), unrelatedinf) anova(model11, model12) #test of significance of geographic distance for parasite similarity of unrelated nestlings chickmorphknown<-subset(unrelatedinf,Chicks.have.the.same.morph>-1) # create subset of compared unrelated chicks with known own morphs only fathersknown<-subset(unrelatedinf,Fathers.have.the.same.morph>-1) # create subset of compared unrelated chicks with known father's morphs only mothersknown<-subset(unrelatedinf,Mothers.have.same.morph>-1) # create subset of compared unrelated chicks with known mother's morphs only model5<-lmer(similarity~nestlingssame+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), chickmorphknown) model6<-lmer(similarity~1+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), chickmorphknown) anova(model5, model6) # test significance of chick's morph similarity summary(model5) mant4<-mantel(infections$similarity~infections$Chicks.have.the.same.morph+infections$Fathers.have.the.same.morph+infections$Mothers.have.same.morph+infections$Family..0...unrelated..1..siblings.across.years..2...nestmates.+infections$Geographic.distance.in.km+infections$Difference.in.years.between.both.chicks,nperm=1000000, pboot=0.9, cboot=0.95) mant4 #partial Mantel test of chick's morph similarity's effect on parasite similarity model7<-lmer(similarity~fatherssame+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), fathersknown) model8<-lmer(similarity~1+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), fathersknown) anova(model7, model8) # test significance of father's morph similarity summary(model7) mant5<-mantel(infections$similarity~infections$Fathers.have.the.same.morph+infections$Mothers.have.same.morph+infections$Family..0...unrelated..1..siblings.across.years..2...nestmates.+infections$Geographic.distance.in.km+infections$Difference.in.years.between.both.chicks+infections$Chicks.have.the.same.morph,nperm=1000000, pboot=0.9, cboot=0.95) mant5 #partial Mantel test of father's morph similarity's effect on parasite similarity model9<-lmer(similarity~motherssame+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), mothersknown) model10<-lmer(similarity~1+(1|chick1)+(1|chick2)+(1|Brood.identity.of.chick1)+(1|Brood.identity.of.chick2), mothersknown) anova(model9, model10) # test significance of mother's morph similarity summary(model9) mant6<-mantel(infections$similarity~infections$Mothers.have.same.morph+infections$Family..0...unrelated..1..siblings.across.years..2...nestmates.+infections$Geographic.distance.in.km+infections$Difference.in.years.between.both.chicks+infections$Chicks.have.the.same.morph+infections$Fathers.have.the.same.morph,nperm=1000000, pboot=0.9, cboot=0.95) mant6 #partial Mantel test of mother's morph similarity's effect on parasite similarity