Skip to content

Commit

Permalink
Change: Use caret for one-hot encoding sample_metadata in mldm
Browse files Browse the repository at this point in the history
  • Loading branch information
dileep-kishore committed Nov 9, 2021
1 parent 1284ea8 commit 9ddff41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions micone/pipelines/envs/micone-mldm/env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ channels:
dependencies:
- python=3.8
- r-base
- r-caret
- openjdk
- pip>=20.2.4
18 changes: 11 additions & 7 deletions micone/pipelines/templates/network_inference/direct/mldm.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#!/usr/bin/env Rscript

library(mLDM)
library(caret)

otu_file <- "${otu_file}"
sample_metadata <- "${sample_metadata}"
Z_mean <- ${Z_mean}
max_iteration <- ${max_iteration}
corr_file <- "${meta.id}_corr.tsv"

read_data <- function(datafile) {
data <- read.table(datafile, header=TRUE, comment.char="", sep="\\t")
data.rownames <- data[, 1]
data <- data.matrix(data[, 2:ncol(data)])
rownames(data) <- data.rownames
return(data)
read_data <- function(tablefile) {
table <- read.table(tablefile, header=TRUE, comment.char="", sep="\\t")
table.rownames <- table[, 1]
table <- table[, 2:ncol(table)]
dmy <- dummyVars(" ~ .", data=table)
table.frame <- data.frame(predict(dmy, newdata=table))
table.matrix <- data.matrix(table.frame)
rownames(table.matrix) <- table.rownames
return(table.matrix)
}

otu <- read_data(otu_file)
sample.md <- read_data(sample_metadata) # Must be purely numeric metadata
sample.md <- read_data(sample_metadata) # Must be purely numeric or categorical metadata

mldmNetwork <- mLDM(X=t(otu), M=sample.md, Z_mean=Z_mean, max_iteration=max_iteration, verbose=TRUE)

Expand Down

0 comments on commit 9ddff41

Please sign in to comment.