Commit eae8412e authored by Kosmas Hench's avatar Kosmas Hench

Merge branch 'reformat'

reformating done
parents a50f6f0d d3fa0614
......@@ -7,3 +7,4 @@
2_output/07_phased_variants/*
!2_output/08_popGen/00_synteny
2_output/09_expression/*
2_output/10_simulation/*
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
get_anno_df_single_line <- function(searchLG,gfffile,
xrange,
genes_of_interest,
genes_of_sec_interest,
anno_rown=3){
gff_filter <- list(seqid=searchLG)
data <- as.data.frame(readGFF(gfffile,filter=gff_filter)) %>% mutate(Parent=as.character(Parent))#%>%
#rowwise() %>% mutate(Parent=ifelse(length(Parent)==0,ID,Parent))
mRNAs <- data %>% filter(type=='mRNA',end>xrange[1],start<xrange[2]) %>%
ungroup() %>% mutate(yl=row_number()%%anno_rown+2) %>% rowwise()%>%
mutate(checkStart =ifelse(start<xrange[1],-Inf,start),
checkEnd =ifelse(end>xrange[2],Inf,end),
ps=ifelse(strand=='-',checkEnd,checkStart),
pe=ifelse(strand=='-',checkStart,checkEnd),
labelx=mean(c(sort(c(xrange[1],ps))[2],
sort(c(xrange[2],pe))[1])),
window='bold(Gene)',
clr=ifelse(Parentgenename %in% genes_of_interest,"y",
ifelse(Parentgenename %in% genes_of_sec_interest,"z","x"))) %>%
select(-Parent);
names(mRNAs)[names(mRNAs)=='ID'] <- 'Parent'
exons <- data %>% filter(type=='exon',end>xrange[1],start<xrange[2]) %>%
merge(.,mRNAs %>% select(Parent,yl,clr),by='Parent',all.x=T) %>%
mutate(ps=ifelse(strand=='-',end,start),
pe=ifelse(strand=='-',start,end),
window='bold(Gene)')
return(list(mRNAs,exons))}
This diff is collapsed.
create_K_plot <- function(searchLG,gfffile,xr,searchgene,secondary_genes,searchsnp,muskID){
source('../../0_data/0_scripts/E1.functions.R');
source('../../0_data/0_scripts/E1.getFSTs.R')
source('../../0_data/0_scripts/E1.getGxP.R')
source('../../0_data/0_scripts/E1.getDXY.R')
source('../../0_data/0_scripts/F3.functions.R');
source('../../0_data/0_scripts/F3.getFSTs.R')
source('../../0_data/0_scripts/F3.getDXY.R')
highclr <- '#3bb33b'
theme_set(theme_minimal(base_size = 6))
......@@ -20,11 +19,6 @@ create_K_plot <- function(searchLG,gfffile,xr,searchgene,secondary_genes,searchs
global_fst<-fst_list$global_fst;
data_fst<-fst_list$data_fst
# get pfst values
pfst_list <- getGxP(searchLG,xr)
# data_pfst_pw<-pfst_list$data_pfst_pw;
data_pfst<-pfst_list$data_pfst
# get dxy values
dxy_list <- getDXY(searchLG,xr)
#data_dxy_pw<-dxy_list$data_dxy_pw;
......@@ -87,24 +81,24 @@ create_K_plot <- function(searchLG,gfffile,xr,searchgene,secondary_genes,searchs
panel.border = element_blank()
);
if(muskID=='A'){
if(muskID=='a'){
p11$layers[[4]]$data$label <- c("italic(sox10)","italic(rnaseh2a)")
} else if(muskID=='B'){
} else if(muskID=='b'){
p11$layers[[4]]$data$label <- c("italic(casz1.3)","italic(casz1.2)","italic(casz1.1)")
} else if(muskID=='C'){
} else if(muskID=='c'){
p11$layers[[4]]$data$label <- c('italic(hoxc10a)',"italic(hoxc11a)","italic(hoxc12a)","italic(hoxc13a)","italic(calcoco1)")
}else if(muskID=='E'){
}else if(muskID=='e'){
p11$layers[[4]]$data$label <- c("italic(polr1d)","italic(ednrb)")
} else if(muskID=='F'){
} else if(muskID=='f'){
p11$layers[[4]]$data$label <- c("italic(foxd3)","italic(alg6)","italic(efcab7)")
} else if(muskID=='D'){
} else if(muskID=='d'){
p11$layers[[4]]$data$label <- c("italic(hcfc1)","italic(hcfc1[2])","italic(hcfc1[1])",'italic(paste(sws2a,"\u03B2"))',
'italic(paste(sws2a,"\u03B1"))',"italic(sw2b)","italic(lws)",
"italic(gnl3l)","italic(tfe3)","italic(mdfic2)","italic(cxxc1[3])",
"italic(cxxc1[1])",'italic(mbd1)','italic(ccdc120)')
}else if(muskID=='G'){
}else if(muskID=='g'){
p11$layers[[4]]$data$label <- c("italic(lgals3bpb)","italic(mpnd)","italic(sh3gl1)","italic(rorb)")
}else if(muskID=='H'){
}else if(muskID=='h'){
p11$layers[[4]]$data$label <- c("italic(alg2)","italic(sec61b)","italic(nr4a3)",
"italic(stx17)","italic(erp44)","italic(invs)")
}
......@@ -127,20 +121,6 @@ create_K_plot <- function(searchLG,gfffile,xr,searchgene,secondary_genes,searchs
guides(linetype= guide_legend(override.aes = list(color = 'black')))+plotSET
p13 <- ggplot()+coord_cartesian(xlim=xr)+
geom_line(data=(data_pfst %>% filter(POS > xr[1],POS<xr[2]))
,aes(x=POS,y=avgp_wald,col=run),lwd=LW)+
# geom_line(data=(data_pfst_pw %>% filter(POS > xr[1],POS<xr[2]))
# ,aes(x=POS,y=avgp_wald,col=run,linetype=group),lwd=1)+
scale_color_manual(values=c(clr,annoclr),
breaks=c("nig-pue","nig-uni","pue-uni","x","y","z"),guide=F)+
facet_grid(window~.,scales='free_y',
switch = 'y',labeller = label_parsed,as.table = T)+
scale_x_continuous(name=searchLG,expand=c(0,0),position = 'top')+
scale_y_continuous(breaks = seq(0,9,length.out = 4))+
scale_linetype(name='location',label=c('Belize','Honduras','Panama'))+
guides(linetype= guide_legend(override.aes = list(color = 'black')))+plotSET
p14 <- ggplot()+coord_cartesian(xlim=xr)+
geom_line(data=(data_dxy %>% filter(POS > xr[1],POS<xr[2]))
,aes(x=POS,y=dxy,col=run),lwd=LW)+
# geom_line(data=(data_dxy_pw %>% filter(POS > xr[1],POS<xr[2]))
......@@ -153,7 +133,7 @@ create_K_plot <- function(searchLG,gfffile,xr,searchgene,secondary_genes,searchs
scale_linetype(name='location',label=c('Belize','Honduras','Panama'))+
guides(linetype= guide_legend(override.aes = list(color = 'black')))+plotSET
p2 <- plot_grid(p11,p12,p13,p14,
p2 <- plot_grid(p11,p12,p13,
ncol = 1,align = 'v',axis = 'r',
rel_heights = c(1.3,rep(1,3)))
rel_heights = c(1.3,rep(1,2)))
return(p2)}
\ No newline at end of file
se <- function(x){
x2 <- x[!is.na(x)]
return(sd(x2)/sqrt(length(x2)))}
trplot <- function(sel){
files <- c("global","boc","bel","hon","pue","nig","uni","nig-pue","nig-uni","pue-uni")
data <- read.csv(paste('../../2_output/08_popGen/07_LD/',files[sel],'-10000-bins.txt',sep=''),sep='\t')
message(files[sel])
s1=17620000;s2=19910000;s3=21960000;s4=22320000;
e2=20660000;e3=22460000;
stp=20000;
l1=500000;l2=750000;l3=500000;l4=500000
scling <- c(-s1,-s2+(l1+stp),-s3+(l1+l2+2*stp),-s4+(l1+l2+l3+(stp*3)))
dt <- data %>% mutate(miX = floor(Mx/10000),miY=floor(My/10000))
genes <- data.frame(start=c(17871610,20186151,22225149,22553187,22556763,22561894,22573388),
end=c(17873915,20347811,22228342,22555052,22559742,22566321,22575503),
sclr=c(1,2,3,4,4,4,4),
LG=c("LG09","LG12-1","LG12-2","LG17","LG17","LG17","LG17"),
name=c("sox10",'casz1',"hoxc13a","sws2a\u03B1","sws2a\u03B2","sws2b","lws"))
genes <- genes %>% mutate(Nx1 = (start+scling[sclr])/10000,Nx2 = (end+scling[sclr])/10000,
labPOS = (Nx1+Nx2)/2)
genes$labPOS[genes$name %in% c("sws2a\u03B1","sws2a\u03B2","sws2b","lws")] <- genes$labPOS[genes$name %in% c("sws2a\u03B1","sws2a\u03B2","sws2b","lws")]+c(-16,-1,12,20)
GZrS <- 40000;GZrS2 <- 20000; #gene zoom offset
BS <- c(-5,5,-4,3,-8,8,-20,-10,-6,5,7,16,17,22)*10000 # Backshifter for gene zoom
GZdf <- data.frame(x=c(genes$start[1],genes$end[1],genes$end[1]+GZrS+BS[1],genes$start[1]+GZrS+BS[2],genes$start[1],
genes$start[2],genes$end[2],genes$end[2]+GZrS+BS[3],genes$start[2]+GZrS+BS[4],genes$start[2],
genes$start[3],genes$end[3],genes$end[3]+GZrS+BS[5],genes$start[3]+GZrS+BS[6],genes$start[3],
genes$start[4],genes$end[4],genes$end[4]+GZrS+BS[7],genes$start[4]+GZrS+BS[8],genes$start[4],
genes$start[5],genes$end[5],genes$end[5]+GZrS+BS[9],genes$start[5]+GZrS+BS[10],genes$start[5],
genes$start[6],genes$end[6],genes$end[6]+GZrS+BS[11],genes$start[6]+GZrS+BS[12],genes$start[6],
genes$start[7],genes$end[7],genes$end[7]+GZrS+BS[13],genes$start[7]+GZrS+BS[14],genes$start[7])+GZrS2,
y=c(genes$start[1],genes$end[1],genes$end[1]-GZrS+BS[1],genes$start[1]-GZrS+BS[2],genes$start[1],
genes$start[2],genes$end[2],genes$end[2]-GZrS+BS[3],genes$start[2]-GZrS+BS[4],genes$start[2],
genes$start[3],genes$end[3],genes$end[3]-GZrS+BS[5],genes$start[3]-GZrS+BS[6],genes$start[3],
genes$start[4],genes$end[4],genes$end[4]-GZrS+BS[7],genes$start[4]-GZrS+BS[8],genes$start[4],
genes$start[5],genes$end[5],genes$end[5]-GZrS+BS[9],genes$start[5]-GZrS+BS[10],genes$start[5],
genes$start[6],genes$end[6],genes$end[6]-GZrS+BS[11],genes$start[6]-GZrS+BS[12],genes$start[6],
genes$start[7],genes$end[7],genes$end[7]-GZrS+BS[13],genes$start[7]-GZrS+BS[14],genes$start[7])-GZrS2,
grp=rep(letters[1:7],each=5)) %>%
mutate(sclr=rep(c(1,2,3,4,4,4,4),each=5),
Nx1 = (x+scling[sclr])/10000,
Nx2 = (y+scling[sclr])/10000)
clr = c(viridis::inferno(5)[c(1,1:5)])
Gcol <- '#3bb33b'
Zcol = rgb(.94,.94,.94)
DG <- rgb(.4,.4,.4)
LGoffset <- 15
GLABoffset <- 8
if(sel %in% c(1,8)){
rS <- 100000 # width of grey annotation band
zmRange <- data.frame(x=c(s1,s1+l1,s1+l1+rS,s1+rS,s1,
s2,s2+l2,s2+l2+rS,s2+rS,s2,
s3,s3+l3,s3+l3+rS,s3+rS,s3,
s4,s4+l4,s4+l4+rS,s4+rS,s4),
y=c(s1,s1+l1,s1+l1-rS,s1-rS,s1,
s2,s2+l2,s2+l2-rS,s2-rS,s2,
s3,s3+l3,s3+l3-rS,s3-rS,s3,
s4,s4+l4,s4+l4-rS,s4-rS,s4),
grp=rep(letters[1:4],each=5)) %>%
mutate(sclr=rep(1:4,each=5),
Nx1 = (x+scling[sclr])/10000-1,
Nx2 = (y+scling[sclr])/10000)
rS2 <- .75*rS
zmRange2 <- data.frame(x=c(s1,s1+l1,s1+l1+rS2,s1+rS2,s1,
s2,s2+l2,s2+l2+rS2,s2+rS2,s2,
s3,s3+l3,s3+l3+rS2,s3+rS2,s3,
s4,s4+l4,s4+l4+rS2,s4+rS2,s4),
y=c(s1,s1+l1,s1+l1-rS2,s1-rS2,s1,
s2,s2+l2,s2+l2-rS2,s2-rS2,s2,
s3,s3+l3,s3+l3-rS2,s3-rS2,s3,
s4,s4+l4,s4+l4-rS2,s4-rS2,s4),
grp=rep(letters[1:4],each=5)) %>%
mutate(sclr=rep(1:4,each=5),
Nx1 = (x+scling[sclr])/10000-1,
Nx2 = (y+scling[sclr])/10000)
rS3 <- .07*rS
zmRange3 <- data.frame(x=c(s1,s1+l1,s1+l1+rS3,s1+rS3,s1,
s2,s2+l2,s2+l2+rS3,s2+rS3,s2,
s3,s3+l3,s3+l3+rS3,s3+rS3,s3,
s4,s4+l4,s4+l4+rS3,s4+rS3,s4),
y=c(s1,s1+l1,s1+l1-rS3,s1-rS3,s1,
s2,s2+l2,s2+l2-rS3,s2-rS3,s2,
s3,s3+l3,s3+l3-rS3,s3-rS3,s3,
s4,s4+l4,s4+l4-rS3,s4-rS3,s4),
grp=rep(letters[1:4],each=5)) %>%
mutate(sclr=rep(1:4,each=5),
Nx1 = (x+scling[sclr])/10000-1,
Nx2 = (y+scling[sclr])/10000)
zmLab <- data.frame(x=c(s1+.5*l1,s2+.5*l2,s3+.5*l3,s4+.5*l4),
label=c('LG09 (A)','LG12 (B)','LG12 (C)','LG17 (D)')) %>%
mutate(sclr=1:4, Nx= (x+scling[sclr])/10000)
zmEND <- data.frame(x=c(s1,s1+l1,
s2,s2+l2,
s3,s3+l3,
s4,s4+l4)) %>%
mutate(sclr=rep(1:4,each=2),
Nx = ((x+scling[sclr])/10000)+rep(c(2.5,-4),4),
label=round((x/1000000),2))
textSCALE1 <- c(1.8,rep(NA,6),.7)
textSCALE2 <- c(2,rep(NA,6),1)
textSCALE3 <- c(3.5,rep(NA,6),1.75)
p1 <- ggplot(dt %>% filter(!is.na(Mval)),aes(fill=Mval))+
coord_equal()+
geom_polygon(inherit.aes = F,data=zmRange,
aes(x=Nx1+1,y=Nx2-1,group=grp),fill='lightgray')+
geom_polygon(inherit.aes = F,data=zmRange2,
aes(x=Nx1+11,y=Nx2-11,group=grp),fill=DG)+
geom_polygon(inherit.aes = F,data=zmRange3,
aes(x=Nx1+1.1,y=Nx2-1.1,group=grp),fill=DG)+
geom_polygon(inherit.aes = F,data=GZdf,
aes(x=Nx1,y=Nx2,group=grp),fill=Zcol)+
geom_segment(inherit.aes = F,data=genes,
aes(x=Nx1+1,y=Nx1-1,xend=Nx2+1,yend=Nx2-1),
col=Gcol,size=1.5)+
geom_tile(aes(x=miX,y=miY))+
geom_text(inherit.aes = F,data=zmEND,
aes(x=Nx+LGoffset,y=Nx-LGoffset,label=paste(label,'\n(Mb)')),
angle=45,size=textSCALE1[sel])+
geom_text(inherit.aes = F,data=genes,
aes(x=labPOS+GLABoffset,y=labPOS-GLABoffset,label=name),
angle=-45,fontface='italic',size=textSCALE2[sel])+
geom_text(inherit.aes = F,data=zmLab,
aes(x=Nx+LGoffset-.8,y=Nx-LGoffset+.8,label=label),
angle=-45,fontface='bold',size=textSCALE3[sel],col='white')+
scale_x_continuous(expand=c(0,0))+
scale_y_continuous(expand=c(0,0),
trans = 'reverse')+
scale_fill_gradientn(name=expression(bar(italic(r)^2)),colours=clr,
values=rescale(c(1,.5,.08,.03,.015,.01,0)),
limits=c(0,1),
guide = 'legend',breaks=c(0,.005,.01,.02,.03,.1,1))+
theme_void()+
theme(legend.position = c(.9,.75),
legend.direction = 'vertical')
} else {
p1 <- ggplot(dt %>% filter(!is.na(Mval)),aes(fill=Mval))+
coord_equal()+
geom_segment(inherit.aes = F,data=genes,
aes(x=Nx1+1.5,y=Nx1-1.5,xend=Nx2+1.5,yend=Nx2-1.5),
col=Gcol,size=1)+
geom_tile(aes(x=miX,y=miY))+
scale_x_continuous(expand=c(0,0))+
scale_y_continuous(expand=c(0,0),
trans = 'reverse')+
scale_fill_gradientn(name=expression(bar(r^2)),colours=clr,
values=rescale(c(1,.08,.03,.015,.01,0)),
limits=c(0,1),guide = 'legend',breaks=c(0,.005,.01,.02,.03,.1,1))+
theme_void()+
theme(legend.position = c(.7,.75),legend.direction = 'vertical')
}
return(p1)
}
run_one_sample_test <- function(pop,n,data){
df <- data %>%
filter(run == pop)
x <- df$R.2 %>% na.omit() %>% as.vector()
exp_mu <- 1/(2*n)
test_result <- wilcox.test(x,mu = exp_mu)
return(tibble(population = pop,
mean = x %>% mean,
sd = x %>% sd,
se = x %>% se,
var = x %>% var,
n = length(x),
exp_mu = exp_mu) %>% bind_cols(
test_result %>% broom::tidy()))
}
\ No newline at end of file
BW <- read.csv('../../2_output/08_popGen/07_LD/subsets/glob_between.interchrom.hap.ld',sep='\t') %>%
select(R.2) %>%
mutate(type='Global',run='Global')
for(j in 1:6){
flS <- c("boc","bel","hon","pue","nig","uni")
flL <- c("Panana","Belize","Honduras","H. puella","H. nigricans","H. unicolor")
flT <- c(rep('Geo',3),rep('Spec',3))
k <- flS[j]
q <- flL[j]
u <- flT[j]
print(j)
BW <- BW %>%
rbind(.,(read.csv(paste('../../2_output/08_popGen/07_LD/subsets/glob_between.',k,'.interchrom.hap.ld',sep=''),
sep='\t') %>%
select(R.2) %>%
mutate(type=u,run=q)))
}
BW$run <- factor(BW$run,levels=c('Global',"Panana","Belize","Honduras",
"H. nigricans","H. puella","H. unicolor"))
dt2 <- BW %>%
group_by(run) %>%
summarise(meanR2=mean(R.2,na.rm = T),medR2=median(R.2,na.rm = T)) %>%
gather(key = 'type',value = 'val',2:3)
BC <-rgb(.7,.7,.7)
clr <-colorRampPalette(colors = c('white',BC,'black'))(8)
# tests
locations <- c('Global',"Panana","Belize","Honduras","H. puella","H. nigricans","H. unicolor")
sample_sizes <- c(110,39,36,35,37,37,36)
test_gw <- purrr::map2(locations,sample_sizes,run_one_sample_test,data=BW) %>% bind_rows()
test_gw$xS <- factor(test_gw$population,
levels = c('Global',"Panana","Belize","Honduras",
"H. nigricans","H. puella","H. unicolor")) %>%
as.numeric()
pBOX <- ggplot(BW,aes(x=run,y=R.2))+
geom_boxplot(fill=BC,width=.7,outlier.size = .1)+
coord_fixed(ylim=c(0,.031),ratio = 250)+
geom_segment(inherit.aes = FALSE,
data=test_gw,aes(x=xS-.38,
xend=xS+.38,
y=exp_mu,yend=exp_mu),col='red',size=.5)+
geom_point(inherit.aes = F, data=dt2,aes(x=run,y=val,fill=type),shape=23,size=1)+
scale_x_discrete(labels = expression(Global,Panama,Belize,Honduas,
italic("H. nigricans"),italic("H. puella"),italic("H. unicolor")))+
scale_y_continuous(name=expression(Genome~wide~ILD~(italic(r)^2)))+
scale_fill_manual('',values = clr[c(6,1)],labels=c('mean','median'))+
guides(shape = guide_legend(ncol = 1))+
theme(legend.position = c(-.4,1.27),
text = element_text(size=10),
axis.title.x = element_blank(),
axis.text.y = element_text(size=7),
axis.text.x = element_text(size=7,angle=45,hjust = 1),
panel.background = element_blank(),
plot.background = element_blank())
dataBoxGenes <- data.frame(R.2=c(),run=c(),stringsAsFactors = F)
for (file in dir("../../2_output/08_popGen/07_LD/",pattern = "interchrom.hap.ld.gz")) {
nm <- str_remove_all(file, "spotlight.") %>% str_remove_all(.,".interchrom.hap.ld.gz")
if(nm %in% c("global","uni","pue","nig","hon","bel","boc")){
dataBoxGenes <- read.csv(gzfile(paste('../../2_output/08_popGen/07_LD/',file,sep='')),sep='\t') %>%
mutate(run = nm) %>%
select(R.2,run) %>%
rbind(dataBoxGenes,.)
}
}
dataBoxGenes$xS <- factor(dataBoxGenes$run,
levels = c("global","boc","bel","hon","nig","pue","uni"))
BoxGenes_summary <- dataBoxGenes %>%
group_by(xS) %>%
summarise(run = run[1],
meanR2 = mean(R.2,na.rm = T),
medR2 = median(R.2,na.rm = T),
sdR2 = sd(R.2,na.rm=T),
seR2 = se(R.2),
nanr = sum(is.na(R.2)),
minR2 = min(R.2,na.rm = T),
maxR2 = max(R.2,na.rm = T),
lengthR2 = length(R.2)) %>%
select(xS,meanR2,medR2) %>%
gather(key = 'type',value = 'val',2:3)
# tests
locations <- c("global","boc","bel","hon","nig","pue","uni")
sample_sizes <- c(110,39,36,35,37,37,36)
test_area <- purrr::map2(locations,sample_sizes,run_one_sample_test,data=dataBoxGenes) %>%
bind_rows()
test_area$xS <- factor(test_area$population,
levels = c("global","boc","bel","hon","nig","pue","uni")) %>%
as.numeric()
boxGenes <- ggplot(dataBoxGenes,aes(x=xS))+
geom_boxplot(aes(y=R.2),fill=BC,width=.7,outlier.size = .1) +
geom_segment(inherit.aes = FALSE,
data=test_area,aes(x=xS-.38,
xend=xS+.38,
y=exp_mu,yend=exp_mu),col='red',size=.5)+
geom_point(data=BoxGenes_summary,aes(y=val,fill=type),shape=23,size=1)+
coord_fixed(ylim=c(0,.031),ratio = 250)+
scale_y_continuous(expression(Candidate~gene~ILD~(italic(r)^2)))+
scale_x_discrete(labels = expression(Global,Panama,Belize,Honduas,
italic("H. nigricans"),italic("H. puella"),italic("H. unicolor")))+
scale_fill_manual('',values = clr[c(6,1)],labels=c('mean','median'))+
guides(shape = guide_legend(ncol = 1))+
theme(legend.position = c(.35,1.27),
text = element_text(size=10),
axis.title.x = element_blank(),
axis.title.y = element_text(hjust=1.25),
axis.text.y = element_text(size=7),
axis.text.x = element_text(size=7,angle=45,hjust = 1),
panel.background = element_blank(),
plot.background = element_blank())
create_K_plot <- function(searchLG,gfffile,xr,xr2,muskID){
source('../../0_data/0_scripts/S07.functions.R');
source('../../0_data/0_scripts/E1.getFSTs.R')
source('../../0_data/0_scripts/F3.getFSTs.R')
highclr <- '#3bb33b'
theme_set(theme_minimal(base_size = 5))
......
......@@ -2,11 +2,11 @@ trplot <- function(sel){
files <- c("global","boc","bel","hon","pue","nig","uni","nig-pue","nig-uni","pue-uni")
data <- read.csv(paste('../../2_output/08_popGen/08_LD_extended/',files[sel],'.ext-10000-bins.txt',sep=''),sep='\t')
message(files[sel])
s1=5760000;s2=1884000;s3=12860000;s4=17745000;s5=20149000;s6=22085000;s7=22445000;s8=13730000
e2=2134000;e3=13110000;e5=20399000;e6=22335000
stp=20000;lALL=250000
scling <- c(-s1,
-s2+(lALL+stp),
-s3+((lALL+stp)*2),
......@@ -15,7 +15,7 @@ trplot <- function(sel){
-s6+((lALL+stp)*5),
-s7+((lALL+stp)*6),
-s8+((lALL+stp)*7))
dt <- data %>% mutate(miX = floor(Mx/10000),miY=floor(My/10000))
genes <- data.frame(start=c(5884279,2009113,12992396,17871610,20186151,22228342,22553187,22556763,22561894,22573388,13862931),
end=c(5878614,2010303,12976894,17873915,20347811,22225149,22555052,22559742,22566321,22575503,13884003),
......@@ -25,7 +25,7 @@ trplot <- function(sel){
genes <- genes %>% mutate(Nx1 = (start+scling[sclr])/10000,Nx2 = (end+scling[sclr])/10000,
labPOS = (Nx1+Nx2)/2)
genes$labPOS[genes$name %in% c("sws2a\u03B1","sws2a\u03B2","sws2b","lws")] <- genes$labPOS[genes$name %in% c("sws2a\u03B1","sws2a\u03B2","sws2b","lws")]+c(-7,-3,5,9)
GZrS <- 40000;GZrS2 <- 20000; #gene zoom offset
BS <- c(-2,2, # ednrb
2,-2, # foxd3
......@@ -61,11 +61,11 @@ trplot <- function(sel){
genes$start[9],genes$end[9],genes$end[9]-GZrS+BS[17],genes$start[9]-GZrS+BS[18],genes$start[9],
genes$start[10],genes$end[10],genes$end[10]-GZrS+BS[19]+OPSoffset,genes$start[10]-GZrS+BS[20]+OPSoffset,genes$start[10],
genes$start[11],genes$end[11],genes$end[11]-GZrS+BS[21],genes$start[11]-GZrS+BS[22],genes$start[11])-GZrS2,
grp=rep(letters[1:11],each=5)) %>%
grp=rep(letters[1:11],each=5)) %>%
mutate(sclr=rep(c(1,2,3,4,5,6,7,7,7,7,8),each=5),
Nx1 = (x+scling[sclr])/10000,
Nx2 = (y+scling[sclr])/10000)
clr = c(viridis::inferno(5)[c(1,1:5)])
Gcol <- '#3bb33b'
Zcol = rgb(.94,.94,.94)
......@@ -89,7 +89,7 @@ trplot <- function(sel){
s6,s6+lALL,s6+lALL-rS,s6-rS,s6,
s7,s7+lALL,s7+lALL-rS,s7-rS,s7,
s8,s8+lALL,s8+lALL-rS,s8-rS,s8),
grp=rep(letters[1:8],each=5)) %>%
grp=rep(letters[1:8],each=5)) %>%
mutate(sclr=rep(1:8,each=5),
Nx1 = (x+scling[sclr])/10000-1,
Nx2 = (y+scling[sclr])/10000)
......@@ -110,11 +110,11 @@ trplot <- function(sel){
s6,s6+lALL,s6+lALL-rS2,s6-rS2,s6,
s7,s7+lALL,s7+lALL-rS2,s7-rS2,s7,
s8,s8+lALL,s8+lALL-rS2,s8-rS2,s8),
grp=rep(letters[1:8],each=5)) %>%
grp=rep(letters[1:8],each=5)) %>%
mutate(sclr=rep(1:8,each=5),
Nx1 = (x+scling[sclr])/10000-1,
Nx2 = (y+scling[sclr])/10000)
rS3 <- .07*rS
zmRange3 <- data.frame(x=c(s1,s1+lALL,s1+lALL+rS3,s1+rS3,s1,
s2,s2+lALL,s2+lALL+rS3,s2+rS3,s2,
......@@ -132,16 +132,16 @@ trplot <- function(sel){
s6,s6+lALL,s6+lALL-rS3,s6-rS3,s6,
s7,s7+lALL,s7+lALL-rS3,s7-rS3,s7,
s8,s8+lALL,s8+lALL-rS3,s8-rS3,s8),
grp=rep(letters[1:8],each=5)) %>%
grp=rep(letters[1:8],each=5)) %>%
mutate(sclr=rep(1:8,each=5),
Nx1 = (x+scling[sclr])/10000-1,
Nx2 = (y+scling[sclr])/10000)
zmLab <- data.frame(x=c(s1+.5*lALL,s2+.5*lALL,s3+.5*lALL,s4+.5*lALL,
s5+.5*lALL,s6+.5*lALL,s7+.5*lALL,s8+.5*lALL),
label=c("LG4 (E)","LG08 (F)","LG08 (G)",'LG09 (A)','LG12 (B)','LG12 (C)','LG17 (D)',"LG20 (H)")) %>%
mutate(sclr=1:8, Nx= (x+scling[sclr])/10000)
zmEND <- data.frame(x=c(s1,s1+lALL,
s2,s2+lALL,
s3,s3+lALL,
......@@ -149,17 +149,17 @@ trplot <- function(sel){
s5,s5+lALL,
s6,s6+lALL,
s7,s7+lALL,
s8,s8+lALL)) %>%
s8,s8+lALL)) %>%
mutate(sclr=rep(1:8,each=2),
Nx = ((x+scling[sclr])/10000)+rep(c(2.5,-4),8),
label=round((x/1000000),2))
DG <- rgb(.4,.4,.4)
gnShift <- c(rep(0,6),3.5,0,0,3.5,0)
textSCALE1 <- c(1.8,rep(NA,6),.9)
textSCALE2 <- c(2,rep(NA,6),1)
textSCALE3 <- c(2.5,rep(NA,6),1.25)
p1 <- ggplot(dt %>% filter(!is.na(Mval)),aes(fill=Mval))+
coord_equal()+
geom_polygon(inherit.aes = F,data=zmRange,
......
create_K_plot <- function(searchLG,gfffile,xr,searchgene,secondary_genes,searchsnp,muskID){
source('../../0_data/0_scripts/E1.functions.R');
source('../../0_data/0_scripts/E1.getFSTs.R')
source('../../0_data/0_scripts/E1.getGxP.R')
source('../../0_data/0_scripts/E1.getDXY.R')