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