[Genabel-commits] r1008 - branches/ProbABEL-refactoring/ProbABEL/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 5 23:15:26 CET 2012


Author: maartenk
Date: 2012-11-05 23:15:25 +0100 (Mon, 05 Nov 2012)
New Revision: 1008

Modified:
   branches/ProbABEL-refactoring/ProbABEL/src/data.h
   branches/ProbABEL-refactoring/ProbABEL/src/gendata.cpp
   branches/ProbABEL-refactoring/ProbABEL/src/gendata.h
   branches/ProbABEL-refactoring/ProbABEL/src/phedata.h
   branches/ProbABEL-refactoring/ProbABEL/src/regdata.cpp
Log:
-  initialized variables in constructor with NULL or 0 that were not initialized
- changed whitespace (removed tabs, extra space around "=" etc.)

Modified: branches/ProbABEL-refactoring/ProbABEL/src/data.h
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/data.h	2012-11-05 14:14:03 UTC (rev 1007)
+++ branches/ProbABEL-refactoring/ProbABEL/src/data.h	2012-11-05 22:15:25 UTC (rev 1008)
@@ -14,8 +14,7 @@
 #include "phedata.h"
 #include "gendata.h"
 
-class mlinfo
-{
+class mlinfo {
 public:
     int nsnps;
     std::string * name;
@@ -28,16 +27,23 @@
     std::string * map;
     mlinfo()
     {
+        Freq1 = NULL;
+        MAF = NULL;
+        Quality = NULL;
+        Rsq = NULL;
+        nsnps = 0;
+        A1 = NULL;
+        A2 = NULL;
+        name = NULL;
+        map = NULL;
     }
     mlinfo(char * filename, char * mapname);
     ~mlinfo();
 };
 
-class InvSigma
-{
+class InvSigma {
 
 private:
-
     static const unsigned MAXIMUM_PEOPLE_AMOUNT = 1000000;
     unsigned npeople; //amount of people
     std::string filename;

Modified: branches/ProbABEL-refactoring/ProbABEL/src/gendata.cpp
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/gendata.cpp	2012-11-05 14:14:03 UTC (rev 1007)
+++ branches/ProbABEL-refactoring/ProbABEL/src/gendata.cpp	2012-11-05 22:15:25 UTC (rev 1008)
@@ -19,78 +19,74 @@
 void gendata::get_var(int var, float * data)
 {
     if (DAG == NULL)
-	for (int i = 0; i < G.nrow; i++)
-	    data[i] = G.get(i, var);
+        for (int i = 0; i < G.nrow; i++)
+            data[i] = G.get(i, var);
     else if (DAG != NULL)
     {
-	float tmpdata[DAG->getNumObservations()];
-	DAG->readVariableAs((unsigned long int) var, tmpdata);
-	unsigned int j = 0;
-	for (unsigned int i = 0; i < DAG->getNumObservations(); i++)
-	    if (!DAGmask[i])
-		data[j++] = tmpdata[i];
-	//fprintf(stdout,"%i %i %i\n",j,DAG->get_nobservations(),nids);
-    }
-    else
-	report_error("cannot get gendata");
+        float tmpdata[DAG->getNumObservations()];
+        DAG->readVariableAs((unsigned long int) var, tmpdata);
+        unsigned int j = 0;
+        for (unsigned int i = 0; i < DAG->getNumObservations(); i++)
+            if (!DAGmask[i])
+                data[j++] = tmpdata[i];
+        //fprintf(stdout,"%i %i %i\n",j,DAG->get_nobservations(),nids);
+    } else
+        report_error("cannot get gendata");
 }
 
 gendata::gendata()
 {
     nsnps = nids = ngpreds = 0;
+    DAG = NULL;
+    DAGmask = NULL;
 }
 
 void gendata::re_gendata(string filename, unsigned int insnps,
-			 unsigned int ingpreds, unsigned int npeople,
-			 unsigned int nmeasured,
-			 unsigned short int * allmeasured,
-			 std::string * idnames)
+        unsigned int ingpreds, unsigned int npeople, unsigned int nmeasured,
+        unsigned short int * allmeasured, std::string * idnames)
 {
     nsnps = insnps;
     ngpreds = ingpreds;
     DAG = new FileVector(filename, 128, true);
     DAGmask = new unsigned short int[DAG->getNumObservations()];
     if (DAG->getNumObservations() != npeople)
-	report_error("dimension of fvf-data and phenotype data do not match\n");
+        report_error("dimension of fvf-data and phenotype data do not match\n");
     if (DAG->getNumVariables() != insnps * ingpreds)
-	report_error("dimension of fvf-data and mlinfo data do not match\n");
+        report_error("dimension of fvf-data and mlinfo data do not match\n");
     long int j = -1;
     for (unsigned int i = 0; i < npeople; i++)
     {
-	if (allmeasured[i] == 0)
-	    DAGmask[i] = 1;
-	else
-	{
-	    DAGmask[i] = 0;
-	    j++;
-	}
-	string DAGobsname = DAG->readObservationName(i).name;
+        if (allmeasured[i] == 0)
+            DAGmask[i] = 1;
+        else
+        {
+            DAGmask[i] = 0;
+            j++;
+        }
+        string DAGobsname = DAG->readObservationName(i).name;
 
-	if (DAGobsname.find("->") != string::npos)
-	    DAGobsname = DAGobsname.substr(DAGobsname.find("->") + 2);
+        if (DAGobsname.find("->") != string::npos)
+            DAGobsname = DAGobsname.substr(DAGobsname.find("->") + 2);
 
 //if (allmeasured[i] && idnames[j] != DAGobsname)
-	//		error("names do not match for observation at phenofile line (phe/geno) %i/+1 (%s/%s)\n",
-	//			i+1,idnames[i].c_str(),DAGobsname.c_str());
-	// fix thanks to Vadym Pinchuk
-	if (allmeasured[i] && idnames[j] != DAGobsname)
-	    report_error(
-		    "names do not match for observation at phenofile line(phe/geno) %i/+1 (%s/%s)\n",
-		    i + 1, idnames[j].c_str(), DAGobsname.c_str());
+        //		error("names do not match for observation at phenofile line (phe/geno) %i/+1 (%s/%s)\n",
+        //			i+1,idnames[i].c_str(),DAGobsname.c_str());
+        // fix thanks to Vadym Pinchuk
+        if (allmeasured[i] && idnames[j] != DAGobsname)
+            report_error(
+                    "names do not match for observation at phenofile line(phe/geno) %i/+1 (%s/%s)\n",
+                    i + 1, idnames[j].c_str(), DAGobsname.c_str());
 
     }
     nids = j + 1;
     //fprintf(stdout,"in INI: %i %i\n",nids,npeople);
     if (nids != nmeasured)
-	report_error("nids != mneasured (%i != %i)\n", nids, nmeasured);
+        report_error("nids != mneasured (%i != %i)\n", nids, nmeasured);
 
 }
 void gendata::re_gendata(char * fname, unsigned int insnps,
-			 unsigned int ingpreds, unsigned int npeople,
-			 unsigned int nmeasured,
-			 unsigned short int * allmeasured,
-			 int skipd,
-			 std::string * idnames)
+        unsigned int ingpreds, unsigned int npeople, unsigned int nmeasured,
+        unsigned short int * allmeasured, int skipd, std::string * idnames)
 {
     nids = nmeasured;
     nsnps = insnps;
@@ -105,7 +101,7 @@
     infile.open(fname);
     if (!infile)
     {
-	std::cerr << "gendata: cannot open file " << fname << endl;
+        std::cerr << "gendata: cannot open file " << fname << endl;
     }
 
     char tmp[100], tmpn[100];
@@ -113,65 +109,62 @@
 
     int k = 0;
     for (unsigned int i = 0; i < npeople; i++)
-	if (allmeasured[i] == 1)
-	{
-	    if (skipd > 0)
-	    {
-		//				int ttt;
-		char ttt[100];
-		infile >> tmp;
-		//				sscanf(tmp,"%d->%s",&ttt, tmpn);
-		//		these changes are thanks to BMM & BP :)
-		//				sscanf(tmp,"%s->%s",&ttt, tmpn);
-		//				sscanf(tmp,"%[^->]->%[^->]",&ttt, tmpn);
-		tmpstr = tmp;
-		if (tmpstr.find("->") != string::npos)
-		{
-		    sscanf(tmp, "%[^->]->%s", ttt, tmpn);
-		    tmpid = tmpn;
-		}
-		else
-		{
-		    tmpid = tmpstr;
-		    //fprintf(stdout,"%s;%s;%s;%s;%s\n",tmp,ttt,tmpn,tmpid.c_str(),idnames[k].c_str());
-		}
-		if (tmpid != idnames[k])
-		{
-		    cerr << "phenotype file and dose or probability file "
-			 << "did not match at line " << i+2 << "(" << tmpid
-			 << " != " << idnames[k] << ")" << endl;
-		    infile.close();
-		    exit(1);
-		}
-	    }
-	    for (int j = 1; j < skipd; j++)
-	    {
-		infile >> tmp;
-	    }
-	    for (int j = 0; j < (nsnps * ngpreds); j++)
-	    {
-		if (infile.good())
-		{
-		    infile >> tmp;
-		}
-		else
-		{
-		    std::cerr
-			    << "cannot read dose-file: check skipd and ngpreds parameters\n";
-		    infile.close();
-		    exit(1);
-		}
-		G.put(atof(tmp), k, j);
-	    }
-	    k++;
-	}
-	else
-	{
-	    for (int j = 0; j < skipd; j++)
-		infile >> tmp;
-	    for (int j = 0; j < (nsnps * ngpreds); j++)
-		infile >> tmp;
-	}
+        if (allmeasured[i] == 1)
+        {
+            if (skipd > 0)
+            {
+                //				int ttt;
+                char ttt[100];
+                infile >> tmp;
+                //				sscanf(tmp,"%d->%s",&ttt, tmpn);
+                //		these changes are thanks to BMM & BP :)
+                //				sscanf(tmp,"%s->%s",&ttt, tmpn);
+                //				sscanf(tmp,"%[^->]->%[^->]",&ttt, tmpn);
+                tmpstr = tmp;
+                if (tmpstr.find("->") != string::npos)
+                {
+                    sscanf(tmp, "%[^->]->%s", ttt, tmpn);
+                    tmpid = tmpn;
+                } else
+                {
+                    tmpid = tmpstr;
+                    //fprintf(stdout,"%s;%s;%s;%s;%s\n",tmp,ttt,tmpn,tmpid.c_str(),idnames[k].c_str());
+                }
+                if (tmpid != idnames[k])
+                {
+                    cerr << "phenotype file and dose or probability file "
+                            << "did not match at line " << i + 2 << "(" << tmpid
+                            << " != " << idnames[k] << ")" << endl;
+                    infile.close();
+                    exit(1);
+                }
+            }
+            for (int j = 1; j < skipd; j++)
+            {
+                infile >> tmp;
+            }
+            for (int j = 0; j < (nsnps * ngpreds); j++)
+            {
+                if (infile.good())
+                {
+                    infile >> tmp;
+                } else
+                {
+                    std::cerr
+                            << "cannot read dose-file: check skipd and ngpreds parameters\n";
+                    infile.close();
+                    exit(1);
+                }
+                G.put(atof(tmp), k, j);
+            }
+            k++;
+        } else
+        {
+            for (int j = 0; j < skipd; j++)
+                infile >> tmp;
+            for (int j = 0; j < (nsnps * ngpreds); j++)
+                infile >> tmp;
+        }
     infile.close();
 }
 // HERE NEED A NEW CONSTRUCTOR BASED ON DATABELBASECPP OBJECT
