This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Editing Manta structural VCF file

Hi,

Is there a way for filtering/removing the structural variants identified in ChrUn and other random contigs or in non-main chromosomes? I am using hg38 assembly.

Will 'vcftools' --chr filtering work here?

I followed 'https://www.biostars.org/p/201603/#273150'. Tried the below code, but it didn't filter the non-main chromosomes in my vcf.

grep -w '^#\|chr[1-9]\|chr[1-2][0-9]\|chr[X]\|chr[Y]' my.vcf > my_filtered.vcf

Example of Manta vcf:

CHROM POS ID REF ALT QUAL FILTER INFO FORMAT Normal1 Tumor1

chr1 30405827 MantaBND:0:70561:70576:1:0:0:0 T ]chr1_KI270760v1_alt:58532]T . PASS SVTYPE=BND;MATEID=MantaBND:0:70561:70576:1:0:0:1;IMPRECISE;CIPOS=-568,568;SOMATIC;SOMATICSCORE=41;BND_DEPTH=54;MATE_BND_DEPTH =24 PR 16,0 26,7

In the case of structural variants, translocation events will be present. So, I will have to remove the random chromosomes from ALT columns too. I am trying to do this to keep only chr1-22, X, Y in the Manta structural vcf file to do a circos plot.

Thanks for the help!

vcf structural variants manta wgs

2 answers

try with awk:

$ awk '/^#/ || !/chr[0-9A-Za-z]+_/' test.vcf

This would print header rows of vcf and removes any line with chr(single of multiple number,upper or lower case text), followed by underscore _. Little risky without example data. But removes rows with text such as chrun_ or chr1_KI270760v1_alt:58532

Thanks for the reply. This way the ALT column was not modified. Sorry, I forgot to mention about that. I have modified my question.

updated the code. Entire row is modified. Please be careful of output as it is a generic regex.

Personally I prefer to use bcftools rather than regex as it has multithreading capability, can work with bcf files and the syntax is much easier to understand when you are revisiting the script.

Depending on the naming convention of your chromosomes, this will do it

bcftools view -r chr1,chr2,chr3,chr4,chr5,chr6,chr7,chr8,chr9,chr10,chr11,chr12,chr13,chr14,chr15,chr16,chr17,chr18,chr19,chr20,chr21,chr22,chrx,chry in.vcf

Or just remove the "chr" before each number and change the X/Y chromosome names accordingly.

Thanks for the answer. But this removes only the chromosomes in #CHROM position. In the case of structural variants, translocation events will be there (ALT column), so that is not being removed by this method.

CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT  Normal1   Tumor1

chr1    30405827             MantaBND:0:70561:70576:1:0:0:0  T       ]chr1_KI270760v1_alt:58532]T    .       PASS    SVTYPE=BND;MATEID=MantaBND:0:70561:70576:1:0:0:1;IMPRECISE;CIPOS=-568,568;SOMATIC;SOMATICSCORE=41;BND_DEPTH=54;MATE_BND_DEPTH=24        PR      16,0    26,7

OK - can you edit your original question to include an example of those lines and format them using the code tags (`), since I can't really understand that as it is. Thanks.

Log in to answer this question.