반응형
VCF 파일에서 filter 열 PASS 만 골라내기
방법1: python script
#extract.py
cnt = 0
with open("sample1.vcf", "r") as fr:
for line in fr:
if line.startswith("#"):
pass
else:
l = line.split()
if l[6] == "PASS":
cnt += 1
print(cnt)
방법2: linux command line
awk -F '\t' '{if($0 ~ /\#/) print; else if($7 == "PASS") print}' sample1.vcf > sample1_pass.vcf
#or
awk '$7=="PASS" {print $0}' sample1.vcf > sample1_pass.vcf
방법3: bcftools
bcftools view -i 'ID="PASS"' sample1.vcf > sample1_pass.vcf
#or
bcftools view -i "%FILTER='PASS' | %FILTER='.'" sample1.vcf.gz
#or
bcftools view -f 'PASS,.' sample1.vcf.gz
참고:https://samtools.github.io/bcftools/bcftools.html
bcftools(1)
HTSlib was designed with BCF format in mind. When parsing VCF files, all records are internally converted into BCF representation. Simple operations, like removing a single column from a VCF file, can be therefore done much faster with standard UNIX comman
samtools.github.io
반응형
'Bioinformatics' 카테고리의 다른 글
VCF 파일에서 SNP, Indel 개수 세기 (1) | 2024.03.13 |
---|---|
VCF 파일에서 변이 개수 세기 (0) | 2024.03.13 |
VCF 파일에서 샘플 개수 세기 (0) | 2024.03.12 |
VCF 파일에서 header 와 data 분리하기 (2) | 2024.03.12 |
[bcftools] 사용 방법/명령어 총정리 -2 (4) | 2023.12.13 |