### R code from vignette source 'biosigner.Rnw' ################################################### ### code chunk number 1: style-Sweave ################################################### BiocStyle::latex() ################################################### ### code chunk number 2: biosigner.Rnw:62-63 ################################################### library(biosigner) ################################################### ### code chunk number 3: biosigner.Rnw:68-69 ################################################### data(diaplasma) ################################################### ### code chunk number 4: biosigner.Rnw:74-78 ################################################### attach(diaplasma) strF(dataMatrix) strF(sampleMetadata) strF(variableMetadata) ################################################### ### code chunk number 5: biosigner.Rnw:95-97 (eval = FALSE) ################################################### ## with(sampleMetadata, plot(age, bmi, cex = 1.5, col = ifelse(type == "T1", "blue", "red"))) ## legend("topleft", cex = 1.5, legend = paste0("T", 1:2), text.col = c("blue", "red")) ################################################### ### code chunk number 6: biosigner.Rnw:100-104 ################################################### pdf("biosigner-figCovariate.pdf") with(sampleMetadata, plot(age, bmi, cex = 1.5, col = ifelse(type == "T1", "blue", "red"))) legend("topleft", cex = 1.5, legend = paste0("T", 1:2), text.col = c("blue", "red")) dev.off() ################################################### ### code chunk number 7: biosigner.Rnw:119-123 ################################################### featureSelVl <- variableMetadata[, "mzmed"] >= 450 & variableMetadata[, "mzmed"] < 500 sum(featureSelVl) dataMatrix <- dataMatrix[, featureSelVl] variableMetadata <- variableMetadata[featureSelVl, ] ################################################### ### code chunk number 8: biosigner.Rnw:126-129 (eval = FALSE) ################################################### ## set.seed(123) ## diaSign <- biosign(dataMatrix, sampleMetadata[, "type"], bootI = 5) ## set.seed(NULL) ################################################### ### code chunk number 9: biosigner.Rnw:132-135 ################################################### set.seed(123) diaSign <- biosign(dataMatrix, sampleMetadata[, "type"], bootI = 5, plotL = FALSE) set.seed(NULL) ################################################### ### code chunk number 10: biosigner.Rnw:138-139 ################################################### plot(diaSign, file.pdfC = "biosigner-figTier.pdf") ################################################### ### code chunk number 11: biosigner.Rnw:173-174 (eval = FALSE) ################################################### ## plot(diaSign, typeC = "boxplot") ################################################### ### code chunk number 12: biosigner.Rnw:177-178 ################################################### plot(diaSign, typeC = "boxplot", file.pdfC = "biosigner-figBoxplot.pdf") ################################################### ### code chunk number 13: biosigner.Rnw:191-192 ################################################### variableMetadata[getSignatureLs(diaSign)[["complete"]], ] ################################################### ### code chunk number 14: biosigner.Rnw:201-203 ################################################### trainVi <- 1:floor(0.8 * nrow(dataMatrix)) testVi <- setdiff(1:nrow(dataMatrix), trainVi) ################################################### ### code chunk number 15: biosigner.Rnw:206-209 (eval = FALSE) ################################################### ## set.seed(123) ## diaTrain <- biosign(dataMatrix[trainVi, ], sampleMetadata[trainVi, "type"], bootI = 5) ## set.seed(NULL) ################################################### ### code chunk number 16: biosigner.Rnw:212-215 ################################################### set.seed(123) diaTrain <- biosign(dataMatrix[trainVi, ], sampleMetadata[trainVi, "type"], bootI = 5, plotL = FALSE) set.seed(NULL) ################################################### ### code chunk number 17: biosigner.Rnw:220-221 ################################################### diaFitDF <- predict(diaTrain) ################################################### ### code chunk number 18: biosigner.Rnw:226-228 ################################################### lapply(diaFitDF, function(predFc) table(actual = sampleMetadata[trainVi, "type"], predicted = predFc)) ################################################### ### code chunk number 19: biosigner.Rnw:233-238 ################################################### sapply(diaFitDF, function(predFc) { conf <- table(sampleMetadata[trainVi, "type"], predFc) conf <- sweep(conf, 1, rowSums(conf), "/") round(mean(diag(conf)), 3) }) ################################################### ### code chunk number 20: biosigner.Rnw:243-244 ################################################### round(getAccuracyMN(diaTrain)["S", ], 3) ################################################### ### code chunk number 21: biosigner.Rnw:249-255 ################################################### diaTestDF <- predict(diaTrain, newdata = dataMatrix[testVi, ]) sapply(diaTestDF, function(predFc) { conf <- table(sampleMetadata[testVi, "type"], predFc) conf <- sweep(conf, 1, rowSums(conf), "/") round(mean(diag(conf)), 3) }) ################################################### ### code chunk number 22: biosigner.Rnw:262-263 ################################################### detach(diaplasma) ################################################### ### code chunk number 23: biosigner.Rnw:268-269 (eval = FALSE) ################################################### ## sessionInfo() ################################################### ### code chunk number 24: biosigner.Rnw:271-272 ################################################### toLatex(sessionInfo()) ################################################### ### code chunk number 25: biosigner.Rnw:283-288 ################################################### data(sacurine) set.seed(123) ## sacSign <- biosign(sacurine[["dataMatrix"]], sacurine[["sampleMetadata"]][, "gender"], methodVc = "plsda") set.seed(NULL) ################################################### ### code chunk number 26: biosigner.Rnw:295-302 ################################################### library(BioMark) data(SpikePos) group1Vi <- which(SpikePos[["classes"]] %in% c("control", "group1")) appleMN <- SpikePos[["data"]][group1Vi, ] spikeFc <- factor(SpikePos[["classes"]][group1Vi]) annotDF <- SpikePos[["annotation"]] rownames(annotDF) <- colnames(appleMN) ################################################### ### code chunk number 27: biosigner.Rnw:307-309 ################################################### pcaLs <- opls(appleMN, plotL = FALSE) plot(pcaLs, parAsColFcVn = spikeFc) ################################################### ### code chunk number 28: biosigner.Rnw:314-315 ################################################### plsLs <- opls(appleMN, spikeFc) ################################################### ### code chunk number 29: biosigner.Rnw:320-323 (eval = FALSE) ################################################### ## set.seed(123) ## appleSign <- biosign(appleMN, spikeFc) ## set.seed(NULL) ################################################### ### code chunk number 30: biosigner.Rnw:328-331 (eval = FALSE) ################################################### ## annotDF <- SpikePos[["annotation"]] ## rownames(annotDF) <- colnames(appleMN) ## annotDF[getSignatureLs(appleSign)[["complete"]], c("adduct", "found.in.standards")] ################################################### ### code chunk number 31: biosigner.Rnw:338-347 ################################################### library(golubEsets) data(Golub_Merge) golubMN <- t(exprs(Golub_Merge)) leukemiaFc <- pData(Golub_Merge)[["ALL.AML"]] table(leukemiaFc) varSubVi <- 1501:2000 set.seed(123) golubSign <- biosign(golubMN[, varSubVi], leukemiaFc, methodVc = "svm") set.seed(NULL) ################################################### ### code chunk number 32: biosigner.Rnw:354-358 ################################################### library(hu6800.db) sapply(getSignatureLs(golubSign)[["complete"]], function(probeC) get(probeC, env = hu6800GENENAME)) ################################################### ### code chunk number 33: biosigner.Rnw:363-364 (eval = FALSE) ################################################### ## rm(list = ls())