-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.qmd
executable file
·235 lines (171 loc) · 13.1 KB
/
index.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
---
title: "Introduction to Python"
---
## Introduction
This workshop is designed to give beginners a solid foundation in **Python programming**, with a specific focus on applications in cancer biology. Participants will gain a thorough understanding of essential programming concepts through a blend of theoretical lessons, hands-on coding exercises, and practical applications.
The workshop will cover essential programming concepts and gradually introduce more advanced topics, with a focus on using the `pandas` library for efficient data handling and analysis and `plotnine` (`ggplot`) library for data visualization. By the end of the workshop, attendees will be equipped with the skills to enhance the reproducibility and efficiency of scientific research through powerful data analysis tools and effective visualization techniques.
## Learning Objectives
Participants will gain the following skills:
- Proficiency in using Python for data analysis.
- Basic Python programming skills.
- Reading, tidying, and joining datasets using `pandas` library.
- Data manipulation and transformation using `pandas` library.
- Creating various types of plots using `plotnine` library.
## Prerequisites
Before starting this course you will need to ensure that your computer is set up with the required software. If you have any difficulty installing any of this software then please contact one of the trainers for help.
### Step 1: Installing Python
There are multiple ways you can use Python at Peter Mac. The easiest and most convenient way is to install Python on your own computer. However, if you prefer to avoid the installation process or need additional computational capabilities the alternative option is to use the cluster.
#### Install Python on your own computer
For new users, we recommend installing **Anaconda**. Anaconda conveniently installs *Python*, the *Jupyter Notebook*, and other commonly used packages.
```{=html}
<details>
<summary style="color: #4492B4; font-weight: 600;" >
Windows
</summary>
```
If you have admin rights, follow [Anaconda Navigator Installation](https://docs.anaconda.com/free/anaconda/install/). Otherwise, contact the IT Support.
</details>
```{=html}
<details>
<summary style="color: #4492B4; font-weight: 600;" >
macOS
</summary>
```
Install the Anaconda Navigator from the PeterMac Self-Service → Research Applications tab or from the [Anaconda Navigator Installation](https://docs.anaconda.com/free/anaconda/install/).
</details>
```{=html}
<details>
<summary style="color: #4492B4; font-weight: 600;" >
Linux
</summary>
```
Install the Anaconda Navigator from [here](https://docs.anaconda.com/anaconda/install/linux/).
</details>
- If you are using Anaconda/Conda on your laptop/desktop on the Peter Mac network you may need to provide proxy settings by adding the following proxy servers as shown [here](https://confluence.petermac.org.au/display/IC/Installation+Guides#InstallationGuides-HowtoinstallPythononyourowncomputer?)
- To update the .condarc file follow the [quick start guide](https://docs.anaconda.com/psm-cloud/quickstart/#using-anaconda-behind-a-firewall-or-proxy-optional).
If you are having trouble opening the Anaconda Navigator please follow their [troubleshooting page](https://docs.anaconda.com/free/navigator/troubleshooting/#:~:text=Navigator%20error%20on%20start%20up,condarc%20file%20and%20restart%20Navigator).
Once installed, open the anaconda-navigator directly or type the following command in the terminal to open it.
```{python}
#| eval: false
anaconda-navigator
```
![Figure 1: Anaconda Navigator](vignettes/images/anaconda-navigator.png){fig-align="center"}
**Useful links:**
- [Getting started with Navigator](https://docs.anaconda.com/free/navigator/getting-started/)
- [How to create a Python environment?](https://docs.anaconda.com/free/navigator/tutorials/create-python35-environment/)
- [Creating and managing Python environments](https://docs.anaconda.com/free/navigator/tutorials/manage-environments.html#:~:text=In%20the%20environments%20list%2C%20select,IPython%20Console%2C%20or%20Jupyter%20Notebook)
- [Using multiple versions of Python with Navigator](https://docs.anaconda.com/free/navigator/tutorials/use-multiple-python-versions/)
- [Installing and managing Python packages](https://docs.anaconda.com/free/navigator/tutorials/manage-packages/)
- [How to install and run Pandas from Anaconda Navigator?](https://docs.anaconda.com/free/navigator/tutorials/pandas/)
- [How to use special characters in username/password for HTTP proxy?](https://superuser.com/questions/273799/how-to-use-special-characters-in-username-password-for-http-proxy)
#### Use Python on the cluster?
Follow the quick start guide on [this page](https://confluence.petermac.org.au/display/BIOIN/Conda).
### Step 2: Installing Integrated Development Environment (IDE)
Once Python is installed, the next step is to install a preferred Integrated Development Environment (IDE) to start coding with Python. If you are a new user, we suggest using the **Jupyter Notebook**. Alternatively, if you are accustomed to using R Studio, it can also serve as a platform for Python coding.
#### Install Jupyter Notebook on your own computer
- Open Anaconda Navigator and click install Jupyter Notebook.
- Launch the Jupyter Notebook directly from the Anaconda Navigator or start the notebook server from the command line by typing the following command.
```{python}
#| eval: false
jupyter notebook
```
- You should see the notebook home page open in your web browser.
![Figure 2: Jupyter Notebook](vignettes/images/jupyter-notebook.png)
- To install Jupyter Notebook, see [Installing Jupyter Notebook](https://docs.jupyter.org/en/latest/install.html).
**Useful links:**
- [Jupyter Notebook Documentation](https://jupyter-notebook.readthedocs.io/en/latest/)
- [How to use Jupyter Notebooks - DataCamp](https://www.datacamp.com/tutorial/tutorial-jupyter-notebook)
- [Jupyter Notebook: An Introduction](https://realpython.com/jupyter-notebook-introduction/)
### Use Jupyter Notebook on Open OnDemand
Follow the guide on [this page](https://confluence.petermac.org.au/display/BIOIN/Using+Open+OnDemand#UsingOpenOnDemand-LaunchingJupyterNotebook).
**Useful links:**
- [Using Jupyter on the cluster](https://confluence.petermac.org.au/display/BIOIN/Using+Jupyter+on+the+Cluster)
- [How to login and use Ope OnDemand](https://confluence.petermac.org.au/display/BIOIN/Using+Open+OnDemand#UsingOpenOnDemand-Howtologin)
### Use R Studio for Python coding
The [RStudio IDE](https://posit.co/download/rstudio-desktop/) is a free and open-source IDE for Python, as well as R. You can write scripts, import modules, and interactively use Python within the RStudio IDE. Whether your intention is to seamlessly combine R and Python or solely concentrate on Python programming, there are several ways you can advance your coding:
- [Run Python Scripts in the RStudio IDE](https://posit.co/wp-content/themes/Posit/public/markdown-blogs/three-ways-to-program-in-python-with-rstudio/index.html#1-run-python-scripts-in-the-rstudio-ide)
- [Use R and Python in a single project with the reticulate Package](https://posit.co/wp-content/themes/Posit/public/markdown-blogs/three-ways-to-program-in-python-with-rstudio/index.html#2-use-r-and-python-in-a-single-project-with-the-reticulate-package)
- [Use your Python editor of choice within RStudio tools](https://posit.co/wp-content/themes/Posit/public/markdown-blogs/three-ways-to-program-in-python-with-rstudio/index.html#3-use-your-python-editor-of-choice-within-rstudio-tools)
### Step 3: Installing a Python library
If you are currently using Python using conda (or Anaconda) or if you are using the cluster, a Python library can be installed with Anaconda or Miniconda. For example, to install the `pandas` and `plotnine` libraries of Python use the following command on the terminal.
```{python}
#| eval: false
conda install conda-forge::pandas, plotnine, matplotlib, numpy
```
If you installed Python using Pip, then a Python library can be installed via pip from Python Package Index ([PyPI](https://pypi.org/project/pandas)). To install the required libraries of Python use the following command on the terminal.
```{python}
#| eval: false
pip install pandas, matplotlib, plotnine, numpy
```
If Anaconda Navigator is installed and you prefer to use the Navigator instead of typing commands on a terminal refer to [Installing and managing Python packages](https://docs.anaconda.com/free/navigator/tutorials/manage-packages/).
**Useful links:**
- [Installing conda packages](https://docs.anaconda.com/free/anaconda/packages/install-packages.html)
- [Installing and managing Python packages](https://docs.anaconda.com/free/navigator/tutorials/manage-packages/)
- [Python Package Index (PyPI)](https://pypi.org/project/pandas)
## Data
The Metabric study characterized the genomic mutations and gene expression profiles for 2509 primary breast tumours. In addition to the gene expression data generated using microarrays, genome-wide copy number profiles were obtained using SNP microarrays. Targeted sequencing was performed for 2509 primary breast tumours, along with 548 matched normals, using a panel of 173 of the most frequently mutated breast cancer genes as part of the Metabric study.
**Refrences:**
- [Curtis *et al.*, Nature 486:346-52, 2012](https://pubmed.ncbi.nlm.nih.gov/22522925)
- [Pereira *et al.*, Nature Communications 7:11479, 2016](https://www.ncbi.nlm.nih.gov/pubmed/27161491)
Both the clinical data and the gene expression values were downloaded from [cBioPortal](https://www.cbioportal.org/study/summary?id=brca_metabric).
We excluded observations for patient tumor samples lacking expression data, resulting in a data set with fewer rows.
The following table illustrates the column names and descriptions of the metabric data frame we will be using for subsequent analysis.
::: scrolling
```{=html}
<table class="no-spacing" cellspacing="0" >
<caption>Description of column names in the metabric dataset</caption>
<thead>
<tr>
<th>Column Name</th>
<th style="padding-left: 120px; " >Description</th>
</tr>
</thead>
<tbody>
<tr><td>Patient_ID</td> <td>#Identifier to uniquely specify a patient.</td></tr>
<tr><td>Cohort</td> <td>Cohort</td></tr>
<tr><td>Age_at_diagnosis</td> <td>Age at Diagnosis</td></tr>
<tr><td>Survival_time/Os_Months</td> <td>Overall survival in months since initial diagonosis.</td></tr>
<tr><td>Survival_status/Os_Status</td> <td>Overall patient survival status.</td></tr>
<tr><td>Vital_status</td> <td>The survival state of the person.</td></tr>
<tr><td>Chemotherapy</td> <td>Chemotherapy.</td></tr>
<tr><td>RadioTherapy</td> <td>RadioTherapy</td></tr>
<tr><td>Tumor_size</td> <td>Tumor size in mm.</td></tr>
<tr><td>Tumor_stage</td> <td>Tumor stage.</td></tr>
<tr><td>Neoplasm_histologic_grade/Grade</td> <td>Numeric value to express the degree of abnormality of cancer cells, a measure of differentiation and aggressiveness.</td></tr>
<tr><td>Lymph_nodes_examined_positive</td> <td>Number of lymphnodes positive</td></tr>
<tr><td>Lymph_nodes_status</td> <td>Lymphnodes status</td></tr>
<tr><td>Cancer_type</td> <td>Cancer Type</td></tr>
<tr><td>ER_status/Er_Ihc</td> <td>ER Status measured by IHC</td></tr>
<tr><td>PR_Status</td> <td>PR Status</td></tr>
<tr><td>HER2_status</td> <td>HER2 Status</td></tr>
<tr><td>HER2_status_measured_by_SNP6</td> <td>HER2 status measured by SNP6</td></tr>
<tr><td>PAM50/Claudin_Subtype</td> <td>Pam50 + Claudin-low subtype.</td></tr>
<tr><td>3-gene_classifier/Threegene</td> <td>3-Gene classifier subtype</td></tr>
<tr><td>Nottingham_prognostic_index/Npi</td> <td>Nottingham prognostic index</td></tr>
<tr><td>Cellularity</td> <td>Tumor Content</td></tr>
<tr><td>Integrative_cluster/Intclust</td> <td>Integrative Cluster</td></tr>
<tr><td>Mutation_count</td> <td>Mutation count</td></tr>
<tr><td>FOXA1</td> <td>FOXA1 Expression data</td></tr>
<tr><td>MLPH</td> <td>MLPH Expression data</td></tr>
<tr><td>ESR1</td> <td>ESR1 Expression data</td></tr>
<tr><td>ERBB2</td> <td>ERBB2 Expression data</td></tr>
<tr><td>TP53</td> <td>TP53 Expression data</td></tr>
<tr><td>PIK3CA</td> <td>PIK3CA Expression data</td></tr>
<tr><td>GATA3</td> <td>GATA3 Expression data</td></tr>
<tr><td>PGR</td> <td>PGR Expression data</td></tr>
<tr><td>Cancer_Type_Detailed</td> <td>Cancer Type Detailed</td></tr>
<tr><td>Oncotree_Code</td> <td>Oncotree Code</td></tr>
<tr><td>Sample_Type</td> <td>The type of sample (i.e., normal, primary, met, recurrence).</td></tr>
<tr><td>Tmb_Nonsynonymous</td> <td>TMB (nonsynonymous)</td></tr>
</tbody>
</table>
```
:::
## Credits and Acknowledgement
These content were adapted from the following course materials:
- [R for Data Science book](https://r4ds.had.co.nz/index.html)
- [OHI Data Science Training](http://ohi-science.org/data-science-training/index.html)
- [Data Carpentry](https://datacarpentry.org)
- [WEHI tidyr coursebook](https://bookdown.org/ansellbr/WEHI_tidyR_course_book/) by Brendan R. E. Ansell
- content developed by Maria Doyle.
------------------------------------------------------------------------