Repository navigation
Expand file tree
/
Copy pathVarianceGenes.R
More file actions
executable file
·68 lines (41 loc) · 1.95 KB
/
Copy pathVarianceGenes.R
File metadata and controls
executable file
·68 lines (41 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/env Rscript
## Getting the destination pathway
actualPathway <- getwd()
destinationPathway <- file.path(normalizePath(dirname("../output")), "output")
setwd(destinationPathway)
## Reading the dataframe of data
openingFile <- read.csv("CompleteData.csv")
## Creating a function to compute varience of each gene
savingVariances <- function(x){
return(var(x))
}
## Creating a dataframe of variance of each gene
varianceDataframe <- apply(X = openingFile[, 2:(ncol(openingFile) - 1)], MARGIN = 2, FUN = savingVariances)
## Reformating the variance gene data in a dataframe R object
varianceDataframe <- as.data.frame(varianceDataframe)
## Sorting gene varience in an descending order
varianceDataframe <- varianceDataframe[order(varianceDataframe, decreasing = TRUE),, drop=FALSE]
## Creating a function to save genes with a varience superior to a threshold
SavingVarienceDataframe <- function(x){
## Selecting genes with variences superior to a threshold
columnsToSelect <- as.vector(rownames(varianceDataframe[varianceDataframe$varianceDataframe > x,, drop = FALSE]))
## Subset Dataframe columns with columnsToSelect (columns with genes whose the variance > x)
dataFrameSubset <- subset(openingFile, select = columnsToSelect)
## Adding labels to the newDataFrame
dataFrameSubset <- cbind(openingFile$X, dataFrameSubset)
dataFrameSubset <- cbind(dataFrameSubset, openingFile$Labels)
colnames(dataFrameSubset)[1] <- "X"
colnames(dataFrameSubset)[ncol(dataFrameSubset)] <- "Labels"
## Saving dataframes in folder according the thresholds
if (x == 10){
write.csv(dataFrameSubset, file = "399GenesDataframe/newDataFrame.csv",
row.names=FALSE, quote = FALSE)
}
else{
write.csv(dataFrameSubset, file = "2264GenesDataframe/newDataFrame.csv",
row.names=FALSE, quote = FALSE)
}
}
## Saving genes with varience superior to threshold
SavingVarienceDataframe(4)
SavingVarienceDataframe(10)