Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update goea_nbt3102 notebook #265

Merged
merged 2 commits into from
Mar 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions notebooks/goea_nbt3102.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"subpopulations of cells\n",
"](http://www.nature.com/nbt/journal/v33/n2/full/nbt.3102.html#methods)\n",
"\n",
"Note: you must have the Python package, **xlrd**, installed to run this example. \n",
"Note: you must have the Python packages, **xlrd**, **pandas** and **openpyxl**, installed to run this example. \n",
"\n",
"Note: To create plots, you must have:\n",
" * Python packages: **pyparsing**, **pydot**\n",
Expand Down Expand Up @@ -160,9 +160,7 @@
"metadata": {},
"source": [
"### 2c. Load Background gene set\n",
"In this example, the background is all mouse protein-codinge genes. \n",
"\n",
"Follow the instructions in the `background_genes_ncbi` notebook to download a set of background population genes from NCBI."
"In this example, the background is all mouse protein-codinge genes.",
]
},
{
Expand All @@ -179,7 +177,7 @@
}
],
"source": [
"from genes_ncbi_10090_proteincoding import GENEID2NT as GeneID2nt_mus\n",
"from goatools.test_data.genes_NCBI_10090_ProteinCoding import GENEID2NT as GeneID2nt_mus\n",
"print(len(GeneID2nt_mus))"
]
},
Expand Down Expand Up @@ -251,21 +249,22 @@
}
],
"source": [
"# Data will be stored in this variable\n",
"import os\n",
"geneid2symbol = {}\n",
"import goatools\n",
"# Get xlsx filename where data is stored\n",
"ROOT = os.path.dirname(os.getcwd()) # go up 1 level from current working directory\n",
"din_xlsx = os.path.join(ROOT, \"goatools/test_data/nbt_3102/nbt.3102-S4_GeneIDs.xlsx\")\n",
"ROOT = os.path.dirname(goatools.__file__) # goatool root directory\n",
"din_xlsx = os.path.join(ROOT, \"test_data\", \"nbt_3102\", \"nbt.3102-S4_GeneIDs.xlsx\")\n",
"# Read data\n",
"if os.path.isfile(din_xlsx): \n",
" import xlrd\n",
" book = xlrd.open_workbook(din_xlsx)\n",
" pg = book.sheet_by_index(0)\n",
" for r in range(pg.nrows):\n",
" symbol, geneid, pval = [pg.cell_value(r, c) for c in range(pg.ncols)]\n",
" if geneid:\n",
" geneid2symbol[int(geneid)] = symbol\n",
" import pandas as pd\n",
" df = pd.read_excel(\n",
" din_xlsx,\n",
" header=None, \n",
" names=[\"symbol\", \"geneid\", \"pval\"], \n",
" dtype={\"symbol\": str, \"geneid\": int, \"pval\": float},\n",
" index_col=1,\n",
" ) # requires openpyxl\n",
" geneid2symbol = df[\"symbol\"].to_dict()\n",
" print('{N} genes READ: {XLSX}'.format(N=len(geneid2symbol), XLSX=din_xlsx))\n",
"else:\n",
" raise RuntimeError('FILE NOT FOUND: {XLSX}'.format(XLSX=din_xlsx))"
Expand Down