Mercurial > repos > tomnl > deconrank
annotate h-concatenate.R @ 4:b37f97bda760 draft
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit d4159f1962ef3fe37dd4f3047e4050afe013c15a-dirty
author | tomnl |
---|---|
date | Thu, 03 May 2018 05:20:17 -0400 |
parents | defa57c7775e |
children |
rev | line source |
---|---|
1
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
1 library(optparse) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
2 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
3 option_list <- list( |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
4 make_option(c("-f", "--files"), type="character"), |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
5 make_option(c("-c", "--columns"), type="character"), |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
6 make_option(c("-o", "--out_dir"), type="character"), |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
7 make_option(c("-u", "--uc"), type="character") |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
8 ) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
9 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
10 # store options |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
11 opt<- parse_args(OptionParser(option_list=option_list), args = commandArgs(trailingOnly = TRUE)) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
12 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
13 print(sessionInfo()) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
14 print(opt) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
15 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
16 file_paths <- trimws(strsplit(opt$files, ';')[[1]]) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
17 file_paths <- file_paths[file_paths != ""] |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
18 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
19 columns <- trimws(strsplit(opt$columns, ';')[[1]]) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
20 columns <- columns[columns != ""] |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
21 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
22 columns <- lapply(columns, function(x){trimws(strsplit(x, ',')[[1]])}) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
23 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
24 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
25 readIn <- function(f, c){ |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
26 print('#### reading in file with columns ####') |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
27 print(f) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
28 print(c) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
29 df <- read.table(f, header = TRUE, sep='\t', stringsAsFactors=FALSE) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
30 if (sum(colnames(df) %in% c)==0){ |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
31 print('PLEASE CHECK: Selected columns not in file!!') |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
32 print(colnames(df)) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
33 print(c) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
34 q() |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
35 } |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
36 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
37 df <- df[ , (colnames(df) %in% c)] |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
38 if (length(c)==1){ |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
39 df <- data.frame(df) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
40 colnames(df) <- c |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
41 } |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
42 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
43 return(df) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
44 } |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
45 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
46 m <- mapply(readIn, file_paths, columns, SIMPLIFY = FALSE) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
47 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
48 m <- unname(m) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
49 merged <- do.call(cbind, m) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
50 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
51 if(!is.null(opt$uc)){ |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
52 uc <- trimws(strsplit(opt$uc, ',')[[1]]) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
53 uc <- uc[uc != ""] |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
54 print(colnames(merged)) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
55 print(uc) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
56 merged <- merged[uc] |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
57 } |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
58 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
59 print(head(merged)) |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
60 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
61 write.table(merged, file.path(opt$out_dir, 'combined_table.tsv'), row.names=FALSE, sep='\t') |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
62 |
defa57c7775e
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff
changeset
|
63 |