annotate selection.R @ 6:7dc6ce39fb89 default tip

add selection tool
author blanck
date Wed, 29 Apr 2015 10:08:52 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
1 args<-commandArgs(TRUE)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
2
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
3 input=args[1]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
4 dataResponse=args[2]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
5 chrom=args[3]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
6 tmp_dir=args[4]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
7 signal=args[5]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
8 snp=type.convert(args[6])
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
9 settingsType=args[7]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
10 tumor=args[8]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
11 fold=as.integer(args[9])
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
12 loss=args[10]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
13 plot=type.convert(args[11])
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
14 output=args[12]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
15 user=args[13]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
16 package=args[14]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
17
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
18
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
19 library(MPAgenomics)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
20 library(glmnet)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
21 library(spikeslab)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
22 library(lars)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
23 workdir=file.path(tmp_dir, "mpagenomics",user)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
24 setwd(workdir)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
25
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
26 if (grepl("all",tolower(chrom)) | chrom=="None") {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
27 chrom_vec=c(1:25)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
28 } else {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
29 chrom_tmp <- strsplit(chrom,",")
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
30 chrom_vecstring <-unlist(chrom_tmp)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
31 chrom_vec <- as.numeric(chrom_vecstring)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
32 }
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
33
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
34
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
35 if (settingsType == "tumor") {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
36 if (signal=="CN") {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
37 res=markerSelection(input,dataResponse, chromosome=chrom_vec, signal=signal, normalTumorArray=tumor, onlySNP=snp, loss=loss, plot=plot, nbFolds=fold, pkg=package)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
38 } else {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
39 res=markerSelection(input,dataResponse, chromosome=chrom_vec,signal=signal,normalTumorArray=tumor, loss=loss, plot=plot, nbFolds=fold,pkg=package)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
40 }
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
41 } else {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
42 if (signal=="CN") {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
43 res=markerSelection(input,dataResponse, chromosome=chrom_vec, signal=signal, onlySNP=snp, loss=loss, plot=plot, nbFolds=fold,pkg=package)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
44 } else {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
45 res=markerSelection(input,dataResponse, chromosome=chrom_vec, signal=signal, loss=loss, plot=plot, nbFolds=fold,pkg=package)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
46 }
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
47 }
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
48
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
49 res
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
50
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
51 df=data.frame()
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
52 list_chr=names(res)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
53 markerSelected=FALSE
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
54
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
55 for (i in list_chr) {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
56 chr_data=res[[i]]
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
57 len=length(chr_data$markers.index)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
58 if (len != 0)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
59 {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
60 markerSelected=TRUE
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
61 chrdf=data.frame(rep(i,len),chr_data$markers.position,chr_data$markers.index,chr_data$markers.names,chr_data$coefficient)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
62 df=rbind(df,chrdf)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
63 }
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
64 }
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
65
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
66 if (markerSelected) {
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
67 colnames(df) <- c("chr","position","index","names","coefficient")
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
68 sink(output)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
69 print(format(df),row.names=FALSE)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
70 sink()
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
71 #write.table(df,output,row.names = FALSE, quote = FALSE, sep = "\t")
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
72 } else
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
73 writeLines("no SNP selected", output)
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
74
7dc6ce39fb89 add selection tool
blanck
parents:
diff changeset
75