Skip to content

Commit

Permalink
Merge pull request #23 from soelmicheletti/main
Browse files Browse the repository at this point in the history
Corrected file path in cobra
  • Loading branch information
marouenbg authored Oct 12, 2023
2 parents 7763a55 + e01b1df commit bd22b18
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions netbooks/netZooPy/cobra.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "7e26ed88",
"metadata": {},
"source": [
"# Decomposing gene co-expression networks with COBRA (Python version)\n",
Expand All @@ -12,6 +13,7 @@
},
{
"cell_type": "markdown",
"id": "8520e757",
"metadata": {},
"source": [
"## 1. Introduction\n",
Expand All @@ -29,6 +31,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "fe567bf2",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -37,6 +40,7 @@
},
{
"cell_type": "markdown",
"id": "c27aff27",
"metadata": {},
"source": [
"On the server, we need to change the working directory to the `data` folder of the current useer."
Expand All @@ -45,6 +49,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "7e5dc5ad",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -55,6 +60,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "402463e2",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -66,18 +72,20 @@
{
"cell_type": "code",
"execution_count": null,
"id": "1f43ac8c",
"metadata": {},
"outputs": [],
"source": [
"gene_expression = pd.read_csv(ppath+\"gene_expression_thca.csv\", index_col = 0).to_numpy()\n",
"metadata = pd.read_csv(ppath+\"data/thca_metadata.csv\", index_col = 0)\n",
"metadata = pd.read_csv(ppath+\"thca_metadata.csv\", index_col = 0)\n",
"batch = metadata['batch'].to_numpy()\n",
"cancer = metadata['status'].to_numpy()\n",
"sex = metadata['sex'].to_numpy()"
]
},
{
"cell_type": "markdown",
"id": "f01301b9",
"metadata": {},
"source": [
"Here gene_expression is a gene expression matrix for 19711 genes and 572 samples. Batch, cancer, and sex are sample-specific metadata as vectors of length 572."
Expand All @@ -86,6 +94,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "eefe741a",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -97,6 +106,7 @@
},
{
"cell_type": "markdown",
"id": "e23e09b2",
"metadata": {},
"source": [
"## 2. Applications of COBRA\n",
Expand All @@ -114,6 +124,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "56c0ce1f",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -122,6 +133,7 @@
},
{
"cell_type": "markdown",
"id": "19e30957",
"metadata": {},
"source": [
"For batch correction, the design matrix must contain an intercept in the first column, and the batches (encoded usy dummy coding for identifiability) in the remaining columns. "
Expand All @@ -130,6 +142,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "008a3832",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -140,6 +153,7 @@
},
{
"cell_type": "markdown",
"id": "db8d69f1",
"metadata": {},
"source": [
"We get a design matrix with 17 covariates (an intercept and 16 for the dummy coding) for the 572 samples in our study. "
Expand All @@ -148,6 +162,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "45b0a40d",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -156,6 +171,7 @@
},
{
"cell_type": "markdown",
"id": "9556f9b9",
"metadata": {},
"source": [
"We are now ready to fit COBRA"
Expand All @@ -164,6 +180,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "c0b3776b",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -172,6 +189,7 @@
},
{
"cell_type": "markdown",
"id": "f07cae8c",
"metadata": {},
"source": [
"The batch corrected network consider only the mean effect after removing the contribution of the batch variables. It is computed as follows. "
Expand All @@ -180,6 +198,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "feb8b5a5",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -188,6 +207,7 @@
},
{
"cell_type": "markdown",
"id": "3c577a75",
"metadata": {},
"source": [
"### 3.2 Differential co-expression analysis\n",
Expand All @@ -197,6 +217,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "fc0a5747",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -205,6 +226,7 @@
},
{
"cell_type": "markdown",
"id": "21a412df",
"metadata": {},
"source": [
"In this case, the design matrix contains an intercept an a second column with an indicator for cancer/ healthy. The additional columns are for the variables we want to adjust for. Similarly as before, we consider the batch variable. "
Expand All @@ -213,6 +235,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d26518b1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -224,6 +247,7 @@
},
{
"cell_type": "markdown",
"id": "0df93493",
"metadata": {},
"source": [
"We are now ready to fit COBRA and extract the component corresponding to the differential co-expression. Since the indicator variable for cancer is the second column in our design matrix, the COBRA-adjusted differential co-expression network corresponds to the second component of COBRA's decomposition. "
Expand All @@ -232,6 +256,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "3887dba5",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -241,6 +266,7 @@
},
{
"cell_type": "markdown",
"id": "15b8e757",
"metadata": {},
"source": [
"### 3.3 Identifying the component for a covariate of interest\n",
Expand All @@ -251,6 +277,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "c3f136eb",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -261,6 +288,7 @@
},
{
"cell_type": "markdown",
"id": "78f33e7b",
"metadata": {},
"source": [
"With this design, the last component of COBRA's decomposition describes the sex differes in cancer between male and females. "
Expand All @@ -269,6 +297,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a55644d4",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -278,6 +307,7 @@
},
{
"cell_type": "markdown",
"id": "8286994c",
"metadata": {},
"source": [
"## Reference\n",
Expand All @@ -288,7 +318,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -302,7 +332,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit bd22b18

Please sign in to comment.