[Genabel-commits] r876 - branches/ProbABEL-refactoring/ProbABEL/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Mar 30 21:06:42 CEST 2012
Author: maartenk
Date: 2012-03-30 21:06:42 +0200 (Fri, 30 Mar 2012)
New Revision: 876
Added:
branches/ProbABEL-refactoring/ProbABEL/src/regdata.cpp
branches/ProbABEL-refactoring/ProbABEL/src/regdata.h
Modified:
branches/ProbABEL-refactoring/ProbABEL/src/Makefile.am
branches/ProbABEL-refactoring/ProbABEL/src/data.cpp
branches/ProbABEL-refactoring/ProbABEL/src/data.h
branches/ProbABEL-refactoring/ProbABEL/src/reg1.h
Log:
move regdata class from data.cpp to own file
Modified: branches/ProbABEL-refactoring/ProbABEL/src/Makefile.am
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/Makefile.am 2012-03-29 12:45:16 UTC (rev 875)
+++ branches/ProbABEL-refactoring/ProbABEL/src/Makefile.am 2012-03-30 19:06:42 UTC (rev 876)
@@ -3,7 +3,7 @@
## Using wildcards in these lists doesn't work. Also GNU make's ($wildcard,) doesn't
## work. It gives warning message about portability, but in the end doesn't work,
## I tried :-).
-REGFILES = data.h data.cpp gendata.h gendata.cpp mematrix.h mematri1.h reg1.h usage.h usage.cpp main.cpp utilities.h utilities.cpp phedata.h phedata.cpp cholesky.h cholesky.cpp
+REGFILES = data.h data.cpp gendata.h gendata.cpp mematrix.h mematri1.h reg1.h usage.h usage.cpp main.cpp utilities.h utilities.cpp phedata.h phedata.cpp cholesky.h cholesky.cpp regdata.h regdata.cpp
## Filevector files:
FVSRC = fvlib/AbstractMatrix.cpp fvlib/CastUtils.cpp \
Modified: branches/ProbABEL-refactoring/ProbABEL/src/data.cpp
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/data.cpp 2012-03-29 12:45:16 UTC (rev 875)
+++ branches/ProbABEL-refactoring/ProbABEL/src/data.cpp 2012-03-30 19:06:42 UTC (rev 876)
@@ -57,115 +57,7 @@
return (nids);
}
-regdata::regdata(const regdata &obj) {
- nids = obj.nids;
- ncov = obj.ncov;
- ngpreds = obj.ngpreds;
- noutcomes = obj.noutcomes;
- X = obj.X;
- Y = obj.Y;
- masked_data = new unsigned short int[nids];
- for (int i = 0; i < nids; i++) {
- masked_data[i] = 0;
- }
-}
-regdata::regdata(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;
- }
- ngpreds = gend.ngpreds;
- if (snpnum >= 0) {
- ncov = phed.ncov + ngpreds;
- } else {
- ncov = phed.ncov;
- }
- noutcomes = phed.noutcomes;
- X.reinit(nids, (ncov + 1));
- Y.reinit(nids, noutcomes);
- for (int i = 0; i < nids; i++) {
- X.put(1., i, 0);
- Y.put((phed.Y).get(i, 0), i, 0);
- }
- for (int j = 1; j <= phed.ncov; j++)
- for (int i = 0; i < nids; i++)
- X.put((phed.X).get(i, j - 1), i, j);
- if (snpnum > 0)
- 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 + 1 + j));
- }
- // for (int i=0;i<nids;i++)
- // for (int j=0;j<ngpreds;j++)
- // X.put((gend.G).get(i,(snpnum*ngpreds+j)),i,(ncov-ngpreds+1+j));
-}
-void regdata::update_snp(gendata &gend, int snpnum) {
- for (int j = 0; j < ngpreds; j++) {
- float snpdata[nids];
- 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], i, (ncov + 1 - j - 1));
- if (isnan(snpdata[i]))
- masked_data[i] = 1;
- }
- }
-}
-regdata::~regdata() {
- delete[] regdata::masked_data;
- // delete X;
- // delete Y;
-}
-
-regdata regdata::get_unmasked_data() {
- regdata to; // = regdata(*this);
- int nmeasured = 0;
- for (int i = 0; i < nids; i++)
- if (masked_data[i] == 0)
- nmeasured++;
- to.nids = nmeasured;
- //cout << to.nids << " in get_unmasked_data\n";
- to.ncov = ncov;
- to.ngpreds = ngpreds;
- to.noutcomes = noutcomes;
- int dim2Y = Y.ncol;
- int dim2X = X.ncol;
- (to.X).reinit(to.nids, dim2X);
- (to.Y).reinit(to.nids, dim2Y);
-
- int j = 0;
- for (int i = 0; i < nids; i++) {
- if (masked_data[i] == 0) {
- for (int nc = 0; nc < dim2X; nc++)
- (to.X).put(X.get(i, nc), j, nc);
- for (int nc = 0; nc < dim2Y; nc++)
- (to.Y).put(Y.get(i, nc), j, nc);
- j++;
- }
- }
-
- //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;
- //fprintf(stdout,"get_unmasked: %i %i %i\n",to.nids,dim2X,dim2Y);
- return (to);
-}
-
-mematrix<double> regdata::extract_genotypes(void) {
- mematrix<double> out;
- out.reinit(X.nrow, ngpreds);
- for (int i = 0; i < X.nrow; i++)
- for (int j = 0; j < ngpreds; j++)
- out[i * ngpreds + j] = X.get(i, (ncov - ngpreds + 1 + j));
- return out;
-}
-
// compare for sort of times
int cmpfun(const void *a, const void *b) {
double el1 = *(double*) a;
Modified: branches/ProbABEL-refactoring/ProbABEL/src/data.h
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/data.h 2012-03-29 12:45:16 UTC (rev 875)
+++ branches/ProbABEL-refactoring/ProbABEL/src/data.h 2012-03-30 19:06:42 UTC (rev 876)
@@ -14,80 +14,58 @@
#include "phedata.h"
#include "gendata.h"
-
-class regdata
-{
+class coxph_data {
public:
- int nids;
- int ncov;
- int ngpreds;
- int noutcomes;
- unsigned short int * masked_data;
- mematrix<double> X;
- mematrix<double> Y;
- regdata(){}
- regdata(const regdata &obj) ;
- regdata(phedata &phed, gendata &gend, int snpnum);
- mematrix<double> extract_genotypes();
- void update_snp(gendata &gend, int snpnum);
- regdata get_unmasked_data();
- ~regdata();
-private:
+ int nids;
+ int ncov;
+ int ngpreds;
+ mematrix<double> weights;
+ mematrix<double> stime;
+ mematrix<int> sstat;
+ mematrix<double> offset;
+ mematrix<int> strata;
+ mematrix<double> X;
+ mematrix<int> order;
+ unsigned short int * masked_data;
+ coxph_data get_unmasked_data();
+ coxph_data() {
+ }
+ coxph_data(const coxph_data &obj);
+ coxph_data(phedata &phed, gendata &gend, int snpnum);
+ void update_snp(gendata &gend, int snpnum);
+ ~coxph_data();
};
-class coxph_data
-{
+class mlinfo {
public:
- int nids;
- int ncov;
- int ngpreds;
- mematrix<double> weights;
- mematrix<double> stime;
- mematrix<int> sstat;
- mematrix<double> offset;
- mematrix<int> strata;
- mematrix<double> X;
- mematrix<int> order;
- unsigned short int * masked_data;
- coxph_data get_unmasked_data();
- coxph_data(){}
- coxph_data(const coxph_data &obj);
- coxph_data(phedata &phed, gendata &gend, int snpnum);
- void update_snp(gendata &gend, int snpnum);
- ~coxph_data();
-
+ int nsnps;
+ std::string * name;
+ std::string * A1;
+ std::string * A2;
+ double * Freq1;
+ double * MAF;
+ double * Quality;
+ double * Rsq;
+ std::string * map;
+ mlinfo() {
+ }
+ mlinfo(char * filename, char * mapname);
+ ~mlinfo();
};
-class mlinfo
-{
-public:
- int nsnps;
- std::string * name;
- std::string * A1;
- std::string * A2;
- double * Freq1;
- double * MAF;
- double * Quality;
- double * Rsq;
- std::string * map;
- mlinfo(){}
- mlinfo(char * filename, char * mapname);
- ~mlinfo();
-};
-
class InvSigma {
private:
- static const unsigned MAXIMUM_PEOPLE_AMOUNT = 1000000;
- unsigned npeople; //amount of people
- std::string filename;
- mematrix<double> matrix; //file is stored here
+ static const unsigned MAXIMUM_PEOPLE_AMOUNT = 1000000;
+ unsigned npeople; //amount of people
+ std::string filename;
+ mematrix<double> matrix; //file is stored here
public:
- InvSigma(const char * filename_, phedata * phe);
- mematrix<double> & get_matrix();
- ~InvSigma();
+ InvSigma(const char * filename_, phedata * phe);
+ mematrix<double> & get_matrix();
+ ~InvSigma();
};
#endif /* DATA_H_ */
Modified: branches/ProbABEL-refactoring/ProbABEL/src/reg1.h
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/reg1.h 2012-03-29 12:45:16 UTC (rev 875)
+++ branches/ProbABEL-refactoring/ProbABEL/src/reg1.h 2012-03-30 19:06:42 UTC (rev 876)
@@ -25,6 +25,7 @@
#include <cmath>
#include "cholesky.h"
+#include "regdata.h"
extern "C" {
#include "survproto.h"
}
Added: branches/ProbABEL-refactoring/ProbABEL/src/regdata.cpp
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/regdata.cpp (rev 0)
+++ branches/ProbABEL-refactoring/ProbABEL/src/regdata.cpp 2012-03-30 19:06:42 UTC (rev 876)
@@ -0,0 +1,135 @@
+/*
+ * regdata.cpp
+ *
+ * Created on: Mar 29, 2012
+ * Author: mkooyman
+ */
+
+#include "fvlib/AbstractMatrix.h"
+#include "fvlib/CastUtils.h"
+#include "fvlib/const.h"
+#include "fvlib/convert_util.h"
+#include "fvlib/FileVector.h"
+#include "fvlib/frutil.h"
+#include "fvlib/frversion.h"
+#include "fvlib/Logger.h"
+#include "fvlib/Transposer.h"
+
+#include "regdata.h"
+
+regdata::regdata() {
+}
+;
+
+regdata::regdata(const regdata &obj) {
+ nids = obj.nids;
+ ncov = obj.ncov;
+ ngpreds = obj.ngpreds;
+ noutcomes = obj.noutcomes;
+ X = obj.X;
+ Y = obj.Y;
+ masked_data = new unsigned short int[nids];
+ for (int i = 0; i < nids; i++) {
+ masked_data[i] = 0;
+ }
+}
+regdata::regdata(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;
+ }
+
+ ngpreds = gend.ngpreds;
+ if (snpnum >= 0) {
+ ncov = phed.ncov + ngpreds;
+ } else {
+ ncov = phed.ncov;
+ }
+ noutcomes = phed.noutcomes;
+ X.reinit(nids, (ncov + 1));
+ Y.reinit(nids, noutcomes);
+ for (int i = 0; i < nids; i++) {
+ X.put(1., i, 0);
+ Y.put((phed.Y).get(i, 0), i, 0);
+ }
+ for (int j = 1; j <= phed.ncov; j++)
+ for (int i = 0; i < nids; i++)
+ X.put((phed.X).get(i, j - 1), i, j);
+ if (snpnum > 0)
+ 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 + 1 + j));
+ }
+ // for (int i=0;i<nids;i++)
+ // for (int j=0;j<ngpreds;j++)
+ // X.put((gend.G).get(i,(snpnum*ngpreds+j)),i,(ncov-ngpreds+1+j));
+}
+void regdata::update_snp(gendata &gend, int snpnum) {
+ for (int j = 0; j < ngpreds; j++) {
+ float snpdata[nids];
+ 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], i, (ncov + 1 - j - 1));
+ if (isnan(snpdata[i]))
+ masked_data[i] = 1;
+ }
+ }
+}
+regdata::~regdata() {
+ delete[] regdata::masked_data;
+ // delete X;
+ // delete Y;
+}
+
+regdata regdata::get_unmasked_data() {
+ regdata to; // = regdata(*this);
+ int nmeasured = 0;
+ for (int i = 0; i < nids; i++)
+ if (masked_data[i] == 0)
+ nmeasured++;
+ to.nids = nmeasured;
+ //cout << to.nids << " in get_unmasked_data\n";
+ to.ncov = ncov;
+ to.ngpreds = ngpreds;
+ to.noutcomes = noutcomes;
+ int dim2Y = Y.ncol;
+ int dim2X = X.ncol;
+ (to.X).reinit(to.nids, dim2X);
+ (to.Y).reinit(to.nids, dim2Y);
+
+ int j = 0;
+ for (int i = 0; i < nids; i++) {
+ if (masked_data[i] == 0) {
+ for (int nc = 0; nc < dim2X; nc++) {
+ (to.X).put(X.get(i, nc), j, nc);
+ }
+
+ for (int nc = 0; nc < dim2Y; nc++) {
+ (to.Y).put(Y.get(i, nc), j, nc);
+ }
+ j++;
+ }
+ }
+
+ //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;
+ //fprintf(stdout,"get_unmasked: %i %i %i\n",to.nids,dim2X,dim2Y);
+ return (to);
+}
+
+mematrix<double> regdata::extract_genotypes(void) {
+ mematrix<double> out;
+ out.reinit(X.nrow, ngpreds);
+ for (int i = 0; i < X.nrow; i++)
+ for (int j = 0; j < ngpreds; j++)
+ out[i * ngpreds + j] = X.get(i, (ncov - ngpreds + 1 + j));
+ return out;
+}
+
Property changes on: branches/ProbABEL-refactoring/ProbABEL/src/regdata.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: branches/ProbABEL-refactoring/ProbABEL/src/regdata.h
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/regdata.h (rev 0)
+++ branches/ProbABEL-refactoring/ProbABEL/src/regdata.h 2012-03-30 19:06:42 UTC (rev 876)
@@ -0,0 +1,39 @@
+/*
+ * regdata.h
+ *
+ * Created on: Mar 29, 2012
+ * Author: mkooyman
+ */
+
+#ifndef REGDATA_H_
+#define REGDATA_H_
+
+#include "mematrix.h"
+#include "mematri1.h"
+#include "gendata.h"
+#include "phedata.h"
+
+class regdata
+{
+public:
+ int nids;
+ int ncov;
+ int ngpreds;
+ int noutcomes;
+ unsigned short int * masked_data;
+ mematrix<double> X;
+ mematrix<double> Y;
+ regdata();
+ regdata(const regdata &obj) ;
+ regdata(phedata &phed, gendata &gend, int snpnum);
+ mematrix<double> extract_genotypes();
+ void update_snp(gendata &gend, int snpnum);
+ regdata get_unmasked_data();
+ ~regdata();
+private:
+
+};
+
+
+
+#endif /* REGDATA_H_ */
Property changes on: branches/ProbABEL-refactoring/ProbABEL/src/regdata.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
More information about the Genabel-commits
mailing list