Skip to content
Snippets Groups Projects
Commit 4e1e14c4 authored by yadit97's avatar yadit97
Browse files

First commit

parent d60edcaa
No related branches found
No related tags found
No related merge requests found
.Rproj.user
.Rhistory
.RData
.Ruserdata
# scRNAseq_tutorial # scRNAseq_tutorial
## Getting started ## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps. To make it easy for you to get started with GitLab, here's a list of recommended next steps.
...@@ -10,10 +8,10 @@ Already a pro? Just edit this README.md and make it your own. Want to make it ea ...@@ -10,10 +8,10 @@ Already a pro? Just edit this README.md and make it your own. Want to make it ea
## Add your files ## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
``` ```
cd existing_repo cd existing_repo
git remote add origin https://git.imp.fu-berlin.de/yadit97/scrnaseq_tutorial.git git remote add origin https://git.imp.fu-berlin.de/yadit97/scrnaseq_tutorial.git
git branch -M main git branch -M main
...@@ -22,29 +20,29 @@ git push -uf origin main ...@@ -22,29 +20,29 @@ git push -uf origin main
## Integrate with your tools ## Integrate with your tools
- [ ] [Set up project integrations](https://git.imp.fu-berlin.de/yadit97/scrnaseq_tutorial/-/settings/integrations) - [ ] [Set up project integrations](https://git.imp.fu-berlin.de/yadit97/scrnaseq_tutorial/-/settings/integrations)
## Collaborate with your team ## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy ## Test and Deploy
Use the built-in continuous integration in GitLab. Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
*** ------------------------------------------------------------------------
# Editing this README # Editing this README {#editing-this-readme}
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
...@@ -53,30 +51,39 @@ When you're ready to make this README your own, just edit this file and use the ...@@ -53,30 +51,39 @@ When you're ready to make this README your own, just edit this file and use the
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name ## Name
Choose a self-explaining name for your project. Choose a self-explaining name for your project.
## Description ## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges ## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals ## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation ## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage ## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support ## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap ## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README. If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing ## Contributing
State if you are open to contributions and what your requirements are for accepting them. State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
...@@ -84,10 +91,13 @@ For people who want to make changes to your project, it's helpful to have some d ...@@ -84,10 +91,13 @@ For people who want to make changes to your project, it's helpful to have some d
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment ## Authors and acknowledgment
Show your appreciation to those who have contributed to the project. Show your appreciation to those who have contributed to the project.
## License ## License
For open source projects, say how it is licensed. For open source projects, say how it is licensed.
## Project status ## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
---
title: "Single Cell RNASeq"
author: "Yadik"
date: "2024-06-03"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Annotate cell types
## Step 1. Load library and your seurat object
```{r}
library(SingleR)
library(Seurat)
library(celldex)
library(dplyr)
library(pheatmap)
sobj= readRDS("C:/Users/yadik/Downloads/bc_tutorial(1).rds")
sobj
```
## Step 2. Prepare inputs for running automatic cell type annotaion
**We need to extract the normalization data using GetAssayData()**
```{r}
sobj_count <- GetAssayData(sobj, layer = "data")
str(sobj_count)
```
**Get the Blueprint and Encode reference data from celldex package:**
```{r}
ref <- celldex::BlueprintEncodeData()
ref
```
## Step 3. Run SingleR to label cell types
```{r}
pred <- SingleR(test=sobj_count, ref = ref, labels = ref$label.main)
pred %>% head()
unique(pred$labels)
```
Next, we put the prediction results back to our seurat object for visualization
```{r}
sobj$labels <- pred[match(rownames(sobj@meta.data), rownames(pred)), "labels"]
sobj@meta.data %>% head()
```
## Step 4. Visualize the data
```{r}
umap_pred <- DimPlot(
sobj, reduction = 'umap', group.by = 'labels', label = TRUE)
umap_pred
```
**Compare with your previous data**
```{r}
umap_sobj <- DimPlot(
sobj, reduction = 'umap', group.by = 'seurat_clusters', label = TRUE)
umap_sobj | umap_pred
```
```{r}
plotScoreHeatmap(pred)
```
## Step 5. Marker-based method: CellMarker v2
**Load the human markers from CellMarker 2.0, file uncludes cell marrkers of different cell types from different tissue in human**
```{r}
human_marker <- read.csv("C:/Users/yadik/OneDrive/Dokumente/Bioinformatik/CellMakerv2_Human.csv")
str(human_marker)
```
**Select marker for ovary from the tissue class column**
```{r}
ovary_marker <- human_marker %>%
filter(species=='Human' & tissue_class=='Ovary') %>%
select(c(3,5,6,7,8,9,16))
ovary_marker %>% head()
```
**Get the markers table from your seurat object**
```{r}
sobj.markers <- FindAllMarkers(sobj, only.pos = TRUE)
sobj.markers %>% head()
```
**Combine CellMarker with our markers sobj.markers**
```{r}
merged_cellmarker <- sobj.markers %>%
filter(p_val_adj<0.05 & avg_log2FC>1 & pct.1 > 0.8 & pct.2 < 0.5) %>%
left_join(ovary_marker[,c(3,4,6)], join_by(gene==marker), relationship = "many-to-many")
merged_cellmarker %>% head()
```
**Let's try to see if there are fibroblast and astrocytes**
```{r}
merged_cellmarker %>%
filter(cluster==2 & cell_type=="Cancer cell") %>%
select(c(7,8,9))
```
From the results, we found PDGRFA, CAV1 and ACTA2 pointing to Fibroblast in cancer cells
Check again using FeaturePlot()
```{r}
genes <- c("PDGFRA", "CAV1", "ACTA2")
FeaturePlot(sobj, features = genes)
```
## Step 6. Annotate the cells
rename cluster 2 to Fibroblasts using RenameIdents()
```{r}
sobj_new <- RenameIdents(sobj, "2" = 'Fibroblasts')
DimPlot(sobj_new, reduction = 'umap', label = TRUE)
```
## Step 7. Differentially expressed genes (Bonus)
Can we distinguish cluster 7?
```{r}
merged_cellmarker %>%
filter(cluster==7 & cell_type=="Cancer cell") %>%
select(c(7,8,9)) %>%
str()
```
```{r}
BiocManager::install("clusterProfiler")
BiocManager::install("org.Hs.eg.db")
BiocManager::install("DOSE")
options(connectionObserver = NULL)
library(clusterProfiler)
library(org.Hs.eg.db)
library(DOSE)
```
```{r}
marker_7_2 <- FindMarkers(sobj, ident.1 = 7, ident.2 = 2)
marker_7_2_sig <- marker_7_2 %>%
filter(abs(avg_log2FC)>=1 & p_val_adj<0.05 & pct.2<0.5)
str(marker_7_2_sig)
```
```{r}
log2 <- marker_7_2_sig$avg_log2FC
names(log2) <- rownames(marker_7_2_sig)
log2_sort <- sort(log2, decreasing = TRUE)
log2_sort[1:5]
```
**Run gene set enrichment analysis:**
```{r}
gse <- gseGO(geneList =log2_sort,
ont="ALL",
keyType="SYMBOL",
nPerm=10000,
OrgDb = "org.Hs.eg.db")
```
Visualize the results
```{r}
dotplot(gse)
```
```
```
Pur the identity back
```{r}
sobj_new <- RenameIdents(sobj, '7' = 'Mesenchymal Cells', '2' = 'Fibroblasts')
DimPlot(sobj_new, reduction = 'umap', label = TRUE)
```
```{r}
```
This diff is collapsed.
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment