Mercurial > repos > galaxyp > custom_pro_db_annotation_data_manager
comparison data_manager/customProDB_annotation.R @ 0:663ee21a8609 draft
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/bumbershoot/data_manager_customProDB commit 141369f97aa2804d2bbfd9ed620ea2a5574994c2-dirty
| author | galaxyp |
|---|---|
| date | Thu, 21 Jan 2016 18:19:52 -0500 |
| parents | |
| children | 20a1b026b798 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:663ee21a8609 |
|---|---|
| 1 #!/usr/bin/env Rscript | |
| 2 | |
| 3 initial.options <- commandArgs(trailingOnly = FALSE) | |
| 4 script_parent_dir <- dirname(sub("--file=", "", initial.options[grep("--file=", initial.options)])) | |
| 5 | |
| 6 ## begin warning handler | |
| 7 withCallingHandlers({ | |
| 8 | |
| 9 library(methods) # Because Rscript does not always do this | |
| 10 | |
| 11 options('useFancyQuotes' = FALSE) | |
| 12 | |
| 13 suppressPackageStartupMessages(library("optparse")) | |
| 14 suppressPackageStartupMessages(library("RGalaxy")) | |
| 15 | |
| 16 | |
| 17 option_list <- list() | |
| 18 option_list$dbkey <- make_option('--dbkey', type='character') | |
| 19 option_list$outputFile <- make_option('--outputFile', type='character') | |
| 20 | |
| 21 opt <- parse_args(OptionParser(option_list=option_list)) | |
| 22 | |
| 23 | |
| 24 customProDB_annotation <- function( | |
| 25 dbkey = GalaxyCharacterParam(required=TRUE), | |
| 26 outputFile = GalaxyOutput("output","json")) | |
| 27 { | |
| 28 if (!file.exists(outputFile)) | |
| 29 { | |
| 30 gstop("json params file does not exist") | |
| 31 } | |
| 32 | |
| 33 suppressPackageStartupMessages(library(rjson)) | |
| 34 params = fromJSON(file=outputFile) | |
| 35 target_directory = params$output_data[[1]]$extra_files_path | |
| 36 data_description = params$param_dict$advanced$data_description | |
| 37 data_id = params$param_dict$advanced$data_id | |
| 38 dir.create(target_directory) | |
| 39 | |
| 40 tryCatch( | |
| 41 { | |
| 42 #file.remove(outputFile) | |
| 43 }, error=function(err) | |
| 44 { | |
| 45 gstop("failed to remove json params file after reading") | |
| 46 }) | |
| 47 | |
| 48 ucscTableCodingFastaURL = paste("http://genome.ucsc.edu/cgi-bin/hgTables?db=", dbkey, "&hgSeq.cdsExon=on&hgSeq.granularity=gene&hgSeq.casing=exon&hgSeq.repMasking=lower&hgta_doGenomicDna=get+sequence&hgta_group=genes&hgta_track=refGene&hgta_table=refGene&hgta_regionType=genome", sep="") | |
| 49 ucscTableProteinFastaURL = paste("http://genome.ucsc.edu/cgi-bin/hgTables?db=", dbkey, "&hgta_geneSeqType=protein&hgta_doGenePredSequence=submit&hgta_track=refGene&hgta_table=refGene", sep="") | |
| 50 codingFastaFilepath = paste(target_directory, "/", dbkey, ".cds.fa", sep="") | |
| 51 proteinFastaFilepath = paste(target_directory, "/", dbkey, ".protein.fa", sep="") | |
| 52 suppressPackageStartupMessages(library(customProDB)) | |
| 53 options(timeout=3600) | |
| 54 cat(paste("Downloading coding FASTA from:", ucscTableCodingFastaURL, "\n")) | |
| 55 download.file(ucscTableCodingFastaURL, codingFastaFilepath, quiet=T, mode='wb') | |
| 56 cat(paste("Downloading protein FASTA from:", ucscTableProteinFastaURL, "\n")) | |
| 57 download.file(ucscTableProteinFastaURL, proteinFastaFilepath, quiet=T, mode='wb') | |
| 58 customProDB::PrepareAnnotationRefseq(genome=dbkey, CDSfasta=codingFastaFilepath, pepfasta=proteinFastaFilepath, annotation_path=target_directory) | |
| 59 | |
| 60 outputPath = paste("customProDB/", dbkey, sep="") | |
| 61 output = list(data_tables = list()) | |
| 62 output[["data_tables"]][["customProDB"]]=c(path=outputPath, name=dbkey, value=dbkey) | |
| 63 write(toJSON(output), file=outputFile) | |
| 64 } | |
| 65 | |
| 66 | |
| 67 params <- list() | |
| 68 for(param in names(opt)) | |
| 69 { | |
| 70 if (!param == "help") | |
| 71 params[param] <- opt[param] | |
| 72 } | |
| 73 | |
| 74 setClass("GalaxyRemoteError", contains="character") | |
| 75 wrappedFunction <- function(f) | |
| 76 { | |
| 77 tryCatch(do.call(f, params), | |
| 78 error=function(e) new("GalaxyRemoteError", conditionMessage(e))) | |
| 79 } | |
| 80 | |
| 81 | |
| 82 suppressPackageStartupMessages(library(RGalaxy)) | |
| 83 do.call(customProDB_annotation, params) | |
| 84 | |
| 85 ## end warning handler | |
| 86 }, warning = function(w) { | |
| 87 cat(paste("Warning:", conditionMessage(w), "\n")) | |
| 88 invokeRestart("muffleWarning") | |
| 89 }) |
