diff r-gpca.R @ 3:8def7dda3bee draft

planemo upload for repository https://github.com/blankenberglab/galaxy-tools-blankenberg/tree/master/tools/r-gpca commit f5a03b0978b3a7473f034b87a87765ff1d65d720
author blankenberglab
date Mon, 03 Dec 2018 15:04:08 -0500
parents 4865e7f4e9c5
children
line wrap: on
line diff
--- a/r-gpca.R	Tue Nov 27 12:29:58 2018 -0500
+++ b/r-gpca.R	Mon Dec 03 15:04:08 2018 -0500
@@ -3,7 +3,6 @@
 library(gPCA)
 options(bitmapType='cairo')
 
-
 # parse options
 option_list = list(
    make_option(
@@ -38,7 +37,7 @@
     action = "store_true",
     default = FALSE,
     help = "Is the input batch and data centered [default %default]"
-	 ),
+   ),
    make_option(
     c("-y", "--scaleY"),
     action = "store_true",
@@ -51,7 +50,7 @@
     default = NULL,
     type = 'numeric',
     help = "Retain features"
-	 ),
+   ),
    make_option(
     c( "--npcs"),
     action = "store",
@@ -79,7 +78,7 @@
     default = NA, 
     type = 'character',
     help = "Numbers output"
- 	 ),
+   ),
    make_option(
     c("-o", "--html_outfile"),
     action = "store",
@@ -98,7 +97,6 @@
 }
 
 # Check parameter values
-
 if ( ! file.exists(opt$batch)){
   stop((paste('File for batch', opt$batch, 'does not exist')))
 }
@@ -111,20 +109,38 @@
 batch<-as.matrix(read.delim(opt$batch, header=TRUE, row.names=1, sep="\t"))
 
 write('#Batch\tDelta\tP-value\tCumulative Variance',file = opt$numbers_outfile, append=TRUE)
