{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install datasets[s3]" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import datasets\n", "import json\n", "from datasets import load_from_disk\n", "\n", "s3 = datasets.filesystems.S3FileSystem(anon=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# GTEx" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "s3 = datasets.filesystems.S3FileSystem(anon=True) \n", "gtex_code2tissue = {}\n", "gtex_tissue2filepath = {}\n", "\n", "PATH = \"recount-opendata/recount3/release/human/data_sources/gtex/gene_sums/\"\n", "\n", "for dirpath, dirnames, filenames in s3.walk(PATH):\n", "# care about the how many directories your bucket have\n", " dirpath_ = dirpath.split('/')\n", " if len(dirpath_) == 9:\n", " gtex_code2tissue[dirpath_[-2]] = dirpath_[-1]\n", " for filename in filenames:\n", " if \"G029\" in filename:\n", " file_path = os.path.join(dirpath, filename)\n", " gtex_tissue2filepath[dirpath_[-1]] = file_path" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# gtex_tissue2filepath\n", "# gtex_code2tissue\n", "\n", "for filename, d in {\n", " \"gtex_tissue2filepath.json\": gtex_tissue2filepath,\n", " \"gtex_code2tissue.json\": gtex_code2tissue,\n", "}.items():\n", " js_dump = json.dumps(d, sort_keys=True, indent=4, separators=(',', \": \"))\n", " with open(filename, 'w+') as f:\n", " f.write(js_dump)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# TCGA" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "s3 = datasets.filesystems.S3FileSystem(anon=True) \n", "tcga_code2cancer = {}\n", "tcga_cancer2filepath = {}\n", "for dirpath, dirnames, filenames in s3.walk(\"recount-opendata/recount3/release/human/data_sources/tcga/gene_sums/\"):\n", "# care about the how many directories your bucket have\n", " dirpath_ = dirpath.split('/')\n", " if len(dirpath_) == 9:\n", " tcga_code2cancer[dirpath_[-2]] = dirpath_[-1]\n", " for filename in filenames:\n", " if \"G029\" in filename:\n", " file_path = os.path.join(dirpath, filename)\n", " tcga_cancer2filepath[dirpath_[-1]] = file_path\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "# tcga_cancer2filepath\n", "# tcga_code2cancer\n", "\n", "for filename, d in {\n", " \"tcga_cancer2filepath.json\": tcga_cancer2filepath,\n", " \"tcga_code2cancer.json\": tcga_code2cancer,\n", "}.items():\n", " js_dump = json.dumps(d, sort_keys=True, indent=4, separators=(',', \": \"))\n", " with open(filename, 'w+') as f:\n", " f.write(js_dump)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# SRA" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "s3 = datasets.filesystems.S3FileSystem(anon=True) \n", "sra_dir2studies = {}\n", "sra_study2filepath = {}\n", "for dirpath, dirnames, filenames in s3.walk(\"recount-opendata/recount3/release/human/data_sources/sra/gene_sums/\"):\n", "# care about the how many directories your bucket have\n", " dirpath_ = dirpath.split('/')\n", " if len(dirpath_) == 9:\n", " if dirpath_[-2] in sra_dir2studies:\n", " sra_dir2studies[dirpath_[-2]].append(dirpath_[-1])\n", " else:\n", " sra_dir2studies[dirpath_[-2]] = [dirpath_[-1]]\n", " \n", " for filename in filenames:\n", " if \"G029\" in filename:\n", " file_path = os.path.join(dirpath, filename)\n", " sra_study2filepath[dirpath_[-1]] = file_path" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "for filename, d in {\n", " \"sra_study2filepath.json\": sra_study2filepath,\n", " \"sra_dir2studies.json\": sra_dir2studies,\n", "}.items():\n", " js_dump = json.dumps(d, sort_keys=True, indent=4, separators=(',', \": \"))\n", " with open(filename, 'w+') as f:\n", " f.write(js_dump)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# s3.ls(\"recount-opendata/recount3/release/human/data_sources/sra/gene_sums/00/DRP003300\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.9 ('recount')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "ed875d186ce08f1d09fded8cb618f7757e0d4e9a9ff702057ff3018e00fc337a" } } }, "nbformat": 4, "nbformat_minor": 2 }