Mercurial > repos > caleb-easterly > peca
annotate peca.R @ 13:4dcfde657dc3 draft default tip
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
author | caleb-easterly |
---|---|
date | Thu, 08 Mar 2018 18:35:49 -0500 |
parents | 19bb06146c2e |
children |
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"), |
11
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
17 sep = '\t', |
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
18 stringsAsFactors=FALSE) |
0
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
19 |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
20 # 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
|
21 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
|
22 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
|
23 |
5
5a39fa8a235a
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
3
diff
changeset
|
24 # test type |
5a39fa8a235a
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
3
diff
changeset
|
25 ttype <- args[4] |
11
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
26 |
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
27 # paired or not |
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
28 pair <- args[5] == "true" |
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
29 |
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
30 # output file name |
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
31 out_file <- args[6] |
0
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
32 |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
33 # get vectors of column names |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
34 df_names <- colnames(quant_file) |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
35 group1_names <- df_names[group1_ind_file] |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
36 group2_names <- df_names[group2_ind_file] |
11
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
37 |
0
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
38 # run PECA_df |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
39 # id column is first column (hard-coded) |
11
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
40 results <- PECA_df(df = quant_file, |
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
41 samplenames1 = group1_names, |
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
42 samplenames2 = group2_names, |
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
43 test = ttype, |
19bb06146c2e
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
6
diff
changeset
|
44 paired = pair, |
5
5a39fa8a235a
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
3
diff
changeset
|
45 id = df_names[1]) |
0
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
46 |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
47 # put add protein names column |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
48 results$prot <- row.names(results) |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
49 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
|
50 |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
51 # write to output |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
52 write.table(results, file=out_file, |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
53 quote=FALSE, |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
54 sep ='\t', |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
55 row.names = FALSE) |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
56 } |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
57 |
f50bb34c1a37
planemo upload for repository https://github.com/caleb-easterly/galaxytools/peca
caleb-easterly
parents:
diff
changeset
|
58 main() |