annotate segmentation.R @ 0:4d539083cf7f draft

planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
author sblanck
date Tue, 12 May 2020 10:40:36 -0400
parents
children 3fcbb8030fcc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
1 #!/usr/bin/env Rscript
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
2 # setup R error handling to go to stderr
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
3 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
4
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
5 # we need that to not crash galaxy with an UTF8 error on German LC settings.
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
6 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
7
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
8 library("optparse")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
9
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
10 ##### Read options
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
11 option_list=list(
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
12 make_option("--input",type="character",default=NULL, dest="input"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
13 make_option("--output",type="character",default=NULL, dest="output"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
14 make_option("--new_file_path",type="character",default=NULL, dest="new_file_path"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
15 make_option("--nbcall",type="character",default=NULL, dest="nbcall"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
16 make_option("--outputgraph",type="character",default=NULL, dest="outputgraph"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
17 make_option("--graph",type="character",default=NULL, dest="graph"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
18 make_option("--signalType",type="character",default=NULL, dest="signalType"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
19 make_option("--cellularity",type="character",default=NULL, dest="cellularity"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
20 make_option("--outputlog",type="character",default=NULL, dest="outputlog"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
21 make_option("--log",type="character",default=NULL, dest="log"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
22 make_option("--user_id",type="character",default=NULL, dest="userid"),
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
23 make_option("--method",type="character",default=NULL, dest="method")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
24 );
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
25
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
26 opt_parser = OptionParser(option_list=option_list);
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
27 opt = parse_args(opt_parser);
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
28
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
29 if(is.null(opt$input)){
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
30 print_help(opt_parser)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
31 stop("input required.", call.=FALSE)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
32 }
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
33
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
34 #loading libraries
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
35
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
36 input=opt$input
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
37 output=opt$output
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
38 tmp_dir=opt$new_file_path
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
39 nbcall=as.numeric(opt$nbcall)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
40 outputgraph=type.convert(opt$outputgraph)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
41 cellularity=as.numeric(opt$cellularity)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
42 userId=opt$userid
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
43 method=opt$method
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
44 log=opt$log
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
45 outputlog=opt$outputlog
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
46 graph=opt$graph
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
47 signalType=opt$signalType
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
48
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
49 #args<-commandArgs(TRUE)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
50 #
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
51 #input=args[1]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
52 #tmp_dir=args[2]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
53 #nbcall=as.numeric(args[3])
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
54 #cellularity=as.numeric(args[4])
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
55 #output=args[5]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
56 #method=args[6]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
57 #userId=args[7]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
58 #signalType=args[8]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
59
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
60 library(MPAgenomics)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
61 workdir=file.path(tmp_dir,"mpagenomics",userId)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
62 setwd(workdir)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
63
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
64 if (outputlog){
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
65 sinklog <- file(log, open = "wt")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
66 sink(sinklog ,type = "output")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
67 sink(sinklog, type = "message")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
68 }
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
69
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
70 CN=read.table(input,header=TRUE)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
71 uniqueChr=unique(CN$chromosome)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
72 drops=c("chromosome","position","probeName")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
73 CNsignal=CN[,!(names(CN)%in% drops),drop=FALSE]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
74
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
75 samples=names(CNsignal)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
76
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
77 if (signalType=="CN")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
78 {
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
79
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
80 result=data.frame(sampleNames=character(0),chrom=character(0),chromStart=numeric(0),chromEnd=numeric(0),probes=numeric(0),means=numeric(0),calls=character(0),stringsAsFactors=FALSE)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
81
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
82 for (chr in uniqueChr)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
83 {
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
84 currentSubset=subset(CN, chromosome==chr)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
85 currentPositions=currentSubset["position"]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
86 for (sample in samples)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
87 {
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
88 currentSignal=currentSubset[sample]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
89 if (length(which(!is.na(unlist(currentSignal))))>1)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
90 {
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
91 currentSeg=segmentation(signal=unlist(currentSignal),position=unlist(currentPositions),method=method)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
92 callobj= callingObject(copynumber=currentSeg$signal, segmented=currentSeg$segmented,chromosome=rep(chr,length(currentSeg$signal)), position=currentSeg$startPos,sampleNames=sample)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
93 currentCall=callingProcess(callobj,nclass=nbcall,cellularity=cellularity,verbose=TRUE)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
94 currentResult=currentCall$segment
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
95 currentResult["sampleNames"]=c(rep(sample,length(currentCall$segment$chrom)))
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
96 result=rbind(result,currentResult)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
97 }
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
98 }
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
99 }
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
100 finalResult=data.frame(sampleNames=result["sampleNames"],chrom=result["chrom"],chromStart=result["chromStart"],chromEnd=result["chromEnd"],probes=result["probes"],means=result["means"],calls=result["calls"],stringsAsFactors=FALSE)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
101
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
102 write.table(finalResult,output,row.names = FALSE, quote=FALSE, sep = "\t")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
103 } else {
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
104 result=data.frame(sampleNames=character(0),chrom=character(0),start=numeric(0),end=numeric(0),points=numeric(0),means=numeric(0),stringsAsFactors=FALSE)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
105
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
106 for (chr in uniqueChr)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
107 {
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
108 cat(paste0("chromosome ",chr,"\n"))
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
109 currentSubset=subset(CN, chromosome==chr)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
110 currentPositions=currentSubset["position"]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
111 for (sample in samples)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
112 {
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
113 cat(paste0(" sample ",sample,"..."))
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
114 currentSignal=currentSubset[sample]
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
115 if (length(which(!is.na(unlist(currentSignal))))>1)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
116 {
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
117 currentSeg=segmentation(signal=unlist(currentSignal),position=unlist(currentPositions),method=method)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
118 currentResult=currentSeg$segment
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
119 currentResult["chrom"]=c(rep(chr,length(currentSeg$segment$means)))
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
120 currentResult["sampleNames"]=c(rep(sample,length(currentSeg$segment$means)))
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
121 result=rbind(result,currentResult)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
122
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
123 }
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
124 cat(paste0("OK\n"))
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
125 }
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
126 }
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
127 finalResult=data.frame(sampleNames=result["sampleNames"],chrom=result["chrom"],chromStart=result["start"],chromEnd=result["end"],probes=result["points"],means=result["means"],stringsAsFactors=FALSE)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
128 write.table(finalResult,output,row.names = FALSE, quote=FALSE, sep = "\t")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
129 }
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
130
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
131 if (outputgraph){
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
132 file.rename(file.path(tmp_dir,"mpagenomics",userId,"Rplots.pdf"), graph)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
133 }
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
134
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
135 if (outputlog){
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
136 sink(type="output")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
137 sink(type="message")
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
138 close(sinklog)
4d539083cf7f planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff changeset
139 }