├── LICENSE ├── README.md └── fpfilter.pl /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | variant-filter 2 | ============== 3 | 4 | A false-positive filter for variants called from massively parallel sequencing 5 | 6 | Update (5/30/2017): This repo is no longer maintained. Use the `fpfilter.pl` at https://github.com/genome/fpfilter-tool instead. 7 | 8 | Quick start 9 | ----------- 10 | 11 | Download the `fpfilter.pl` script, and view the detailed usage manual: 12 | 13 | curl -LO https://github.com/ckandoth/variant-filter/archive/master.zip; unzip master.zip 14 | perl variant-filter-master/fpfilter.pl --help 15 | 16 | Given `snvs.vcf` a single sample VCF listing SNVs, generate a list of variant loci in a subfolder: 17 | 18 | mkdir fpfilter 19 | perl -ane 'print join("\t",@F[0,1,1])."\n" unless(m/^#/)' snvs.vcf > fpfilter/snvs.var 20 | 21 | Given `tumor.bam`, a BAM file containing the SNVs, and its reference FASTA `grch37.fa`, run [bam-readcount](https://gist.github.com/ckandoth/87ba44948cb747916f8d#file-build_bam_readcount-txt): 22 | 23 | bam-readcount -q1 -b15 -w1 -l fpfilter/snvs.var -f grch37.fa tumor.bam > fpfilter/snvs.readcount 24 | 25 | Run the `fpfilter.pl` script using the readcounts as an input: 26 | 27 | perl fpfilter.pl --var-file snvs.vcf --readcount-file fpfilter/snvs.readcount --output-file fpfilter/snvs.fpfilter 28 | 29 | The last two columns of the resulting file `snvs.fpfilter` contains a VCF friendly `FILTER` code, and an extra column with details. 30 | 31 | Provenance 32 | ---------- 33 | 34 | The original `fpfilter.pl` script for filtering Single Nucleotide Variants (SNVs) was written by [Dan Koboldt](https://www.linkedin.com/in/dan-koboldt-75715a2/) for [VarScan](http://sourceforge.net/projects/varscan/files/scripts/), and [Dave Larson](https://www.linkedin.com/in/david-ernfrid-larson/) for [SomaticSniper](https://github.com/genome/somatic-sniper/tree/master/src/scripts). The latest version of the script is maintained by Dan, Dave, and other developers at the [The Genome Institute](http://genome.wustl.edu/people/), as a Perl module named [FilterFalsePositives.pm](https://github.com/genome/genome/blob/master/lib/perl/Genome/Model/Tools/Somatic/FilterFalsePositives.pm). They even wrote a module named [FilterFalseIndels.pm](https://github.com/genome/genome/blob/master/lib/perl/Genome/Model/Tools/Somatic/FilterFalseIndels.pm) for small indels. However, those modules are not very portable, and have [dependencies](https://github.com/genome/gms) on their internal codebase. So this repository was my attempt to remove those dependencies, make it easier to use, and add other improvements like VCF support. More recently, there have been forks of this repo, and [this one](https://github.com/genome/fpfilter-tool) is what I recommend using, which also does non-complex indels. 35 | 36 | Authors 37 | ------- 38 | 39 | Cyriac Kandoth (ckandoth@gmail.com) 40 | Dan Koboldt, Analysis Manager, Human Genetics Group, The Genome Institute 41 | David Larson, Director of Bioinformatics, The Genome Institute 42 | -------------------------------------------------------------------------------- /fpfilter.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use warnings; 4 | use strict; 5 | use Getopt::Long; 6 | use IO::File; 7 | 8 | ## Define filtering parameters ## 9 | 10 | # Minimum required depth to call a variant with confidence 11 | my $min_depth = 8; 12 | 13 | # Minimums for variant allele fraction, and the number of variant-supporting reads 14 | my $min_var_frac = 0.05; 15 | my $min_var_count = 3; 16 | 17 | # Minimum avg relative distance of variant from start/end of read 18 | my $min_read_pos = 0.10; 19 | 20 | # Minimum representation of variant allele on each strand 21 | my $min_strandedness = 0.01; 22 | 23 | # Maximum difference of mismatch quality sum between var/ref reads (paralog filter) 24 | my $max_mmqs_diff = 50; 25 | 26 | # Maximum mismatch quality sum of reference-supporting reads 27 | my $max_var_mmqs = 100; 28 | 29 | # Maximum difference of mapping quality between variant and reference reads 30 | my $max_mapqual_diff = 30; 31 | 32 | # Maximum difference of average supporting read length between variant and reference reads (paralog filter) 33 | my $max_readlen_diff = 25; 34 | 35 | # Minimum average distance to effective 3prime end of read (real end or Q2) for variant-supporting reads 36 | my $min_var_dist_3 = 0.2; 37 | 38 | ## Parse arguments ## 39 | 40 | my ( $var_file, $readcount_file, $output_file, $help ); 41 | my $opt_result = GetOptions( 42 | 'var-file=s' => \$var_file, 43 | 'readcount-file=s' => \$readcount_file, 44 | 'output-file=s' => \$output_file, 45 | 'min-depth=f' => \$min_depth, 46 | 'min-read-pos=f' => \$min_read_pos, 47 | 'min-strandedness=f' => \$min_strandedness, 48 | 'min-var-count=f' => \$min_var_count, 49 | 'min-var-frac=f' => \$min_var_frac, 50 | 'max-mmqs-diff=f' => \$max_mmqs_diff, 51 | 'max-mapqual-diff=f' => \$max_mapqual_diff, 52 | 'max-readlen-diff=f' => \$max_readlen_diff, 53 | 'min-var-dist-3=f' => \$min_var_dist_3, 54 | 'max-var-mmqs=f' => \$max_var_mmqs, 55 | 'help' => \$help, 56 | ) or die help_text(); 57 | 58 | # If help text was explicitly requested, print it to STDOUT rather than STDERR 59 | if( $help ) { 60 | print help_text(); 61 | exit 0; 62 | } 63 | 64 | # Make sure input files are properly defined and non-empty 65 | unless( $var_file and $readcount_file ) { 66 | warn "var-file and readcount-file are required arguments!\n"; 67 | die help_text(); 68 | } 69 | die "Variant file not found, or is empty: $var_file\n" unless( -s $var_file ); 70 | die "Readcount file not found, or is empty: $readcount_file\n" unless( -s $readcount_file ); 71 | 72 | # If output file is undefined, use the input filename as a prefix 73 | $output_file = "$var_file.fpfilter" unless( defined $output_file ); 74 | 75 | ## Load the read counts into a hash for quick lookup ## 76 | 77 | my %readcounts_by_position = (); 78 | my $rc_fh = IO::File->new( $readcount_file ) or die "Can't open file $readcount_file: $!\n"; 79 | while( my $line = $rc_fh->getline ) { 80 | chomp( $line ); 81 | my ( $chrom, $position ) = split( /\t/, $line ); 82 | $readcounts_by_position{"$chrom\t$position"} = $line; 83 | } 84 | $rc_fh->close; 85 | 86 | ## Parse the input file and write pass/fail status to output file ## 87 | 88 | my $input_fh = new IO::File->new( $var_file ) or die "Can't open file $var_file: $!\n"; 89 | 90 | # Open the output file for writing, and write a header line with column names 91 | my $output_fh = IO::File->new( $output_file, "w" ) or die "Can't open file $output_file: $!\n"; 92 | $output_fh->print( "#CHROM\tPOS\tREF\tVAR\tDEPTH\tRAF\tVAF\tFILTER\tFILTER_DETAILS\n" ); 93 | 94 | # Initialize all variant fail/pass counters to zero 95 | my %stats = map{($_,0)} qw( num_variants num_fail_depth num_fail_pos num_fail_strand num_fail_varcount 96 | num_fail_varfrac num_fail_mmqs num_fail_var_mmqs num_fail_mapqual num_fail_readlen 97 | num_fail_dist3 num_no_readcounts num_pass_filter ); 98 | 99 | my $input_is_vcf = undef; 100 | while( my $line = $input_fh->getline ) { 101 | 102 | # Skip blank lines 103 | next if( $line =~ m/^\s*$/ ); 104 | 105 | # If the first non-blank line in the file is a VCF version tag, then remember that this as a VCF 106 | unless( defined $input_is_vcf ) { 107 | $input_is_vcf = 0; 108 | $input_is_vcf = 1 if( $line =~ /^##fileformat=VCF/ ); 109 | } 110 | 111 | # Skip comment lines 112 | next if( $line =~ /^#/ ); 113 | 114 | chomp( $line ); 115 | my @fields = split( "\t", $line ); 116 | 117 | # We'll only need the chromosome name, genomic position, and ref/var alleles from input 118 | my ( $chrom, $position, $ref, $var ); 119 | if( $input_is_vcf ) { 120 | # Follow convention of choosing the first of listed alternate alleles 121 | ( $chrom, $position, undef, $ref, my $alt ) = @fields[0..4]; 122 | ( $var ) = split( /,/, $alt ); 123 | } 124 | else { 125 | ( $chrom, $position, $ref, $var ) = @fields; 126 | } 127 | $ref = uc( $ref ); 128 | $var = uc( $var ); 129 | 130 | # If the variant allele isn't all ACGTs then it likely contains IUPAC codes that need conversion 131 | if( $var !~ /^[ACGT]+$/ ) { 132 | $var = join( "", map{iupac_to_base( $ref, $_ )} split( //, $var )); 133 | } 134 | 135 | # Accumulate the total number of variants, for the final summarized report 136 | $stats{'num_variants'}++; 137 | 138 | # Proceed only if readcounts are available for this position 139 | if( $readcounts_by_position{"$chrom\t$position"} ) { 140 | my $readcounts = $readcounts_by_position{"$chrom\t$position"}; 141 | my $ref_result = read_counts_by_allele( $readcounts, $ref ); 142 | my $var_result = read_counts_by_allele( $readcounts, $var ); 143 | 144 | # Proceed only if readcounts are available for reference and variant alleles 145 | if( $ref_result && $var_result ) { 146 | # Parse out the bam-readcounts details for each allele. The fields should be in this order: 147 | # total_reads : num_reads : avg_mapqual : avg_basequal : avg_semq : reads_plus : reads_minus : 148 | # avg_clip_read_pos : avg_mmqs : reads_q2 : avg_dist_to_q2 : avgRLclipped : avg_eff_3'_dist 149 | my ( $total_depth, $ref_count, $ref_map_qual, $ref_base_qual, $ref_semq, $ref_plus, $ref_minus, $ref_pos, 150 | $ref_subs, $ref_mmqs, $ref_q2_reads, $ref_q2_dist, $ref_avg_rl, $ref_dist_3 ) = split( /\t/, $ref_result ); 151 | my ( undef, $var_count, $var_map_qual, $var_base_qual, $var_semq, $var_plus, $var_minus, $var_pos, 152 | $var_subs, $var_mmqs, $var_q2_reads, $var_q2_dist, $var_avg_rl, $var_dist_3 ) = split( /\t/, $var_result ); 153 | 154 | # Set conservative defaults if read positions or mismatch quality sums are not available 155 | $ref_dist_3 = 0.5 unless( $ref_dist_3 ); 156 | $ref_mmqs = 50 unless( $ref_mmqs ); 157 | $var_mmqs = 0 unless( $var_mmqs ); 158 | my $mismatch_qualsum_diff = $var_mmqs - $ref_mmqs; 159 | 160 | # Determine map qual diff between ref/var reads 161 | my $mapqual_diff = $ref_map_qual - $var_map_qual; 162 | 163 | # Determine difference in average supporting read length 164 | my $readlen_diff = $ref_avg_rl - $var_avg_rl; 165 | 166 | # Set max strandedness cutoff 167 | my $max_strandedness = 1 - $min_strandedness; 168 | 169 | # Set conservative default values for reference and variant strandedness 170 | my ( $ref_strandedness, $var_strandedness ) = ( 0.5, 0.5 ); 171 | 172 | # Determine reference strandedness 173 | if(( $ref_plus + $ref_minus ) > 0 ) { 174 | $ref_strandedness = $ref_plus / ( $ref_plus + $ref_minus ); 175 | $ref_strandedness = sprintf( "%.2f", $ref_strandedness ); 176 | } 177 | 178 | # Determine variant strandedness 179 | if(( $var_plus + $var_minus ) > 0 ) { 180 | $var_strandedness = $var_plus / ( $var_plus + $var_minus ); 181 | $var_strandedness = sprintf( "%.2f", $var_strandedness ); 182 | } 183 | 184 | # Determine reference/variant allele fractions, and add as columns for output 185 | my $raf = sprintf( "%.4f", $total_depth ? $ref_count/$total_depth : 0 ); 186 | my $vaf = sprintf( "%.4f", $total_depth ? $var_count/$total_depth : 0 ); 187 | $line = "$chrom\t$position\t$ref\t$var\t$total_depth\t$raf\t$vaf"; 188 | 189 | ## We must have non-zero variant read counts to proceed ## 190 | if( $var_count && ( $var_plus + $var_minus )) { 191 | 192 | ## FAILURE: Average distance of variant from clipped read ends ## 193 | if($var_pos < $min_read_pos) { 194 | $line .= "\tReadPos\t$var_pos < $min_read_pos\n"; 195 | $stats{'num_fail_pos'}++; 196 | } 197 | 198 | ## FAILURE: Variant is strand-specific but reference is NOT strand-specific ## 199 | elsif(($var_strandedness < $min_strandedness || $var_strandedness > $max_strandedness) && 200 | ($ref_strandedness >= $min_strandedness && $ref_strandedness <= $max_strandedness)) { 201 | ## Print failure to output file if desired ## 202 | $line .= "\tStrandedness\tRef=$ref_strandedness,Var=$var_strandedness,MinMax=[$min_strandedness,$max_strandedness]\n"; 203 | $stats{'num_fail_strand'}++; 204 | } 205 | 206 | ## FAILURE: Variant allele count does not meet minimum ## 207 | elsif($var_count < $min_var_count) { 208 | $line .= "\tVarCount\t$var_count < $min_var_count\n"; 209 | $stats{'num_fail_varcount'}++; 210 | } 211 | 212 | ## FAILURE: Read depth is too low to proceed onto next few filters ## 213 | elsif($total_depth < $min_depth) { 214 | $line .= "\tLowDepth\t$total_depth < $min_depth\n"; 215 | $stats{'num_fail_depth'}++; 216 | } 217 | 218 | ## FAILURE: Variant allele fraction does not meet minimum ## 219 | elsif($vaf < $min_var_frac) { 220 | $line .= "\tVarFrac\t$vaf < $min_var_frac\n"; 221 | $stats{'num_fail_varfrac'}++; 222 | } 223 | 224 | ## FAILURE: Paralog filter for sites where variant allele mismatch-quality-sum is significantly higher than the reference allele MMQS 225 | elsif( $mismatch_qualsum_diff > $max_mmqs_diff ) { 226 | ## Print failure to output file if desired ## 227 | $line .= "\tMismatchQualsum\t$var_mmqs-$ref_mmqs=$mismatch_qualsum_diff > $max_mmqs_diff\n"; 228 | $stats{'num_fail_mmqs'}++; 229 | } 230 | 231 | ## FAILURE: Mapping quality difference exceeds allowable maximum ## 232 | elsif($mapqual_diff > $max_mapqual_diff) { 233 | $line .= "\tMapQual\t$ref_map_qual-$var_map_qual=$mapqual_diff > $max_mapqual_diff\n"; 234 | $stats{'num_fail_mapqual'}++; 235 | } 236 | 237 | ## FAILURE: Read length difference exceeds allowable maximum ## 238 | elsif( $readlen_diff > $max_readlen_diff ) { 239 | $line .= "\tReadLen\t$ref_avg_rl-$var_avg_rl=$readlen_diff > $max_readlen_diff\n"; 240 | $stats{'num_fail_readlen'}++; 241 | } 242 | 243 | ## FAILURE: Avg distance from 3' ends of reads is lower than allowed minimum ## 244 | elsif( $var_dist_3 < $min_var_dist_3 ) { 245 | $line .= "\tVarDist3\t$var_dist_3 < $min_var_dist_3\n"; 246 | $stats{'num_fail_dist3'}++; 247 | } 248 | 249 | ## FAILURE: Mismatch quality sum indicative of errors from misalignment ## 250 | elsif( $var_mmqs > $max_var_mmqs ) { 251 | $line .= "\tVarMMQS\t$var_mmqs > $max_var_mmqs\n"; 252 | $stats{'num_fail_var_mmqs'}++; 253 | } 254 | 255 | ## SUCCESS: Passes all filters above ## 256 | else { 257 | $line .= "\tPASS\t\n"; 258 | $stats{'num_pass_filter'}++; 259 | } 260 | } 261 | else { 262 | $line .= "\tNoVariantReads\t\n"; 263 | $stats{'num_no_readcounts'}++; 264 | } 265 | } 266 | else { 267 | $line = "$chrom\t$position\t$ref\t$var\t0\t0\t0\tNoReadCounts\t\n"; 268 | $stats{'num_no_readcounts'}++; 269 | } 270 | } 271 | else { 272 | $line = "$chrom\t$position\t$ref\t$var\t0\t0\t0\tNoReadCounts\t\n"; 273 | $stats{'num_no_readcounts'}++; 274 | } 275 | 276 | # Print to output file along with filter status and additional information 277 | $output_fh->print( $line ); 278 | } 279 | 280 | $input_fh->close; 281 | $output_fh->close; 282 | 283 | ## Print filtering stats ## 284 | 285 | print $stats{'num_variants'} . " variants\n"; 286 | print $stats{'num_fail_pos'} . " had a position near the ends of most supporting reads (position < $min_read_pos)\n"; 287 | print $stats{'num_fail_strand'} . " had strandedness < $min_strandedness (most supporting reads are in the same direction)\n"; 288 | print $stats{'num_fail_varcount'} . " had var_count < $min_var_count (not enough supporting reads)\n"; 289 | print $stats{'num_fail_depth'} . " had depth < $min_depth\n"; 290 | print $stats{'num_fail_varfrac'} . " had var_frac < $min_var_frac (low-fraction variants are likely artifacts or from crosstalk between samples in the same lane)\n"; 291 | print $stats{'num_fail_mmqs'} . " had mismatch qualsum difference > $max_mmqs_diff (likely a result of paralogous misalignments)\n"; 292 | print $stats{'num_fail_var_mmqs'} . " had variant MMQS > $max_var_mmqs (likely a result of paralogous misalignments)\n" if($stats{'num_fail_var_mmqs'}); 293 | print $stats{'num_fail_mapqual'} . " had mapping quality difference > $max_mapqual_diff\n"; 294 | print $stats{'num_fail_readlen'} . " had read length difference > $max_readlen_diff\n"; 295 | print $stats{'num_fail_dist3'} . " had var_distance_to_3' < $min_var_dist_3 (illumina errors are more frequent at the 3' ends of reads)\n"; 296 | print $stats{'num_pass_filter'} . " passed all filters\n"; 297 | print $stats{'num_no_readcounts'} . " had no readcounts for the variant allele\n"; 298 | 299 | ## iupac_to_base - Convert IUPAC ambiguity codes to variant bases ## 300 | 301 | sub iupac_to_base { 302 | my ( $allele1, $allele2 ) = @_; 303 | 304 | return( $allele2 ) if( $allele2 eq "A" or $allele2 eq "C" or $allele2 eq "G" or $allele2 eq "T" ); 305 | 306 | # Choose the most likely base-pair, or the default for triallelic variants 307 | if( $allele2 eq "M" ) { 308 | return( "C" ) if( $allele1 eq "A" ); 309 | return( "A" ) if( $allele1 eq "C" ); 310 | return( "A" ); 311 | } elsif( $allele2 eq "R" ) { 312 | return( "G" ) if( $allele1 eq "A" ); 313 | return( "A" ) if( $allele1 eq "G" ); 314 | return( "A" ); 315 | } elsif( $allele2 eq "W" ) { 316 | return( "T" ) if( $allele1 eq "A" ); 317 | return( "A" ) if( $allele1 eq "T" ); 318 | return( "A" ); 319 | } elsif( $allele2 eq "S" ) { 320 | return( "C" ) if( $allele1 eq "G" ); 321 | return( "G" ) if( $allele1 eq "C" ); 322 | return( "C" ); 323 | } elsif( $allele2 eq "Y" ) { 324 | return( "C" ) if( $allele1 eq "T" ); 325 | return( "T" ) if( $allele1 eq "C" ); 326 | return( "C" ); 327 | } elsif( $allele2 eq "K" ) { 328 | return( "G" ) if( $allele1 eq "T" ); 329 | return( "T" ) if( $allele1 eq "G" ); 330 | return( "G" ); 331 | } 332 | 333 | die "Failed to interpret variant allele: $allele2"; 334 | } 335 | 336 | ## read_counts_by_allele - Retrieve relevant read counts for a certain allele ## 337 | 338 | sub read_counts_by_allele { 339 | my ( $line, $allele ) = @_; 340 | 341 | my @lineContents = split(/\t/, $line); 342 | my $numContents = @lineContents; 343 | my $total_depth = $lineContents[3]; 344 | 345 | for(my $colCounter = 5; $colCounter < $numContents; $colCounter++) { 346 | my $this_allele = $lineContents[$colCounter]; 347 | my @alleleContents = split(/\:/, $this_allele); 348 | if($alleleContents[0] eq $allele) { 349 | my $numAlleleContents = @alleleContents; 350 | 351 | return("") if($numAlleleContents < 8); 352 | 353 | my $return_string = ""; 354 | my $return_sum = 0; 355 | for(my $printCounter = 1; $printCounter < $numAlleleContents; $printCounter++) { 356 | $return_sum += $alleleContents[$printCounter]; 357 | $return_string .= "\t" if($return_string); 358 | $return_string .= $alleleContents[$printCounter]; 359 | } 360 | 361 | return("$total_depth\t$return_string"); 362 | 363 | } 364 | } 365 | 366 | return(""); 367 | } 368 | 369 | ## help_text - Returns usage syntax and documentation ## 370 | 371 | sub help_text { 372 | return <