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

modify one_metric_df function and update meta.yml in propd #5682

Merged
merged 2 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion modules/nf-core/propr/propd/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ output:
pattern: "*.propd.tsv"
- fdr:
type: file
description: (optional) propr fdr table
description: (optional) propd fdr table
pattern: "*.fdr.tsv"
- adj:
type: file
description: (optional) propd adj table
pattern: "*.adj.csv"
- warnings:
type: file
description: propd warnings
pattern: "*.warnings.txt"
- session_info:
type: file
description: dump of R SessionInfo
Expand Down
39 changes: 21 additions & 18 deletions modules/nf-core/propr/propd/templates/propd.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,27 @@ read_delim_flexible <- function(file, header = TRUE, row.names = 1, check.names
#'
#' @param object propd object
one_metric_df <- function(object){
result <- getResults(object)
genes <- unique(c(result\$Pair, result\$Partner))

empty_matrix <- matrix(NA, nrow = length(genes), ncol = length(genes), dimnames = list(genes, genes))

if (object@active == "theta_d"){
metric <- "theta"
}else{
metric <- object@active
}

for (i in 1:nrow(result)) {
row_name <- result\$Pair[i]
col_name <- result\$Partner[i]
empty_matrix[row_name, col_name] <- result[[metric]][i]
empty_matrix[col_name, row_name] <- result[[metric]][i]
}
return(empty_matrix)
results <- getResults(object)
#keep only the metric of interest
one_metric <- cbind(results\$Partner, results\$Pair, results\$theta)
colnames(one_metric) <- c("Partner", "Pair", "theta")
one_metric <- as.data.frame(one_metric)

# Extract the unique gene names
gene_names <- sort(unique(c(one_metric\$Partner, one_metric\$Pair)))
# Initialize a square matrix with NA
square_matrix <- matrix(NA, nrow = length(gene_names), ncol = length(gene_names))
rownames(square_matrix) <- gene_names
colnames(square_matrix) <- gene_names

# Use the `match` function to get the row and column indices
row_indices <- match(one_metric\$Partner, gene_names)
col_indices <- match(one_metric\$Pair, gene_names)
# Use these indices to populate the matrix
square_matrix[cbind(row_indices, col_indices)] <- one_metric[["theta"]]
# Populate the reverse pairs to ensure symmetry
square_matrix[cbind(col_indices, row_indices)] <- one_metric[["theta"]]
return(square_matrix)
}

#' Extract the differential proportionality cutoff for a specified FDR value.
Expand Down
18 changes: 9 additions & 9 deletions modules/nf-core/propr/propd/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-04-16T11:55:35.703293"
"timestamp": "2024-05-23T13:10:06.778954"
},
"Test propr/propd using theta_e and boxcox permutation - results": {
"content": [
Expand All @@ -31,7 +31,7 @@
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-04-16T11:59:33.28078"
"timestamp": "2024-05-23T13:13:35.158486"
},
"Test propr/propd using theta_e permutation - results": {
"content": [
Expand All @@ -48,7 +48,7 @@
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-04-16T11:57:24.038188"
"timestamp": "2024-05-23T13:12:03.500722"
},
"versions": {
"content": [
Expand All @@ -60,7 +60,7 @@
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-04-16T11:53:45.165637"
"timestamp": "2024-05-23T13:07:07.588326"
},
" - results": {
"content": [
Expand All @@ -77,7 +77,7 @@
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-04-16T14:13:47.602525"
"timestamp": "2024-05-23T13:16:44.428551"
},
" Test propr/propd using default boxcox permutation - results": {
"content": [
Expand All @@ -94,7 +94,7 @@
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-04-16T11:55:32.476341"
"timestamp": "2024-05-23T13:10:02.25738"
},
"Test propr/propd using default permutation - results": {
"content": [
Expand All @@ -111,7 +111,7 @@
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-04-16T11:53:43.056295"
"timestamp": "2024-05-23T13:07:04.720183"
},
"Test propr/propd with adjacency matrix - adj": {
"content": [
Expand All @@ -120,14 +120,14 @@
{
"id": "test"
},
"test.adj.csv:md5,f9d19255f9400e6c4daa01f86d74f017"
"test.adj.csv:md5,9da907136fba72b0e098c7fbacbeb837"
]
]
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-04-16T14:13:47.427246"
"timestamp": "2024-05-23T13:16:38.527389"
}
}
Loading