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

Pathway Enrichment Analysis #86

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
added pathway enrichment analysis
  • Loading branch information
bouchetj committed Sep 5, 2024
commit 62eefca8cff12443d7c3715f1e3e89795c1036e0
3 changes: 3 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ diffexp:
# model: ~jointly_handled + treatment_1 + treatment_2
model: ""

pathway:
# Generates the Hallmark pathway analysis and heatmap
activate: True

params:
cutadapt-pe: ""
Expand Down
8 changes: 8 additions & 0 deletions workflow/envs/pathway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
channels:
- conda-forge
- bioconda
- nodefaults
dependencies:
- r-gsva
- r-msigdbr
- r-pheatmap
3 changes: 3 additions & 0 deletions workflow/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def get_final_output():
final_output.extend(
expand("results/pca.{variable}.svg", variable=pca_variables)
)
if config["pathway"]["activate"]:
final_output.append("results/pathway/hallmark_GSVA.csv")
final_output.append("results/pathway/hallmark_GSVA.svg")
return final_output


Expand Down
12 changes: 12 additions & 0 deletions workflow/rules/pathway.smk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
rule GSVA:
input:
"results/deseq2/normcounts.tsv"
output:
"results/pathway/hallmark_GSVA.csv",
"results/pathway/hallmark_GSVA.svg",
log:
"logs/pathway/gsva.log",
conda:
"../envs/pathway.yaml"
script:
"../scripts/pathway.R"
8 changes: 8 additions & 0 deletions workflow/schemas/config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ properties:
type: string
required:
- contrasts

pathway:
type: object
properties:
activate:
type: boolean
required:
- activate

params:
type: object
Expand Down
39 changes: 39 additions & 0 deletions workflow/scripts/pathway.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
library("msigdbr")
library("GSVA")
library("pheatmap")

species_name <- snakemake@config[["ref"]][["species"]]
species_name <- gsub("(^|\\s)([a-z])", "\\1\\U\\2", tools::toTitleCase(gsub("_", " ", species_name)), perl=TRUE)

# Load just the Hallmark gene sets from MSigDB
gene_sets = msigdbr(species = species_name, category = 'H')

# Format and convert to GMT
gene_sets <- gene_sets[,c("gs_name","ensembl_gene")]
gene_sets <- gene_sets[!duplicated(gene_sets),]
gmt <- split(x = gene_sets$ensembl_gene, f = gene_sets$gs_name)

# Load the data
norm_counts <- read.table(snakemake@input[[1]], sep='\t', header=1, row.names = "gene")
norm_counts_log <- log2(norm_counts + 1)

# Run GSVA
gsva.param <- gsvaParam(as.matrix(norm_counts_log), gmt, kcdf="Poisson")
data.gsva <- gsva(gsva.param)

# Write it out; look at this table as a heatmap in python
write.table(data.gsva, 'hallmark_GSVA.csv', sep=',', col.names= NA, file = snakemake@output[[1]])

# Save heatmap
svg(snakemake@output[[2]])
pheatmap(data.gsva,
scale = "row",
clustering_method = "complete",
clustering_distance_rows = "euclidean",
clustering_distance_cols = "euclidean",
show_rownames = TRUE,
show_colnames = TRUE,
color = colorRampPalette(c("navy", "white", "firebrick3"))(50),
main = "GSVA Heatmap"
)
dev.off()
Loading