forked from Czh3/iSeq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.R
More file actions
31 lines (28 loc) · 906 Bytes
/
Copy pathReadFile.R
File metadata and controls
31 lines (28 loc) · 906 Bytes
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
# read csv Expression data for iSeq
csvRead <- function(file){
exp = read.csv(file, header= T, sep=',', stringsAsFactors = F)
if (ncol(exp) == 1){
exp = read.table(file, header= T, sep='\t', stringsAsFactors = F)
}
genes = exp[,1]
if ( length(genes) != length(unique(genes)) ){
dup_gene = duplicated(genes)
#exp = exp[!duplicated(genes),]
dup_gene_name = genes[dup_gene]
genes = genes[!dup_gene]
for (j in unique(dup_gene_name)){
tmp = exp[exp[,1] == j,-1]
tmp = matrix(as.numeric( unlist(tmp)), ncol = ncol(tmp), byrow = F)
tmp = colSums(tmp)
exp = exp[exp[,1] != j,]
exp = rbind(exp, c(j, tmp))
}
}
rownames(exp) = exp[,1]
exp = exp[,-1]
exp1 = matrix(as.numeric( unlist(exp)), ncol = ncol(exp), byrow = F)
exp1 = as.data.frame(exp1)
rownames(exp1) = rownames(exp)
colnames(exp1) = colnames(exp)
return(exp1)
}