├── LICENSE ├── README.md ├── .gitignore └── 01_load_data_from_bigquery.ipynb /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 MIT Laboratory for Computational Physiology 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pittsburgh GOSSIS Datathon (2024) 2 | 3 | This repository contains resources for the Pittsburgh GOSSIS Datathon. GOSSIS is the [Global Open Source Severity of Illness Score](https://gossis.mit.edu/). 4 | 5 | ## Contents 6 | 7 | 1. Getting started 8 | 2. Documentation 9 | 3. Databases on BigQuery 10 | 4. Analysing data with Google Colab 11 | 5. An example in Python 12 | 6. An example in R 13 | 14 | ## 1. Getting started 15 | 16 | The datasets are hosted on Google Cloud, which requires a Gmail account to manage permissions. 17 | 18 | 1. Create a [Gmail account](https://www.google.com/gmail/about/), if you don't already have one. It will be used to manage your access to the resources. 19 | 2. Give your gmail address to the session hosts via the form provided in the data access instructions. 20 | 21 | ## 2. Documentation 22 | 23 | We will be working with two care datasets during the event: 24 | 25 | - WIDS datathon data (GOSSIS subset): https://physionet.org/content/widsdatathon2020/ 26 | - GOSSIS-1 Dataset (eICU only): https://physionet.org/content/gossis-1-eicu 27 | 28 | ## 3. Databases on BigQuery 29 | 30 | BigQuery is a database system that makes it easy to explore data with Structured Query Language ("SQL"). There are several datasets on BigQuery available for you to explore, including `widsdatathon2020` (the WIDS Datathon data) and `gossis_1_eicu` (the GOSSIS-1 eICU Dataset). 31 | 32 | 1. [Open BigQuery](https://console.cloud.google.com/bigquery?project=gossis-datathon). 33 | 2. At the top of the console, select `gossis-datathon` as the project. This indicates the account used for billing. 34 | 3. "Pin" a project to the resources menu to view available datasets. In the Resources menu on the left, click "Add data", "Pin a project", then add the following project names: `physionet-data`. 35 | 4. You should be able preview the data available on these projects using the graphical interface. 36 | 5. Now try running a query. For example, try counting the number of rows in the demo eICU patient table: 37 | 38 | ```SQL 39 | SELECT count(*) 40 | FROM `physionet-data.widsdatathon2020.training_v2` 41 | ``` 42 | 43 | ## 4. Analysing data with Google Colab 44 | 45 | Python is an popular programming language for analysing data. We will explore the data using Python notebooks, which allow code and text to be combined into executable documents. First, try opening a blank document using the link below: 46 | 47 | - [https://colab.research.google.com/](https://colab.research.google.com/) 48 | 49 | ## 5. An example in Python 50 | 51 | Several tutorials are provided below. Requirements for these notebooks are: (1) you have a Gmail account and (2) your Gmail address has been added to the appropriate Google Group by the workshop hosts. 52 | 53 | - Coming shortly... 54 | 55 | ## 6. An example in R 56 | 57 | If you prefer working in R, then you can connect to Google Cloud from your code in a similar way: 58 | 59 | - Coming shortly... 60 | 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /01_load_data_from_bigquery.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "authorship_tag": "ABX9TyPwRiUH6+1baAn6Bo/4j7pR", 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "# Notebook 1: Loading data from BigQuery\n", 33 | "\n", 34 | "The aim of this notebook is to demonstrate how to load data hosted on BigQuery (a Google database engine)." 35 | ], 36 | "metadata": { 37 | "id": "6_XXgy_gjgnl" 38 | } 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "source": [ 43 | "## Prerequisites\n", 44 | "\n", 45 | "- If you do not have a Gmail account, please create one at http://www.gmail.com.\n", 46 | "- If you have not yet signed the data use agreement (DUA) sent by the organizers, please do so now to get access to the dataset." 47 | ], 48 | "metadata": { 49 | "id": "3QJ5WvM9j0rl" 50 | } 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "source": [ 55 | "## Load libraries and connect to the data\n", 56 | "\n", 57 | "Run the following cells to load the Google Cloud libraries needed to connect to the database." 58 | ], 59 | "metadata": { 60 | "id": "fibnXVVkj6le" 61 | } 62 | }, 63 | { 64 | "cell_type": "code", 65 | "source": [ 66 | "# Access data using Google BigQuery.\n", 67 | "from google.colab import auth\n", 68 | "from google.cloud import bigquery\n", 69 | "import os" 70 | ], 71 | "metadata": { 72 | "id": "x0ZVSJFZj_za" 73 | }, 74 | "execution_count": 16, 75 | "outputs": [] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "source": [ 80 | "Before running any queries, you need to first authenticate with Google Cloud. You will be asked to log in using your Gmail account. You will be given a string of verification code, which you will copy and paste into the notebook." 81 | ], 82 | "metadata": { 83 | "id": "53V7iB9WkKDq" 84 | } 85 | }, 86 | { 87 | "cell_type": "code", 88 | "source": [ 89 | "auth.authenticate_user()" 90 | ], 91 | "metadata": { 92 | "id": "1yuPbvkbkheH" 93 | }, 94 | "execution_count": 17, 95 | "outputs": [] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "source": [ 100 | "We'll also set the project details (used for billing)" 101 | ], 102 | "metadata": { 103 | "id": "uzM_VdG7km96" 104 | } 105 | }, 106 | { 107 | "cell_type": "code", 108 | "source": [ 109 | "project_id='gossis-datathon'\n", 110 | "os.environ[\"GOOGLE_CLOUD_PROJECT\"]=project_id" 111 | ], 112 | "metadata": { 113 | "id": "CRh8Y0KlkkUV" 114 | }, 115 | "execution_count": 18, 116 | "outputs": [] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "source": [ 121 | "# \"Querying\" our database with SQL\n", 122 | "\n", 123 | "Now we can start exploring the data. We'll begin by running a simple query to load all columns of the `patient` table to a Pandas DataFrame. The query is written in SQL, a common language for extracting data from databases. The structure of an SQL query is:\n", 124 | "\n", 125 | "```sql\n", 126 | "SELECT \n", 127 | "FROM \n", 128 | "WHERE \n", 129 | "```\n", 130 | "\n", 131 | "`*` is a wildcard that indicates all columns" 132 | ], 133 | "metadata": { 134 | "id": "C9xli8l6kvPj" 135 | } 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "source": [ 140 | "# BigQuery\n", 141 | "\n", 142 | "Our dataset is stored on BigQuery, Google's database engine. We can run our query on the database using some special (\"magic\") [BigQuery syntax](https://googleapis.dev/python/bigquery/latest/magics.html)." 143 | ], 144 | "metadata": { 145 | "id": "K6NjczHXkz-B" 146 | } 147 | }, 148 | { 149 | "cell_type": "code", 150 | "source": [ 151 | "%%bigquery patient --project physionet-data\n", 152 | "\n", 153 | "SELECT *\n", 154 | "FROM `physionet-data.widsdatathon2020.training_v2`" 155 | ], 156 | "metadata": { 157 | "id": "SZxisphFkxWW" 158 | }, 159 | "execution_count": null, 160 | "outputs": [] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "source": [ 165 | "We have now assigned the output to our query to a variable called `patient`. Let's use the `head` method to view the first few rows of our data." 166 | ], 167 | "metadata": { 168 | "id": "zUYNQgXhk_Eq" 169 | } 170 | }, 171 | { 172 | "cell_type": "code", 173 | "source": [ 174 | "# view the top few rows of the patient data\n", 175 | "patient.head()" 176 | ], 177 | "metadata": { 178 | "id": "8QTEN1YblAui" 179 | }, 180 | "execution_count": null, 181 | "outputs": [] 182 | } 183 | ] 184 | } --------------------------------------------------------------------------------