# HG changeset patch # User Kyle Ellrott # Date 1351146673 25200 # Node ID 93c4d2fad9af3f7e2fe8215849a90b692715a955 # Parent a104cc98359c55e6f4933d1614605f79aa30f2eb Fixing bugs and bad code diff -r a104cc98359c -r 93c4d2fad9af synapse_create.xml --- a/synapse_create.xml Tue Jul 24 17:34:37 2012 -0400 +++ b/synapse_create.xml Wed Oct 24 23:31:13 2012 -0700 @@ -1,4 +1,4 @@ - + Create Synapse $script_file @@ -13,6 +13,28 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -26,11 +48,6 @@ - - - - - @@ -40,33 +57,52 @@ rcode=""" require(synapseClient) -if (nchar("$user") > 0 && nchar("$pass") > 0) { - synapseLogin(username="$user", password="$pass") +galaxyClean <- function(x) { +y = gsub("__gt__", ">", x); +y = gsub("__lt__", "<", y ); +y = gsub("__sq__", "'", y); +y = gsub("__dq__", "\\"",y); +y = gsub("__ob__", "[", y); +y = gsub("__cb__", "]", y); +y = gsub("__oc__", "{", y); +y = gsub("__cc__", "}", y); +y = gsub("__at__", "@", y); +y = gsub("__cn__", "\\n", y); +y = gsub("__cr__", "\\r", y); +y = gsub("__tc__", "\\t", y); +y = gsub("__pd__", "#", y); +y = gsub("__at__", "@", y); +return(y); } -ent <- ${etype}( list(name="${name}") ) +if (nchar("$user") && nchar("$pass")) { + synapseLogin(username=galaxyClean("$user"), password=galaxyClean("$pass")) +} + + +ent <- ${etype}( list(name=galaxyClean("${name}")) ) #for $a in $annotations: -annotValue(ent, "${a.name}") <- "${a.value}" +annotValue(ent, galaxyClean("${a.name}")) <- galaxyClean("${a.value}") #end for #for a in $properties: -propertyValue(ent, "${a.name}") <- "${a.value}" +propertyValue(ent, galaxyClean("${a.name}")) <- galaxyClean("${a.value}") #end for ent <- createEntity(ent) #if $attachment != 'None' #if $attachment_name == '': -ent <- addFile(ent, "${attachment}") +ent <- addFile(ent, galaxyClean("${attachment}")) #else -ent <- addFile(ent, "${attachment}", "${attachment_name}") +ent <- addFile(ent, galaxyClean("${attachment}"), galaxyClean("${attachment_name}")) #end if #end if ent <- storeEntity(ent) -write(properties(ent)\$id, file="${outfile}"); +write(properties(ent)\$id, file=galaxyClean("${outfile}")); """ @@ -89,4 +125,14 @@ ]]> - + + +Install R SynapseClient: + source('http://depot.sagebase.org/CRAN.R') + pkgInstall("synapseClient") + +`To setup auto login (so you don't have to type in your password) <https://sagebionetworks.jira.com/wiki/display/SYNR/How+to+configure+automatic+login>`_ + + + + \ No newline at end of file diff -r a104cc98359c -r 93c4d2fad9af synapse_download.xml --- a/synapse_download.xml Tue Jul 24 17:34:37 2012 -0400 +++ b/synapse_download.xml Wed Oct 24 23:31:13 2012 -0700 @@ -1,23 +1,13 @@ - + Download Synapse Entity - $script_file -#if str( $user ) != '': - -u "$user" -#end if -#if str( $pass ) != '': - -p "$pass" -#end if --s $synid -$data_type --o $outfile - + $script_file - - + + @@ -26,33 +16,44 @@ ", x); +y = gsub("__lt__", "<", y ); +y = gsub("__sq__", "'", y); +y = gsub("__dq__", "\\"",y); +y = gsub("__ob__", "[", y); +y = gsub("__cb__", "]", y); +y = gsub("__oc__", "{", y); +y = gsub("__cc__", "}", y); +y = gsub("__at__", "@", y); +y = gsub("__cn__", "\\n", y); +y = gsub("__cr__", "\\r", y); +y = gsub("__tc__", "\\t", y); +y = gsub("__pd__", "#", y); +y = gsub("__at__", "@", y); +return(y); } -ent <- loadEntity(opt\$synid); +if (nchar("$user") && nchar("$pass")) { + synapseLogin(username=galaxyClean("$user"), password=galaxyClean("$pass")) +} + -if (!is.null(opt\$eset)) { +cat("Loading...") +ent <- loadEntity("$synid"); +cat("Done\n") + +if ("e" == "$data_type") { eset <- exprs(ent\$objects\$eset); - write(paste(c("PROBE", colnames(eset)), collapse="\\t"), file=opt\$outfile) - write.table(eset, opt\$outfile, col.names=FALSE, sep="\\t", quote=FALSE, append=TRUE); + write(paste(c("PROBE", colnames(eset)), collapse="\\t"), file="$outfile") + write.table(eset, "$outfile", col.names=FALSE, sep="\\t", quote=FALSE, append=TRUE); } -if (!is.null(opt\$attach)) { +if ("a" == "$data_type") { fpath <- file.path(ent\$cacheDir, ent\$files[[1]]); - file.copy(fpath, opt\$outfile, overwrite=T); + file.copy(fpath, "$outfile", overwrite=T); } """ @@ -66,9 +67,26 @@ os.write(h,rcode) os.close(h) -print subprocess.check_output( ["Rscript", path] + sys.argv[1:], stderr=subprocess.STDOUT ) +cmd_args = ["R", "CMD", "BATCH", path ] +proc = subprocess.Popen(cmd_args, stderr=subprocess.PIPE) +stdout, stderr = proc.communicate() +if proc.poll() != 0: + sys.stderr.write(stderr) os.unlink(path) - ]]> - + + +This tool current supports two types of data from Synapse: Affy eset data and attachment files. +For Affy eset data, it will attempt to turn the eset into a table and write a tab separated file. For attachment files, it will +save the first attached file as the output. + +Install R SynapseClient:: + + source('http://depot.sagebase.org/CRAN.R') + pkgInstall("synapseClient") + +`To setup auto login (so you don't have to type in your password) <https://sagebionetworks.jira.com/wiki/display/SYNR/How+to+configure+automatic+login>`_ + + + \ No newline at end of file diff -r a104cc98359c -r 93c4d2fad9af synapse_query.xml --- a/synapse_query.xml Tue Jul 24 17:34:37 2012 -0400 +++ b/synapse_query.xml Wed Oct 24 23:31:13 2012 -0700 @@ -1,19 +1,12 @@ Query Synapse - $script_file -#if str( $user ) != '': - -u "$user" -#end if - -#if str( $pass ) != '': - -p "$pass" -#end if --o $outfile - + $script_file - + + + - + ", x); +y = gsub("__lt__", "<", y ); +y = gsub("__sq__", "'", y); +y = gsub("__dq__", "\\"",y); +y = gsub("__ob__", "[", y); +y = gsub("__cb__", "]", y); +y = gsub("__oc__", "{", y); +y = gsub("__cc__", "}", y); +y = gsub("__at__", "@", y); +y = gsub("__cn__", "\\n", y); +y = gsub("__cr__", "\\r", y); +y = gsub("__tc__", "\\t", y); +y = gsub("__pd__", "#", y); +y = gsub("__at__", "@", y); +return(y); } +if (nchar("$user") && nchar("$pass")) { + synapseLogin(username=galaxyClean("$user"), password=galaxyClean("$pass")) +} + + + +query <- galaxyClean("${query}"); +cat(query) + query.out <- synapseQuery(query); -write.table(query.out, quote=F, file=opt\$outfile, row.name=F, sep="\\t") +write.table(query.out, quote=F, file="$outfile", row.name=F, sep="\\t") """ import tempfile @@ -55,18 +63,32 @@ import sys import subprocess -h, path = tempfile.mkstemp() +h, path = tempfile.mkstemp(dir="/tmp") os.write(h,rcode) os.close(h) -proc = subprocess.Popen( ["Rscript", path] + sys.argv[1:], stderr=subprocess.PIPE, stdout=subprocess.PIPE ) +proc = subprocess.Popen( ["Rscript", path], stderr=subprocess.PIPE, stdout=subprocess.PIPE ) (stdoutdata, stderrdata) = proc.communicate() if proc.returncode: sys.stderr.write(stderrdata) sys.stdout.write(stdoutdata) os.unlink(path) - ]]> - + + +Install R SynapseClient:: + + source('http://depot.sagebase.org/CRAN.R') + pkgInstall("synapseClient") + +`To setup auto login (so you don't have to type in your password) <https://sagebionetworks.jira.com/wiki/display/SYNR/How+to+configure+automatic+login>`_ + +Example Query: + +select * from entity where parentId=="syn300013" + + + + \ No newline at end of file