【问题标题】:Opening a VCF.bgz file in python - edit在 python 中打开 VCF.bgz 文件 - 编辑
【发布时间】:2023-01-07 08:37:10
【问题描述】:

我已经从 gnomad - https://gnomad.broadinstitute.org/downloads 下载了一些数据。 它以 VCF.bgz 文件的形式出现,我想将其作为 vcf 文件阅读。

我在这里找到了一些代码:Partially expand VCF bgz file in Linux 通过@rnorris。

import gzip
ifile = gzip.GzipFile("gnomad.genomes.r2.1.1.sites.2.vcf.bgz")
ofile = open("truncated.vcf", "wb")
LINES_TO_EXTRACT = 100000

for line in range(LINES_TO_EXTRACT):
    ofile.write(ifile.readline())

ifile.close()
ofile.close()

我在我的数据上试了一下,得到:

Not a gzipped file (b'TB')

有什么办法可以解决吗?我不明白问题出在哪里。

【问题讨论】:

    标签: file zip gzip vcf-variant-call-format


    【解决方案1】:
    【解决方案2】:

    gnomAD 数据集绝对应该是有效的 block-gzipped VCF 文件。无论如何,我认为您使用Hail 可能会有更好的时间(免责声明:我是 Hail 维护者)。

    如果安装 GCS 连接器,Hail 可以直接从 Google Cloud Storage 中读取。

    curl https://broad.io/install-gcs-connector | bash
    

    然后在 Python 中:

    import hail as hl
    
    mt = hl.read_matrix_table(
        'gs://gcp-public-data--gnomad/release/2.1.1/ht/exomes/gnomad.exomes.r2.1.1.sites.ht'
    )
    mt = mt.head(100_000)
    sites = mt.collect()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      • 2016-01-05
      • 2015-04-09
      • 2018-01-05
      • 1970-01-01
      相关资源
      最近更新 更多