Mercurial > repos > sblanck > mpagenomics_wrappers
comparison selection.R @ 8:d5ed62b4d3ac draft default tip
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233
author | sblanck |
---|---|
date | Tue, 12 May 2020 13:40:07 +0000 |
parents | af4f63f27c77 |
children |
comparison
equal
deleted
inserted
replaced
7:f2d24110f65a | 8:d5ed62b4d3ac |
---|---|
1 args<-commandArgs(TRUE) | 1 #!/usr/bin/env Rscript |
2 # setup R error handling to go to stderr | |
3 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) | |
2 | 4 |
3 input=args[1] | 5 # we need that to not crash galaxy with an UTF8 error on German LC settings. |
4 dataResponse=args[2] | 6 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
5 chrom=args[3] | 7 |
6 tmp_dir=args[4] | 8 library("optparse") |
7 signal=args[5] | 9 |
8 snp=type.convert(args[6]) | 10 ##### Read options |
9 settingsType=args[7] | 11 option_list=list( |
10 tumor=args[8] | 12 make_option("--chrom",type="character",default=NULL, dest="chrom"), |
11 fold=as.integer(args[9]) | 13 make_option("--input",type="character",default=NULL, dest="input"), |
12 loss=args[10] | 14 make_option("--output",type="character",default=NULL, dest="output"), |
13 plot=type.convert(args[11]) | 15 make_option("--new_file_path",type="character",default=NULL, dest="new_file_path"), |
14 output=args[12] | 16 make_option("--response",type="character",default=NULL, dest="response"), |
15 user=args[13] | 17 make_option("--settingsType",type="character",default=NULL, dest="settingsType"), |
16 package=args[14] | 18 make_option("--outputgraph",type="character",default=NULL, dest="outputgraph"), |
19 make_option("--settingsSnp",type="character",default=NULL, dest="settingsSnp"), | |
20 make_option("--settingsSignal",type="character",default=NULL, dest="settingsSignal"), | |
21 make_option("--settingsLoss",type="character",default=NULL, dest="settingsLoss"), | |
22 make_option("--pdffigures",type="character",default=NULL, dest="pdffigures"), | |
23 make_option("--folds",type="character",default=NULL, dest="folds"), | |
24 make_option("--outputlog",type="character",default=NULL, dest="outputlog"), | |
25 make_option("--log",type="character",default=NULL, dest="log"), | |
26 make_option("--userId",type="character",default=NULL, dest="userid"), | |
27 make_option("--settingsPackage",type="character",default=NULL, dest="settingsPackage") | |
28 ); | |
29 | |
30 opt_parser = OptionParser(option_list=option_list); | |
31 opt = parse_args(opt_parser); | |
32 | |
33 if(is.null(opt$input)){ | |
34 print_help(opt_parser) | |
35 stop("input required.", call.=FALSE) | |
36 } | |
37 | |
38 #loading libraries | |
39 | |
40 | |
41 chrom=opt$chrom | |
42 dataset=opt$input | |
43 dataResponse=opt$response | |
44 output=opt$output | |
45 tmp_dir=opt$new_file_path | |
46 signal=opt$settingsSignal | |
47 settingsType=opt$settingsType | |
48 outputfigures=type.convert(opt$outputgraph) | |
49 snp=type.convert(opt$settingsSnp) | |
50 user=opt$userid | |
51 folds=as.numeric(opt$folds) | |
52 loss=opt$settingsLoss | |
53 log=opt$log | |
54 outputlog=opt$outputlog | |
55 outputgraph=opt$outputgraph | |
56 pdffigures=opt$pdffigures | |
57 package=opt$settingsPackage | |
17 | 58 |
18 | 59 |
19 library(MPAgenomics) | 60 library(MPAgenomics) |
20 library(glmnet) | 61 library(glmnet) |
21 library(spikeslab) | 62 library(spikeslab) |
22 library(lars) | 63 library(lars) |
64 | |
65 inputDataset=read.table(file=dataset,stringsAsFactors=FALSE) | |
66 input=inputDataset[1,2] | |
23 workdir=file.path(tmp_dir, "mpagenomics",user) | 67 workdir=file.path(tmp_dir, "mpagenomics",user) |
68 print(workdir) | |
24 setwd(workdir) | 69 setwd(workdir) |
25 | 70 |
26 if (grepl("all",tolower(chrom)) | chrom=="None") { | 71 if (grepl("all",tolower(chrom)) | chrom=="None") { |
27 chrom_vec=c(1:25) | 72 chrom_vec=c(1:25) |
28 } else { | 73 } else { |
29 chrom_tmp <- strsplit(chrom,",") | 74 chrom_tmp <- strsplit(chrom,",") |
30 chrom_vecstring <-unlist(chrom_tmp) | 75 chrom_vecstring <-unlist(chrom_tmp) |
31 chrom_vec <- as.numeric(chrom_vecstring) | 76 chrom_vec <- as.numeric(chrom_vecstring) |
32 } | 77 } |
33 | 78 |
34 | 79 if (outputlog){ |
80 sinklog <- file(log, open = "wt") | |
81 sink(sinklog ,type = "output") | |
82 sink(sinklog, type = "message") | |
83 } | |
84 | |
35 if (settingsType == "tumor") { | 85 if (settingsType == "tumor") { |
36 if (signal=="CN") { | 86 if (signal=="CN") { |
37 res=markerSelection(input,dataResponse, chromosome=chrom_vec, signal=signal, normalTumorArray=tumor, onlySNP=snp, loss=loss, plot=plot, nbFolds=fold, pkg=package) | 87 res=markerSelection(input,dataResponse, chromosome=chrom_vec, signal=signal, normalTumorArray=tumor, onlySNP=snp, loss=loss, plot=outputfigures, nbFolds=folds, pkg=package) |
38 } else { | 88 } else { |
39 res=markerSelection(input,dataResponse, chromosome=chrom_vec,signal=signal,normalTumorArray=tumor, loss=loss, plot=plot, nbFolds=fold,pkg=package) | 89 res=markerSelection(input,dataResponse, chromosome=chrom_vec,signal=signal,normalTumorArray=tumor, loss=loss, plot=outputfigures, nbFolds=folds,pkg=package) |
40 } | 90 } |
41 } else { | 91 } else { |
42 if (signal=="CN") { | 92 if (signal=="CN") { |
43 res=markerSelection(input,dataResponse, chromosome=chrom_vec, signal=signal, onlySNP=snp, loss=loss, plot=plot, nbFolds=fold,pkg=package) | 93 res=markerSelection(input,dataResponse, chromosome=chrom_vec, signal=signal, onlySNP=snp, loss=loss, plot=outputfigures, nbFolds=folds,pkg=package) |
44 } else { | 94 } else { |
45 res=markerSelection(input,dataResponse, chromosome=chrom_vec, signal=signal, loss=loss, plot=plot, nbFolds=fold,pkg=package) | 95 res=markerSelection(input,dataResponse, chromosome=chrom_vec, signal=signal, loss=loss, plot=outputfigures, nbFolds=folds,pkg=package) |
46 } | 96 } |
47 } | 97 } |
48 | 98 |
49 res | 99 res |
50 | 100 |
61 chrdf=data.frame(rep(i,len),chr_data$markers.position,chr_data$markers.index,chr_data$markers.names,chr_data$coefficient) | 111 chrdf=data.frame(rep(i,len),chr_data$markers.position,chr_data$markers.index,chr_data$markers.names,chr_data$coefficient) |
62 df=rbind(df,chrdf) | 112 df=rbind(df,chrdf) |
63 } | 113 } |
64 } | 114 } |
65 | 115 |
116 if (outputgraph){ | |
117 file.rename(file.path(tmp_dir,"mpagenomics",user,"Rplots.pdf"), pdffigures) | |
118 } | |
119 | |
120 if (outputlog){ | |
121 sink(type="output") | |
122 sink(type="message") | |
123 close(sinklog) | |
124 } | |
125 | |
66 if (markerSelected) { | 126 if (markerSelected) { |
67 colnames(df) <- c("chr","position","index","names","coefficient") | 127 colnames(df) <- c("chr","position","index","names","coefficient") |
68 sink(output) | 128 #sink(output) |
69 print(format(df),row.names=FALSE) | 129 #print(format(df),row.names=FALSE) |
70 sink() | 130 #sink() |
71 #write.table(df,output,row.names = FALSE, quote = FALSE, sep = "\t") | 131 write.table(df,output,row.names = FALSE, quote = FALSE, sep = "\t") |
72 } else | 132 } else |
73 writeLines("no SNP selected", output) | 133 writeLines("no SNP selected", output) |
74 | 134 |
75 | 135 |