1
$\begingroup$

Related to this other question but in this case the CAF is defined as "An ordered, comma delimited list of allele frequencies...".

I tried using vcffilterjdk and the command suggested by Pierre

java -jar dist/vcffilterjdk.jar -e 'variant.variant.getAttributeAsStringList("CAF","1.0").stream().skip(1L).map(A->Double.parseDouble(A)).anyMatch(A->A<0.01);' input.vcf

but predictably returned an error

java.lang.NumberFormatException: For input string: "0.1]"

I don't know javascript so how should I change the command to make it work?

EDIT:

HEADER

##INFO=<ID=CAF,Number=.,Type=String,Description="An ordered, comma delimited list of allele frequencies based on 1000Genomes, starting with the reference allele followed by alternate alleles as ordered in the ALT column. Where a 1000Genomes alternate allele is not in the dbSNPs alternate allele set, the allele is added to the ALT column.  The minor allele is the second largest value in the list, and was previuosly reported in VCF as the GMAF.  This is the GMAF reported on the RefSNP and EntrezSNP pages and VariationReporter">  

LINE

chr1    51479   rs116400033     T       A       .       PASS    ASP;CAF=[0.8926,0.1074];COMMON=1;G5;G5A;KGPROD;KGPhase1;OTHERKG;RS=116400033;RSPOS=51479;SAO=0;SSR=0;VC=SNV;VLD;VP=0x050000000005170016000100;WGT=1;dbSNPBuildID=132
$\endgroup$
1
  • $\begingroup$ Can you show us the line from your VCF file that causes the error? And also the header line where CAF is defined? $\endgroup$
    – terdon
    Mar 15, 2019 at 16:59

1 Answer 1

0
$\begingroup$

Printing a bracketed list of numerical values is not typical for VCF—I'd guess it's not strictly allowed. A list should be printed only with the commas to separate values. Perhaps the solution is as simple as removing the square brackets.

cat input.vcf | perl -ne 's/CAF=\[([^\]]+)\]/CAF=$1/; print' > fixed.vcf

Replace cat with gunzip -c if your VCF file is gzip-compressed.

The Perl regular expression is

  • looking for the string CAF=[...]
  • grabbing the characters in ...
  • replacing the entire match with CAF=...

Here's a detailed breakdown of the Perl regular expression.

  • s/.../.../; — substitution syntax; replace the contents of the left block with the contents of the right block
  • [^\]]+ — one or more non-] characters; this is the trickiest bit; see this tutorial for more info on the [] syntax for character classes and the special ^ symbol for character class negation
  • (...) — the parentheses capture the matched pattern into the $1 variable
  • CAF=$1 — replaces everything matched in the first block with CAF= followed by the captured characters
$\endgroup$
1
  • $\begingroup$ That's probably a better (and easier) solution than changing the javascript code. Thanks for the suggestion. $\endgroup$
    – Dario R
    Mar 19, 2019 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.