1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
# Recuperation des sequences
# Simon Octobre 2006
##########################################################################################
# #
# extractseqs.socket #
# #
##########################################################################################
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
if(verbose) cat("I'm checking the arguments...\n")
if( !inherits(socket, "sockconn") ) stop(paste("argument socket = ", socket, "is not a socket connection."))
if( !is.character(listname) ) stop(paste("argument listname = ", listname, "is not a character string."))
if(verbose) cat("... and everything is OK up to now.\n")
# Check arguments:
# Check if format is acnuc", "fasta", or "flat"
if(verbose) cat("Format is ",format,"\n")
if ((format != "fasta") && (format != "flat") && (format != "acnuc")) stop(paste("argument format = ", format, "is wrong. Format should be \"fasta\", \"flat\" or \"acnuc\"! "))
# Check if operation "is simple", "translate", "fragment", "feature" or "region"
if(verbose) cat("Operation is ",operation,"\n")
if ((operation != "simple") && (operation != "translate") && (operation != "fragment") && (operation != "feature") && (operation != "region") ) {
stop(paste("argument operation = ", operation, "is wrong. Operation should be \"simple\", \"translate\", \"fragment\", \"feature\" or \"region\"! "))
}
# Check optionals
if ((feature != "xx") && (verbose))cat("feature = ", feature, ".\n")
if ((bounds != "xx") && (verbose)) cat("bounds = ", bounds, ".\n")
if ((minbounds != "xx") && (verbose)) cat("minbounds = ", minbounds, ".\n")
if ((operation == "feature") && (feature =="xx")) stop(paste("You should specify a feature!\n"))
if ((operation == "fragment") && (bounds =="xx")) stop(paste("You should specify bounds!\n"))
if ((operation == "region") && ((bounds =="xx") || (feature =="xx"))) stop(paste("You should specify bounds and region!\n"))
#
# Build request:
#
# listname is a list
lrank <- glr(listname)
if(verbose) cat("The rank of the list ",listname, "is ",lrank,".\n")
if (is.na(lrank)) {
stop(paste("Problem in rank list!\n"))
}
request <- paste("extractseqs&lrank=", lrank, "&format=", format, "&operation=", operation, sep = "")
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 = "")
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:
writeLines(request , socket, sep="\n")
# Read result from server:
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
|