comparison pcaFactoMineR_galaxy.R @ 0:7acfb3bdad66 draft default tip

planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
author vmarcon
date Thu, 18 Jan 2018 07:57:36 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:7acfb3bdad66
1 #!/usr/local/bioinfo/bin/Rscript --vanilla --slave --no-site-file
2
3 ################################################################################################
4 # pcaFactoMineR_galaxy #
5 # #
6 # Author : Sandrine Laguerre / Marie Tremblay-Franco / Jean-Francois Martin #
7 # User : Galaxy #
8 # Original data : -- #
9 # Starting date : 24-03-2015 #
10 # Version 1 : 20-05-2015 #
11 # Version 2 : 24-02-2016 #
12 # #
13 # #
14 # Input files : dataMatrix.txt #
15 # Output files : graph_output.pdf ; #
16 # #
17 ################################################################################################
18
19 ##------------------------------
20 ## Options
21 ##------------------------------
22 strAsFacL <- options()$stringsAsFactors
23 options(stringsAsFactors = FALSE)
24
25 ##------------------------------
26 ## Libraries laoding
27 ##------------------------------
28 # For parseCommandArgs function
29 library(batch)
30 library(pcaMethods)
31 library(FactoMineR)
32
33 # R script call
34 source_local <- function(fname)
35 {
36 argv <- commandArgs(trailingOnly = FALSE)
37 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
38 source(paste(base_dir, fname, sep="/"))
39 }
40
41 #Import the different functions used for PCA
42 source_local("pcaFactoMineR_functions.R")
43
44 ##------------------------------
45 ## Constants
46 ##------------------------------
47 topEnvC <- environment()
48 flagC <- "\n"
49
50
51 ##------------------------------
52 ## Lecture parametres
53 ##------------------------------
54 argLs <- parseCommandArgs(evaluate=FALSE)
55
56 log_file <- argLs[["logOut"]]
57 # Inputs
58 # Matrice donnees
59 data <- read.table(argLs[["datafile"]],header=TRUE,sep="\t",dec=".",check.names = FALSE)
60 rownames(data) <- data[,1]
61
62 # Facteur biologique
63 hb=0
64 if(argLs[["factor"]] != "None")
65 {
66 metadatasample <- read.table(argLs[["samplemetadata"]],header=TRUE,sep="\t",dec=".",check.names = FALSE)
67 rownames(metadatasample) <- metadatasample[,1]
68 # Test si le facteur choisi est bien dans le samplemetadata
69 if (any(argLs[["factor"]] %in% colnames(metadatasample)) ==FALSE)
70 {
71 #log_error(simpleCondition("Factor is not in samplemetadata."))
72 cat("<HTML><HEAD><TITLE>PCA FactoMineR report</TITLE></HEAD><BODY>\n",file=log_file,append=F,sep="")
73 cat("&#9888 An error occurred while trying to read your factor table.\n<BR>",file=log_file,append=T,sep="")
74 cat("Please check that:\n<BR>",file=log_file,append=T,sep="")
75 cat("<UL>\n",file=log_file,append=T,sep="")
76 cat(" <LI> you wrote the name of the column of the factor matrix corresponding to the qualitative variable </LI>\n",file=log_file,append=T,sep="")
77 cat(" <LI> you wrote the column name correctly (it is case sensitive)</LI>\n",file=log_file,append=T,sep="")
78 cat("</UL>\n",file=log_file,append=T,sep="")
79 cat("</BODY></HTML>\n",file=log_file,append=T,sep="")
80 q(save="no",status=1)
81 }
82 # On cree une dataframe avec l’id des samples (1ere colonne de metadatasample+ le facteur choisi
83 # qui est en colonne “colfactor”
84 colfactor <- which(argLs[["factor"]] == colnames(metadatasample))
85 facteur <- data.frame(metadatasample[,1], metadatasample[[colfactor]])
86 facteur[[2]] <- as.factor(facteur[[2]])
87 hb=1
88 }
89
90 # Appel de la fonction
91 eigenplot=0
92 contribplot=0
93 scoreplot=0
94 loadingplot=0
95 variable_in_line=0
96
97 if (argLs[["plotev"]]=="yes")
98 {
99 eigenplot=1
100 }
101
102 if (argLs[["plotcontrib"]]=="yes")
103 {
104 contribplot=1
105 }
106
107
108 if (argLs[["plotindiv"]]=="yes")
109 {
110 scoreplot=1
111 }
112
113
114 if (argLs[["plotvar"]]=="yes")
115 {
116 loadingplot=1
117 }
118
119 if (argLs[["varinline"]]=="yes")
120 {
121 variable_in_line=1
122 }
123
124
125
126
127
128 # Outputs
129 nomGraphe <- argLs[["outgraphpdf"]]
130 res.pca <- pca.main(ids=data,bioFact=facteur,ncp=argLs[["npc"]],hb=hb,
131 minContribution=c(argLs[["contribh"]],argLs[["contribv"]]),mainTitle=argLs[["title"]],
132 textSize=argLs[["tc"]],principalPlane=c(argLs[["pch"]],argLs[["pcv"]]),eigenplot=eigenplot,
133 contribplot=contribplot,scoreplot=scoreplot,loadingplot=loadingplot,
134 nomGraphe=argLs[["outgraphpdf"]],variable_in_line=variable_in_line,log_file=log_file)
135
136
137 ################################# fin ##############################################