annotate VCFToolFilter/VCFToolsFilter.pl @ 22:9954edc41095 draft

Deleted selected files
author dereeper
date Mon, 23 Mar 2015 05:48:52 -0400
parents 1b672da89d00
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
1
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
2 #!/usr/bin/perl
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
3
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
4 use strict;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
5 use Switch;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
6 use Getopt::Long;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
7 use Bio::SeqIO;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
8
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
9 my $usage = qq~Usage:$0 <args> [<opts>]
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
10
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
11 where <args> are:
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
12
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
13 -i, --input <VCF input>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
14 -o, --out <Output basename>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
15
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
16 <opts> are:
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
17
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
18 -s, --samples <Samples to be analyzed. Comma separated list>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
19 -c, --chromosomes <Chromosomes to be analyzed. Comma separated list>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
20 -e, --export <Output format (VCF/freq/plink. Default: VCF>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
21 -f, --frequency <Minimum MAF. Default: 0.001>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
22 -m, --max_freq <Maximum MAF. Default: 0.5>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
23 -a, --allow_missing <Allowed missing data proportion per site. Must be comprised between 0 and 1. Default: 0>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
24 -n, --nb_alleles <Accepted number of alleles (min,max). Default: 2,4>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
25 -t, --type <Type of polymorphisms to keep (ALL/SNP/INDEL). Default: ALL>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
26 -b, --bounds <Lower bound and upper bound for a range of sites to be processed (start,end). Default: 1, 100000000>
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
27 ~;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
28 $usage .= "\n";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
29
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
30 my ($input,$out);
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
31
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
32
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
33 #my $indel_size_max = 500;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
34 #my $indel_size_min = 1;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
35 my $frequency_max = 0.5;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
36 my $frequency_min = 0.001;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
37 my $pos_max = 100000000000;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
38 my $pos_min = 0;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
39 my $filter_snp_type = "all";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
40
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
41 my $missing_data = 0;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
42 my $export = "VCF";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
43 my $type = "ALL";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
44 my $nb_alleles;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
45 my $bounds;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
46 my $samples;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
47 my $chromosomes;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
48
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
49 GetOptions(
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
50 "input=s" => \$input,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
51 "out=s" => \$out,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
52 "samples=s" => \$samples,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
53 "chromosomes=s" => \$chromosomes,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
54 "frequency=s" => \$frequency_min,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
55 "max_freq=s" => \$frequency_max,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
56 "allow_missing=s"=> \$missing_data,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
57 "export=s" => \$export,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
58 "type=s" => \$type,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
59 "nb_alleles=s" => \$nb_alleles,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
60 "bounds=s" => \$bounds,
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
61 );
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
62
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
63
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
64 die $usage
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
65 if ( !$input || !$out);
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
66
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
67 if ($samples && $samples =~/^([\w\,]+)\s*$/){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
68 $samples = $1;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
69 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
70 elsif ($samples){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
71 die "Error: Samples must be a comma separated list of string\n";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
72 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
73 if ($chromosomes && $chromosomes =~/^([\w\,]+)\s*$/){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
74 $chromosomes = $1;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
75 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
76 elsif($chromosomes){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
77 die "Error: Chromosomes must be a comma separated list of string\n";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
78 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
79 if ($bounds && $bounds =~/^([\d\,]+)\s*$/){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
80 $bounds = $1;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
81 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
82 elsif($bounds){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
83 die "Error: Bounds must be a comma separated list of integers\n";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
84 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
85
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
86 if ($frequency_min && $frequency_min =~/^([\d\.]+)\s*$/){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
87 $frequency_min = $1;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
88 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
89 elsif ($frequency_min){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
90 die "Error: frequency must be an integer\n";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
91 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
92 if ($frequency_max && $frequency_max =~/^([\d\.]+)\s*$/){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
93 $frequency_max = $1;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
94 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
95 elsif($frequency_max){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
96 die "Error: frequency must be an integer\n";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
97 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
98 if ($missing_data && $missing_data =~/^([\d\.]+)\s*$/){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
99 $missing_data = $1;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
100 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
101 elsif ($missing_data){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
102 die "Error: Missing data must be an integer\n";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
103 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
104 if ($nb_alleles && $nb_alleles =~/^([\d\.\,]+)\s*$/){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
105 $nb_alleles = $1;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
106 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
107 elsif($nb_alleles){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
108 die "Error: Nb alleles must be two integers\n";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
109 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
110 if ($export && $export =~/^([\w]+)\s*$/){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
111 $export = $1;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
112 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
113 elsif($export){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
114 die "Error: Export must be a string\n";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
115 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
116 if ($type && $type =~/^([\w]+)\s*$/){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
117 $type = $1;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
118 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
119 elsif($type){
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
120 die "Error: Type must be a string\n";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
121 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
122
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
123
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
124 my @dnasamples;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
125 if ($samples)
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
126 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
127 @dnasamples = split(",",$samples);
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
128 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
129 my @nalleles;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
130 if ($nb_alleles)
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
131 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
132 @nalleles = split(",",$nb_alleles);
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
133 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
134 my @boundaries;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
135 if ($bounds)
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
136 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
137 @boundaries = split(",",$bounds);
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
138 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
139 my @chromosomes_list;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
140 if ($chromosomes)
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
141 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
142 @chromosomes_list = split(",",$chromosomes);
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
143 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
144
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
145
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
146 my $experiment = "chromosomes";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
147 my $table = "";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
148 my %genes;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
149 my @snp_ids;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
150 my @snp_ids_and_positions;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
151 my @snp_ids_and_positions_all;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
152 my $gene;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
153 my $snp_num = 0;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
154 my %ref_sequences;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
155 my %snps_of_gene;
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
156
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
157
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
158
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
159
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
160 my $indiv_cmd = "";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
161 if (@dnasamples)
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
162 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
163 $indiv_cmd = "--indv " . join(" --indv ",@dnasamples);
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
164 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
165
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
166 my $chrom_cmd = "";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
167 if (@chromosomes_list)
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
168 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
169 $chrom_cmd = "--chr " . join(" --chr ",@chromosomes_list);
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
170 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
171
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
172 my $export_cmd = "--recode";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
173 if ($export eq "freq")
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
174 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
175 $export_cmd = "--freq";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
176 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
177 if ($export eq "plink")
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
178 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
179 $export_cmd = "--plink";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
180 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
181
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
182
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
183
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
184 my $nb_alleles_cmd = "--min-alleles 1 --max-alleles 4";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
185 if (@nalleles)
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
186 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
187 $nb_alleles_cmd = "--min-alleles $nalleles[0] --max-alleles $nalleles[1]";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
188 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
189 my $bounds_cmd = "--from-bp 1 --to-bp 100000000";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
190 if (@boundaries)
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
191 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
192 $bounds_cmd = "--from-bp $boundaries[0] --to-bp $boundaries[1]";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
193 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
194
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
195
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
196 my $type_cmd = "";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
197 if ($type eq "INDEL")
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
198 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
199 $type_cmd = "--keep-only-indels";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
200 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
201 if ($type eq "SNP")
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
202 {
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
203 $type_cmd = "--remove-indels";
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
204 }
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
205
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
206
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
207 system("vcftools --vcf $input --out $out --keep-INFO-all --remove-filtered-all $type_cmd $export_cmd $chrom_cmd $indiv_cmd $nb_alleles_cmd --maf $frequency_min --max-maf $frequency_max --max-missing $missing_data >>vcftools.log 2>&1");
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
208
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
209
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
210
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
211
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
212
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
213
1b672da89d00 Uploaded
dereeper
parents:
diff changeset
214