void gcta::read_imp_info_beagle(string zinfofile)
{
    _dosage_flag=true;

    const int MAX_LINE_LENGTH = 1000;
    char buf[MAX_LINE_LENGTH];
    string str_buf, errmsg="Error: Reading SNP summary information filed? Please check the format of ["+zinfofile+"].";

    string c_buf;
    int i_buf;
    double f_buf=0.0;
    gzifstream zinf;
    zinf.open( zinfofile.c_str() );
    if(! zinf.is_open()) throw("Error: can not open the file ["+zinfofile+"] to read.");
    cout<<"Reading summary information of the imputed SNPs (BEAGLE) ..."<<endl;
    zinf.getline(buf, MAX_LINE_LENGTH, '\n'); // skip the header
    while(1){
        zinf.getline(buf, MAX_LINE_LENGTH, '\n');
        if(zinf.fail() || !zinf.good()) break;
        stringstream ss(buf);
        string nerr=errmsg+"\nError line: "+ss.str();
        if(!(ss>>i_buf)) throw(nerr);
        _chr.push_back(i_buf);
        if(!(ss>>str_buf)) throw(nerr);
        _snp_name.push_back(str_buf);
        if(!(ss>>i_buf)) throw(nerr);
        _bp.push_back(i_buf);
        if(!(ss>>c_buf)) throw(nerr);
        _allele1.push_back(c_buf);
        if(!(ss>>c_buf)) throw(nerr);
        _allele2.push_back(c_buf);
        if(!(ss>>str_buf)) throw(nerr);
        if(!(ss>>str_buf)) throw(nerr);
        if(!(ss>>str_buf)) throw(nerr);
        if(!(ss>>f_buf)) throw(nerr);
        if(!(ss>>f_buf)) throw(nerr);
        if(!(ss>>f_buf)) throw(nerr);
        _impRsq.push_back(f_buf);
        if(!(ss>>f_buf)) throw(nerr);
        if(!(ss>>f_buf)) throw(nerr);
        if(ss>>f_buf) throw(nerr);
    }
    zinf.clear();
    zinf.close();
    _snp_num=_snp_name.size();
    cout<<_snp_num<<" SNPs to be included from ["+zinfofile+"]."<<endl;
    _genet_dst.resize(_snp_num);
    _ref_A=_allele1;
    _other_A=_allele2;

 	// Initialize _include
	init_include();
}
void gcta::read_imp_info_mach(string zinfofile)
{
    _dosage_flag=true;

    int i=0;
    const int MAX_LINE_LENGTH = 1000;
    char buf[MAX_LINE_LENGTH];
    gzifstream zinf;
    zinf.open( zinfofile.c_str() );
    if(! zinf.is_open()) throw("Error: can not open the file ["+zinfofile+"] to read.");

    string str_buf, errmsg="Reading dosage data failed. Please check the format of the map file.";
    string c_buf;
    double f_buf=0.0;
    cout<<"Reading map file of the imputed dosage data from ["+zinfofile+"]."<<endl;
    zinf.getline(buf, MAX_LINE_LENGTH, '\n'); // skip the header
    vector<string> vs_buf;
    int col_num=StrFunc::split_string(buf, vs_buf);
    if(col_num<7) throw(errmsg);
    if(vs_buf[6]!="Rsq") throw(errmsg);
    _snp_name.clear();
    _allele1.clear();
    _allele2.clear();
    _impRsq.clear();
    while(1){
        zinf.getline(buf, MAX_LINE_LENGTH, '\n');
        stringstream ss(buf);
        string nerr=errmsg+"\nError occurs in line: "+ss.str();
        if(!(ss>>str_buf)) break;
        _snp_name.push_back(str_buf);
        if(!(ss>>c_buf)) throw(nerr);
        _allele1.push_back(c_buf);
        if(!(ss>>c_buf)) throw(nerr);
        _allele2.push_back(c_buf);
        for(i=0; i<4; i++) if(!(ss>>f_buf)) throw(nerr);
        _impRsq.push_back(f_buf);
        if(zinf.fail() || !zinf.good()) break;
    }
    zinf.clear();
    zinf.close();
    _snp_num=_snp_name.size();
    _chr.resize(_snp_num);
    _bp.resize(_snp_num);
    _genet_dst.resize(_snp_num);
    _ref_A=_allele1;
    _other_A=_allele2;

	// Initialize _include
	init_include();
    cout<<_snp_num<<" SNPs to be included from ["+zinfofile+"]."<<endl;
}
void gcta::read_bimfile(string bimfile)
{
	// Read bim file: recombination rate is defined between SNP i and SNP i-1
	int ibuf=0;
	string cbuf="0";
	double dbuf=0.0;
	string str_buf;
	ifstream Bim(bimfile.c_str());
	if(!Bim) throw("Error: can not open the file ["+bimfile+"] to read.");
	cout<<"Reading PLINK BIM file from ["+bimfile+"]."<<endl;
	_chr.clear();
	_snp_name.clear();
	_genet_dst.clear();
	_bp.clear();
	_allele1.clear();
	_allele2.clear();
	while(Bim){
	    Bim>>ibuf;
	    if(Bim.eof()) break;
		_chr.push_back(ibuf);
		Bim>>str_buf;
		_snp_name.push_back(str_buf);
		Bim>>dbuf;
		_genet_dst.push_back(dbuf);
		Bim>>ibuf;
		_bp.push_back(ibuf);
		Bim>>cbuf;
        //StrFunc::to_upper(cbuf);
		_allele1.push_back(cbuf);
		Bim>>cbuf;
        //StrFunc::to_upper(cbuf);
		_allele2.push_back(cbuf);
	}
	Bim.close();
	_snp_num=_chr.size();
	_ref_A=_allele1;
    _other_A=_allele2;
	cout<<_snp_num<<" SNPs to be included from ["+bimfile+"]."<<endl;

	// Initialize _include
	init_include();
}
Example #4
0
void init_preprocess(void)
{
   int i;
   char *cp;

   init_symtbl();
   for (i = 0; predefs[i]; i++)
   {
      cp = copyofstr("1");
      check_os_malloc(cp);
      define(predefs[i], -1, (unsigned char *) cp, DEF_PREDEF);
   }

   init_include();
   keep_comments = 0;
   no_line_lines = 0;
   do_at_ctrls = 0;
   incldep = 0;
   willbefirst = 1;
   quote = 0;
   ifstack = 0;
   n_skipped_ifs = 0;
}