Mercurial > repos > lecorguille > xcms_merge
comparison xcms_merge.r @ 11:67ab853b89f3 draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit f01148783819c37e474790dbd56619862960448a
| author | lecorguille |
|---|---|
| date | Tue, 03 Apr 2018 11:38:21 -0400 |
| parents | 47e953d9da82 |
| children | 9efcd7620cde |
comparison
equal
deleted
inserted
replaced
| 10:47e953d9da82 | 11:67ab853b89f3 |
|---|---|
| 11 args <- parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects | 11 args <- parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects |
| 12 | 12 |
| 13 | 13 |
| 14 cat("\tXSET MERGING...\n") | 14 cat("\tXSET MERGING...\n") |
| 15 | 15 |
| 16 for(image in args$images) { | 16 mergeXDataReturn <- mergeXData(args) |
| 17 load(image) | 17 xdata <- mergeXDataReturn$xdata |
| 18 print(args) | 18 singlefile <- mergeXDataReturn$singlefile |
| 19 # Handle infiles | 19 md5sumList <- mergeXDataReturn$md5sumList |
| 20 if (!exists("singlefile")) singlefile <- NULL | 20 sampleNamesList <- mergeXDataReturn$sampleNamesList |
| 21 if (!exists("zipfile")) zipfile <- NULL | |
| 22 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args) | |
| 23 zipfile <- rawFilePath$zipfile | |
| 24 singlefile <- rawFilePath$singlefile | |
| 25 directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile) | |
| 26 | |
| 27 if (!exists("xdata")) stop("\n\nERROR: The RData doesn't contain any object called 'xdata'. This RData should have been created by an old version of XMCS 2.*") | |
| 28 cat(sampleNamesList$sampleNamesOrigin,"\n") | |
| 29 if (!exists("xdata_merged")) { | |
| 30 xdata_merged <- xdata | |
| 31 singlefile_merged <- singlefile | |
| 32 md5sumList_merged <- md5sumList | |
| 33 sampleNamesList_merged <- sampleNamesList | |
| 34 } else { | |
| 35 xdata_merged <- c(xdata_merged,xdata) | |
| 36 singlefile_merged <- c(singlefile_merged,singlefile) | |
| 37 md5sumList_merged$origin <- rbind(md5sumList_merged$origin,md5sumList$origin) | |
| 38 sampleNamesList_merged$sampleNamesOrigin <- c(sampleNamesList_merged$sampleNamesOrigin,sampleNamesList$sampleNamesOrigin) | |
| 39 sampleNamesList_merged$sampleNamesMakeNames <- c(sampleNamesList_merged$sampleNamesMakeNames,sampleNamesList$sampleNamesMakeNames) | |
| 40 } | |
| 41 } | |
| 42 rm(image) | |
| 43 xdata <- xdata_merged; rm(xdata_merged) | |
| 44 singlefile <- singlefile_merged; rm(singlefile_merged) | |
| 45 md5sumList <- md5sumList_merged; rm(md5sumList_merged) | |
| 46 sampleNamesList <- sampleNamesList_merged; rm(sampleNamesList_merged) | |
| 47 | |
| 48 if (!is.null(args$sampleMetadata)) { | |
| 49 cat("\tXSET PHENODATA SETTING...\n") | |
| 50 sampleMetadataFile <- args$sampleMetadata | |
| 51 sampleMetadata <- read.table(sampleMetadataFile, h=F, sep=";", stringsAsFactors=F) | |
| 52 if (ncol(sampleMetadata) < 2) sampleMetadata <- read.table(sampleMetadataFile, h=F, sep="\t", stringsAsFactors=F) | |
| 53 if (ncol(sampleMetadata) < 2) sampleMetadata <- read.table(sampleMetadataFile, h=F, sep=",", stringsAsFactors=F) | |
| 54 if (ncol(sampleMetadata) < 2) { | |
| 55 error_message="Your sampleMetadata file seems not well formatted. The column separators accepted are ; , and tabulation" | |
| 56 print(error_message) | |
| 57 stop(error_message) | |
| 58 } | |
| 59 xdata@phenoData@data$sample_group=sampleMetadata$V2[match(xdata@phenoData@data$sample_name,sampleMetadata$V1)] | |
| 60 | |
| 61 if (any(is.na(pData(xdata)$sample_group))) { | |
| 62 sample_missing <- pData(xdata)$sample_name[is.na(pData(xdata)$sample_group)] | |
| 63 error_message <- paste("Those samples are missing in your sampleMetadata:", paste(sample_missing, collapse=" ")) | |
| 64 print(error_message) | |
| 65 stop(error_message) | |
| 66 } | |
| 67 } | |
| 68 | 21 |
| 69 # Create a sampleMetada file | 22 # Create a sampleMetada file |
| 70 sampleNamesList <- getSampleMetadata(xdata=xdata, sampleMetadataOutput="sampleMetadata.tsv") | 23 sampleNamesList <- getSampleMetadata(xdata=xdata, sampleMetadataOutput="sampleMetadata.tsv") |
| 71 | 24 |
| 72 cat("\n\n") | 25 cat("\n\n") |
