forked from Axolotl233/Simple_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vcf.tajimaD.pl
85 lines (76 loc) · 2.09 KB
/
Vcf.tajimaD.pl
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
#! perl
use warnings;
use strict;
use File::Basename;
my $cut = 10;
my $pop1 = shift or die "need pop1 \n";
my $pop2 = shift or die "need pop2 \n";
my $vcf = shift or die "need vcf";
(my $p1_n = basename $pop1) =~ s/(.*)\..*/$1/;
(my $p2_n = basename $pop2) =~ s/(.*)\..*/$1/;
print STDERR "### enter your window\n";
chomp(my @a = <STDIN>);
for my $a1 (@a){
(my $w_name = ($a1/1000)."K");
my $o = "$w_name";
`vcftools --gzvcf $vcf --keep $pop1 --TajimaD $a1 --out TajimaD.$p1_n.$o`;
`vcftools --gzvcf $vcf --keep $pop2 --TajimaD $a1 --out TajimaD.$p2_n.$o`;
my $o_prefix = "$o.Tajima.D";
my @file = grep {/$o_prefix$/} `ls ./`;
for my $f(@file){
chomp $f;
$f =~ /TajimaD\.(.*)\.$o/;
my $p = $1;
#print $p;exit;
&phase($f,$p);
}
`cat *phase > $p1_n.$p2_n.tajimaD`;
&plot("$p1_n.$p2_n.tajimaD");
}
sub phase{
my $fi = shift @_;
my $p = shift @_;
open IN,'<',$fi;
open O,'>',"$fi.phase";
readline IN;
while(<IN>){
chomp;
my @l = split/\t/;
next if $l[2] < $cut;
next if $l[3] eq "nan";
print O $_."\t$p\n";
}
close IN;
close O;
}
sub plot{
my $f = shift @_;
open R,'>',"$f.R";
print R "library(ggplot2)
data = as.data.frame(read.table(\"$f\"))
colnames(data) = c(\"Chr\",\"start\",\"num\",\"TajimaD\",\"g\")
median.quartile <- function(x)\{
out <- quantile(x, probs = c(0.25,0.5,0.75))
names(out) <- c(\"ymin\",\"y\",\"ymax\")
return(out)
\}
median.for.violin <- function(x){
out <- quantile(x, probs = c(0.5))
names(out) <- c(\"y\")
return(out)
}
a = ggplot(data=data, aes(x=g,y=TajimaD))+
geom_violin(aes(fill=g))+theme_bw()+
geom_boxplot(width=0.08,position=position_dodge(0.9),fill=\"white\")+
scale_fill_manual(
#values = c(\"#1b86ee\",\"#ee0000\")
values = c(\"#fb8072\",\"#80b1d3\")
)+
scale_y_continuous(
breaks = seq(-3,5,1),limits = c(-3,5)
)
#stat_summary(fun.y=median.quartile,geom='line')+
#stat_summary(fun.y=median.for.violin,geom='point')
ggsave(\"$f.pdf\",a,width = 4,height = 4)\n";
`Rscript $f.R`;
}