반응형
VCF -> Dataframe
1. VCF 파일 불러오기
2. metadata 제거
3. 나머지 데이터 pandas 전환
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'})
참고:https://dmnfarrell.github.io/bioinformatics/multi-sample-vcf-dataframe
Bioinformatics and other bits - Convert a multi-sample VCF to a pandas DataFrame
Background Here is some code I wrote to convert a vcf file with many samples into a table format. This was done to make the calls for many samples easier to read. Reading a multi sample vcf is tortuous. The vcf is read in using pyVCF and for each record (a
dmnfarrell.github.io
반응형
'Python' 카테고리의 다른 글
python VCF file 데이터 불러오기 (0) | 2024.04.16 |
---|---|
기업 코딩 테스트 후기 (Bioinformatics 포지션) (0) | 2024.04.08 |
python 판다스(pandas) DataFrame 기초통계 확인하기 (24) | 2023.11.18 |
python 판다스(pandas) DataFrame categorical 범주형 데이터 작업 (10) | 2023.11.18 |
python 판다스(pandas) DataFrame 결측치 확인 및 처리 (6) | 2023.11.18 |