Skip to content

Commit

Permalink
Add model matrix as output in rule to allow downstream rules to make …
Browse files Browse the repository at this point in the history
…use of it e.g., contrasts (#30)
  • Loading branch information
bednarsky authored Jan 8, 2025
1 parent f0c40b1 commit 0d22c8c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions workflow/rules/dea.smk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rule dea:
output:
dea_results = os.path.join(result_path,'{analysis}','results.csv'),
lmfit_object = os.path.join(result_path,'{analysis}','lmfit_object.rds'),
model_matrix = os.path.join(result_path,'{analysis}','model_matrix.csv'),
resources:
mem_mb=config.get("mem", "16000"),
threads: config.get("threads", 1)
Expand Down
3 changes: 2 additions & 1 deletion workflow/scripts/limma.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ metadata_path <- snakemake@input[[2]]
# outputs
dea_result_path <- snakemake@output[["dea_results"]]
lmfit_object_path <- snakemake@output[["lmfit_object"]]
model_matrix_path <- snakemake@output[["model_matrix"]]

# parameters
feature_annotation <- snakemake@params[["feature_annotation"]]
Expand Down Expand Up @@ -94,7 +95,7 @@ for(col in names(reference_levels)){
model_matrix <- model.matrix(design, metadata)
# save model matrix
# write.csv(model_matrix, file=file.path(result_dir,"model_matrix.csv"))
fwrite(as.data.frame(model_matrix), file=file.path(result_dir,"model_matrix.csv"), row.names=TRUE)
fwrite(as.data.frame(model_matrix), file=file.path(model_matrix_path), row.names=TRUE)

# check if the model represented by the design matrix has full rank ie linearly independent columns, which is required to make the model identifiable!
# new: more efficient and computationally stable compared to the svd() function, especially for large matrices, and it does not require rounding the singular values or checking for non-zero values.
Expand Down

0 comments on commit 0d22c8c

Please sign in to comment.