Last active
February 17, 2025 16:19
-
-
Save dceoy/99d976a2c01e7f0ba1c813778f9db744 to your computer and use it in GitHub Desktop.
[Python] Read VCF (variant call format) as pandas.DataFrame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import io | |
import os | |
import pandas as pd | |
def read_vcf(path): | |
with open(path, 'r') as f: | |
lines = [l for l in f if not l.startswith('##')] | |
return pd.read_csv( | |
io.StringIO(''.join(lines)), | |
dtype={'#CHROM': str, 'POS': int, 'ID': str, 'REF': str, 'ALT': str, | |
'QUAL': str, 'FILTER': str, 'INFO': str}, | |
sep='\t' | |
).rename(columns={'#CHROM': 'CHROM'}) |
It works great. Thanks
Hi,
Did you find a solution for not finding the result after you use the python script ? I am facing the same issue
This was all I need for now. Thank you very much!! :)
That was indeed usefull! Thank you very much!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was so so useful. Thank you very much @dceoy