@@ -180,8 +173,8 @@
 
     if (DAG != NULL)
     {
-	delete DAG;
-	delete[] DAGmask;
+        delete DAG;
+        delete[] DAGmask;
     }
 
     //		delete G;

Modified: branches/ProbABEL-refactoring/ProbABEL/src/gendata.h
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/gendata.h	2012-11-05 14:14:03 UTC (rev 1007)
+++ branches/ProbABEL-refactoring/ProbABEL/src/gendata.h	2012-11-05 22:15:25 UTC (rev 1008)
@@ -16,24 +16,18 @@
 #include "mematrix.h"
 #endif
 
-class gendata
-{
+class gendata {
 public:
     unsigned int nsnps;
     unsigned int nids;
     unsigned int ngpreds;
     gendata();
-    void re_gendata(char * fname, unsigned int insnps,
-		    unsigned int ingpreds, unsigned int npeople,
-		    unsigned int nmeasured,
-		    unsigned short int * allmeasured,
-		    int skipd,
-		    std::string * idnames);
-    void re_gendata(string filename, unsigned int insnps,
-		    unsigned int ingpreds, unsigned int npeople,
-		    unsigned int nmeasured,
-		    unsigned short int * allmeasured,
-		    std::string * idnames);
+    void re_gendata(char * fname, unsigned int insnps, unsigned int ingpreds,
+            unsigned int npeople, unsigned int nmeasured,
+            unsigned short int * allmeasured, int skipd, std::string * idnames);
+    void re_gendata(string filename, unsigned int insnps, unsigned int ingpreds,
+            unsigned int npeople, unsigned int nmeasured,
+            unsigned short int * allmeasured, std::string * idnames);
     void get_var(int var, float * data);
     ~gendata();
 

Modified: branches/ProbABEL-refactoring/ProbABEL/src/phedata.h
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/phedata.h	2012-11-05 14:14:03 UTC (rev 1007)
+++ branches/ProbABEL-refactoring/ProbABEL/src/phedata.h	2012-11-05 22:15:25 UTC (rev 1008)
@@ -10,16 +10,26 @@
 
 #if EIGEN
 #include "eigen_mematrix.h"
+#include "eigen_mematri1.h"
 #else
 #include "mematrix.h"
+#include "mematri1.h"
 #endif
 
-class phedata
-{
+class phedata {
 
 public:
     phedata()
     {
+        nids_all = 0;
+        nids = 0;
+        noutcomes = 0;
+        ncov = 0;
+        allmeasured = NULL;
+        idnames = NULL;
+        is_interaction_excluded = 0;
+        n_model_terms = 0;
+        model_terms = NULL;
 
     }
     phedata(char * fname, int noutc, int npeople, int interaction, bool iscox);

Modified: branches/ProbABEL-refactoring/ProbABEL/src/regdata.cpp
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/regdata.cpp	2012-11-05 14:14:03 UTC (rev 1007)
+++ branches/ProbABEL-refactoring/ProbABEL/src/regdata.cpp	2012-11-05 22:15:25 UTC (rev 1008)
@@ -19,6 +19,13 @@
 
 regdata::regdata()
 {
+    nids = 0;
+    ncov = 0;
+    ngpreds = 0;
+    noutcomes = 0;
+    is_interaction_excluded = false;
+    masked_data = NULL;
+
 }
 ;
 
@@ -28,7 +35,7 @@
     ncov = obj.ncov;
     ngpreds = obj.ngpreds;
     noutcomes = obj.noutcomes;
-    is_interaction_excluded=obj.is_interaction_excluded;
+    is_interaction_excluded = obj.is_interaction_excluded;
     X = obj.X;
     Y = obj.Y;
     masked_data = new unsigned short int[nids];
@@ -116,7 +123,7 @@
     to.ncov = ncov;
     to.ngpreds = ngpreds;
     to.noutcomes = noutcomes;
-    to.is_interaction_excluded=is_interaction_excluded;
+    to.is_interaction_excluded = is_interaction_excluded;
     int dim2Y = Y.ncol;
     int dim2X = X.ncol;
     (to.X).reinit(to.nids, dim2X);



More information about the Genabel-commits mailing list