annotate peca.R @ 4:07bd2582526b draft

planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
author caleb-easterly
date Thu, 22 Feb 2018 11:35:33 -0500
parents 784c107c5861
children 5a39fa8a235a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
1 #!/usr/bin/env Rscript
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
2
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
3 library(PECA)
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
4
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
5 # Set up R error handling to go to stderr
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
6 options(show.error.messages=F, error=function(){cat(geterrmessage(),file=stderr());q("no",1,F)})
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
7
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
8 # Avoid crashing Galaxy with an UTF8 error on German LC settings
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
9 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
10
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
11 main <- function() {
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
12 args <- commandArgs(trailingOnly = TRUE)
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
13
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
14 # read first argument, which is quant file (proteins in rows, samples in columns)
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
15 quant_file <- read.delim(args[1],
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
16 na.strings = c("0", "NA"),
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
17 sep = '\t')
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
18
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
19 # read 2nd and 3rd argument, which are path to files with group 1 and 2 column indices
3
784c107c5861 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents: 0
diff changeset
20 group1_ind_file <- as.vector(as.matrix(read.csv(args[2], header = FALSE)[1, ]))
784c107c5861 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents: 0
diff changeset
21 group2_ind_file <- as.vector(as.matrix(read.csv(args[3], header = FALSE)[1, ]))
0
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
22
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
23 # read 4th argument, which is output file name
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
24 out_file <- args[4]
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
25
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
26 # get vectors of column names
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
27 df_names <- colnames(quant_file)
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
28 group1_names <- df_names[group1_ind_file]
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
29 group2_names <- df_names[group2_ind_file]
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
30
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
31 # run PECA_df
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
32 # id column is first column (hard-coded)
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
33 results <- PECA_df(quant_file, group1_names, group2_names, id = df_names[1])
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
34
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
35 # put add protein names column
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
36 results$prot <- row.names(results)
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
37 results <- results[, c("prot", "slr", "t", "score", "n", "p", "p.fdr")]
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
38
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
39 # write to output
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
40 write.table(results, file=out_file,
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
41 quote=FALSE,
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
42 sep ='\t',
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
43 row.names = FALSE)
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
44 }
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
45
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
46 main()