END_TEST START_TEST (test_resi) { const char *commands[] = {"c1, resi 1+2-4", "c2, resi 2-4", "c3, resi 1", "c4, resi 1 AND resi 2-4", "c5, resi 1 OR resi 2-4", "c6, resi 1-2+2-4", "c7, resi 1+2-4+3", "c8, resi 1-2+7+9+3-5+100", "c9, resi 1-4 AND NOT resi 2-4"}; freesasa_set_verbosity(FREESASA_V_SILENT); test_select(commands,9); freesasa_set_verbosity(FREESASA_V_NORMAL); ck_assert(value[0] > 5); ck_assert(float_eq(value[0], addup(resi_1,result) + addup(resi_2r4,result), 1e-10)); ck_assert(float_eq(value[1], addup(resi_2r4,result), 1e-10)); ck_assert(float_eq(value[2], addup(resi_1,result), 1e-10)); ck_assert(float_eq(value[3], 0, 1e-10)); ck_assert(float_eq(value[4], value[0], 1e-10)); ck_assert(float_eq(value[5], value[0], 1e-10)); ck_assert(float_eq(value[6], value[0], 1e-10)); ck_assert(float_eq(value[7], value[0], 1e-10)); ck_assert(float_eq(value[8], value[2], 1e-10)); }
END_TEST START_TEST (test_symbol) { const char *commands[] = {"c1, symbol o+c", "c2, symbol O", "c3, symbol C", "c4, symbol O AND symbol C", "c5, symbol O OR symbol C", "c6, symbol O+C+SE", "c7, symbol SE", "c8, symbol O+C+SE and not symbol se"}; test_select(commands,8); ck_assert_str_eq(selection_name[0], "c1"); ck_assert_str_eq(selection_name[1], "c2"); ck_assert_str_eq(selection_name[2], "c3"); ck_assert(value[0] > 5); //just to check that it's non-zero ck_assert(float_eq(value[0], addup(symb_O,result) + addup(symb_C,result), 1e-10)); ck_assert(float_eq(value[1], addup(symb_O,result), 1e-10)); ck_assert(float_eq(value[2], addup(symb_C,result), 1e-10)); ck_assert(float_eq(value[3], 0, 1e-10)); ck_assert(float_eq(value[4], value[0], 1e-10)); ck_assert(float_eq(value[5], addup(symb_O,result) + addup(symb_C,result) + addup(symb_SE,result), 1e-10)); ck_assert(float_eq(value[6], addup(symb_SE,result), 1e-10)); ck_assert(float_eq(value[7], value[0], 1e-10)); }
END_TEST START_TEST (test_resn) { const char *commands[] = {"c1, resn ala+arg", "c2, resn ala", "c3, resn arg", "c4, resn ala AND resn arg", "c5, resn ala OR resn arg", "c6, resn ala+arg AND NOT resn arg"}; test_select(commands,6); ck_assert(value[0] > 5); ck_assert(float_eq(value[0], addup(resn_A,result) + addup(resn_R,result), 1e-10)); ck_assert(float_eq(value[1], addup(resn_A,result), 1e-10)); ck_assert(float_eq(value[2], addup(resn_R,result), 1e-10)); ck_assert(float_eq(value[3], 0, 1e-10)); ck_assert(float_eq(value[4], value[0], 1e-10)); ck_assert(float_eq(value[5], value[1], 1e-10)); }
END_TEST START_TEST (test_chain) { const char *commands[] = {"c1, chain A+B", "c2, chain A", "c3, chain B", "c4, chain A AND chain B", "c5, chain A OR chain B", "c6, chain A-B", "c7, chain A-B AND NOT chain A"}; test_select(commands,7); ck_assert(value[0] > 5); ck_assert(float_eq(value[0], addup(chain_A,result) + addup(chain_B,result), 1e-10)); ck_assert(float_eq(value[0], value[4], 1e-10)); ck_assert(float_eq(value[0], value[5], 1e-10)); ck_assert(float_eq(value[1], addup(chain_A,result), 1e-10)); ck_assert(float_eq(value[2], addup(chain_B,result), 1e-10)); ck_assert(float_eq(value[3], 0, 1e-10)); ck_assert(float_eq(value[6], addup(chain_B,result), 1e-10)); }
void agsurv3(int *sn, int *snvar, int *sncurve, int *snpt, int *sse, double *score, double *sy, double *r, double *coef, double *var, double *cmean, int *scn, double *cy, double *cx, double *ssurv, double *varh, double *sused, int *smethod) { register int i,j,k,l; double *start, *stop, *event; int cn; int npt, nvar2, method; int kk=0, psave; int itime; int person; int deaths, nrisk; int need; double *a=0, *a2=0; double weight=0, e_denom, denom; double inc, sumt, km=0; double temp, downwt, d2; double haz, varhaz; double **oldx=0; n = *sn; nvar = *snvar; cn = *scn; npt = *snpt; se = *sse; mean = cmean; ncurve = *sncurve; method = *smethod; death = method/10; method = method - death*10; y = sy; start = cy; stop = cy+ cn; event = cy+ cn+ cn; strata = r; /* ** scratch space */ need = 2*n + se*nvar*(2+ n*(n+1)/2); nscore = (double *) ALLOC(need, sizeof(double)); isurv = nscore + n; for (i=0; i<n; i++) isurv[i]=1; if (se==1) { a = isurv + n; a2= a + nvar; tvar = (double **) ALLOC(n, sizeof(double *)); /* be tricky here, as only the bottom half is used */ tvar[0] = a2 + nvar; for (i=1; i<n; i++) tvar[i] = tvar[i-1] +i; } /* ** Set up the ragged arrays */ if (se==1) oldx = dmatrix(cx, cn, nvar); newx = dmatrix(r+n, n, nvar); imat = dmatrix(var, nvar, nvar); surv = dmatrix(ssurv, npt, ncurve); vsurv = dmatrix(varh, npt, ncurve); used = dmatrix(sused, npt, ncurve); for (i=0; i<ncurve; i++) for (j=0; j<npt; j++) surv[i][j] =1; /* ** compute the risk scores, and center the data for stability */ if (se==1) { for (i=0; i<cn; i++) { for (j=0; j<nvar; j++) oldx[j][i] -= mean[j]; } } for (i=0; i<n; i++) { nscore[i] =0; for (j=0; j<nvar; j++) { newx[j][i] -= mean[j]; nscore[i] += coef[j]* newx[j][i]; } nscore[i] = exp(nscore[i]); } /* ** outer loop keeps a running track of the baseline hazard ** the addup function adds things up */ itime =0; nvar2 = nvar * se; /*simpler than a lot of " if (se==1)" statements */ for (person=0; person<cn;) { if (event[person]==0) person++; else { /* ** compute the mean and denominator over the risk set */ denom =0; e_denom=0; for(i=0; i<nvar2; i++){ a[i] =0; a2[i]=0; } time = stop[person]; nrisk =0; deaths=0; for (k=person; k<cn; k++) { if (start[k] < time) { nrisk++; weight = score[k]; denom += weight; for (i=0; i<nvar2; i++) { a[i] += weight*(oldx[i][k]); } } if (stop[k]==time && event[k]==1) { kk=k; deaths++; e_denom += weight; for (i=0; i<nvar2; i++) { a2[i] += weight*(oldx[i][k]); } } } /* ** Now compute the increment in the hazard and variance at "time" */ if (method <3) for (i=0; i<nvar2; i++) mean[i] = a[i]/denom; if (method==1) { for (psave=person; psave<cn && stop[psave]==time; psave++) /* ** kalbfleisch estimator requires iteration; */ if (deaths == nrisk) km=0; else if (deaths ==1) { km = pow(1- score[kk]/denom, 1/score[kk]); } else { /*find the zero of an equation */ km = .5; inc = .25; for (l=0; l<35; l++) { /* bisect it to death */ sumt =0; for (k=person; k<psave; k++) { if (event[k] ==1) sumt += score[k]/(1-pow(km, score[k])); } if (sumt < denom) km += inc; else km -= inc; inc = inc/2; } } if (km==0) addup(itime, 0.0, 0.0); else { haz = log(km); varhaz = deaths/(denom *(denom-e_denom)); /* Greenwood */ addup(itime, haz, varhaz); } person = psave; } else if (method==2) { addup(itime, deaths/denom, deaths/(denom*denom)); for (; person<cn && stop[person]==time; person++); } else { temp =0; haz=0; varhaz=0; for (k=person; k<cn && stop[k]==time; k++) { if (event[k]==1) { downwt = temp++/deaths; d2 = (denom - downwt*e_denom); haz = 1/d2; varhaz = 1/(d2*d2); for (i=0; i<nvar2; i++) mean[i] = (a[i] - downwt*a2[i])/ d2; addup(itime, haz, varhaz); } person++; } } start[itime] = time; stop[itime] = nrisk; event[itime]= deaths; itime++; } } }