annotate peca.R @ 10:f0de83932f9e draft

planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
author caleb-easterly
date Mon, 05 Mar 2018 18:11:34 -0500
parents e16cd77cf9f7
children 19bb06146c2e
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
5
5a39fa8a235a planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents: 3
diff changeset
23 # test type
5a39fa8a235a planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents: 3
diff changeset
24 ttype <- args[4]
5a39fa8a235a planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents: 3
diff changeset
25
0
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
26 # read 4th argument, which is output file name
5
5a39fa8a235a planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents: 3
diff changeset
27 out_file <- args[5]
0
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
28
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
29 # get vectors of column names
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
30 df_names <- colnames(quant_file)
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
31 group1_names <- df_names[group1_ind_file]
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
32 group2_names <- df_names[group2_ind_file]
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
33
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
34 # run PECA_df
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
35 # id column is first column (hard-coded)
5
5a39fa8a235a planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents: 3
diff changeset
36 results <- PECA_df(quant_file,
5a39fa8a235a planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents: 3
diff changeset
37 group1_names,
5a39fa8a235a planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents: 3
diff changeset
38 group2_names,
5a39fa8a235a planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents: 3
diff changeset
39 id = df_names[1])
0
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
40
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
41 # put add protein names column
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
42 results$prot <- row.names(results)
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
43 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
44
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
45 # write to output
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
46 write.table(results, file=out_file,
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
47 quote=FALSE,
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
48 sep ='\t',
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
49 row.names = FALSE)
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
50 }
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
51
f50bb34c1a37 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
52 main()