forked from z0on/2bRAD_denovo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
removeBayescanOutliers.pl
executable file
·69 lines (59 loc) · 1.29 KB
/
removeBayescanOutliers.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
#!/usr/bin/perl
my $usage="
removeBayescanOutliers.pl
deletes (or extracts) rows from the vcf file corrsponding to outliers in
bayescan _fst.txt output file
arguments:
bayescan=[filename] : BayeScan *_fst.txt file name
vcf=[filename] : vcf file name
FDR=[float] : false discovery rate cutoff (q-value in BayeScan file), default 0.1
mode=[delete|extract] : whether to delete (default) or extract the outlier rows
";
my $vcf;
my $bs;
my $fdr=0.1;
my $mode="delete";
if ("@ARGV"=~/bayescan=(\S+)/) { $bs=$1;}
else {die $usage;}
if ("@ARGV"=~/vcf=(\S+)/) { $vcf=$1;}
else {die $usage;}
if ("@ARGV"=~/FDR=(\S+)/) { $fdr=$1;}
if ("@ARGV"=~/mode=extract/) { $mode="extract";}
open BS, $bs or die "cannot open bayescan file $bs\n";
open VCF, $vcf or die "cannot open vcf file $vcf\n";
my @splits=();
my $qval;
my @outs=();
while(<BS>) {
chomp;
@splits=split(/\s/,$_);
$qval=$splits[4];
# warn "q: $qval\n";
if ($qval<$fdr) {
push @outs, $splits[0];
warn "outlier : ",$_,"\n";
}
}
close BS;
if ($#outs==0) { exit "no outliers found\n";}
my $count=0;
while (<VCF>) {
if ($_=~/^#/) {
print $_;
next;
}
$count++;
if (" @outs "=~/ $count /) {
if ($mode eq "delete") {
warn "$count : ",$_;
}
else {
print $_;
}
}
else {
if ($mode eq "delete") {
print $_;
}
}
}