comparison loadandplot.R @ 74:2bb6b44093ba draft

Uploaded 20170619
author fabio
date Mon, 19 Jun 2017 12:08:59 -0400
parents fcc0eb90fb07
children
comparison
equal deleted inserted replaced
73:156b29da2f0b 74:2bb6b44093ba
17 # as second column the corresponding ids and as third column the names 17 # as second column the corresponding ids and as third column the names
18 tryCatch({ 18 tryCatch({
19 regionsheader=read.delim(args_values$regionsheaderfile,header=FALSE,stringsAsFactors=FALSE,row.names=1,sep="\t") 19 regionsheader=read.delim(args_values$regionsheaderfile,header=FALSE,stringsAsFactors=FALSE,row.names=1,sep="\t")
20 regionsfilenames=unlist(strsplit(args_values$regionsfilenames,'\\|')) 20 regionsfilenames=unlist(strsplit(args_values$regionsfilenames,'\\|'))
21 if(length(setdiff(regionsfilenames,row.names(regionsheader)))) { 21 if(length(setdiff(regionsfilenames,row.names(regionsheader)))) {
22 write("IWTomics message: Not all region files are present in the first column of header file for regions.", stderr())
22 quit(save="no", status=11) 23 quit(save="no", status=11)
23 stop('Not all regionsfilenames are present in the first column of regionsheader.')
24 } 24 }
25 id_regions=regionsheader[regionsfilenames,1] 25 id_regions=regionsheader[regionsfilenames,1]
26 name_regions=regionsheader[regionsfilenames,2] 26 name_regions=regionsheader[regionsfilenames,2]
27 }, error = function(err) { 27 }, error = function(err) {
28 write("IWTomics message: An error has occurred reading the header file for regions. Please try again.", stderr())
28 quit(save="no", status=10) #error on header file 29 quit(save="no", status=10) #error on header file
29 stop(err)
30 }) 30 })
31 }else{ 31 }else{
32 eval(parse(text=args[[which(args_names=='regionsgalaxyids')]])) 32 eval(parse(text=args[[which(args_names=='regionsgalaxyids')]]))
33 id_regions=paste0('data_',regionsgalaxyids) 33 id_regions=paste0('data_',regionsgalaxyids)
34 name_regions=paste0('data_',regionsgalaxyids) 34 name_regions=paste0('data_',regionsgalaxyids)
39 # as second column the corresponding ids and as third column the names 39 # as second column the corresponding ids and as third column the names
40 tryCatch({ 40 tryCatch({
41 featuresheader=read.delim(args_values$featuresheaderfile,header=FALSE,stringsAsFactors=FALSE,row.names=1,sep="\t") 41 featuresheader=read.delim(args_values$featuresheaderfile,header=FALSE,stringsAsFactors=FALSE,row.names=1,sep="\t")
42 featuresfilenames=unlist(strsplit(args_values$featuresfilenames,'\\|')) 42 featuresfilenames=unlist(strsplit(args_values$featuresfilenames,'\\|'))
43 if(length(setdiff(featuresfilenames,row.names(featuresheader)))) { 43 if(length(setdiff(featuresfilenames,row.names(featuresheader)))) {
44 write("IWTomics message: Not all feature files are present in the first column of header file for features.", stderr())
44 quit(save="no", status=21) 45 quit(save="no", status=21)
45 stop('Not all featuresfilenames are present in the first column of featuresheader.')
46 } 46 }
47 id_features=featuresheader[featuresfilenames,1] 47 id_features=featuresheader[featuresfilenames,1]
48 name_features=featuresheader[featuresfilenames,2] 48 name_features=featuresheader[featuresfilenames,2]
49 }, error = function(err) { 49 }, error = function(err) {
50 write("IWTomics message: An error has occurred reading the header file for features. Please try again.", stderr())
50 quit(save="no", status=20) #error on header file 51 quit(save="no", status=20) #error on header file
51 stop(err)
52 }) 52 })
53 }else{ 53 }else{
54 eval(parse(text=args[[which(args_names=='featuresgalaxyids')]])) 54 eval(parse(text=args[[which(args_names=='featuresgalaxyids')]]))
55 id_features=paste0('data_',featuresgalaxyids) 55 id_features=paste0('data_',featuresgalaxyids)
56 name_features=paste0('data_',featuresgalaxyids) 56 name_features=paste0('data_',featuresgalaxyids)
65 tryCatch({ 65 tryCatch({
66 regionsFeatures=IWTomicsData(regionspaths,featurespaths,alignment, 66 regionsFeatures=IWTomicsData(regionspaths,featurespaths,alignment,
67 id_regions,name_regions,id_features,name_features,start.are.0based=start.are.0based) 67 id_regions,name_regions,id_features,name_features,start.are.0based=start.are.0based)
68 }, error = function(err) { 68 }, error = function(err) {
69 if(grepl('invalid format',err$message)){ 69 if(grepl('invalid format',err$message)){
70 write("IWTomics message: Not enough columns in input file.", stderr())
70 quit(save="no", status=31) # error, not enough columns in input file 71 quit(save="no", status=31) # error, not enough columns in input file
71 }else if(grepl('duplicated regions',err$message)){ 72 }else if(grepl('duplicated regions',err$message)){
73 write("IWTomics message: Duplicated regions in region file.", stderr())
72 quit(save="no", status=32) # error, duplicated regions in region file 74 quit(save="no", status=32) # error, duplicated regions in region file
73 }else if(grepl('duplicated windows',err$message)){ 75 }else if(grepl('duplicated windows',err$message)){
76 write("IWTomics message: Duplicated windows in feature file.", stderr())
74 quit(save="no", status=33) # error, duplicated windows in feature file 77 quit(save="no", status=33) # error, duplicated windows in feature file
75 }else if(grepl('overlapping windows',err$message)){ 78 }else if(grepl('overlapping windows',err$message)){
79 write("IWTomics message: Overlapping windows in feature file.", stderr())
76 quit(save="no", status=34) # error, overlapping windows in feature file 80 quit(save="no", status=34) # error, overlapping windows in feature file
77 }else if(grepl('not all regions in datasets',err$message)){ 81 }else if(grepl('not all regions in datasets',err$message)){
82 write("IWTomics message: Windows in feature files do not cover all regions in region files.", stderr())
78 quit(save="no", status=35) # error, windows in feature files do not cover all regions in region files 83 quit(save="no", status=35) # error, windows in feature files do not cover all regions in region files
79 }else if(grepl('ifferent size windows',err$message)){ 84 }else if(grepl('ifferent size windows',err$message)){
85 write("IWTomics message: All windows in a feature file must have the same size.", stderr())
80 quit(save="no", status=36) # error, all windows in a feature files must have the same size 86 quit(save="no", status=36) # error, all windows in a feature files must have the same size
81 } 87 }
82 #error loading data 88 #error loading data
83 89 write("IWTomics message: An error has occurred reading the data. Please try again.", stderr())
84 stop(err) 90 quit(save="no", status=30)
85
86 quit(save="no", status=30)
87
88 }) 91 })
89 92
90 # smooth data 93 # smooth data
91 if(smoothing!='no'){ 94 if(smoothing!='no'){
92 tryCatch({ 95 tryCatch({
109 }else{ 112 }else{
110 regionsFeatures=smooth(regionsFeatures,type=smoothing,fill_gaps=fill_gaps, 113 regionsFeatures=smooth(regionsFeatures,type=smoothing,fill_gaps=fill_gaps,
111 bandwidth=bandwidth,degree=degree,dist_knots=dist_knots) 114 bandwidth=bandwidth,degree=degree,dist_knots=dist_knots)
112 } 115 }
113 }, error = function(err) { 116 }, error = function(err) {
117 write("IWTomics message: An error has occurred smoothing the data. Please try again.", stderr())
114 quit(save="no", status=40) #error on smoothing 118 quit(save="no", status=40) #error on smoothing
115 stop(err)
116 }) 119 })
117 } 120 }
118 121
119 # plot data 122 # plot data
120 pdf(outpdf,width=10,height=8) 123 pdf(outpdf,width=10,height=8)
134 #write.table(cbind(unlist(strsplit(args_values$featuresfilenames,'\\|')),idFeatures(regionsFeatures),nameFeatures(regionsFeatures)), 137 #write.table(cbind(unlist(strsplit(args_values$featuresfilenames,'\\|')),idFeatures(regionsFeatures),nameFeatures(regionsFeatures)),
135 #file=outfeatures,quote=FALSE,sep='\t',row.names=FALSE,col.names=FALSE) 138 #file=outfeatures,quote=FALSE,sep='\t',row.names=FALSE,col.names=FALSE)
136 write.table(as.data.frame(t(idFeatures(regionsFeatures))),file=outfeatures,quote=FALSE,sep='\t',row.names=FALSE,col.names=FALSE) 139 write.table(as.data.frame(t(idFeatures(regionsFeatures))),file=outfeatures,quote=FALSE,sep='\t',row.names=FALSE,col.names=FALSE)
137 save(regionsFeatures,file=outrdata) 140 save(regionsFeatures,file=outrdata)
138 }else{ 141 }else{
142 write("IWTomics message: Missing IWTomics package. Please be sure to have it installed before using this tool.", stderr())
139 quit(save="no", status=255) 143 quit(save="no", status=255)
140 stop("Missing IWTomics package")
141 } 144 }