-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_analysis.R
executable file
·74 lines (63 loc) · 2.43 KB
/
run_analysis.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
args <- commandArgs(TRUE)[1];
.libPaths("/home/zhangz/R/x86_64-pc-linux-gnu-library/3.3");
fn <- paste(args, 'inputs.rds', sep='/');
if (!file.exists(fn)) {
message <- "File of input data not exist.";
} else {
input <- readRDS(fn);
require(DEGandMore);
data("DeMethodMeta");
mtrx <- list(input$filtered, input$normalized$count, input$normalized$logged);
mthd <- input$methods;
grps <- input$groups;
pair <- input$paired;
speed <- DeMethodMeta[mthd, 'Speed'];
mthd <- mthd[order(speed)];
fs <- paste(args, 'status.txt', sep='/');
if (!file.exists(fs)) file.remove(fs);
file.create(fs);
# RUNNING
msg <- sapply(mthd, function(m) {
lg <- DeMethodMeta[m, 'Logged'] == 'Yes';
nm <- DeMethodMeta[m, 'Normalization'] == 'Yes';
if (!lg & nm) d <- mtrx[[1]] else if (!lg) d <- mtrx[[2]] else d <- mtrx[[3]];
#####################################################################
tryCatch({
stat <- DeWrapper(d, grps, m, pair)$results$stat[, 1:6];
if (lg) {
un <- 2^mtrx[[3]];
un <- un * (mean(mtrx[[1]], na.rm=TRUE)/mean(un, na.rm=TRUE));
m1 <- rowMeans(un[, grps[[1]], drop=FALSE]);
m2 <- rowMeans(un[, grps[[2]], drop=FALSE]);
stat[, 1:3] <- cbind(m1, m2, m2-m1);
};
saveRDS(stat, paste(args, '/', m, '.rds', sep=''));
write(paste(m, 1, sep='\t'), fs, append = TRUE);
NA;
}, error = function(e) {
write(paste(m, 0, sep='\t'), fs, append = TRUE);
paste(m, as.character(e), sep=': ');
});
#####################################################################
});
# Error messages
msg <- as.vector(msg[!is.na(msg)]);
if (length(msg) == 0) message <- '' else
message <- paste(gsub('\n', '', msg), collapse='\n');
writeLines(message, paste(args, 'message.txt', sep='/'));
fn <- paste(args, 'email.txt', sep='/');
if (file.exists(fn)) {
ln <- readLines(fn);
msg <- paste(
ln[1], ' ', 'RNA-seq 2G has finished this analysis.',
'Go to http://rnaseq2g.awsomics.org, open the [Result] page,',
'choose [Option 2], and copy/paste the analysis ID to load results.'
);
cmd <- paste('echo', msg, '| mail -s "[No Reply] RNA-seq 2G analysis is done."', '[email protected]');
system(cmd);
if (length(ln)>=2 & ln[2]!='') {
cmd <- paste('echo', msg, '| mail -s "[No Reply] RNA-seq 2G analysis is done."', ln[2]);
system(cmd);
}
}
}