Skip to content

Commit

Permalink
initial implementation of reading gz-ed plain text genotype files
Browse files Browse the repository at this point in the history
  • Loading branch information
mkooyman committed Nov 12, 2015
1 parent db04fbc commit 486ccda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ RHEADERS = include/R.h include/Rmath.h include/R_ext/Arith.h \
include/R_ext/Print.h include/R_ext/Random.h include/R_ext/Utils.h \
include/R_ext/RS.h

LDADD = -lboost_iostreams -lz

bin_PROGRAMS =
if BUILD_palinear
bin_PROGRAMS += palinear
Expand Down
22 changes: 17 additions & 5 deletions src/gendata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include "eigen_mematrix.h"
#include "eigen_mematrix.cpp"
#include "utilities.h"
#include <iostream>
#include <fstream>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>


void gendata::mldose_line_to_matrix(const int k,
Expand Down Expand Up @@ -247,12 +251,20 @@ void gendata::re_gendata(const char * fname,

G.reinit(nids, (nsnps * ngpreds));

std::ifstream infile;
infile.open(fname);
std::ifstream file(fname, std::ios_base::in | std::ios_base::binary);
boost::iostreams::filtering_istream infile;
std::string filename=fname;
if (filename.compare(filename.length()-2,2,"gz")== 0){
infile.push(boost::iostreams::gzip_decompressor());
}else{
std::cout << "no gziped:"<< ":\n";
}
infile.push(file);

if (!infile)
if (!file)
{
std::cerr << "gendata: cannot open file " << fname << endl;
exit(1);
}

std::string tmpid, tmpstr;
Expand Down Expand Up @@ -282,7 +294,7 @@ void gendata::re_gendata(const char * fname,
cerr << "phenotype file and dose or probability file "
<< "did not match at line " << i + 2 << " ("
<< tmpid << " != " << idnames[k] << ")" << endl;
infile.close();
file.close();
exit(1);
}
}
Expand Down Expand Up @@ -312,7 +324,7 @@ void gendata::re_gendata(const char * fname,
}
}

infile.close();
file.close();
}

// HERE NEED A NEW CONSTRUCTOR BASED ON DATABELBASECPP OBJECT
Expand Down

0 comments on commit 486ccda

Please sign in to comment.