[Bioc-devel] Newbie Question - How to submit patches
Robert Gentleman
rgentlem at fhcrc.org
Fri Oct 14 19:39:29 CEST 2005
Hi
Paul Gordon wrote:
> Robert Gentleman wrote:
>
>> As for coding standards etc, I refer you to the document Writing R
>> Extensions, and possibly to the R Installation and Administration
>> Guide (both of which should have come with your R).
>
>
> Thanks for the pointer, it has lot of good tips. This document though
> seems to use ANSI as a baseline:
>
> The following tools can "safely be assumed" for R extensions.
>
> * An ISO 9899, also known as ISO C89 or ANSI C compiler...Any
> extensions, such as POSIX or ISO C99, must be tested for,
> typically using Autoconf
>
Yes, but you still have not provided me with a reference to what you
think ANSI says.
> Does bioconductor use autoconf, or perhaps autoconf doesn't catch the
> flag requirement as it should?
>
>> Perhaps if you showed us the real output from your compiler more could
>> be determined and less guessed. I see from your second email that you
>> did not in fact find the "first" declaration in the file, but rather
>> the first that was not at the start of a block.
>>
>> I've created
>>
>>> patches for the few source files affected (using malloc() to
>>> dynamically create these arrays), but how should I submit these? Am
>>> I the first person not using gcc under Unix?
>>
>>
>>
>> I suspect not.
>>
>> And no we really don't want to malloc, Ralloc might be lived with,
>> but first let's make sure we agree on the problem and then see what
>> the fix is.
>
>
> Since it is only allocated once, realloc and malloc function
> equivalently, so I chose the former (one less parameter to type :-))
> I've attached my revisions for your perusal (relevant lines are label
> with a comment with my name). Once again, I'm new to R and
> Bioconductor, so my questions are not meant to insult anyone's code, but
> rather to help me understand how I can get my development in line with
> the R way...
My use of Ralloc was not a typo, it is not realloc. It is typically
not such a good idea to be futzing with malloc in a language that does
its own memory management.
I still await the compiler errors, as I said earlier, the place to
start is with a agreement on what the problem is. Have you checked to
see if this is merely a compiler switch for you? And if so, why would
that not be the best solution?
Best wishes,
Robert
>
>> Robert
>>
>>>
>>> Thanks in advance for your input,
>>>
>>> Paul Gordon
>>>
>>> _______________________________________________
>>> Bioc-devel at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>>>
>>
>
>
>
> ------------------------------------------------------------------------
>
> #include <R.h>
> #include <Rdefines.h>
> #include <stdlib.h>
> #include <stdio.h>
>
> void pAUC(double *data, int *nd, double *cutp, int *nc, int *truth,
> double *spec, double *sens, double *area, double *b) {
>
> int i, j, k, pred, d, rsum, csum, rcount, ccount, lx;
> double x[*nc];
> double y[*nc];
> double m;
> double h;
> double yb;
>
> /* Paul Gordon - these vars were declared elsewhere in the function, but Sun's cc didn't like that */
> double *xin;
> double *yin;
> double *xall;
> double *yall;
> double *xdummy;
> double *ydummy;
>
> /* this code computes roc for a given n * n matrix at given
> cut points */
> for(k=0; k<nd[0]; k++){ /* iterate over rows (genes) */
> for(i=k; i<*nc*nd[0]; i+=nd[0]){ /* iterate over cut points */
> rsum = csum = rcount = ccount = 0;
> for(j=k, d=0; j<nd[0]*nd[1]; j+=nd[0], d++){ /* iterate over
> columns (samples) */
> pred = data[j] > cutp[i] ? 1 : 0;
> if(truth[d] == 1){
> rsum += pred;
> rcount++;
> }
> else{
> csum+=(1-pred);
> ccount++;
> }
> } /* for j */
> sens[i] = (double)rsum/rcount;
> spec[i] = (double)csum/ccount;
> } /* for i */
>
>
> /* this computes pAUC for roc curve in row k*/
> for(i=k,d=0; i<*nc*nd[0]; i+=nd[0],d++){
> x[d] = 1 - spec[i];
> y[d] = sens[i];
> }
> lx = d;
>
> if(x[0] > x[lx]){ /* reverse order if necessary */
> /* Paul Gordon - double xdummy[lx] and ydummy[lx] were declared here */
> if((xdummy = (double *) malloc(sizeof(double)*lx)) == NULL){
> perror("While creating dummy 'x' array in pAUC (genefilter package)");
> }
> if((ydummy = (double *) malloc(sizeof(double)*lx)) == NULL){
> perror("While creating dummy 'y' array in pAUC (genefilter package)");
> }
> for(i=0; i<lx; i++){
> xdummy[i] = x[i];
> ydummy[i] = y[i];
> }
> for(i=1; i<lx+1; i++){
> x[i-1] = xdummy[lx-i];
> y[i-1] = ydummy[lx-i];
> }
> free(xdummy);
> free(ydummy);
> }
>
> /* Paul Gordon - double xin[lx] and yin[lx] were declared here */
> if((xin = (double *) malloc(sizeof(double)*lx)) == NULL){
> perror("While creating input 'x' array in pAUC (genefilter package)");
> }
> if((yin = (double *) malloc(sizeof(double)*lx)) == NULL){
> perror("While creating input 'y' array in pAUC (genefilter package)");
> }
> d = 0;
> for(i=0; i<lx; i++){ /* subset for iteration */
> if(x[i] <= *b){
> xin[d] = x[i];
> yin[d] = y[i];
> d++;
> }
> }
> lx = d-1; /* extend subset to include boundaries */
> /* Paul Gordon - double xall[lx+2] and double yall[lx+2] were declared here */
> if((xall = (double *) malloc(sizeof(double)*(lx+2))) == NULL){
> perror("While creating all 'x' array in pAUC (genefilter package)");
> }
> if((yall = (double *) malloc(sizeof(double)*(lx+2))) == NULL){
> perror("While creating all 'y' array in pAUC (genefilter package)");
> }
> xall[0] = 0;
> yall[0] = 0;
> for(i=0; i<=lx; i++){
> xall[i+1] = xin[i];
> yall[i+1] = yin[i];
> }
> /* Paul Gordon - these arrays are no longer needed */
> free(xin);
> free(yin);
>
> m = (*b-x[lx]) / (x[lx+1] - x[lx]); /* interpolation at right boundary */
> yb = y[lx] + (y[lx+1] - y[lx]) * m;
> xall[lx+2] = *b;
> yall[lx+2] = yb;
> lx = lx+2;
> for(i=0; i<lx; i++){ /* compute area */
> h = xall[i+1] - xall[i];
> area[k] += h * (yall[i+1] + yall[i]);
> }
> area[k] *= 0.5;
>
> /* Paul Gordon - these arrays are no longer needed */
> free(xall);
> free(yall);
>
> }
> }
>
>
>
> ------------------------------------------------------------------------
>
> #include <math.h>
> #include <R.h>
> #include <Rmath.h>
> #include <stdlib.h>
> #include <stdio.h>
> /*#include "nmath.h"*/
> /*#include "dpq.h"*/
> #define min(x1,x2) ((x1) > (x2))? (x2):(x1)
> #define max(x1,x2) ((x1) > (x2))? (x1):(x2)
>
> double posty(double p, double mu,double tau,double lower_bound, double *ans)
> {
> /* double lower_bound=.5;*/
>
> int a=1;
> int step = 60,K0,K,i;
> double base;
> double G1=0,F1=0;
> double tmp;
> double *pnorms, *g, diff_pnorms;
>
> base = exp(log(pow(2,16))/step);
> /* mylog = function(x) log(x, base);*/
> K0 = max(0, floor(log(lower_bound)/log(base)) + 1.0);
> K = floor(log(p)/log(base));
>
> /* Paul Gordon - double pnorms[K+1] and g[K+2] and diff_pnorms were declared here */
> if((pnorms = malloc(sizeof(double)*(K+1))) == NULL){
> perror("While creating 'pnorms' array in posty (gcrma package)");
> }
> if((g = malloc(sizeof(double)*(K+2))) == NULL){
> perror("While creating 'g' array in posty (gcrma package)");
> }
> pnorms[0]=pnorm(log(p - pow(base,K0)), mu, tau,1,0);
> G1=(1/pow(lower_bound,a) + 1/pow(base,(a * K0)))/2*(pnorm(log(p -lower_bound), mu, tau,1,0) - pnorm(log(p - pow(base,K0)), mu, tau,1,0));
> F1= G1 * log(lower_bound/2 + pow(base,K0)/2);
>
> for (i=1;i<=K-K0;i++){
> pnorms[i] = pnorm(log(p - pow(base,(K0+i))), mu, tau,1,0);
> diff_pnorms = pnorms[i-1] - pnorms[i];
> tmp = (pow(base,a) + 1)/pow(base,(a * (K0+i)))/2 * diff_pnorms;
> G1+=tmp;
> F1+=tmp * log(pow(base,(K0+i-1)) * (base + 1)/2);
> }
> /* Paul Gordon - these arrays are no longer needed */
> free(pnorms);
> free(g);
>
> tmp= (pow(base,a) + 1)/pow(base,(a * (K + 1))) * pnorm(log(p - pow(base,K)), mu, tau,1,0);
> G1+=tmp;
> F1+= tmp * log(pow(base,K)/2 + p/2);
> *ans=F1/G1;
>
> }
>
> void Rposty1(double *p, double *mu, double *tau, double *k,double *ans){
> posty(*p,*mu,*tau,*k,ans);
> }
>
>
> void Rposty(double *p, double *mu, double *tau,int *G, double *k, double *ans){
> int i;
> for(i=0;i<*G;i++) posty(p[i],mu[i],tau[0],*k,ans+i);
> }
--
Robert Gentleman, PhD
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
PO Box 19024
Seattle, Washington 98109-1024
206-667-7700
rgentlem at fhcrc.org
More information about the Bioc-devel
mailing list