[Seqinr-commits] r1979 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jul 12 19:08:12 CEST 2016
Author: jeanlobry
Date: 2016-07-12 19:08:12 +0200 (Tue, 12 Jul 2016)
New Revision: 1979
Modified:
pkg/R/extractseqs.R
Log:
adding a zlib argument to extractseqs
Modified: pkg/R/extractseqs.R
===================================================================
--- pkg/R/extractseqs.R 2016-07-07 18:55:51 UTC (rev 1978)
+++ pkg/R/extractseqs.R 2016-07-12 17:08:12 UTC (rev 1979)
@@ -4,15 +4,15 @@
-###################################################################################################
+##########################################################################################
# #
# extractseqs.socket #
# #
-###################################################################################################
+##########################################################################################
-extractseqs <- function(listname, socket = autosocket(), format="fasta",operation="simple", feature="xx", bounds="xx", minbounds="xx",verbose = FALSE, nzlines=1000){
- if (.Platform$OS.type == "windows") {
- stop(paste("This function is not implemented for windows.\n"))
+extractseqs <- function(listname, socket = autosocket(), format="fasta", operation="simple", feature="xx", bounds="xx", minbounds="xx", verbose = FALSE, nzlines=1000, zlib = FALSE){
+ if (zlib == TRUE && .Platform$OS.type == "windows") {
+ stop(paste("Zlib compressed sockets is not implemented for windows.\n"))
}
debug<-0
if (verbose) debug <- 1
@@ -52,7 +52,7 @@
if ((operation == "region") && ((bounds =="xx") || (feature =="xx"))) stop(paste("You should specify bounds and region!\n"))
-
+#
# Build request:
#
# listname is a list
@@ -67,7 +67,13 @@
if (feature != "xx") request <- paste(request,"&feature=", feature, sep = "")
if (bounds != "xx") request <- paste(request,"&bounds=",bounds, sep = "")
if (minbounds != "xx") request <- paste(request,"&minbounds=",minbounds, sep = "")
- request <- paste(request,"&zlib=T", sep = "")
+
+ if(zlib) {
+ request <- paste(request,"&zlib=T", sep = "")
+ }
+ else {
+ request <- paste(request,"&zlib=F", sep = "")
+ }
if(verbose) cat("request : ",request,"\n")
# Write request into the socket:
@@ -75,16 +81,33 @@
writeLines(request , socket, sep="\n")
# Read result from server:
-
- lastres <- .Call("getzlibsock", socket, nzlines, debug,PACKAGE = "seqinr")
-
- #
- # Remove empty lines at the end of lastres:
- #
-
- return( lastres[nchar(lastres) != 0] )
+
+ if(zlib) {
+ lastres <- .Call("getzlibsock", socket, nzlines, debug,PACKAGE = "seqinr")
+ }
+ else {
+ lastres <- readLines(socket)
+ }
+ if(zlib) {
+ #
+ # Remove empty lines at the end of lastres:
+ #
+ return( lastres[nchar(lastres) != 0] )
+ }
+ else {
+ #
+ # Remove flags from server:
+ #
+ lastres <- lastres[-1] # code=0
+ lastres <- lastres[-length(lastres)] # extractseqs END.
+ lastres <- lastres[-grep("count=", lastres)] # count=
+ return(lastres)
+ }
}
+#
+# Define a shorthcut for extractseqs
+#
exseq <- extractseqs
More information about the Seqinr-commits
mailing list