annotate MClust_all.R @ 1:f3fa21cda5f5 draft default tip

planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
author labis-app
date Fri, 10 Aug 2018 15:45:44 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
1 ###
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
2 # title: ""
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
3 # author: "Diego M. Riano-Pachon, Rodrigo R. Dorado Goitia"
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
4 # date: ""
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
5 # output: pdf
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
6 ###
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
7
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
8 ###
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
9 # Description
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
10 ###
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
11
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
12 ### Installers ###
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
13 # install.packages("qvalue")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
14 # install.packages("ggplot2")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
15 # install.packages("mclust")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
16 # install.packages("reshape2")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
17 # install.packages('getopt')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
18
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
19 rm(list=ls())
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
20
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
21 #Load required packages
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
22 suppressMessages(library(qvalue))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
23 suppressMessages(library(ggplot2))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
24 suppressMessages(library(mclust))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
25 suppressMessages(library(reshape2))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
26 suppressMessages(library(getopt))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
27
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
28 ###
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
29
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
30 # Set Functions
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
31
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
32 # Set The directory to start the execution and read a csv file
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
33 # directoryName String Name of the directory.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
34 # filename String Name of the csv file.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
35 # Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
36 readCsvDirectory<-function(directoryName, filename, SpaceString) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
37 setwd(directoryName)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
38 fileData <- read.csv(filename,
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
39 sep = "\t",
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
40 header=TRUE,
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
41 na.strings = 'NaN',
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
42 dec=SpaceString,
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
43 stringsAsFactors=FALSE)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
44 return(fileData)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
45 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
46
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
47 # Print the dim, columns name and the first 5 rows of a variable
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
48 # dataToInform Object Name of the varaible.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
49 # Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
50 printInfo <- function(dataToInform) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
51 print('Length')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
52 print(length(dataToInform))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
53 print('---------------')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
54 print('Dim')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
55 print(dim(dataToInform))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
56 print('***************')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
57 print('Column Names')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
58 print(colnames(dataToInform))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
59 print('_______________')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
60 print('Firsts rows')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
61 print(head(dataToInform))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
62 print('_______________')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
63 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
64
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
65 ## Put the id of protein as row name, get only the data of the experiments
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
66 ## proteins matrix All the proteins data
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
67 ## column_id int The number of the column where the is the id
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
68 ## init_column int The number of the colmun of the initial experiment
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
69 ## number_exp int The number of experiments
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
70 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
71 getDataofInfo <- function(proteins, column_id, init_column, number_exp) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
72 selected_columns <- proteins[1:nrow(proteins), c(init_column:number_exp)]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
73 id_proteins_column <- proteins[1:nrow(proteins), column_id]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
74 ids <- matrix(, ncol = 1, nrow = nrow(proteins))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
75 j <- 1
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
76 for(i in id_proteins_column){
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
77 id_proteins_aux <- strsplit(i, ";")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
78 unlist(id_proteins_aux)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
79 ids[j] <- id_proteins_aux[[1]][1]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
80 j <- j + 1
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
81 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
82 row.names(selected_columns) <- ids
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
83 return(selected_columns)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
84 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
85
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
86 ## Verify if the protein contain at least one group with all the values different to NaN
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
87 ## proteins matrix All the proteins data
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
88 ## orderCondition int The division per experiment
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
89 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
90 VarifyAComplteGroup <- function(proteins, orderCondition) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
91 protein_erase <- c()
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
92 col_names <- colnames(proteins)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
93 ## Get every protein
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
94 count <- 0
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
95 for (protein in 1:nrow(proteins)) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
96 ok_protein <- FALSE
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
97 num_div <- ncol(orderCondition)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
98 columnNumber <- 1
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
99 ## Move by a experiment
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
100 for (result_exp in seq(1, nrow(orderCondition))) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
101 ok_group <- TRUE
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
102 pos_NaN <- c()
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
103 pos_valid <- c()
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
104 ## Get the name of the experiment
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
105 column_name <- row.names(orderCondition)[result_exp]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
106 ## Move into the divisions
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
107 for (div_pos in 1:num_div) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
108 if (is.na(orderCondition[result_exp, div_pos])){
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
109 break
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
110 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
111 pos <- columnNumber
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
112 columnNumber <- columnNumber + 1
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
113 ## pos <- result_exp + (div_pos - 1)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
114 ## check if is NaN
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
115 if(is.na(proteins[protein, pos])){
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
116 ok_group <- FALSE
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
117 pos_NaN <- c(pos_NaN, pos)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
118 } else {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
119 pos_valid <- c(pos_valid, pos)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
120 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
121 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
122 ##Check if in the group, if the three are valid
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
123 if (ok_group) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
124 ok_protein <- TRUE
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
125 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
126 switch_var <- length(pos_NaN)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
127 allPos <- c(pos_valid, pos_NaN)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
128 ## Execute conditions
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
129
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
130 if(length(pos_valid) == 0){
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
131 proteins[protein, pos_NaN] <- 0
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
132 }else if(length(pos_NaN) > 0){
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
133 proteins[protein, pos_NaN] <- getTheMedian(proteins, protein, pos_valid)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
134 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
135 resultValue <- getTheMedian(proteins, protein, allPos)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
136 ##if (switch_var == 0) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
137 ##resultValue <- getTheMedian(proteins, protein, allPos)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
138 ##caso1 <- caso1 + 1
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
139 ##}
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
140 ##if (switch_var == 1) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
141 ##proteins[protein, pos_NaN] <- mean(as.numeric(proteins[protein, pos_valid]))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
142 ##resultValue <- getTheMedian(proteins, protein, allPos)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
143 ##caso2 <- caso2 + 1
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
144 ##}
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
145 ##if (switch_var == 2) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
146 ##proteins[protein, pos_NaN] <- 0
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
147 #### resultValue <- 0
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
148 ##resultValue <- proteins[protein, ]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
149 ##caso3 <- caso3 + 1
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
150 ##}
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
151 ##if (switch_var == 3) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
152 ##proteins[protein, pos_NaN] <- 0
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
153 ##resultValue <- 0
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
154 ##caso4 <- caso4 + 1
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
155 ##}
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
156 ## Get the unique value
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
157 proteins[protein, column_name] <- resultValue
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
158 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
159 ## Check if the protein conatin at least one group valid
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
160 if (!ok_protein) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
161 protein_erase <- c(protein_erase, protein)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
162 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
163 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
164 ## return the list
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
165 if(length(protein_erase) > 0) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
166 return(proteins[-protein_erase,])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
167 }else{
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
168 return(proteins)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
169 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
170 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
171
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
172 ## Get the median of a group
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
173 ## proteins matrix All the proteins
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
174 ## protein int The actual protein
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
175 ## positions int The number of experiment
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
176 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
177 getTheMedian <- function(proteins, protein, positions) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
178 return(median(as.numeric(proteins[protein, positions])))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
179 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
180
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
181 ## Merge two data frames by the id
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
182 ## proteins Data Frame The first data frame
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
183 ## p_values Data Frame The second data frame
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
184 mergeById <- function(proteins, p_values) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
185 proteins$auxiliar <- row.names(proteins)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
186 p_values$auxiliar <- row.names(p_values)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
187 proteins <- merge(proteins, p_values, by.x = 'auxiliar', by.y = 'auxiliar')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
188 row.names(proteins) <- proteins[, 'auxiliar']
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
189 return(proteins[, -1])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
190 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
191
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
192 ## Get the p values of the ANOVA
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
193 ## proteins Data Frame All the data of the experiments
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
194 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
195
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
196 ##p_values <- calculateANOVA(proteins_for_ANOVA, orderCondition, ANOVA_type)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
197
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
198 calculateANOVA <- function(proteins, orderCondition, type = "ONE-WAY") { #"ONE-WAY", "TOW_WAY"
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
199 all_p_values <- c()
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
200 for (i in 1:nrow(proteins)) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
201 groupNames <- c()
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
202 for (j in colnames(proteins)) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
203 groupNames <- c(groupNames, row.names(which(orderCondition == j, arr.ind = TRUE)))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
204 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
205 MToANOVA <- data.frame(groupNames, as.numeric(t(proteins[i, ])))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
206 colnames(MToANOVA) <- c('GROUP', 'DATA')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
207 aov1 <- aov(DATA ~ GROUP, data = MToANOVA)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
208 all_p_values <- c(all_p_values, summary(aov1)[[1]][["Pr(>F)"]][1])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
209 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
210 p_values <- data.frame(all_p_values)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
211 row.names(p_values) <- row.names(proteins)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
212 return(p_values)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
213 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
214
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
215 ## Select the data that has less than 0.05 the p_value; Replace NA by 0
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
216 ## selected_columns_proteins Matrix the selected columns of the data
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
217 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
218 selectSignificanProteinsExpression <- function(selected_columns_proteins) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
219 protein_Qvalues <- qvalue(selected_columns_proteins$all_p_values, lambda=0)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
220 selected_columns_proteins$QValue <- protein_Qvalues$qvalues
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
221 selectedSignificantExpr <- selected_columns_proteins[which(selected_columns_proteins$QValue < 0.05), c(1:10)]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
222 all_row_names <- row.names(selectedSignificantExpr)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
223 selectedSignificantExpr <- as.data.frame(sapply(selectedSignificantExpr, as.numeric))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
224 row.names(selectedSignificantExpr) <- all_row_names
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
225 ##selectedSignificantExpr[is.na(selectedSignificantExpr)] <- 0
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
226 return(selectedSignificantExpr)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
227 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
228
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
229 ## Get Z Values of the proteins Expression
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
230 ## selectedSignificantExpr Matrix The values of the selected proteins
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
231 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
232 getZValueSgnificantProteinExpression <- function(selectedSignificantExpr) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
233 return(as.data.frame(t(scale(t(selectedSignificantExpr)))))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
234 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
235
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
236 ## Execute cluster function, save the result in a csv file. Note: add the condition of max clusters
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
237 ## ZValues Matrix The z values to cluster
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
238 ## numOfClusters int The max number of clusters
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
239 ## filename String The name of the csv fil
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
240 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
241 executeMClust <- function(ZValues, directoryCSV, filename, numOfClusters = 60) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
242 print("Clustering")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
243 print(numOfClusters)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
244 clusterResult <- Mclust(ZValues, G = 2:numOfClusters)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
245 print(summary(clusterResult))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
246 Num_clusters <- max(clusterResult$classification, na.rm=TRUE)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
247 if (Num_clusters >= numOfClusters) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
248 newNumOfClusters <- numOfClusters + 30
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
249 executeMClust(ZValues, filename, newNumOfClusters)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
250 } else {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
251 clusters <- data.frame(ProteinID = names(clusterResult$classification), Cluster = clusterResult$classification, row.names = NULL)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
252 table(clusters$Cluster)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
253 setwd(directoryCSV)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
254 #write.csv(clusters, filename, row.names = FALSE, quote = FALSE)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
255 write.table(clusters, file = filename, row.names = FALSE, quote = FALSE, sep = "\t")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
256 return(clusters)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
257 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
258 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
259
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
260 ## Prepare data structure
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
261 ## ZValues Matrix the Z Values of the proteins selected
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
262 ## clusters Matrix The clusters of the proteins
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
263 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
264 getZvaluesMelt <- function(ZValues, clusters, orderCondition, columnsNameTime) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
265 timesCond <- row.names(orderCondition)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
266 ZValues_melt <- ZValues
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
267 ZValues_melt$ProteinID <- rownames(ZValues_melt)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
268 ZValues_melt <- merge(ZValues_melt, clusters, by.x = 'ProteinID', by.y = 'ProteinID')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
269 ZValues_melt <- melt(ZValues_melt, id.vars = c('ProteinID','Cluster'))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
270 colnames(ZValues_melt) <- c('ProteinID', 'Cluster', 'Time', 'RelativeExpression')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
271 ZValues_melt$Cluster <- as.factor(ZValues_melt$Cluster)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
272 for(cond in 1:nrow(orderCondition)) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
273 ZValues_melt$Time2[ZValues_melt$Time == timesCond[cond]] <- as.numeric(columnsNameTime[timesCond[cond], 2])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
274 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
275 return(ZValues_melt)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
276 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
277
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
278 ## Test the cluster function with diferent sizes
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
279 ## zvalues data Frame The Z values of the data to get clustered
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
280 ## number_times array The sizes of the test
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
281 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
282 testCluster <- function (zvalues, number_times) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
283 for (i in number_times) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
284 print("***********")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
285 print(i)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
286 cluster_result <- Mclust(zvalues, G = 2:i)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
287 print(summary(cluster_result))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
288 print("-----------")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
289 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
290 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
291
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
292
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
293 ## Set the color of the background of the image
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
294 ## Rodrigo dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
295 setBackGroundColors <- function() {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
296 rects <- as.data.frame(matrix(ncol = 3,nrow=2))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
297 colnames(rects) <- c('xstart','xend','col')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
298 rects[1,] <- c(-49,0,'gray0')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
299 rects[2,] <- c(0,73,'white')
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
300 rects$xend <- as.numeric(rects$xend)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
301 rects$xstart <- as.numeric(rects$xstart)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
302 return(rects)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
303 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
304
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
305 ## Create new folder.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
306 ## mainDir String The directory of the new folder.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
307 ## folder String The name of the new folder.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
308 createFolder <- function(mainDir, folder) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
309 if (file.exists(folder)){
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
310 setwd(file.path(mainDir, folder))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
311 } else {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
312 dir.create(file.path(mainDir, folder))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
313 setwd(file.path(mainDir, folder))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
314 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
315 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
316
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
317 # Multiple plot function
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
318 #
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
319 # ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
320 # - cols: Number of columns in layout
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
321 # - layout: A matrix specifying the layout. If present, 'cols' is ignored.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
322 #
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
323 # If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE),
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
324 # then plot 1 will go in the upper left, 2 will go in the upper right, and
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
325 # 3 will go all the way across the bottom.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
326 # http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
327 multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
328 library(grid)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
329
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
330 # Make a list from the ... arguments and plotlist
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
331 plots <- c(list(...), plotlist)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
332
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
333 numPlots = length(plots)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
334
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
335 # If layout is NULL, then use 'cols' to determine layout
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
336 if (is.null(layout)) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
337 # Make the panel
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
338 # ncol: Number of columns of plots
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
339 # nrow: Number of rows needed, calculated from # of cols
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
340 layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
341 ncol = cols, nrow = ceiling(numPlots/cols))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
342 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
343
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
344 if (numPlots==1) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
345 print(plots[[1]])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
346
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
347 } else {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
348 # Set up the page
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
349 grid.newpage()
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
350 pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
351
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
352 # Make each plot, in the correct location
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
353 for (i in 1:numPlots) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
354 # Get the i,j matrix positions of the regions that contain this subplot
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
355 matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
356
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
357 print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
358 layout.pos.col = matchidx$col))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
359 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
360 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
361 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
362
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
363 ## Save all the plots in a pdf file
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
364 ## name String The name of the file
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
365 ## data Array All the plots
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
366 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
367 savePlotPDF <- function(name, data) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
368 pdf(name)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
369 invisible(lapply(data, print))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
370 dev.off()
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
371 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
372
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
373 ## Order the conditions per group
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
374 ## conditions Data Frame All the conditions
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
375 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
376 orderConditionData <- function(conditions) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
377 experimentNames <- unique(conditions[,2])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
378 maxSizeId <- tail(names(sort(table(conditions[,2]))), 1)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
379 maxSize <- nrow(conditions[conditions[,2] == maxSizeId,])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
380 result <- matrix(nrow = length(experimentNames), ncol = maxSize)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
381 row.names(result) <- experimentNames
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
382 colnames(result) <- c(1:maxSize)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
383 for(i in 1:length(experimentNames)) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
384 for (j in 1:maxSize) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
385 result[experimentNames[i],j] <- conditions[conditions[,2] == experimentNames[i],][,1][j]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
386 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
387 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
388 return(result)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
389 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
390
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
391 ## Get the times or names of the conditions.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
392 ## conditions data frame All the text of the control file.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
393 ## separaLine Int The line where the flag was founded.
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
394 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
395 getNamesOfConditions <- function(conditions, separateLine) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
396 columnsNameTime <- conditions[(as.numeric(separateLine) + 1):nrow(conditions), ]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
397 colnames(columnsNameTime) <- columnsNameTime[1,]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
398 columnsNameTime <- columnsNameTime[-1,]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
399 row.names(columnsNameTime) <- columnsNameTime[,1]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
400 ##columnsNameTime <- columnsNameTime[,-1]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
401 return(columnsNameTime)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
402 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
403
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
404 ## Get the directory of a file
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
405 ## file String File name and directory
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
406 ## Rodrigo Dorado
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
407 getDirectoryOfFile <- function(file) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
408 dir <- file
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
409 allDir <- strsplit(dir, "/")[[1]]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
410 allEnters<-length(allDir) - 1
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
411 directory<-allDir[1]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
412 for(i in 2:allEnters) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
413 directory<-paste(directory, allDir[i], sep = "/")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
414 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
415 return(list("directory" = directory, "file" = allDir[length(allDir)]) )
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
416 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
417
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
418 spec = matrix(c(
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
419 'filename', 'f', 1, "character",
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
420 'controlFile', 'c', 1, "character",
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
421 #'projectName', 'p', 1, "character",
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
422 'SpaceString', 's', 1, "character",
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
423 'idColumn', 'i', 1, "integer",
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
424 'firstExperiment', 'e', 1, "integer",
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
425 'csvFile', 'v', 1, "character",
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
426 'pdfFile', 'd', 1, "character"
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
427 ), byrow=TRUE, ncol=4)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
428
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
429 opt = getopt(spec)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
430
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
431 filename <- opt$filename
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
432 controlFileName <- opt$controlFile
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
433 #project_name <- opt$projectName
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
434 SpaceString <- opt$SpaceString
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
435 id_column <- opt$idColumn
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
436 first_experiment <- opt$firstExperiment
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
437 csvFile <- opt$csvFile
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
438 pdfFile <- opt$pdfFile
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
439
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
440
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
441 directoryF <- getDirectoryOfFile(filename)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
442 directoryC <- getDirectoryOfFile(controlFileName)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
443 directoryCSV <- getDirectoryOfFile(csvFile)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
444 directoryPDF <- getDirectoryOfFile(pdfFile)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
445
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
446
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
447 #directory <- "/home/rodrigodorado/MClustDirectory/" ##Directory of the file
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
448 #filename <- "EXP11_paraR_log.txt" ##File name
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
449 #project_name <- "june_20_2018" ##Project name
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
450 #controlFileName <- "EXP11_paraR_log_properties" ##Control File
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
451 #id_column <- 31 ##Column number of the id of the proteins
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
452 #first_experiment <- 0 ##Colmn number where the Experiments start
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
453 #SpaceString <- "."
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
454 ANOVA_type <- "ONE-WAY"
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
455 #ANOVA_type <- "TOW_WAY"
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
456
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
457 All_proteins <- readCsvDirectory(directoryF$directory, directoryF$file, SpaceString)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
458 conditions <- readCsvDirectory(directoryC$directory, directoryC$file, SpaceString)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
459 separateLine <- row.names(conditions[conditions[,1] == '-- SEPARATE --',])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
460 columnsNameTime <- getNamesOfConditions(conditions, separateLine)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
461 conditions <- conditions[1:(as.numeric(separateLine) - 1), ]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
462 printInfo(conditions)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
463 conditions[,1] <- gsub(" ", SpaceString, conditions[,1])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
464 printInfo(conditions)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
465 Column_division <- nrow(conditions)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
466 orderCondition <- orderConditionData(conditions)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
467 printInfo(orderCondition)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
468 printInfo(All_proteins)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
469 #createFolder(directory, project_name)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
470 proteins_complete <- getDataofInfo(All_proteins, id_column, first_experiment, Column_division)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
471 printInfo(proteins_complete)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
472 proteins_New_column <- VarifyAComplteGroup(proteins_complete, orderCondition)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
473 printInfo(proteins_New_column)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
474 proteins_for_ANOVA <- proteins_New_column[,1:Column_division]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
475 proteins <- proteins_New_column[,(Column_division + 1):ncol(proteins_New_column)]
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
476 printInfo(proteins_for_ANOVA)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
477 printInfo(proteins)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
478 #write.csv(proteins_for_ANOVA, "Proteins For Anova.csv",row.names = TRUE, quote = FALSE)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
479 #write.csv(proteins, "Proteins With Conditions.csv",row.names = TRUE, quote = FALSE)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
480 p_values <- calculateANOVA(proteins_for_ANOVA, orderCondition, ANOVA_type)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
481 printInfo(p_values)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
482 proteins <- mergeById(proteins, p_values)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
483 printInfo(proteins)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
484 selectedSignificantExpr <- selectSignificanProteinsExpression(proteins)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
485 printInfo(selectedSignificantExpr)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
486 Sig_Pro_Exp_ZValues <- getZValueSgnificantProteinExpression(selectedSignificantExpr)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
487 printInfo(Sig_Pro_Exp_ZValues)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
488
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
489 clusters <- executeMClust(Sig_Pro_Exp_ZValues, directoryCSV$directory, directoryCSV$file)#'clusters.csv'
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
490 printInfo(clusters)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
491 Sig_Pro_Exp_ZValues_melt <- getZvaluesMelt(Sig_Pro_Exp_ZValues, clusters, orderCondition, columnsNameTime)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
492
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
493 rects <- setBackGroundColors()
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
494
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
495 ##plot the result. note: make function(s)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
496 plots_withBackground <- list()
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
497 plots_withOutBackground <- list()
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
498 for (clusterNumber in 1:max(clusters$Cluster)){
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
499 averageProfile <- as.data.frame(matrix(ncol = nrow(orderCondition),nrow=1))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
500 timesCond <- row.names(orderCondition)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
501 colnames(averageProfile) <- timesCond
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
502 for (cond in 1:nrow(orderCondition)) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
503 averageProfile[timesCond[cond]] <- mean(selectedSignificantExpr[row.names(selectedSignificantExpr) %in% clusters[which(clusters$Cluster == clusterNumber),"ProteinID"], timesCond[cond]])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
504 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
505
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
506 zval_DEGenes_cluster <- as.data.frame(t(scale(t(averageProfile))))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
507 zval_DEGenes_cluster$ClusterNumber <- clusterNumber
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
508 zval_DEGenes_cluster_melt <- melt(zval_DEGenes_cluster, id.vars="ClusterNumber")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
509 zval_DEGenes_cluster_melt$ClusterNumber <- NULL
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
510 colnames(zval_DEGenes_cluster_melt) <- c("Time","RelativeExpression")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
511 zval_DEGenes_cluster_melt$ProteinID <- "Average"
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
512
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
513 for(cond in 1:nrow(orderCondition)) {
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
514 zval_DEGenes_cluster_melt$Time2[zval_DEGenes_cluster_melt$Time == timesCond[cond]] <- as.numeric(columnsNameTime[timesCond[cond], 2])
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
515 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
516
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
517 numberGenes = length(unique(clusters[which(clusters$Cluster == clusterNumber),"ProteinID"]))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
518
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
519 outFilePlot1 = paste("cluster1",clusterNumber,"graphWithoutBackground","pdf",sep=".")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
520 outFilePlot2 = paste("cluster1",clusterNumber,"graphWithBackground","pdf",sep=".")
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
521
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
522 p <- ggplot(Sig_Pro_Exp_ZValues_melt[ which(Sig_Pro_Exp_ZValues_melt$Cluster == clusterNumber),], aes(x = Time2, y = RelativeExpression, group = ProteinID)) +
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
523 geom_line(col = "lightgray") +
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
524 geom_line(data = zval_DEGenes_cluster_melt, aes(x = Time2, y = RelativeExpression)) +
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
525 theme_bw() +
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
526 xlab("Time point") +
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
527 ylab("Relative expression") +
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
528 ggtitle(paste("Cluster 1", clusterNumber, sep = ".")) +
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
529 annotate("text", x = 3, y = 1, label = paste(numberGenes,"proteins", sep = " "))
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
530 ##ggsave(filename = outFilePlot1, plot = p)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
531 plots_withOutBackground[[clusterNumber]] <- p
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
532 }
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
533 setwd(directoryPDF$directory)
f3fa21cda5f5 planemo upload commit 13e72e84c523bda22bda792bbebf4720d28542d5-dirty
labis-app
parents:
diff changeset
534 savePlotPDF(directoryPDF$file, plots_withOutBackground)