Mercurial > repos > iuc > ribowaltz_plot
comparison ribowaltz_plot.R @ 0:4fbc0799c63d draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ribowaltz commit ff002df702f544829d1b500ac4b517c1e70ad14d
| author | iuc |
|---|---|
| date | Thu, 22 Sep 2022 20:28:25 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4fbc0799c63d |
|---|---|
| 1 # setup R error handling to go to stderr | |
| 2 options(show.error.messages = FALSE, error = function() { | |
| 3 cat(geterrmessage(), file = stderr()) | |
| 4 q("no", 1, FALSE) | |
| 5 }) | |
| 6 | |
| 7 # we need that to not crash galaxy with an UTF8 error on German LC settings. | |
| 8 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") | |
| 9 library("getopt") | |
| 10 options(stringAsFactors = FALSE, useFancyQuotes = FALSE) | |
| 11 args <- commandArgs(trailingOnly = TRUE) | |
| 12 | |
| 13 # get options, using the spec as defined by the enclosed list. | |
| 14 # we read the options from the default: commandArgs(TRUE). | |
| 15 spec <- matrix(c( | |
| 16 "quiet", "q", 0, "logical", | |
| 17 "help", "h", 0, "logical", | |
| 18 "input_rdata", "i", 1, "character", | |
| 19 "params_rlength_distr", "r", 0, "character", | |
| 20 "params_rends_heat", "e", 0, "character", | |
| 21 "region_psite_plot", "R", 0, "logical", | |
| 22 "params_trint_periodicity", "t", 0, "character", | |
| 23 "params_metaplots", "m", 0, "character", | |
| 24 "params_codon_usage_psite", "u", 0, "character" | |
| 25 ), byrow = TRUE, ncol = 4) | |
| 26 opt <- getopt(spec) | |
| 27 | |
| 28 # if help was asked for print a friendly message | |
| 29 # and exit with a non-zero error code | |
| 30 if (!is.null(opt$help)) { | |
| 31 cat(getopt(spec, usage = TRUE)) | |
| 32 q(status = 1) | |
| 33 } | |
| 34 | |
| 35 verbose <- is.null(opt$quiet) | |
| 36 | |
| 37 library("riboWaltz") | |
| 38 library("jsonlite") | |
| 39 | |
| 40 load(opt$input_rdata) | |
| 41 | |
| 42 if (!is.null(opt$params_rlength_distr)) { | |
| 43 pdf("read_lengths.pdf") | |
| 44 json_rlength_distr <- fromJSON(opt$params_rlength_distr) | |
| 45 length_dist <- rlength_distr( | |
| 46 reads_psite_list, | |
| 47 sample = names(reads_psite_list), | |
| 48 cl = json_rlength_distr$cl, | |
| 49 multisamples = json_rlength_distr$multisamples, | |
| 50 plot_style = json_rlength_distr$plot_style | |
| 51 ) | |
| 52 print(length_dist) | |
| 53 dev.off() | |
| 54 } | |
| 55 | |
| 56 if (!is.null(opt$params_rends_heat)) { | |
| 57 pdf("read_ends_heatmap.pdf", height = 5 * length(reads_psite_list), width = 15) | |
| 58 json_rends_heat <- fromJSON(opt$params_rends_heat) | |
| 59 for (sample_name in names(reads_psite_list)) { | |
| 60 ends_heatmap <- rends_heat( | |
| 61 reads_psite_list, | |
| 62 annotation_dt, | |
| 63 sample = sample_name, | |
| 64 cl = json_rends_heat$cl, | |
| 65 utr5l = json_rends_heat$utr5l, | |
| 66 cdsl = json_rends_heat$cdsl, | |
| 67 utr3l = json_rends_heat$utr3l | |
| 68 ) | |
| 69 print(ends_heatmap[["plot"]]) | |
| 70 } | |
| 71 dev.off() | |
| 72 } | |
| 73 | |
| 74 if (!is.null(opt$region_psite_plot)) { | |
| 75 pdf("psites_per_region.pdf", height = 12, width = 7 * length(reads_psite_list)) | |
| 76 psite_region <- region_psite(reads_psite_list, annotation_dt, sample = names(reads_psite_list)) | |
| 77 print(psite_region[["plot"]]) | |
| 78 dev.off() | |
| 79 } | |
| 80 | |
| 81 if (!is.null(opt$params_trint_periodicity)) { | |
| 82 pdf("trinucleotide_periodicity.pdf", height = 6 * length(reads_psite_list), width = 10) | |
| 83 json_trint_periodicity <- fromJSON(opt$params_trint_periodicity) | |
| 84 frames_stratified <- frame_psite_length( | |
| 85 reads_psite_list, | |
| 86 sample = names(reads_psite_list), | |
| 87 cl = json_trint_periodicity$cl, | |
| 88 region = json_trint_periodicity$region, | |
| 89 length_range = json_trint_periodicity$length_range | |
| 90 ) | |
| 91 frames_stratified[["plot"]] | |
| 92 frames <- frame_psite_length( | |
| 93 reads_psite_list, | |
| 94 sample = names(reads_psite_list), | |
| 95 region = json_trint_periodicity$region, | |
| 96 length_range = json_trint_periodicity$length_range | |
| 97 ) | |
| 98 print(frames[["plot"]]) | |
| 99 dev.off() | |
| 100 } | |
| 101 | |
| 102 if (!is.null(opt$params_metaplots)) { | |
| 103 pdf("metaplots.pdf", height = 5 * length(reads_psite_list), width = 24) | |
| 104 json_metaplots <- fromJSON(opt$params_metaplots) | |
| 105 metaprofile <- metaprofile_psite( | |
| 106 reads_psite_list, | |
| 107 annotation_dt, | |
| 108 sample = names(reads_psite_list), | |
| 109 multisamples = json_metaplots$multisamples, | |
| 110 plot_style = json_metaplots$plot_style, | |
| 111 length_range = json_metaplots$length_range, | |
| 112 frequency = json_metaplots$frequency, | |
| 113 utr5l = json_metaplots$utr5l, | |
| 114 cdsl = json_metaplots$cdsl, | |
| 115 utr3l = json_metaplots$utr3l, | |
| 116 plot_title = "sample.transcript.length_range" | |
| 117 ) | |
| 118 print(metaprofile) | |
| 119 sample_list <- list() | |
| 120 for (sample_name in names(reads_psite_list)) { | |
| 121 sample_list[[sample_name]] <- c(sample_name) | |
| 122 } | |
| 123 metaheatmap <- metaheatmap_psite( | |
| 124 reads_psite_list, | |
| 125 annotation_dt, | |
| 126 sample = sample_list, | |
| 127 length_range = json_metaplots$length_range, | |
| 128 utr5l = json_metaplots$utr5l, | |
| 129 cdsl = json_metaplots$cdsl, | |
| 130 utr3l = json_metaplots$utr3l, | |
| 131 plot_title = "Comparison metaheatmap" | |
| 132 ) | |
| 133 print(metaheatmap[["plot"]]) | |
| 134 dev.off() | |
| 135 } | |
| 136 | |
| 137 if (!is.null(opt$params_codon_usage_psite)) { | |
| 138 pdf("codon_usage.pdf", height = 6, width = 16) | |
| 139 json_codon_usage_psite <- fromJSON(opt$params_codon_usage_psite) | |
| 140 for (sample_name in names(reads_psite_list)) { | |
| 141 cu_barplot <- codon_usage_psite( | |
| 142 reads_psite_list, | |
| 143 annotation_dt, | |
| 144 sample = sample_name, | |
| 145 fastapath = json_codon_usage_psite$fastapath, | |
| 146 fasta_genome = FALSE, | |
| 147 frequency_normalization = json_codon_usage_psite$frequency | |
| 148 ) | |
| 149 print(cu_barplot[["plot"]]) | |
| 150 } | |
| 151 dev.off() | |
| 152 } |
