annotate build_peca.R @ 3:784c107c5861 draft

planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
author caleb-easterly
date Thu, 22 Feb 2018 11:33:37 -0500
parents 36b7a5891000
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
1 #!/usr/bin/env Rscript
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
2
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
3 library(PECA)
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
4
36b7a5891000 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
36b7a5891000 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)})
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
7
36b7a5891000 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
36b7a5891000 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")
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
10
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
11 main <- function() {
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
12 args <- commandArgs(trailingOnly = TRUE)
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
13
36b7a5891000 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)
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
15 quant_file <- read.delim(args[1],
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
16 na.strings = c("0", "NA"),
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
17 sep = '\t')
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
18
36b7a5891000 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
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
20 group1_ind_file <- read.csv(args[2], header = FALSE)[1, ]
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
21 group2_ind_file <- read.csv(args[3], header = FALSE)[1, ]
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
22
36b7a5891000 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
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
24 out_file <- args[4]
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
25
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
26 # get vectors of column names
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
27 df_names <- colnames(quant_file)
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
28 group1_names <- df_names[group1_ind_file]
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
29 group2_names <- df_names[group2_ind_file]
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
30
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
31 # run PECA_df
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
32 # id column is first column (hard-coded)
36b7a5891000 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])
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
34
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
35 # put add protein names column
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
36 results$prot <- row.names(results)
36b7a5891000 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")]
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
38
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
39 # write to output
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
40 write.table(results, file=out_file,
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
41 quote=FALSE,
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
42 sep ='\t',
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
43 row.names = FALSE)
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
44 }
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
45
36b7a5891000 planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff changeset
46 main()