[BioC] Biostrings C interface :: example not compiling
Charles C. Berry
cberry at tajo.ucsd.edu
Sat Apr 3 18:54:19 CEST 2010
On Fri, 2 Apr 2010, Erik Wright wrote:
> Hello all,
>
> I am trying to interface Biostrings from C for the first time. I
> followed the example given in the header of Biostrings_interface.h to
> the letter (quite literally). In step "e" I paste the example function
> into myFile.c, register it as a .Call entry point and compile with R CMD
> CHECK. I get the following errors:
>
> myFile.c:13: warning: implicit declaration of function ~Qcache_XRaw~R
> myFile.c:13: error: incompatible types in assignment
> myFile.c:14: error: ~QcachedCharSeq~R has no member named ~Qelts~R
> myFile.c:14: error: ~QcachedCharSeq~R has no member named ~Qnelt~R
>
> Based on the error, it seems like I still don't have access to any of
> the Biostrings variable definitions. I have tried everything that I can
> think of, so I am quite stuck. Does anyone know what I am doing
> incorrectly? I have pasted myFile.c below for reference.
Erik,
I have encountered difficulty getting cache_XRaw() to work myself, but
last December I did get it to go.
IIRC, putting together a standalone .so was a nightmare in which I ended
up with hard coded paths and other hacks.
I found the path of least resistance was to set up a package and have
this:
Depends: IRanges
Imports: methods, IRanges
LinkingTo: IRanges
in the description file. (you get cache_XRaw from IRanges.) And I placed a
file called IRanges_subs.c containing one-line:
#include "_IRanges_stubs.c"
in the src/ directory along with this .c file (beware line wrapping!):
/* read some XRaw as integer */
#include <R.h>
#include <Rdefines.h>
#include <R_ext/Error.h>
#include <R_ext/Rdynload.h>
#include "IRanges_interface.h"
SEXP tryXRaw ( SEXP x ) {
SEXP ans;
int i,len;
const char *x_char;
cachedCharSeq X;
X = cache_XRaw(x);
for (i = 0, x_char = X.seq; i < X.length; i++, x_char++)
Rprintf("%x ", *x_char);
Rprintf("\n");
PROTECT( ans = NEW_INTEGER( X.length ) );
for (i = 0, x_char = X.seq; i < X.length; i++, x_char++) INTEGER(ans)[i]=X.seq[i];
UNPROTECT( 1);
return ans;
}
R_CMethodDef cMethods[] =
{
{"tryXRaw", (DL_FUNC)&tryXRaw, 1, NULL},
{NULL,NULL, 0}
};
void R_init_tryXRaw(DllInfo *dll)
{
R_registerRoutines(dll,cMethods,NULL,NULL,NULL);
}
/* end of file */
If this doesn't get you going I can build the package and send the tgz to
you privately as .tgz
HTH,
Chuck
p.s. In the course of researching how to get this going I encountered
alphabetFrequency() which solved the problem I was planning to use
cache_XRaw() for, so I never bothered to go any further.
>
> Thanks!,
> Erik
>
>
>
>
> //myFile.c
>
> #include <Rdefines.h>
> #include <R_ext/Rdynload.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include "Biostrings_interface.h"
>
> SEXP print_XString_bytes(SEXP xstring)
> {
> cachedCharSeq x;
> int i;
> const char *x_char;
>
> x = cache_XRaw(xstring);
> for (i = 0, x_char = x.elts; i < x.nelt; i++, x_char++)
> Rprintf("%x ", *x_char);
> Rprintf("\n");
> return R_NilValue;
> }
>
> /*
> * -- REGISTRATION OF THE .Call ENTRY POINTS ---
> */
> static const R_CallMethodDef callMethods[] = {
> {"print_XString_bytes", (DL_FUNC) &print_XString_bytes, 1},
> {NULL, NULL, 0}
> };
>
> void R_init_GoneFISHing(DllInfo *info)
> {
> R_registerRoutines(info, NULL, callMethods, NULL, NULL);
> }
> [[alternative HTML version deleted]]
>
>
>
> [ Part 3.2: "Included Message" ]
>
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
More information about the Bioconductor
mailing list