+write('<!DOCTYPE html>
+  <html lang="en">
+  <head>
+  <style>  
+  table, td, th {
+    margin-left:auto; 
+    margin-right:auto;
+    border: 2px solid black;
+  }
+  h2, ul {
+    text-align:left;
+  }
+  h1 {
+    text-align:center;
+  }
+  body {
+    text-align: center;
+  }
+  p {
+    font-size: 0px;
+  }  
+  </style>
+  <title>HTML gPCA</title></head><body><p>If you are seeing this then CSS is not whitelisted</p><h2 id = "top">Table of Contents</h2><ul>', file = opt$html_outfile, append=TRUE)
 
-write('<html><body><div align="left" id="top"><p><h1>Table of Contents</h1><ul>',file = opt$html_outfile, append=TRUE)
 for (row in 1:nrow(batch)) {
   write(paste0('<li><a href="#',row.names(batch)[row],'">',row.names(batch)[row],'</a></li>'), file=opt$html_outfile, append=TRUE)
 }
-write('</ul></p></div>', file=opt$html_outfile, append=TRUE)
-
+write('</ul>', file=opt$html_outfile, append=TRUE)
 for (row in 1:nrow(batch)) {
   batch1<-as.numeric(factor(batch[row,]))
-
 out<-gPCA.batchdetect(x=data, batch=batch1, center=opt$center, scaleY=opt$scaleY, nperm=opt$nperm, filt=opt$filt, seed=opt$seed)
-
 out$varPCg1<-((out$varPCg1-out$varPCu1)/out$varPCg1)*100
-
 write(paste(row.names(batch)[row],out$delta,out$p.val,out$varPCg1,sep="\t"),file = opt$numbers_outfile, append=TRUE)
 
 # General Distribution 
@@ -133,66 +149,55 @@
 gDist(out)
 invisible(dev.off())
 
-
 # Guided/Unguided 1v2
 par(mai=c(0.8,0.8,0.1,0.1),cex=0.8)
 png(paste(opt$path,'/guided_1v2_',row,'.png', sep=""), width=1020, height=800, units='px')
 PCplot(out,ug="unguided",type="1v2")
 invisible(dev.off())
-
 par(mai=c(0.8,0.8,0.1,0.1),cex=0.8)
 png(paste(opt$path,'/unguided_1v2_',row,'.png', sep=""), width=1020, height=800, units='px')
 PCplot(out,ug="unguided",type="1v2")
 invisible(dev.off())
 
-
 # Guided/Unguided comp,3
 par(mai=c(0.65,0.65,0.1,0.1),cex=0.8)
 png(paste(opt$path,'/guided_npcs_',row,'.png', sep=""), width=1020, height=800, units='px')
 PCplot(out,ug="guided",type="comp",npcs=opt$npcs)
 invisible(dev.off())
-
 par(mai=c(0.65,0.65,0.1,0.1),cex=0.8)
 png(paste(opt$path,'/unguided_npcs_',row,'.png', sep=""), width=1020, height=800, units='px')
 PCplot(out,ug="unguided",type="comp",npcs=opt$npcs)
 invisible(dev.off())
 
-
 # Guided/Unguided CumlativeVarPlot
 par(mai=c(0.8,0.8,0.1,0.1),cex=0.8)
 png(paste(opt$path,'/guided_var_',row,'.png', sep=""), width=1020, height=800, units='px')
 CumulativeVarPlot(out,ug="guided",col="blue")
 invisible(dev.off())
-
 par(mai=c(0.8,0.8,0.1,0.1),cex=0.8)
 png(paste(opt$path,'/unguided_var_',row,'.png', sep=""), width=1020, height=800, units='px')
 CumulativeVarPlot(out,ug="unguided",col="blue")
 invisible(dev.off())
 
-
 write(paste0('
-<header id=',row.names(batch)[row],'><center><font size="11">',row.names(batch)[row],'</font><center></header>
-<br>           
-<table align="center" border="1">
+<h1 id="',row.names(batch)[row],'">',row.names(batch)[row],'</h1>
+<br>        
+<table>
  <tr>
   <th>Delta</th><th>P-value</th><th>varPCg1</th>
  </tr>
  <tr>
-  <td id="#">',out$delta,'</td><td id=p.val>',out$p.val,'</td><td id=varPCg1>',out$varPCg1,'</td>
+  <td>',out$delta,'&nbsp;</td><td>',out$p.val,'&nbsp;</td><td>',out$varPCg1,'</td>
  </tr>
-</table>
-<center><img src="gDist_',row,'.png"/></center><br>
-<center><title>Guided 1v2</title><br><img src="guided_1v2_',row,'.png"/></center><br>
-<center><title>Unguided 1v2</title><br><img src="unguided_1v2_',row,'.png"/></center><br>
-
-<center><title>Guided Compare to ',opt$npcs,'</title><br><img src="guided_npcs_',row,'.png"/></center><br>
-<center><title>Unguided Compare to ',opt$npcs,'</title><br><img src="unguided_npcs_',row,'.png"/></center><br>
-
-<center><title>Guided Cumulative Variance</title><br><img src="guided_var_',row,'.png"/></center><br>
-<center><title>Unguided Cumulative Variance</title><br><img src="unguided_var_',row,'.png"/></center><br>
-
+</table><br>
+<h3>gDist</h3><br><img src="gDist_',row,'.png" alt="gDist"/>
+<br>
+<h3>Guided 1v2</h3><br><img src="guided_1v2_',row,'.png" alt="guided_1v2" /><br>
+<h3>Unguided 1v2</h3><br><img src="unguided_1v2_',row,'.png" alt="unguided_1v2" /><br>
+<h3>Guided Compare to ',opt$npcs,'</h3><br><img src="guided_npcs_',row,'.png" alt="guided_npcs"/><br>
+<h3>Unguided Compare to ',opt$npcs,'</h3><br><img src="unguided_npcs_',row,'.png" alt="unguided_npcs"/><br>
+<h3>Guided Cumulative Variance</h3><br><img src="guided_var_',row,'.png" alt="guided_var" /><br>
+<h3>Unguided Cumulative Variance</h3><br><img src="unguided_var_',row,'.png" alt="unguided_var" /><br>
 '), file = opt$html_outfile, append=TRUE)
 }
-write(paste('<p><center><a href="#top">Back to Top</a></center></p></body></html>'),file = opt$html_outfile, append=TRUE)
-
-sessionInfo()
+write(paste('<a href="#top">Back to Top</a></body></html>'),file = opt$html_outfile, append=TRUE)