annotate VCFToolsFilter.pl @ 0:9dec9f724a50 draft

Uploaded
author dereeper
date Thu, 12 Feb 2015 15:37:31 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
1
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
2 #!/usr/bin/perl
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
3
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
4 use strict;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
5 use Switch;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
6 use Getopt::Long;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
7 use Bio::SeqIO;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
8
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
9 my $usage = qq~Usage:$0 <args> [<opts>]
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
10
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
11 where <args> are:
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
12
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
13 -i, --input <VCF input>
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
14 -o, --out <Output basename>
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
15
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
16 <opts> are:
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
17
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
18 -s, --samples <Samples to be analyzed. Comma separated list>
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
19 -c, --chromosomes <Chromosomes to be analyzed. Comma separated list>
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
20 -e, --export <Output format (VCF/freq/plink. Default: VCF>
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
21 -f, --frequency <Minimum MAF. Default: 0.001>
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
22 -m, --max_freq <Maximum MAF. Default: 0.5>
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
23 -a, --allow_missing <Allowed missing data proportion per site. Must be comprised between 0 and 1. Default: 1>
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
24 -n, --nb_alleles <Accepted number of alleles (min,max). Default: 2,4>
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
25 -t, --type <Type of polymorphisms to keep (ALL/SNP/INDEL). Default: ALL>
9dec9f724a50 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>
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
27 ~;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
28 $usage .= "\n";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
29
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
30 my ($input,$out);
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
31
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
32
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
33 #my $indel_size_max = 500;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
34 #my $indel_size_min = 1;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
35 my $frequency_max = 0.5;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
36 my $frequency_min = 0.001;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
37 my $pos_max = 100000000000;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
38 my $pos_min = 0;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
39 my $filter_snp_type = "all";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
40
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
41 my $missing_data = 1;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
42 my $export = "VCF";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
43 my $type = "ALL";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
44 my $nb_alleles;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
45 my $bounds;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
46 my $samples;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
47 my $chromosomes;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
48
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
49 GetOptions(
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
50 "input=s" => \$input,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
51 "out=s" => \$out,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
52 "samples=s" => \$samples,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
53 "chromosomes=s" => \$chromosomes,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
54 "frequency=s" => \$frequency_min,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
55 "max_freq=s" => \$frequency_max,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
56 "allow_missing=s"=> \$missing_data,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
57 "export=s" => \$export,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
58 "type=s" => \$type,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
59 "nb_alleles=s" => \$nb_alleles,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
60 "bounds=s" => \$bounds,
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
61 );
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
62
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
63
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
64 die $usage
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
65 if ( !$input || !$out);
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
66
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
67
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
68 my @dnasamples;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
69 if ($samples)
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
70 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
71 @dnasamples = split(",",$samples);
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
72 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
73 my @nalleles;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
74 if ($nb_alleles)
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
75 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
76 @nalleles = split(",",$nb_alleles);
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
77 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
78 my @boundaries;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
79 if ($bounds)
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
80 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
81 @boundaries = split(",",$bounds);
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
82 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
83 my @chromosomes_list;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
84 if ($chromosomes)
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
85 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
86 @chromosomes_list = split(",",$chromosomes);
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
87 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
88
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
89
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
90 my $experiment = "chromosomes";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
91 my $table = "";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
92 my %genes;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
93 my @snp_ids;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
94 my @snp_ids_and_positions;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
95 my @snp_ids_and_positions_all;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
96 my $gene;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
97 my $snp_num = 0;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
98 my %ref_sequences;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
99 my %snps_of_gene;
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
100
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
101
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
102
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
103
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
104 my $indiv_cmd = "";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
105 if (@dnasamples)
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
106 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
107 $indiv_cmd = "--indv " . join(" --indv ",@dnasamples);
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
108 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
109
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
110 my $chrom_cmd = "";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
111 if (@chromosomes_list)
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
112 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
113 $chrom_cmd = "--chr " . join(" --chr ",@chromosomes_list);
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
114 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
115
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
116 my $export_cmd = "--recode";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
117 if ($export eq "freq")
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
118 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
119 $export_cmd = "--freq";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
120 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
121 if ($export eq "plink")
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
122 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
123 $export_cmd = "--plink";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
124 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
125
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
126
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
127
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
128 my $nb_alleles_cmd = "--min-alleles 1 --max-alleles 4";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
129 if (@nalleles)
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
130 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
131 $nb_alleles_cmd = "--min-alleles $nalleles[0] --max-alleles $nalleles[1]";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
132 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
133 my $bounds_cmd = "--from-bp 1 --to-bp 100000000";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
134 if (@boundaries)
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
135 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
136 $bounds_cmd = "--from-bp $boundaries[0] --to-bp $boundaries[1]";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
137 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
138
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
139
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
140 my $type_cmd = "";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
141 if ($type eq "INDEL")
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
142 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
143 $type_cmd = "--keep-only-indels";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
144 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
145 if ($type eq "SNP")
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
146 {
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
147 $type_cmd = "--remove-indels";
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
148 }
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
149
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
150
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
151 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");
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
152
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
153
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
154
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
155
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
156
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
157
9dec9f724a50 Uploaded
dereeper
parents:
diff changeset
158