annotate msnbase_readmsdata.r @ 10:0a0164b8c24d draft

planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 6f3e71bbe985b4c6af622c9395762b17416062ca
author lecorguille
date Tue, 30 Apr 2019 04:06:24 -0400
parents b6ef94529e50
children 226fb89cacc4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
1 #!/usr/bin/env Rscript
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
2
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
3 # ----- LOG FILE -----
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
4 log_file <- file("log.txt", open="wt")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
5 sink(log_file)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
6 sink(log_file, type = "output")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
7
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
8
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
9 # ----- PACKAGE -----
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
10 cat("\tSESSION INFO\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
11
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
12 #Import the different functions
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
13 source_local <- function(fname){ argv <- commandArgs(trailingOnly=FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) }
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
14 source_local("lib.r")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
15
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
16 pkgs <- c("MSnbase","batch")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
17 loadAndDisplayPackages(pkgs)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
18 cat("\n\n");
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
19
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
20
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
21 # ----- ARGUMENTS -----
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
22 cat("\tARGUMENTS INFO\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
23 args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
24 write.table(as.matrix(args), col.names=F, quote=F, sep='\t')
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
25
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
26 cat("\n\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
27
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
28
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
29 # ----- PROCESSING INFILE -----
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
30 cat("\tARGUMENTS PROCESSING INFO\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
31
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
32
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
33 cat("\n\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
34
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
35 # ----- INFILE PROCESSING -----
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
36 cat("\tINFILE PROCESSING INFO\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
37
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
38 # Handle infiles
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
39 if (!exists("singlefile")) singlefile <- NULL
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
40 if (!exists("zipfile")) zipfile <- NULL
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
41 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
42 zipfile <- rawFilePath$zipfile
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
43 singlefile <- rawFilePath$singlefile
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
44 directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
45
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
46 # Check some character issues
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
47 md5sumList <- list("origin" = getMd5sum(directory))
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
48 checkXmlStructure(directory)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
49 checkFilesCompatibilityWithXcms(directory)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
50
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
51
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
52 cat("\n\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
53
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
54
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
55 # ----- MAIN PROCESSING INFO -----
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
56 cat("\tMAIN PROCESSING INFO\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
57
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
58
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
59 cat("\t\tCOMPUTE\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
60
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
61 ## Get the full path to the files
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
62 files <- getMSFiles(directory)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
63
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
64 cat("\t\t\tCreate a phenodata data.frame\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
65 s_groups <- sapply(files, function(x) tail(unlist(strsplit(dirname(x),"/")), n=1))
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
66 s_name <- tools::file_path_sans_ext(basename(files))
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
67 pd <- data.frame(sample_name=s_name, sample_group=s_groups, stringsAsFactors=FALSE)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
68 print(pd)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
69
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
70 cat("\t\t\tLoad Raw Data\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
71 raw_data <- readMSData(files=files, pdata = new("NAnnotatedDataFrame", pd), mode="onDisk")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
72
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
73 # Transform the files absolute pathways into relative pathways
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
74 raw_data@processingData@files <- sub(paste(getwd(), "/", sep="") , "", raw_data@processingData@files)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
75
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
76 # Create a sampleMetada file
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
77 sampleNamesList <- getSampleMetadata(xdata=raw_data, sampleMetadataOutput="sampleMetadata.tsv")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
78
10
0a0164b8c24d planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 6f3e71bbe985b4c6af622c9395762b17416062ca
lecorguille
parents: 8
diff changeset
79 #cat("\t\t\tCompute and Store TIC and BPI\n")
0a0164b8c24d planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 6f3e71bbe985b4c6af622c9395762b17416062ca
lecorguille
parents: 8
diff changeset
80 #chromTIC <- chromatogram(raw_data, aggregationFun = "sum")
0a0164b8c24d planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 6f3e71bbe985b4c6af622c9395762b17416062ca
lecorguille
parents: 8
diff changeset
81 #chromBPI <- chromatogram(raw_data, aggregationFun = "max")
0
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
82
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
83 cat("\n\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
84
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
85 # ----- EXPORT -----
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
86
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
87 cat("\tMSnExp OBJECT INFO\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
88 print(raw_data)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
89 cat("\t\tphenoData\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
90 print(raw_data@phenoData@data)
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
91 cat("\n\n")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
92
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
93 #saving R data in .Rdata file to save the variables used in the present tool
8
b6ef94529e50 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 8ed93601e09e1db2fbaef5af29d58464b639f2a8
lecorguille
parents: 5
diff changeset
94 objects2save <- c("raw_data", "zipfile", "singlefile", "md5sumList", "sampleNamesList") #, "chromTIC", "chromBPI")
0
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
95 save(list=objects2save[objects2save %in% ls()], file="readmsdata.RData")
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
96
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
97
728ebc7ae7dd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
98 cat("\tDONE\n")