Repository 'limma_voom'
hg clone https://toolshed.g2.bx.psu.edu/repos/iuc/limma_voom

Changeset 17:86b3df7db58b (2019-02-18)
Previous changeset 16:5d903d528193 (2019-02-09) Next changeset 18:97e06a4c7c75 (2019-05-05)
Commit message:
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/limma_voom commit 42b1160a549a85c87ed5226a83b55c4e44648597
modified:
limma_voom.R
limma_voom.xml
added:
test-data/matrix_num.txt
b
diff -r 5d903d528193 -r 86b3df7db58b limma_voom.R
--- a/limma_voom.R Sat Feb 09 07:35:04 2019 -0500
+++ b/limma_voom.R Mon Feb 18 17:49:24 2019 -0500
[
@@ -297,35 +297,43 @@
 
 } else {
     # Process the single count matrix
-    counts <- read.table(opt$matrixPath, header=TRUE, sep="\t", strip.white=TRUE, stringsAsFactors=FALSE)
+    counts <- read.table(opt$matrixPath, header=TRUE, sep="\t", strip.white=TRUE, stringsAsFactors=FALSE, check.names=FALSE)
     row.names(counts) <- counts[, 1]
     counts <- counts[ , -1]
     countsRows <- nrow(counts)
 
     # Process factors
     if (is.null(opt$factInput)) {
-            factorData <- read.table(opt$factFile, header=TRUE, sep="\t", strip.white=TRUE)
-            # order samples as in counts matrix
-            factorData <- factorData[match(colnames(counts), factorData[, 1]), ]
-            factors <- factorData[, -1, drop=FALSE]
+        factorData <- read.table(opt$factFile, header=TRUE, sep="\t", strip.white=TRUE)
+        if(!setequal(factorData[, 1], colnames(counts)))
+            stop("Sample IDs in counts and factors files don't match")
+        # order samples as in counts matrix
+        factorData <- factorData[match(colnames(counts), factorData[, 1]), ]
+        factors <- factorData[, -1, drop=FALSE]
     }  else {
-            factors <- unlist(strsplit(opt$factInput, "|", fixed=TRUE))
-            factorData <- list()
-            for (fact in factors) {
-                newFact <- unlist(strsplit(fact, split="::"))
-                factorData <- rbind(factorData, newFact)
-            } # Factors have the form: FACT_NAME::LEVEL,LEVEL,LEVEL,LEVEL,... The first factor is the Primary Factor.
+        factors <- unlist(strsplit(opt$factInput, "|", fixed=TRUE))
+        factorData <- list()
+        for (fact in factors) {
+            newFact <- unlist(strsplit(fact, split="::"))
+            factorData <- rbind(factorData, newFact)
+        } # Factors have the form: FACT_NAME::LEVEL,LEVEL,LEVEL,LEVEL,... The first factor is the Primary Factor.
 
-            # Set the row names to be the name of the factor and delete first row
-            row.names(factorData) <- factorData[, 1]
-            factorData <- factorData[, -1]
-            factorData <- sapply(factorData, sanitiseGroups)
-            factorData <- sapply(factorData, strsplit, split=",")
-            factorData <- sapply(factorData, make.names)
-            # Transform factor data into data frame of R factor objects
-            factors <- data.frame(factorData)
+        # Set the row names to be the name of the factor and delete first row
+        row.names(factorData) <- factorData[, 1]
+        factorData <- factorData[, -1]
+        factorData <- sapply(factorData, sanitiseGroups)
+        factorData <- sapply(factorData, strsplit, split=",")
+        # Transform factor data into data frame of R factor objects
+        factors <- data.frame(factorData)
     }
 }
