<p>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.</p>

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

<p>Replace <code>cat</code> with <code>gunzip -c</code> if your VCF file is gzip-compressed.</p>

<p>The Perl regular expression is</p>

<ul>
<li>looking for the string <code>CAF=[...]</code></li>
<li>grabbing the characters in <code>...</code></li>
<li>replacing the entire match with <code>CAF=...</code></li>
</ul>

<p>Here's a detailed breakdown of the Perl regular expression.</p>

<ul>
<li><code>s/.../.../;</code> — substitution syntax; replace the contents of the left block with the contents of the right block</li>
<li><code>[^\]]+</code> — one or more non-<code>]</code> characters; this is the trickiest bit; see <a href="https://www.regular-expressions.info/charclass.html" rel="nofollow noreferrer">this tutorial</a> for more info on the <code>[]</code> syntax for character classes and the special <code>^</code> symbol for character class negation</li>
<li><code>(...)</code> — the parentheses capture the matched pattern into the <code>$1</code> variable</li>
<li><code>CAF=$1</code> — replaces everything matched in the first block with <code>CAF=</code> followed by the captured characters</li>
</ul>

CC BY-SA 4.0
2019-03-19T07:53:28.013Z
That's probably a better (and easier) solution than changing the javascript code. Thanks for the suggestion.
Dario R
CC BY-SA 4.0
2019-03-18T17:40:32.233Z
2019-03-18T17:40:32.233Z
Daniel Standage
<p>Related to <a href="https://bioinformatics.stackexchange.com/questions/4408/how-to-filter-for-caf-0-5747-0-4253">this other question</a>
but in this case the CAF is defined as "An ordered, comma delimited list of allele frequencies...".</p>

<p>I tried using <a href="http://lindenb.github.io/jvarkit/VcfFilterJdk.html" rel="nofollow noreferrer">vcffilterjdk</a> and the command suggested by Pierre </p>

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

<p>but predictably returned an error </p>

<pre><code>java.lang.NumberFormatException: For input string: "0.1]"
</code></pre>

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

<p>EDIT:</p>

<p>HEADER</p>

<pre><code>##INFO=&lt;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"&gt;  
</code></pre>

<p>LINE</p>

<pre><code>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
</code></pre>

CC BY-SA 4.0
2019-03-15T16:59:34.593Z
Can you show us the line from your VCF file that causes the error? And also the header line where CAF is defined?
terdon
<vcf><file-formats>
Filter VCF for "CAF=[0.9,0.1]"
# Filter VCF for "CAF=[0.9,0.1]"

(Asked by: username_0 on 2019-03-15)

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=  

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

**Tags:** vcf, file-formats
> **Comments:**
> **username_1**: Can you show us the line from your VCF file that causes the error? And also the header line where CAF is defined?  

---

## 1 answers

### Answer by username_2 on 2019-03-18. Score: 0 | Accepted answer

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

> **Comments:**
> **username_0**: That's probably a better (and easier) solution than changing the javascript code. Thanks for the suggestion.  

---

