We want to see TE abundance during an invasion, when piRNA clusters act to stop TE activity. We will use fifty replictes.
We simulate 4 chromosomes with a size of 1Mb. We use a recombination rate of 3cM/Mb for each. Every chromosmome has a piRNA cluster of size 30kb at the beginning. The transposition rate is 0.5 and the population size is 1000. We simulate the invasion for 10000 generations. The starting populatio has 300 insertions randomly distributed. We use 50 replicates and record the status of the invasion all 20 generations.
java -jar invade.jar cluster --genome "mb:1,1,1,1" --rr "cm_mb:3,3,3,3" --cluster "kb:30,30,30,30" --u 0.05 --N 1000 --gen 10000 --basepop "seg:300" --rep 50 --silent --steps 20 > invasion.txt
library(ggplot2)
library(RColorBrewer)
theme_set(theme_bw())
b<-brewer.pal(12,"Paired")
cbbPalette<-c("grey50")
# code used
# java -jar invade.jar cluster --genome "mb:1,1,1,1" --rr "cm_mb:3,3,3,3" --cluster "kb:30,30,30,30" --u 0.05 --N 1000 --gen 10000 --basepop "seg:300" --rep 50 --silent --steps 20 > invasion.txt
t<-read.table("/Users/robertkofler/dev/invade/out/artifacts/invade_jar/invasion.txt")
names(t)<-c("replicate","generation","tmp","fwt","w","diploidtes","popfreq","fixed","tmp2",
"fwcli","cluins","popfreqcluins","fixedcluins","tmp3","diedout","meannovel","sites","clusites","stdevins","stdevcluins","popsize")
g<-ggplot()+theme(legend.position="none")+
scale_colour_manual(values=cbbPalette)+
geom_line(data=t,aes(x=generation,y=diploidtes,group=replicate),alpha=0.5,size=0.3)+
ylab("insertions per diploid individual")+xlab("generations")
pdf(file="/Users/robertkofler/dev/invade/out/artifacts/invade_jar/invasion.pdf",width=8,height=5)
plot(g)
dev.off()
Following we see a TE invasion when piRNA clusters account for 3% of the genome (as in Drosophila). On the y-axis we have the average number of insertions per diploid individual.

The previous example shows TE invasions for 50 replicates. It could be helpful to add a mean value to the graph.
library(ggplot2)
library(RColorBrewer)
library(plyr)
theme_set(theme_bw())
b<-brewer.pal(12,"Paired")
cbbPalette<-c("grey50")
# code used
# java -jar invade.jar cluster --genome "mb:1,1,1,1" --rr "cm_mb:3,3,3,3" --cluster "kb:30,30,30,30" --u 0.05 --N 1000 --gen 10000 --basepop "seg:300" --rep 50 --silent --steps 20 > invasion.txt
t<-read.table("/Users/robertkofler/dev/invade/out/artifacts/invade_jar/invasion.txt")
names(t)<-c("replicate","generation","tmp","fwt","w","diploidtes","popfreq","fixed","tmp2",
"fwcli","cluins","popfreqcluins","fixedcluins","tmp3","diedout","meannovel","sites","clusites","stdevins","stdevcluins","popsize")
ci<- ddply(.data=t,
.(generation),
summarize,
mean= mean(diploidtes),
var=sqrt(var(diploidtes)))
g<-ggplot()+theme(legend.position="none")+
scale_colour_manual(values=cbbPalette)+
geom_line(data=t,aes(x=generation,y=diploidtes,group=replicate),alpha=0.15,size=0.3)+
ylab("insertions per diploid individual")+xlab("generations")+
geom_line(data=ci,aes(x=generation,y=mean),size=1)
pdf(file="/Users/robertkofler/dev/invade/out/artifacts/invade_jar/invasion-mean.pdf",width=8,height=5)
plot(g)

Fixation of a piRNA cluster insertion is an important event, as this marks the death of the TE. It can not be active anymore in any individual.
library(ggplot2)
library(RColorBrewer)
library(plyr)
theme_set(theme_bw())
b<-brewer.pal(12,"Paired")
cbbPalette<-c("#1f78b4","#e41a1c")
t<-read.table("/Users/robertkofler/dev/invade/out/artifacts/invade_jar/invasion.txt")
names(t)<-c("replicate","generation","tmp","fwt","w","diploidtes","popfreq","fixed","tmp2",
"fwcli","cluins","popfreqcluins","fixedcluins","tmp3","diedout","meannovel","sites","clusites","stdevins","stdevcluins","popsize")
t$clufix=0
t[t$fixedcluins>0,]$clufix=1
t$clufix<-as.factor(t$clufix)
g<-ggplot()+theme(legend.position="none")+
geom_line(data=t,aes(x=generation,y=diploidtes,group=replicate,color=clufix),alpha=1,size=0.7)+
ylab("insertions per diploid individual")+xlab("generations")+scale_colour_manual(values=cbbPalette)
pdf(file="/Users/robertkofler/dev/invade/out/artifacts/invade_jar/invasion-clufix.pdf",width=8,height=5)
plot(g)
dev.off()
blue: no cluster insertion is fixed
red: at least one cluster insertion is fixed
This is also interesting biologically! The fluctuation stops with a fixed cluster insertion
Ha cool idea, add different color for first pirna cluster insertion, than for second etc etc etc

library(ggplot2)
library(RColorBrewer)
library(plyr)
theme_set(theme_bw())
b<-brewer.pal(12,"Paired")
cbbPalette<-c("grey50")
t<-read.table("/Users/robertkofler/dev/invade/out/artifacts/invade_jar/invasion.txt")
names(t)<-c("replicate","generation","tmp","fwt","w","diploidtes","popfreq","fixed","tmp2",
"fwcli","cluins","popfreqcluins","fixedcluins","tmp3","diedout","meannovel","sites","clusites","stdevins","stdevcluins","popsize")
g<-ggplot()+theme(legend.position="none")+
geom_line(data=t,aes(x=generation,y=diploidtes,group=replicate,color=popfreq),alpha=1,size=0.7)+
ylab("insertions per diploid individual")+xlab("generations")+
scale_color_gradient(low = "#1f78b4", high = "#e41a1c")
pdf(file="/Users/robertkofler/dev/invade/out/artifacts/invade_jar/invasion-popfreq.pdf",width=8,height=5)
plot(g)
dev.off()
blue indicates a low population frequency and red that the TEs are mostly fixed
