【发布时间】:2019-12-13 04:06:57
【问题描述】:
我想将 txt 文件中的信息提取到数据框中,数据中包含以下字段
1) GENEINFO
2) ID
3) POS
4) ALT
5) CLNSIG
6) CLNDN
我编写了以下代码试图从文件中获取信息,但不知道如何继续。你能帮我指导一些想法吗?
import io
import os
import pandas as pd
def read_vcf(path):
with open('clinvar_final.txt', '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'})
【问题讨论】:
-
你必须运行它
read_vcf("")。如果您不在代码中使用path,我不知道为什么您在def read_vcf(path):中有path。 -
可能你对
read_csv('clinvar_final.txt', comment="#", ...)做同样的事情 - doc: read_csv
标签: python pandas vcf-variant-call-format