-
Notifications
You must be signed in to change notification settings - Fork 0
/
marks_with_msp_bigger_than_0.R
executable file
·52 lines (45 loc) · 1.66 KB
/
marks_with_msp_bigger_than_0.R
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
"Usage: marks_with_msp_bigger_than_0.R (--out1 <O1>) <input1>
-h --help show this
--out1 name1 bed file with all the corrected positions of the MS-DArT Tags
input1 input1 bed file with all MS-DArT Tags
marks_with_msp_bigger_than_0.R -h | --help show this message
" -> doc
# load the docopt library
require(docopt)
# retrieve the command-line arguments
opts <- docopt(doc)
require(gdata)
dados <- read.table(opts$`<input1>`,
header = T,
sep = "\t",
check.names = F)
# Select all sites with counts bigger than one in each column.
for (i in 2:ncol(dados)){
if (i == 2){
data_without_zero_all_samples <- dados[dados[, i] > 0, ]
all_marks <- as.data.frame(data_without_zero_all_samples[, 1])
colnames(all_marks) <- paste(names(dados)[i])
}else{
data_without_zero_sub <- dados[dados[, i] > 0, ]
all_marks_sub <- as.data.frame(data_without_zero_sub[, 1])
colnames(all_marks_sub) <- paste(names(dados)[i])
all_marks <- cbindX(all_marks, all_marks_sub)
}
}
# Separates the columns (samples) accordingly with the experimental groups (first name before the separator "_").
## Writes a file for each group.
y <- data.frame()
for (i in 1:length(names(all_marks))){
x <- as.data.frame(paste(strsplit(names(all_marks)[i], "_")[[1]][1]))
colnames(x) <- "group"
y <- rbind(y, x)
}
y$group <- as.factor(y$group)
for (i in 1:length(levels(y$group))){
group <- all_marks[y$group == sort(levels(y$group))[i]]
write.table(group,
paste(opts$O1),
row.names = F,
quote = F,
sep = "\t")
}