美文网首页python学习
python下载TCGA数据

python下载TCGA数据

作者: dming1024 | 来源:发表于2020-04-19 15:21 被阅读0次

除了使用gdc-client对TCGA中数据进行下载外,还可以利用一下python脚本,对TCGA数据进行下载,但是需要你提供带有fileid的manifest文件

  1. python 脚本: python_tcga.py
  2. manifest 文件:manifest.txt
    脚本的使用
python python_tcga.py manifest.txt

大概20分钟左右,就可以下载2000个左右的RNAseq表达数据。

这个是python_tcga.py脚本内容

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 18 10:17:06 2020

@author: dongl
"""
import requests
import json
import re
import sys
import pandas as pd

data_endpt = "https://api.gdc.cancer.gov/data"

mainfest=pd.read_table(sys.argv[1],sep="\t")

ids=list(mainfest['id'].values)

params = {"ids": ids}

response = requests.post(data_endpt,
                        data = json.dumps(params),
                        headers={
                            "Content-Type": "application/json"
                            })

response_head_cd = response.headers["Content-Disposition"]

file_name = re.findall("filename=(.+)", response_head_cd)[0]

with open(file_name, "wb") as output_file:
    output_file.write(response.content)

相关文章

网友评论

    本文标题:python下载TCGA数据

    本文链接:https://www.haomeiwen.com/subject/wynebhtx.html