[Genabel-commits] r878 - pkg/ProbABEL/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Mar 31 00:27:32 CEST 2012
Author: lckarssen
Date: 2012-03-31 00:27:32 +0200 (Sat, 31 Mar 2012)
New Revision: 878
Modified:
pkg/ProbABEL/src/data.h
Log:
Some code layout reformatting. No functional changes.
Modified: pkg/ProbABEL/src/data.h
===================================================================
--- pkg/ProbABEL/src/data.h 2012-03-30 22:18:29 UTC (rev 877)
+++ pkg/ProbABEL/src/data.h 2012-03-30 22:27:32 UTC (rev 878)
@@ -641,15 +641,16 @@
X = obj.X;
order = obj.order;
masked_data = new unsigned short int [nids];
- for (int i=0;i<nids;i++) masked_data[i] = 0;
+ for (int i=0; i<nids; i++) masked_data[i] = 0;
}
+
coxph_data(phedata &phed, gendata &gend, int snpnum)
{
nids = gend.nids;
masked_data = new unsigned short int [nids];
- for (int i=0;i<nids;i++) masked_data[i] = 0;
+ for (int i=0; i<nids; i++) masked_data[i] = 0;
ngpreds = gend.ngpreds;
- if (snpnum>=0)
+ if (snpnum >= 0)
ncov = phed.ncov + ngpreds;
else
ncov = phed.ncov;
@@ -660,13 +661,14 @@
}
// X.reinit(nids,(ncov+1));
X.reinit(nids,ncov);
- stime.reinit(nids,1);
- sstat.reinit(nids,1);
- weights.reinit(nids,1);
- offset.reinit(nids,1);
- strata.reinit(nids,1);
- order.reinit(nids,1);
- for (int i=0;i<nids;i++)
+ stime.reinit(nids, 1);
+ sstat.reinit(nids, 1);
+ weights.reinit(nids, 1);
+ offset.reinit(nids, 1);
+ strata.reinit(nids, 1);
+ order.reinit(nids, 1);
+
+ for (int i=0; i<nids; i++)
{
// X.put(1.,i,0);
stime[i] = (phed.Y).get(i,0);
@@ -677,17 +679,18 @@
exit(1);
}
}
- for (int j=0;j<phed.ncov;j++)
- for (int i=0;i<nids;i++)
+
+ for (int j=0; j<phed.ncov; j++)
+ for (int i=0; i<nids; i++)
X.put((phed.X).get(i,j),i,j);
if (snpnum>0)
- for (int j=0;j<ngpreds;j++)
+ for (int j=0; j<ngpreds; j++)
{
float snpdata[nids];
gend.get_var(snpnum*ngpreds+j,snpdata);
- for (int i=0;i<nids;i++)
- X.put(snpdata[i],i,(ncov-ngpreds+j));
+ for (int i=0; i<nids; i++)
+ X.put(snpdata[i], i, (ncov-ngpreds+j));
}
// for (int i=0;i<nids;i++)
@@ -703,12 +706,17 @@
// sort by time
double tmptime[nids];
int passed_sorted[nids];
- for (int i=0;i<nids;i++) {tmptime[i] = stime[i];passed_sorted[i]=0;}
- qsort(tmptime,nids,sizeof(double),cmpfun);
for (int i=0;i<nids;i++)
{
+ tmptime[i] = stime[i];
+ passed_sorted[i]=0;
+ }
+ qsort(tmptime, nids, sizeof(double), cmpfun);
+
+ for (int i=0; i<nids; i++)
+ {
int passed = 0;
- for (int j=0;j<nids;j++)
+ for (int j=0; j<nids; j++)
if (tmptime[j] == stime[i])
if (!passed_sorted[j])
{
@@ -719,15 +727,15 @@
}
if (passed != 1)
{
- fprintf(stderr,"cannot recover element %d\n",i);
+ fprintf(stderr,"cannot recover element %d\n", i);
exit(1);
}
}
- stime = reorder(stime,order);
- sstat = reorder(sstat,order);
- weights = reorder(weights,order);
- strata = reorder(strata,order);
- offset = reorder(offset,order);
+ stime = reorder(stime, order);
+ sstat = reorder(sstat, order);
+ weights = reorder(weights, order);
+ strata = reorder(strata, order);
+ offset = reorder(offset, order);
X = reorder(X,order);
X = transpose(X);
// X.print();
@@ -736,24 +744,30 @@
// stime.print();
// sstat.print();
}
+
void update_snp(gendata &gend, int snpnum)
{
// note this sorts by "order"!!!
- for (int j=0;j<ngpreds;j++)
+ for (int j=0; j<ngpreds; j++)
{
float snpdata[nids];
- for (int i=0;i<nids;i++) masked_data[i]=0;
+ for (int i=0; i<nids; i++)
+ masked_data[i]=0;
+
gend.get_var(snpnum*ngpreds+j,snpdata);
- for (int i=0;i<nids;i++) {
- X.put(snpdata[i],(ncov-ngpreds+j),order[i]);
- if (isnan(snpdata[i])) masked_data[order[i]]=1;
+
+ for (int i=0; i<nids; i++) {
+ X.put(snpdata[i], (ncov-ngpreds+j), order[i]);
+ if ( isnan(snpdata[i]) )
+ masked_data[order[i]] = 1;
}
}
// for (int i=0;i<nids;i++)
// for (int j=0;j<ngpreds;j++)
// X.put((gend.G).get(i,(snpnum*ngpreds+j)),(ncov-ngpreds+j),order[i]);
}
+
~coxph_data()
{
delete [] masked_data;
@@ -774,7 +788,7 @@
// filter missing data
int nmeasured = 0;
- for (int i=0;i<nids;i++)
+ for (int i=0; i<nids; i++)
if (masked_data[i]==0) nmeasured++;
to.nids = nmeasured;
// std::cout << "nmeasured=" << nmeasured << "\n";
@@ -784,30 +798,31 @@
int dim1X = X.nrow;
// std::cout << "X.ncol=" << X.ncol << "\n";
// std::cout << "X.nrow=" << X.nrow << "\n";
- (to.weights).reinit(to.nids,1);
- (to.stime).reinit(to.nids,1);
- (to.sstat).reinit(to.nids,1);
- (to.offset).reinit(to.nids,1);
- (to.strata).reinit(to.nids,1);
- (to.order).reinit(to.nids,1);
- (to.X).reinit(dim1X,to.nids);
+ (to.weights).reinit(to.nids, 1);
+ (to.stime).reinit(to.nids, 1);
+ (to.sstat).reinit(to.nids, 1);
+ (to.offset).reinit(to.nids, 1);
+ (to.strata).reinit(to.nids, 1);
+ (to.order).reinit(to.nids, 1);
+ (to.X).reinit(dim1X, to.nids);
// std::cout << "(to.X).ncol=" << (to.X).ncol << "\n";
// std::cout << "(to.X).nrow=" << (to.X).nrow << "\n";
// std::cout << " !!! just before cycle !!! ";
int j = 0;
- for (int i=0;i<nids;i++)
+ for (int i=0; i<nids; i++)
{
// std::cout << nids << " " << i << " " << masked_data[i] << "\n";
- if (masked_data[i]==0) {
- (to.weights).put(weights.get(i,1),j,1);
- (to.stime).put(stime.get(i,1),j,1);
- (to.sstat).put(sstat.get(i,1),j,1);
- (to.offset).put(offset.get(i,1),j,1);
- (to.strata).put(strata.get(i,1),j,1);
- (to.order).put(order.get(i,1),j,1);
+ if (masked_data[i]==0)
+ {
+ (to.weights).put(weights.get(i,1), j, 1);
+ (to.stime).put(stime.get(i,1), j, 1);
+ (to.sstat).put(sstat.get(i,1), j, 1);
+ (to.offset).put(offset.get(i,1), j, 1);
+ (to.strata).put(strata.get(i,1), j, 1);
+ (to.order).put(order.get(i,1), j, 1);
for (int nc=0;nc<dim1X;nc++)
- (to.X).put(X.get(nc,i),nc,j);
+ (to.X).put(X.get(nc,i), nc, j);
j++;
}
}
@@ -815,7 +830,8 @@
//delete [] to.masked_data;
to.masked_data = new unsigned short int [to.nids];
- for (int i=0;i<to.nids;i++) to.masked_data[i] = 0;
+ for (int i=0; i<to.nids; i++)
+ to.masked_data[i] = 0;
//fprintf(stdout,"get_unmasked: %i %i %i\n",to.nids,dim2X,dim2Y);
return(to);
}
More information about the Genabel-commits
mailing list