+# check there are the same number of samples in counts and factors
+if(nrow(factors) != ncol(counts)) {
+    stop("There are a different number of samples in the counts files and factors")
+}
+# make groups valid R names, required for makeContrasts
+factors <- sapply(factors, make.names)
+factors <- data.frame(factors)
 
  # if annotation file provided
 if (haveAnno) {
@@ -339,6 +347,14 @@
 contrastData <- unlist(strsplit(opt$contrastData, split=","))
 contrastData <- sanitiseEquation(contrastData)
 contrastData <- gsub(" ", ".", contrastData, fixed=TRUE)
+# in case input groups start with numbers this will make the names valid R names, required for makeContrasts
+cons <- NULL
+for (i in contrastData) {
+    i <- strsplit(i, split="-")
+    i <- lapply(i, make.names)
+    i <- lapply(i, paste, collapse="-")
+    cons <- append(cons, unlist(i))
+}
 
 plots <- character()
 if (!is.null(opt$plots)) {
@@ -362,8 +378,8 @@
 mdvolOutPng <- character()
 topOut <- character()
 glimmaOut <- character()
-for (i in 1:length(contrastData)) {
-    con <- contrastData[i]
+for (i in 1:length(cons)) {
+    con <- cons[i]
     con <- gsub("\\(|\\)", "", con)
     mdOutPdf[i] <- makeOut(paste0("mdplot_", con, ".pdf"))
     volOutPdf[i] <- makeOut(paste0("volplot_", con, ".pdf"))
@@ -409,6 +425,7 @@
 # Creating naming data
 samplenames <- colnames(data$counts)
 sampleanno <- data.frame("sampleID"=samplenames, factors)
+row.names(factors) <- samplenames # for "Summary of experimental data" table
 
 # Creating colours for the groups
 cols <- as.numeric(factors[, 1])
@@ -451,7 +468,7 @@
 
     if (wantFilt) {
         print("Outputting filtered counts")
-        filt_counts <- data.frame(data$genes, data$counts)
+        filt_counts <- data.frame(data$genes, data$counts, check.names=FALSE)
         write.table(filt_counts, file=filtOut, row.names=FALSE, sep="\t", quote=FALSE)
         linkData <- rbind(linkData, data.frame(Label=paste0(deMethod, "_", "filtcounts.tsv"), Link=paste0(deMethod, "_", "filtcounts"), stringsAsFactors=FALSE))
     }
@@ -520,8 +537,6 @@
 y <- new("DGEList", data)
 
 print("Generating Design")
-# Name rows of factors according to their sample
-row.names(factors) <- names(data$counts)
 factorList <- sapply(names(factors), pasteListName)
 formula <- "~0"
 for (i in 1:length(factorList)) {
@@ -540,7 +555,7 @@
 
 # Generate contrasts information
 print("Generating Contrasts")
-contrasts <- makeContrasts(contrasts=contrastData, levels=design)
+contrasts <- makeContrasts(contrasts=cons, levels=design)
 
 ################################################################################
 ### Data Output
@@ -768,7 +783,7 @@
 
      # Save normalised counts (log2cpm)
     if (wantNorm) {
-        norm_counts <- data.frame(vData$genes, vData$E)
+        norm_counts <- data.frame(vData$genes, vData$E, check.names=FALSE)
         write.table(norm_counts, file=normOut, row.names=FALSE, sep="\t", quote=FALSE)
         linkData <- rbind(linkData, c((paste0(deMethod, "_", "normcounts.tsv")), (paste0(deMethod, "_", "normcounts"))))
     }
@@ -827,8 +842,8 @@
                        lfc=opt$lfcReq)
 sumStatus <- summary(status)
 
-for (i in 1:length(contrastData)) {
-    con <- contrastData[i]
+for (i in 1:length(cons)) {
+    con <- cons[i]
     con <- gsub("\\(|\\)", "", con)
     # Collect counts for differential expression
     upCount[i] <- sumStatus["Up", i]
@@ -979,7 +994,7 @@
     }
 }
 sigDiff <- data.frame(Up=upCount, Flat=flatCount, Down=downCount)
-row.names(sigDiff) <- contrastData
+row.names(sigDiff) <- cons
 
 # Save relevant items as rda object
 if (wantRda) {
b
diff -r 5d903d528193 -r 86b3df7db58b limma_voom.xml
--- a/limma_voom.xml Sat Feb 09 07:35:04 2019 -0500
+++ b/limma_voom.xml Mon Feb 18 17:49:24 2019 -0500
[
b'@@ -1,4 +1,4 @@\n-<tool id="limma_voom" name="limma" version="3.38.3">\n+<tool id="limma_voom" name="limma" version="3.38.3+galaxy1">\n     <description>\n         Perform differential expression with limma-voom or limma-trend\n     </description>\n@@ -162,14 +162,14 @@\n \n             <when value="files">\n                 <repeat name="rep_factor" title="Factor" min="1">\n-                    <param name="factorName" type="text" label="Name" help="Name of experiment factor of interest (e.g. Genotype). One factor must be entered and there must be two or more groups per factor. Optional additional factors (e.g. Batch) can be entered using the Insert Factor button below, see Help section for more information. NOTE: Please only use letters, numbers or underscores, and the first character of each factor must be a letter">\n+                    <param name="factorName" type="text" label="Name" help="Name of experiment factor of interest (e.g. Genotype). One factor must be entered and there must be two or more groups per factor. Optional additional factors (e.g. Batch) can be entered using the Insert Factor button below, see Help section for more information. NOTE: Please only use letters, numbers or underscores.">\n                     <sanitizer>\n                         <valid initial="string.letters,string.digits"><add value="_" /></valid>\n                     </sanitizer>\n                     </param>\n                     <repeat name="rep_group" title="Group" min="2" default="2">\n                         <param name="groupName" type="text" label="Name"\n-                        help="Name of group that the counts files belong to (e.g. WT or Mut). NOTE: Please only use letters, numbers or underscores (case sensitive), and the first character of each group must be a letter">\n+                        help="Name of group that the counts files belong to (e.g. WT or Mut). NOTE: Please only use letters, numbers or underscores (case sensitive).">\n                         <sanitizer>\n                             <valid initial="string.letters,string.digits"><add value="_" /></valid>\n                         </sanitizer>\n@@ -184,7 +184,7 @@\n \n                 <conditional name="fact">\n                     <param name="ffile" type="select" label="Input factor information from file?"\n-                        help="You can choose to input the factor and group information for the samples from a file or manually enter below. NOTE: Please only use letters, numbers or underscores (case sensitive), and the first character of each sample, factor and group must be a letter">\n+                        help="You can choose to input the factor and group information for the samples from a file or manually enter below. NOTE: Please only use letters, numbers or underscores (case sensitive), the group names MUST not contain hyphens.">\n                         <option value="no">No</option>\n                         <option value="yes">Yes</option>\n                     </param>\n@@ -194,12 +194,12 @@\n                     <when value="no" >\n                         <repeat name="rep_factor" title="Factor" min="1">\n                             <param name="factorName" type="text" label="Factor Name"\n-                                help="Name of experiment factor of interest (e.g. Genotype). One factor must be entered and there must be two or more groups per factor. Additional factors (e.g. Batch) can be entered using the Insert Factor button below, see Help section below. NOTE: Please only use letters, numbers or underscores, and the first character of each factor must be a letter">\n+                                help="Name of experiment factor of interest (e.g. Genotype). One factor must be entered and there must be two or more groups per factor. Additional factors (e.g. Batch) can be entered using the Insert Factor button below, see Help section below. NOTE: Please only use letters, numbers or underscores.">\n                                 <validator type="empty_'..b'" >\n                 <assert_contents>\n                     <has_text text="The limma-trend method was used" />\n@@ -648,6 +646,43 @@\n                 </element>\n             </output_collection>\n         </test>\n+        <!-- Ensure samples and groups beginning with numbers can be handled -->\n+        <test expect_num_outputs="3">\n+            <param name="format" value="matrix" />\n+            <param name="counts" value="matrix_num.txt" />\n+            <param name="annoOpt" value="yes" />\n+            <param name="geneanno" value="anno.txt" />\n+            <repeat name="rep_factor">\n+                <param name="factorName" value="Group"/>\n+                <param name="groupNames" value="2,2,2,1,1,1" />\n+            </repeat>\n+            <repeat name="rep_contrast">\n+                <param name="contrast" value="2-1" />\n+            </repeat>\n+            <param name="filt_select" value="yes" />\n+            <param name="format_select" value="counts"/>\n+            <param name="cntReq" value="10"/>\n+            <param name="count_select" value="sample"/>\n+            <param name="cntSampleReq" value="3"/>\n+            <param name="normalisationOption" value="TMM" />\n+            <param name="normCounts" value="true" />\n+            <param name="topgenes" value="6" />\n+            <param name="de_select" value="voom" />\n+            <output_collection name="outTables" count="1">\n+                <element name="limma-voom_X2-X1" ftype="tabular" >\n+                    <assert_contents>\n+                        <has_text_matching expression="EntrezID.*logFC.*AveExpr.*t.*P.Value.*adj.P.Val.*B" />\n+                        <has_text_matching expression="11304.*0.45.*15.52.*4.94.*7.74.*0.0001.*5.27" />\n+                    </assert_contents>\n+                </element>\n+            </output_collection>\n+            <output name="outNorm" ftype="tabular" >\n+                <assert_contents>\n+                    <has_text_matching expression="EntrezID.*2-1.*2-2.*2-3.*1-1.*1-2.*1-3" />\n+                    <has_text_matching expression="11304.*15.7.*15.8.*15.6.*15.3.*15.2.*15.2" />\n+                </assert_contents>\n+            </output>\n+        </test>\n     </tests>\n \n     <help><![CDATA[\n@@ -732,9 +767,9 @@\n     Mut3       Mut          b3\n     ========== ============ =========\n \n-*Factor Name:* The name of the experimental factor being investigated e.g. Genotype, Treatment. One factor must be entered, the name should start with a letter and spaces must not be used. Optionally, additional factors can be included, these are variables that might influence your experiment e.g. Batch, Gender, Subject. If additional factors are entered, an additive linear model will be used.\n+*Factor Name:* The name of the experimental factor being investigated e.g. Genotype, Treatment. One factor must be entered and spaces must not be used. Optionally, additional factors can be included, these are variables that might influence your experiment e.g. Batch, Gender, Subject. If additional factors are entered, an additive linear model will be used.\n \n-*Groups:* The names of the groups for the factor. The names should start with a letter, and only contain letters, numbers and underscores, other characters such as spaces and hyphens must not be used. If entered into the tool form above, the order must be the same as the samples (to which the groups correspond) are listed in the columns of the counts matrix, with the values separated by commas.\n+*Groups:* The names of the groups for the factor. The names should only contain letters, numbers and underscores, other characters such as spaces and hyphens MUST not be used. If entered into the tool form above, the order must be the same as the samples (to which the groups correspond) are listed in the columns of the counts matrix, with the values separated by commas. If the group names begin with a number an X will be added as a prefix.\n \n **Contrasts of Interest:**\n The contrasts you wish to make between levels.\n'
b
diff -r 5d903d528193 -r 86b3df7db58b test-data/matrix_num.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/matrix_num.txt Mon Feb 18 17:49:24 2019 -0500
b
@@ -0,0 +1,7 @@
+GeneID 2-1 2-2 2-3 1-1 1-2 1-3
+11287 1463 1441 1495 1699 1528 1601
+11298 1345 1291 1346 1905 1744 1834
+11302 5 6 5 6 8 7
+11303 1574 1519 1654 2099 1974 2100
+11304 361 397 346 356 312 337
+11305 1762 1942 2027 2528 2438 2493