Skip to content

Instantly share code, notes, and snippets.

@drcjar
Last active November 17, 2022 13:52
Show Gist options
  • Save drcjar/725c5e503d42c777b6dee8fb23e0af72 to your computer and use it in GitHub Desktop.
Save drcjar/725c5e503d42c777b6dee8fb23e0af72 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "f6f70318",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "14c81e03",
"metadata": {},
"outputs": [],
"source": [
"import xlrd"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c2370d51",
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"gerd_instrument_snps_PhenoScanner_GWAS.tsv\", sep=\"\\t\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1164f895",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>snp</th>\n",
" <th>rsid</th>\n",
" <th>hg19_coordinates</th>\n",
" <th>hg38_coordinates</th>\n",
" <th>a1</th>\n",
" <th>a2</th>\n",
" <th>trait</th>\n",
" <th>efo</th>\n",
" <th>study</th>\n",
" <th>pmid</th>\n",
" <th>...</th>\n",
" <th>beta</th>\n",
" <th>se</th>\n",
" <th>p</th>\n",
" <th>direction</th>\n",
" <th>n</th>\n",
" <th>n_cases</th>\n",
" <th>n_controls</th>\n",
" <th>n_studies</th>\n",
" <th>unit</th>\n",
" <th>dataset</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>rs2815749</td>\n",
" <td>rs2815749</td>\n",
" <td>chr1:72814783</td>\n",
" <td>chr1:72349100</td>\n",
" <td>G</td>\n",
" <td>A</td>\n",
" <td>Childhood BMI</td>\n",
" <td>EFO_0004340</td>\n",
" <td>EGGC</td>\n",
" <td>26604143</td>\n",
" <td>...</td>\n",
" <td>0.0579</td>\n",
" <td>0.0102</td>\n",
" <td>1.560000e-08</td>\n",
" <td>+</td>\n",
" <td>35661</td>\n",
" <td>0</td>\n",
" <td>35661</td>\n",
" <td>20</td>\n",
" <td>SDS</td>\n",
" <td>EGGC_Childhood-BMI_EUR_2016</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1 rows × 22 columns</p>\n",
"</div>"
],
"text/plain": [
" snp rsid hg19_coordinates hg38_coordinates a1 a2 \\\n",
"0 rs2815749 rs2815749 chr1:72814783 chr1:72349100 G A \n",
"\n",
" trait efo study pmid ... beta se \\\n",
"0 Childhood BMI EFO_0004340 EGGC 26604143 ... 0.0579 0.0102 \n",
"\n",
" p direction n n_cases n_controls n_studies unit \\\n",
"0 1.560000e-08 + 35661 0 35661 20 SDS \n",
"\n",
" dataset \n",
"0 EGGC_Childhood-BMI_EUR_2016 \n",
"\n",
"[1 rows x 22 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head(1)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "fc19eacd",
"metadata": {},
"outputs": [],
"source": [
"thresh1 = 5e-8 # gwas threshold 1\n",
"thresh2 = 1e-5 # gwas threshold 2"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "02c3784f",
"metadata": {},
"outputs": [],
"source": [
"df.trait = df.trait.str.upper() # capitalize traits"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "b095ada5",
"metadata": {},
"outputs": [],
"source": [
"df = df[df.trait.str.contains('BMI|FAT|MASS|BODY|OBESITY|HIP|CIRCUMFERENCE')] # select obesity related ones"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "431aa376",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"38"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.snp.nunique()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "5284b343",
"metadata": {},
"outputs": [],
"source": [
"df = df[df.study != 'Neale B'] # lets not include 'Neale B'"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "9c1dc257",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.snp.nunique()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "538499a4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[df.p < thresh1].snp.nunique()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "7ec19f2d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['rs2815749', 'rs13107325', 'rs205262', 'rs1716171', 'rs9940128',\n",
" 'rs9636202'], dtype=object)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[df.p < thresh1].snp.unique()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e11c157e",
"metadata": {},
"outputs": [],
"source": [
"pd.DataFrame(df[df.p < thresh1]).to_csv('thresh1_snps_sans_neale_b.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "4108a863",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[df.p < thresh2].snp.nunique()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "828a813e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['rs2815749', 'rs13107325', 'rs329122', 'rs205262', 'rs2396766',\n",
" 'rs1716171', 'rs9940128', 'rs7206608', 'rs9636202'], dtype=object)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[df.p < thresh2].snp.unique()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "2bf3e50b",
"metadata": {},
"outputs": [],
"source": [
"pd.DataFrame(df[df.p < thresh2]).to_csv('thresh2_snps_sans_neale_b.csv', index=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment