Mercurial > repos > lecorguille > xcms_merge
comparison xcms_merge.r @ 7:dca722aecb67 draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e384d6dd5f410799ec211f73bca0b5d5d7bc651e
author | lecorguille |
---|---|
date | Thu, 01 Mar 2018 04:15:19 -0500 |
parents | |
children | 6b5504f877ff |
comparison
equal
deleted
inserted
replaced
6:5c7a7484dc51 | 7:dca722aecb67 |
---|---|
1 #!/usr/bin/env Rscript | |
2 | |
3 #Import the different functions | |
4 source_local <- function(fname){ argv <- commandArgs(trailingOnly=FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } | |
5 source_local("lib.r") | |
6 | |
7 pkgs <- c("xcms","batch") | |
8 loadAndDisplayPackages(pkgs) | |
9 cat("\n\n"); | |
10 | |
11 args <- parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects | |
12 | |
13 # Handle infiles | |
14 if (!exists("singlefile")) singlefile <- NULL | |
15 if (!exists("zipfile")) zipfile <- NULL | |
16 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args) | |
17 zipfile <- rawFilePath$zipfile | |
18 singlefile <- rawFilePath$singlefile | |
19 args <- rawFilePath$args | |
20 directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile) | |
21 | |
22 cat("\tXSET MERGING...\n") | |
23 | |
24 for(image in args$images) { | |
25 load(image) | |
26 cat(sampleNamesList$sampleNamesOrigin,"\n") | |
27 if (!exists("xdata_merged")) { | |
28 xdata_merged <- xdata | |
29 singlefile_merged <- singlefile | |
30 md5sumList_merged <- md5sumList | |
31 sampleNamesList_merged <- sampleNamesList | |
32 } else { | |
33 xdata_merged <- c(xdata_merged,xdata) | |
34 singlefile_merged <- c(singlefile_merged,singlefile) | |
35 md5sumList_merged$origin <- rbind(md5sumList_merged$origin,md5sumList$origin) | |
36 sampleNamesList_merged$sampleNamesOrigin <- c(sampleNamesList_merged$sampleNamesOrigin,sampleNamesList$sampleNamesOrigin) | |
37 sampleNamesList_merged$sampleNamesMakeNames <- c(sampleNamesList_merged$sampleNamesMakeNames,sampleNamesList$sampleNamesMakeNames) | |
38 } | |
39 } | |
40 rm(image) | |
41 xdata <- xdata_merged; rm(xdata_merged) | |
42 singlefile <- singlefile_merged; rm(singlefile_merged) | |
43 md5sumList <- md5sumList_merged; rm(md5sumList_merged) | |
44 sampleNamesList <- sampleNamesList_merged; rm(sampleNamesList_merged) | |
45 | |
46 if (!is.null(args$sampleMetadata)) { | |
47 cat("\tXSET PHENODATA SETTING...\n") | |
48 sampleMetadataFile <- args$sampleMetadata | |
49 sampleMetadata <- read.table(sampleMetadataFile, h=F, sep=";", stringsAsFactors=F) | |
50 if (ncol(sampleMetadata) < 2) sampleMetadata <- read.table(sampleMetadataFile, h=F, sep="\t", stringsAsFactors=F) | |
51 if (ncol(sampleMetadata) < 2) sampleMetadata <- read.table(sampleMetadataFile, h=F, sep=",", stringsAsFactors=F) | |
52 if (ncol(sampleMetadata) < 2) { | |
53 error_message="Your sampleMetadata file seems not well formatted. The column separators accepted are ; , and tabulation" | |
54 print(error_message) | |
55 stop(error_message) | |
56 } | |
57 xdata@phenoData@data$sample_group=sampleMetadata$V2[match(xdata@phenoData@data$sample_name,sampleMetadata$V1)] | |
58 | |
59 if (any(is.na(pData(xdata)$sample_group))) { | |
60 sample_missing <- pData(xdata)$sample_name[is.na(pData(xdata)$sample_group)] | |
61 error_message <- paste("Those samples are missing in your sampleMetadata:", paste(sample_missing, collapse=" ")) | |
62 print(error_message) | |
63 stop(error_message) | |
64 } | |
65 } | |
66 save.image() | |
67 | |
68 cat("\tXCMSnExp OBJECT INFO\n") | |
69 print(pData(xdata)) | |
70 print(xdata) | |
71 cat("\n\n") | |
72 | |
73 cat("\txcmsSet OBJECT INFO\n") | |
74 # Get the legacy xcmsSet object | |
75 xset <- getxcmsSetObject(xdata) | |
76 print(xset@phenoData) | |
77 print(xset) | |
78 cat("\n\n") | |
79 | |
80 cat("\tSAVE RData\n") | |
81 #saving R data in .Rdata file to save the variables used in the present tool | |
82 objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList") | |
83 save(list=objects2save[objects2save %in% ls()], file="merged.RData") |