annotate msnbase_readmsdata.r @ 13:cda005bc221c draft

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