[R] get compressed data via a socket connection
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Nov 8 17:10:21 CET 2006
?gzcon may help, depending exactly what you mean by `zlib-compressed
data'. If not, its code will provide you with a prototype to work on.
There are also private entry points in connections.c to (de)compress
blocks of data to/from a raw vector which again may be a useful statring
point for ideas.
There is no public API to the connections code.
On Wed, 8 Nov 2006, Simon Penel wrote:
> Dear R developers
>
> I am currently working on the seqinR package. The seqinR package
> allows a remote access to biological databases via a socket connection.
> We are using the functions socketConnection, writeLines and readLines
> to open the socket, send request to the server and receive response
> from the
> server respectively.
> Recently, a new function implemented in the socket server allows the
> server to send zlib-compressed data and we would like to use this
> function in R ( seqinR).
> Thus I have 2 questions about this.
> I did not found any R function dedicated to handle compressed data from
> a socket connection. My first question is : Is it possible that this
> function actually exist or
> that it will exist in the future ?
>
> Here there is an example of the R fonction we use, the first time with
> no compression, the second one with compression.
>
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 'help.start()' for an HTML browser interface to help.
> Type 'q()' to quit R.
>
> > library(seqinr) # loading seqinr
> > choosebank("hoverprot") # choose the database ( this operation will
> open the socketanknameSocket$socket )
> > query("toto","k=btg@") # do a query ( it means : give me the
> sequences associated to the keywords begining with btg, save the list in
> toto)
> > socket <- banknameSocket$socket # here I save the socket in "socket"
> >
> request="extractseqs&lrank=2&format=\"fasta\"&operation=\"simple\"&zlib=F"
> # writing a request
> > #( it means : give me the sequence information of the list of rank 2
> ( toto) in fasta format, no compressed
> > writeLines(request, socket, sep = "\n") # put the request into the
> socket
> > seq <- readLines(socket , n = -1) # read the answer of the socket
> server: it works, seq object contains the socket answer with sequence data
>
> >
> request="extractseqs&lrank=2&format=\"fasta\"&operation=\"simple\"&zlib=T"
> # now I try with zlib compression on
> > writeLines(request, socket, sep = "\n") #
> > seq <- readLines(socket , n = -1) # it doesno work
> Warning message:
> incomplete final line found by readLines on '->pbil.univ-lyon1.fr:5558'
> >
>
>
> Finaly I begin to create a C interface to get the compressed data from
> the server. However I am wondering how I can pass a opened socket as
> argument
> to the C interface, especially which R type defined in C I should use
> to handle this. Should I use the structure Rconn defined in
> Rconnection.h ? It seems to me that I may finally have to write a
> modified version of the C function readLines, but I think this not the
> best solution. This my second question....
>
>
> I hope this mail is not irrelevant, thanks for any help about these
> questions
> All the best,
>
> Simon
>
>
>
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list