[Genabel-commits] r1337 - pkg/OmicABEL/src/reshuffle

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Oct 3 12:45:28 CEST 2013


Author: sharapovsodbo
Date: 2013-10-03 12:45:27 +0200 (Thu, 03 Oct 2013)
New Revision: 1337

Added:
   pkg/OmicABEL/src/reshuffle/makefile
Modified:
   pkg/OmicABEL/src/reshuffle/Parameters.cpp
   pkg/OmicABEL/src/reshuffle/Parameters.h
   pkg/OmicABEL/src/reshuffle/iout_file.cpp
   pkg/OmicABEL/src/reshuffle/main.cpp
   pkg/OmicABEL/src/reshuffle/reshuffle.cpp
   pkg/OmicABEL/src/reshuffle/reshuffle.h
Log:
--ver 0.022 non stable - need a check for *nix systems
--getopt.h for parsing command line arguments
--small changes in information output about program's run



Modified: pkg/OmicABEL/src/reshuffle/Parameters.cpp
===================================================================
--- pkg/OmicABEL/src/reshuffle/Parameters.cpp	2013-10-02 14:52:32 UTC (rev 1336)
+++ pkg/OmicABEL/src/reshuffle/Parameters.cpp	2013-10-03 10:45:27 UTC (rev 1337)
@@ -10,56 +10,53 @@
 
 string sep = "--"; // Set separator for cmdline
 
-//	Convert cmdline to string
-string Parameters::get_cmd_line(int argc, char* argv[]) {
-	string cmd_line = "";
-	for (int i = 1; i < argc; i++) {
-		cmd_line += argv[i];
-	}
-	cmd_line += sep; // Need for cmdline parsing
-	return cmd_line;
-}
 //Default constructor
 Parameter::Parameter() {
 	name = "None";
 	use = false;
-	value = "all";
+	def_value = true;
 }
 
 //Overloading operator cout for class Parameter
 ostream &operator <<(ostream &os, Parameter par) {
-	os << "PARAMETR" << "\t" << par.name << "\t" << "USE" << "\t" << par.use
-			<< "\t" << "VALUE" << "\t" << par.value;
+	os << "\nPARAMETR" << "\t" << par.name << "\t" << "USE" << "\t" << par.use<<"\t"<<"Use def_val "<<par.def_value;
 	cout<<"\tNumbers set ";
 	for (set<int>::iterator it= par.numbersset.begin();it!=par.numbersset.end();it++)
 		os <<*it<<" ";
 	cout<<"\tNames set ";
 	for (set<string>::iterator it= par.namesset.begin();it!=par.namesset.end();it++)
 		os <<*it<<" ";
-	//os<<"\toutfile="<<par.outfile;
-	os<<endl;
 	return os;
 }
 
 //Overloading operator cout for class Parameters
 ostream &operator <<(ostream &os, Parameters par) {
-	os << "OmicABEL iout_file is "<<par.iout_fname<<endl;
-	os << "OmicABEL out_file is "<<par.out_fname<<endl;
+	os << "\nOmicABEL iout_file is "<<par.iout_fname;
+	os << "\nOmicABEL out_file is "<<par.out_fname;
 	if (par.default_outfile){
-		os << "Using default out file name"<<endl;
+		os << "\nUsing default out file name";
 	}else
-		os << "Out file name : "<<par.outfile<<endl;
-
-	os << "Print help : " << par.get_help<<endl;
-	os << "Print info : " << par.get_info<<endl;
-	os << "Write data dimension : " << par.write_datadims<<endl;
-	os << par.snpnames;
-	os << par.traitnames;
-	os << par.traits;
-	os << par.snps;
-	os << par.heritabilities;
-	os << par.chi;
-	os << "Write slim data : " << par.write_slim_data;
+		os << "\nOut file name : "<<par.outfile;
+	if(par.get_help)
+		os << "\nPrinting help";
+	if(par.get_info)
+		os << "\nPrinting info about run";
+	if(par.write_datadims)
+		os << "\nWriting data dimension";
+	if(par.snpnames.use)
+		os << par.snpnames;
+	if(par.traitnames.use)
+		os << par.traitnames;
+	if(par.traits.use)
+		os << par.traits;
+	if(par.snps.use)
+		os << par.snps;
+	if(par.herit.use)
+		os << par.herit;
+	if(par.chi.use)
+		os << par.chi;
+	if(par.write_slim_data)
+			os << "\nWriting slim data";
 	return os;
 }
 
@@ -67,78 +64,50 @@
 Parameters::Parameters(){
 }
 
-//Constructor-Parser from command line
-Parameter::Parameter(string cmdline, string paramname, string ofile) {
-
+//Constructor-Parser from command line argument
+Parameter::Parameter(char* cmd_val, string paramname) {
 	name = paramname;
-	outfile=ofile;
-	int parpos = cmdline.find("--"+name)+2; //	position of substring with param's name
-	if (parpos != string::npos+2) { //	check  [FOUND OR NOT]
-		string val = "";
-		unsigned int iter = parpos + name.size() + 1; //	iterator, which run from "=" to sep
-		unsigned int seppos = cmdline.find(sep, parpos); // 	separator position
-		while (iter < seppos) {
-			val += cmdline.at(iter); // build value of parameter
-			iter++;
-		}
-
-		use = true;
-		if (val.size() != 0) {
-			value = val;
-			string val_d=val+",";
-			string str_tmp="";
-			for(unsigned int i=0;i<val_d.size();i++){
-				if(val_d[i]!=','){
-				str_tmp+=val_d[i];
-				}else {
-					string str2="";
-					int postire=str_tmp.find("-");
-					if(postire!=string::npos){
-						string start="";
-						string end="";
-						for(int i=0;i<postire;i++){
-							start+=str_tmp[i];
-						}
-						for(int i=(postire+1);i<str_tmp.size();i++){
-							end+=str_tmp[i];
-						}
-						for(int i=atoi(start.c_str())-1;i<atoi(end.c_str());i++){
-							numbersset.insert(i);
-						}
-					}else if(atoi(str_tmp.c_str())!=0){
-						numbersset.insert(atoi(str_tmp.c_str())-1);
-					}else{
-						if(str_tmp.find("file=")!=string::npos){//Fill outfile name
-							str_tmp=str_tmp.erase(0,5);
-							outfile=str_tmp;
-							value.erase(value.find("file="),5+str_tmp.size());//kill filename substring in value
-						}else
-							namesset.insert(str_tmp);
+	use=true;
+	if (cmd_val!=NULL) {
+		def_value=false;
+		string value = cmd_val;
+		string val_d=value+",";
+		string str_tmp="";
+		for(unsigned int i=0;i<val_d.size();i++){
+			if(val_d[i]!=','){
+			str_tmp+=val_d[i];
+			}else {
+				string str2="";
+				int postire=str_tmp.find("-");
+				if(postire!=string::npos){
+					string start="";
+					string end="";
+					for(int i=0;i<postire;i++){
+						start+=str_tmp[i];
 					}
-					str_tmp="";
+					for(int i=(postire+1);i<str_tmp.size();i++){
+						end+=str_tmp[i];
+					}
+					for(int i=atoi(start.c_str())-1;i<atoi(end.c_str());i++){
+						numbersset.insert(i);
+					}
+				}else if(atoi(str_tmp.c_str())!=0){
+					numbersset.insert(atoi(str_tmp.c_str())-1);
+				}else{
+					if(str_tmp.find("file=")!=string::npos){//Fill outfile name
+						str_tmp=str_tmp.erase(0,5);
+						value.erase(value.find("file="),5+str_tmp.size());//kill filename substring in value
+					}else
+						namesset.insert(str_tmp);
 				}
+				str_tmp="";
 			}
-		} else
-			value = "all"; // default value for parameters is "all"
-		if(value.size()==0)
-			value="all";
-
-	} else { // If parameter aren't in cmdline
-		use = false;
-		value = "None";
+		}
+	} else{
+		def_value = true; // default value for parameters is "all"
 	}
 }
 
-string Parameter::delfromcmdline(string cmdline){
-	if(use){
-		int val=value.size();
-		if(value=="None"||value=="all")
-			val=-1;
-		cmdline.replace(cmdline.find(name)-2,name.size()+val+3,"");
-	}
-	return cmdline;
-}
-
 //	Constructor, which gets info about all parameters from cmdline
 Parameters::Parameters(int argc,char* argv[]) {
 
@@ -172,7 +141,6 @@
 			{"outfile",required_argument,NULL,'o'},
 			{NULL,0,NULL,0}
 	};
-
 	int rez = 0;
 	int option_index = 0;
 		while((rez=getopt_long(argc,argv,short_options,long_options,&option_index))!=-1){
@@ -190,27 +158,32 @@
 				break;
 			}
 			case 'n':{
-				write_datadims=true;
+				traitnames = Parameter(optarg,"traitnames");
 				break;
 			}
 			case 'm':{
-				write_datadims=true;
+				snpnames = Parameter(optarg,"snpnames");
 				break;
 			}
 			case 't':{
-				write_datadims=true;
+				traits = Parameter(optarg,"traits");
 				break;
 			}
 			case 's':{
-				write_datadims=true;
+				snps = Parameter(optarg,"snps");
 				break;
 			}
 			case 'e':{
-				write_datadims=true;
+				herit = Parameter(optarg,"herit");
 				break;
 			}
 			case 'c':{
-				write_datadims=true;
+				chi = Parameter(optarg,"chi");
+				if (chi.numbersset.size()==0){
+					cout<<"\nChi value is not a number. Please, set correct Chi value";
+					exit(1);
+				}
+
 				break;
 			}
 			case 'l':{
@@ -225,28 +198,11 @@
 			}
 
 		}
-	//
-	static string cmdline=get_cmd_line(argc,argv);
-/*	snpnames = Parameter(cmdline, "snpnames","snpnames.txt");
-	cmdline=snpnames.delfromcmdline(cmdline);
-	traitnames = Parameter(cmdline, "traitnames","traitnames.txt");
-	cmdline=traitnames.delfromcmdline(cmdline);
-	traits = Parameter(cmdline, "traits","data.txt");
-	cmdline=traits.delfromcmdline(cmdline);
-	snps = Parameter(cmdline, "snps","data.txt");
-	cmdline=snps.delfromcmdline(cmdline);
-	heritabilities = Parameter(cmdline, "heritabilities","estimates.txt");
-	cmdline=heritabilities.delfromcmdline(cmdline);
-	chi = Parameter(cmdline, "chi","chi_data.txt");
-	cmdline=chi.delfromcmdline(cmdline);
-	defaultstate=write_datadims+snpnames.use+traitnames.use+traits.use
-			+snps.use+heritabilities.use+chi.use+write_slim_data+run_test;
-	if(traits.outfile!="data.txt"&&snps.outfile!="data.txt"){
-		cout<<"You've set outfile name in <<traits>> and <<snps>> parameters"<<endl;
-		cout<<"Please, set outfile name for data ones"<<endl;
-		exit(1);
-	}*/
-
+		defaultstate=write_datadims+snpnames.use+traitnames.use+traits.use
+					+snps.use+herit.use+chi.use+write_slim_data;
+		param_coutner = write_datadims+snpnames.use+traitnames.use +
+				(traits.use||snps.use||chi.use) +
+				(write_slim_data&&chi.use);
 }
 
 void Parameter::setbynames(vector<string> names){
@@ -289,25 +245,25 @@
 				cout<<"REGEXP="<<regexp<<endl;
 			}
 		}
-			for (set<string>::iterator nameit=namesset.begin();nameit!=namesset.end();++nameit){
-				if((*nameit).find("regexp")==string::npos){
-					for(int i=0;i<names.size();i++){
-						if(names[i]==*nameit){
-							numbersset.insert(i);
-							find=1;
-							break;
-						}
+		for (set<string>::iterator nameit=namesset.begin();nameit!=namesset.end();++nameit){
+			if((*nameit).find("regexp")==string::npos){
+				for(int i=0;i<names.size();i++){
+					if(names[i]==*nameit){
+						numbersset.insert(i);
+						find=1;
+						break;
 					}
-					if(find==1)
-						continue;
-				}else{
-					for(int i=0;i<names.size();i++){
-						if((names[i]).find(regexp)==0){
-							numbersset.insert(i);
-							find=1;
-						}
+				}
+				if(find==1)
+					continue;
+			}else{
+				for(int i=0;i<names.size();i++){
+					if((names[i]).find(regexp)==0){
+						numbersset.insert(i);
+						find=1;
 					}
 				}
 			}
 		}
+	}
 }

Modified: pkg/OmicABEL/src/reshuffle/Parameters.h
===================================================================
--- pkg/OmicABEL/src/reshuffle/Parameters.h	2013-10-02 14:52:32 UTC (rev 1336)
+++ pkg/OmicABEL/src/reshuffle/Parameters.h	2013-10-03 10:45:27 UTC (rev 1337)
@@ -22,13 +22,11 @@
 public:
 	string name; 	//name of parameter
 	bool use; 	// Parameter use or not (Is parameter in command line?)
-	string value; 	// value of parameter,chars after "=" symbol
+	bool def_value; 	// using default value
 	set<int> numbersset;
 	set<string> namesset;
-	string delfromcmdline(string);
 	void setbynames(vector<string>);
-	string outfile;
-	Parameter(string,string,string); 	//constructor
+	Parameter(char*,string); 	//constructor
 	Parameter();		//default constructor
 };
 
@@ -49,12 +47,12 @@
 	Parameter traitnames;
 	Parameter traits;
 	Parameter snps;
-	Parameter heritabilities;
+	Parameter herit;
 	Parameter chi;
 	Parameters();
 	Parameters(int, char*[]);		//	Constructor from cmdline
-	static string get_cmd_line(int,char*[]);
 	bool defaultstate;//Check: are there parameters instead of infile's path
+	int param_coutner;
 
 };
 

Modified: pkg/OmicABEL/src/reshuffle/iout_file.cpp
===================================================================
--- pkg/OmicABEL/src/reshuffle/iout_file.cpp	2013-10-02 14:52:32 UTC (rev 1336)
+++ pkg/OmicABEL/src/reshuffle/iout_file.cpp	2013-10-03 10:45:27 UTC (rev 1337)
@@ -71,11 +71,11 @@
 }
 
 ostream &operator <<(ostream &os,labels_data labels) {
-	os <<"NUMBER OF BETAS\t"<<(*labels.beta).size()<<endl;
-	os <<"NUMBER OF SE\t"<<(*labels.se).size()<<endl;
-	os <<"NUMBER OF COVS\t"<<(*labels.cov).size()<<endl;
-	os <<"NUMBER OF SNPNAMES\t"<<(*labels.snp_names).size()<<endl;
-	os <<"NUMBER OF TRAITNAMES\t"<<(*labels.trait_names).size()<<endl;
+	os <<"\nNUMBER OF BETAS\t"<<(*labels.beta).size();
+	os <<"\nNUMBER OF SE\t"<<(*labels.se).size();
+	os <<"\nNUMBER OF COVS\t"<<(*labels.cov).size();
+	os <<"\nNUMBER OF SNPNAMES\t"<<(*labels.snp_names).size();
+	os <<"\nNUMBER OF TRAITNAMES\t"<<(*labels.trait_names).size();
 
 	return os;
 }
@@ -86,18 +86,11 @@
 	int t_off = traitNo % header.tile_t;
 	int m_tile = snpNo / header.tile_m;
 	int m_off = snpNo % header.tile_m;
-
 	int per_trait_per_snp = header.p + header.p * (header.p + 1) / 2;
 
-	//cout <<t_tile<<endl<<t_off<<endl<<m_tile<<endl<<m_off<<endl<<endl;
-	//cout<<(tileCoor)<<endl;
 	tileCoor = (long long)t_tile * header.m * header.tile_t;
-	//cout<<(tileCoor)<<endl;
 	tileCoor += (long long)m_tile * header.tile_m * min(header.tile_t,header.t - header.tile_t * t_tile);
-	//cout<<(tileCoor)<<endl;
 	tileCoor += (long long)t_off * min(header.tile_m, header.m - header.tile_m * m_tile)+ m_off;
-	//cout<<(tileCoor)<<endl;
 	tileCoor *= (long long)per_trait_per_snp * sizeof(double);
-	//cout<<(tileCoor)<<endl;
 	return tileCoor;
 }

Modified: pkg/OmicABEL/src/reshuffle/main.cpp
===================================================================
--- pkg/OmicABEL/src/reshuffle/main.cpp	2013-10-02 14:52:32 UTC (rev 1336)
+++ pkg/OmicABEL/src/reshuffle/main.cpp	2013-10-03 10:45:27 UTC (rev 1337)
@@ -2,15 +2,13 @@
  * main.cpp
  *
  *  Created on: 31.01.2013
- *      Author: Sodbo
+ *      Author: Sodbo Sharapov sharapovsodbo at gmail.com
  */
-#include <iostream>
-#include <ctime>
 #include "iout_file.h"
 #include "Parameters.h"
 #include "reshuffle.h"
-#include <iterator>
 
+
 using namespace std;
 
 void print_help(){
@@ -31,28 +29,32 @@
 }
 
 int main(int argc, char* argv[]) {
-
 	if (argc==1){
 		print_help();
 	}
 	Parameters Params(argc, argv);
-	if(Params.get_info)
-		cout << Params;
 	if((Params.get_help||(Params.iout_fname==".iout"&&Params.out_fname==".out"))&&(!Params.run_test)){
 		print_help();
 	}
-	cout<<"Start reshuffeling"<<endl;
+	if(Params.get_info)
+		cout << Params;
+	if(Params.param_coutner>1){
+		cout<<"\nToo many parameters. Please, reduce number of parameters";
+		exit(1);
+	}
+
+	cout<<"\nStart reshuffeling";
 	iout_file iout_F(Params);
-	cout << "Finish iout_file read\t" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+	cout << "\nFinish iout_file read\t" << double(clock()) / CLOCKS_PER_SEC <<" sec";
 
 	if(Params.traits.use)
 		Params.traits.setbynames(*(iout_F.labels.trait_names));
 	if(Params.snps.use)
 		Params.snps.setbynames(*(iout_F.labels.snp_names));
-	if(Params.heritabilities.use)
-		Params.heritabilities.setbynames(*(iout_F.labels.trait_names));
+	if(Params.herit.use)
+		Params.herit.setbynames(*(iout_F.labels.trait_names));
 	Reshuffle reshh(iout_F,Params);
 	reshh.run();
-	cout << "Finish reshuffling " << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+	cout << "\nFinish reshuffling " << double(clock()) / CLOCKS_PER_SEC <<" sec";
 	return (0);
 }

Added: pkg/OmicABEL/src/reshuffle/makefile
===================================================================
--- pkg/OmicABEL/src/reshuffle/makefile	                        (rev 0)
+++ pkg/OmicABEL/src/reshuffle/makefile	2013-10-03 10:45:27 UTC (rev 1337)
@@ -0,0 +1,14 @@
+all:
+	g++ -O3 -Wall -c -fmessage-length=0 -o iout_file.o "D:\Work\SVNRepository\OmicABEL\src\reshuffle\iout_file.cpp" 
+	g++ -O3 -Wall -c -fmessage-length=0 -o reshuffle.o "D:\Work\SVNRepository\OmicABEL\src\reshuffle\reshuffle.cpp"  
+	g++ -O3 -Wall -c -fmessage-length=0 -o Parameters.o "D:\Work\SVNRepository\OmicABEL\src\reshuffle\Parameters.cpp" 
+	g++ -O3 -Wall -c -fmessage-length=0 -o main.o "D:\Work\SVNRepository\OmicABEL\src\reshuffle\main.cpp" 
+	g++ -o Reshuffle.exe "reshuffle.o" "main.o" "iout_file.o" "Parameters.o"
+
+clean:
+
+	del iout_file.o
+	del reshuffle.o
+	del Parameters.o
+	del main.o
+	del Reshuffle.exe
\ No newline at end of file

Modified: pkg/OmicABEL/src/reshuffle/reshuffle.cpp
===================================================================
--- pkg/OmicABEL/src/reshuffle/reshuffle.cpp	2013-10-02 14:52:32 UTC (rev 1336)
+++ pkg/OmicABEL/src/reshuffle/reshuffle.cpp	2013-10-03 10:45:27 UTC (rev 1337)
@@ -6,12 +6,6 @@
  */
 
 #include "reshuffle.h"
-#include <ctime>
-#include <math.h>
-#include <iterator>
-#include <list>
-#include <sstream>
-#include <string>
 
 using namespace std;
 
@@ -26,50 +20,41 @@
 					* sizeof(double);
 }
 
-string Reshuffle::create_filename(string prename, string name) {
-	string path = prename + "_"+name+".txt";
-	return path;
-}
-string Reshuffle::create_filename(string name) {
-	string path = name+".txt";
-	return path;
-}
-
 void Reshuffle::write_datadims(ofstream& txt_datadims){
 
 	txt_datadims << "Number of traits\t" << (*p_iout_file).header.t << endl;
 	txt_datadims << "Number of SNP\t" << (*p_iout_file).header.m << endl;
 	txt_datadims << "Number of covariates\t" << ((*p_iout_file).header.p - 2);
-	cout<<"End_write_data_dimension\t"<< double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+	cout<<"End write data dimension\t"<< double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
 }
 
 void Reshuffle::write_snpnames(ofstream& txt_snpnames){
 
-	if ((*p_Parameters).snpnames.value == "all"){
+	if ((*p_Parameters).snpnames.def_value){
 		for (unsigned int i=0;i<(*(*p_iout_file).labels.snp_names).size();i++)
 			(*p_Parameters).snpnames.numbersset.insert(i);
-		cout<<"SNPNAMES VALUE SET CHANGED TO ALL"<<endl;
+		cout<<"\nWriting all SNP's names";
 	}
 	for(set<int>::iterator it= (*p_Parameters).snpnames.numbersset.begin();it!=(*p_Parameters).snpnames.numbersset.end();++it)
-		txt_snpnames << "SNP #"<<(*it+1)<<"\t"<<(*(*p_iout_file).labels.snp_names)[*it]<<endl;
-	cout<<"END WRITE SNPNAMES\t" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+		txt_snpnames << "\nSNP #"<<(*it+1)<<"\t"<<(*(*p_iout_file).labels.snp_names)[*it];
+	cout<<"\nEnd write SNP's names\t" << double(clock()) / CLOCKS_PER_SEC <<" sec";
 }
 
 void Reshuffle::write_traitnames(ofstream& txt_traitnames){
 
-	if ((*p_Parameters).traitnames.value == "all"){
+	if ((*p_Parameters).traitnames.def_value){
 		for (unsigned int i=0;i<(*(*p_iout_file).labels.trait_names).size();i++)
 			(*p_Parameters).traitnames.numbersset.insert(i);
-		cout<<"TRAITNAMES VALUE SET CHANGED TO ALL"<<endl;
+		cout<<"\nWriting all trait's names";
 	}
 	for(std::set<int>::iterator it= (*p_Parameters).traitnames.numbersset.begin();it!=p_Parameters->traitnames.numbersset.end();++it)
-		txt_traitnames<<"TRAIT #"<<(*it+1)<<"\t"<<(*(*p_iout_file).labels.trait_names)[*it]<<endl;
-	cout<<"END WRITE TRAITNAMES\t" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+		txt_traitnames<<"TRAIT #"<<(*it+1)<<"\t"<<(*(*p_iout_file).labels.trait_names)[*it];
+	cout<<"\nEnd write trait's names\t" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
 }
 
 void Reshuffle::write_data(ifstream& out_file,ofstream& data){
 	out_file.seekg(0, ios_base::beg);
-	cout << "Start_write_data\t" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+	cout << "\nStart write data\t" << double(clock()) / CLOCKS_PER_SEC <<" sec";
 	data.precision(PRECISION_DOUBLE);
 	data<<"SNP\t";
 	data<<	"Trait\t";
@@ -89,7 +74,6 @@
 			ostr << (*(*p_iout_file).labels.snp_names)[*snp] << "\t";
 			ostr << (*(*p_iout_file).labels.trait_names)[*trait]<<"\t";
 			pos = (*p_iout_file).tilecoordinates(*trait, *snp);
-			//cout << oldPos << "-" << pos << endl;
 			if(pos != oldPos)
 			{
 				out_file.seekg(pos,ios_base::beg);
@@ -105,19 +89,17 @@
 		data << ostr.str();
 		ostr.str("");
 		ostr.clear();
-
-		//txt_trait.close();
-		//cout << "End_write_trait\t" << (*(*p_iout_file).labels.trait_names)[*trait] << " "<< double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
 	}
 	delete buf;
-	cout << "Finish_write_data\t" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+	cout << "\nFinish write data\t" << double(clock()) / CLOCKS_PER_SEC <<" sec";
 }
 
 void Reshuffle::write_data_chi(ifstream& out_file,ofstream& txt_chi){
 	out_file.seekg(0, ios_base::beg);
 	double chi = 0;
-	double CheckChi = (*p_Parameters).chi.value == "all" ? -1.0 : atof((*p_Parameters).chi.value.c_str());
-	cout << "Start_write_chi_data=" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+	set<int>::iterator chi_val = (*p_Parameters).chi.numbersset.begin();
+	double CheckChi = *chi_val+1;
+	cout << "\nStart write chi data=" << double(clock()) / CLOCKS_PER_SEC <<" sec";
 	txt_chi.precision(PRECISION_DOUBLE);
 	txt_chi << "SNP\t";
 	txt_chi << "Trait\t";
@@ -132,11 +114,9 @@
 	char s[30];
 	ostringstream ostr;
 	for (set<int>::iterator trait= (*p_Parameters).traits.numbersset.begin();trait!=(*p_Parameters).traits.numbersset.end();trait++) {
-		//ofstream txt_chi(create_filename("chi_data//chi", (*(*p_iout_file).labels.trait_names)[*trait]).c_str());
 		long long oldPos=0,pos = 0;
 		for (set<int>::iterator snp= (*p_Parameters).snps.numbersset.begin();snp!=(*p_Parameters).snps.numbersset.end();snp++) {
 			pos = (*p_iout_file).tilecoordinates(*trait, *snp);
-			//cout << oldPos << "-" << pos << endl;
 			if(pos != oldPos)
 			{
 				out_file.seekg(pos,ios_base::beg);
@@ -157,25 +137,24 @@
 		txt_chi << ostr.str();
 		ostr.str("");
 		ostr.clear();
-
-		//txt_chi.close();
-		//cout << "End_write_chi_trait\t" << (*(*p_iout_file).labels.trait_names)[*trait] << " "<< double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
 	}
 	delete buf;
-	cout << "Finish_write_chi_data\t" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+	cout << "\nFinish write chi data\t" << double(clock()) / CLOCKS_PER_SEC <<" sec";
 }
 
 void Reshuffle::write_slim_data(ifstream& out_file, ofstream& txt_slim){
+	cout << "\nStart write slim data=" << double(clock()) / CLOCKS_PER_SEC <<" sec";
 	out_file.seekg(0, ios_base::beg);
 	set<int> goodtraits;
 	set<int> goodsnps;
 	double chi = 0;
-	if((*p_Parameters).chi.value=="all"||(*p_Parameters).chi.value=="None"){
-		cout << "ERROR: " << "Chi value doesn't set"<<endl;
-		cout << "Please, set Chi value to get slim data" << endl;
+	if((*p_Parameters).chi.def_value||(!(*p_Parameters).chi.use)){
+		cout << "\nERROR: " << "Chi value doesn't set";
+		cout << "\nPlease, set Chi value to get slim data";
 		exit(1);
 	}
-	double CheckChi = atof((*p_Parameters).chi.value.c_str());
+	set<int>::iterator chi_val = (*p_Parameters).chi.numbersset.begin();
+	double CheckChi = *chi_val+1;
 	double* buf = new double[per_trait_per_snp];
 	for (set<int>::iterator trait= (*p_Parameters).traits.numbersset.begin();trait!=(*p_Parameters).traits.numbersset.end();trait++) {
 		long long oldPos=0,pos = 0;
@@ -232,7 +211,7 @@
 		ostr.clear();
 	}
 	delete buf;
-	cout <<"End_write_slim_data\t" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+	cout <<"\nEnd write slim data\t" << double(clock()) / CLOCKS_PER_SEC <<" sec";
 }
 
 int Reshuffle::est_shift(int counter){
@@ -248,14 +227,15 @@
 }
 
 void Reshuffle::write_herest(ifstream& out_file, ofstream& herest){
+	cout << "\nStart write heritabilities and estimates=" << double(clock()) / CLOCKS_PER_SEC <<" sec";
 	ofstream txt_est("estimates.txt");
 	out_file.seekg(herest_startpos, ios_base::beg);
-	if (p_Parameters->heritabilities.value == "all")
+	if (p_Parameters->herit.def_value)
 		for(unsigned int i=0;i<(*(p_iout_file->labels.trait_names)).size();i++)
-			p_Parameters->heritabilities.numbersset.insert(i);
+			p_Parameters->herit.numbersset.insert(i);
 	txt_est.precision(PRECISION_DOUBLE);
 	txt_est<<"\t";
-	for (set<int>::iterator trait= p_Parameters->heritabilities.numbersset.begin();trait!=p_Parameters->heritabilities.numbersset.end();trait++)
+	for (set<int>::iterator trait= p_Parameters->herit.numbersset.begin();trait!=p_Parameters->herit.numbersset.end();trait++)
 		txt_est << (*(p_iout_file->labels.trait_names))[*trait] << "\t";
 	txt_est << endl;
 	list<string> est_names;
@@ -266,7 +246,7 @@
 	int counter=0;
 	for (list<string>::iterator name = est_names.begin();name != est_names.end(); ++name) {
 		txt_est << *name << "\t";
-		for (std::set<int>::iterator trait= p_Parameters->heritabilities.numbersset.begin();trait!=p_Parameters->heritabilities.numbersset.end();++trait) {
+		for (std::set<int>::iterator trait= p_Parameters->herit.numbersset.begin();trait!=p_Parameters->herit.numbersset.end();++trait) {
 			out_file.seekg(*trait*sizeof(double),ios_base::cur);
 			out_file.read((char *) &tmp_number, sizeof(double));
 			txt_est << tmp_number << "\t";
@@ -283,7 +263,7 @@
 		if (beta != (*(p_iout_file->labels.beta)).size()) {
 			beta--;
 			txt_est << (*(p_iout_file->labels).beta)[beta] << "\t";
-			for (std::set<int>::iterator trait= p_Parameters->heritabilities.numbersset.begin();trait!=p_Parameters->heritabilities.numbersset.end();++trait) {
+			for (std::set<int>::iterator trait= p_Parameters->herit.numbersset.begin();trait!=p_Parameters->herit.numbersset.end();++trait) {
 				out_file.seekg(*trait*sizeof(double),ios_base::cur);
 				out_file.read((char *) &tmp_number, sizeof(double));
 				txt_est << tmp_number << "\t";
@@ -295,7 +275,7 @@
 			beta++;
 		}
 	}
-	cout << "End_write_estimates\t" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
+	cout << "\nEnd write heritabilities and estimates\t" << double(clock()) / CLOCKS_PER_SEC <<" sec";
 }
 
 void Reshuffle::run(){
@@ -316,8 +296,8 @@
 	//Open *.out to read data
 	ifstream out_file((*p_Parameters).out_fname.c_str(), ios::binary | ios::in);
 	if (!out_file) {
-		cout << "Error open " << (*p_Parameters).out_fname << " file";
-		cout << "Maybe, file doesn't exist" << endl;
+		cout << "\nError open " << (*p_Parameters).out_fname << " file";
+		cout << "\nMaybe, file doesn't exist";
 		exit(1);
 	}
 
@@ -325,28 +305,21 @@
 	//(if their values are default all)
 	if((*p_Parameters).traits.use||(*p_Parameters).snps.use||(*p_Parameters).chi.use||!(*p_Parameters).defaultstate){
 
-			if((*p_Parameters).traits.value=="all"||(*p_Parameters).traits.value=="None"){
+			if((*p_Parameters).traits.def_value||(!(*p_Parameters).traits.use)){
 				for(unsigned int i=0;i<(*(*p_iout_file).labels.trait_names).size();i++)
 				(*p_Parameters).traits.numbersset.insert(i);
-			cout<<"TRAITS VALUE SET CHANGED TO ALL"<<endl;
+			cout<<"\nWriting data for all traits";
 		}
 
-		if((*p_Parameters).snps.value=="all"||(*p_Parameters).snps.value=="None"){
+		if((*p_Parameters).snps.def_value||(!(*p_Parameters).snps.use)){
 			for(unsigned int i=0;i<(*(*p_iout_file).labels.snp_names).size();i++)
 				(*p_Parameters).snps.numbersset.insert(i);
-			cout<<"SNPS VALUE SET CHANGED TO ALL"<<endl;
+			cout<<"\nWriting data for all SNPs";
 		}
 	}
 
 	if((((*p_Parameters).traits.use||(*p_Parameters).snps.use)&&!(*p_Parameters).chi.use)||!(*p_Parameters).defaultstate){
-		ofstream data;
-		if((*p_Parameters).traits.outfile!="data.txt"){
-			data.open((*p_Parameters).outfile.c_str());
-		}else
-			if((*p_Parameters).snps.outfile!="data.txt"){
-				data.open((*p_Parameters).outfile.c_str());
-			}else
-				data.open("data.txt");
+		ofstream data((*p_Parameters).outfile.c_str());
 		write_data(out_file,data);
 	}
 
@@ -362,7 +335,7 @@
 
 	}
 
-	if((*p_Parameters).heritabilities.use){
+	if((*p_Parameters).herit.use){
 		ofstream herest((*p_Parameters).outfile.c_str());
 		write_herest(out_file,herest);
 	}

Modified: pkg/OmicABEL/src/reshuffle/reshuffle.h
===================================================================
--- pkg/OmicABEL/src/reshuffle/reshuffle.h	2013-10-02 14:52:32 UTC (rev 1336)
+++ pkg/OmicABEL/src/reshuffle/reshuffle.h	2013-10-03 10:45:27 UTC (rev 1337)
@@ -10,6 +10,12 @@
 
 #include "Parameters.h"
 #include "iout_file.h"
+#include <ctime>
+#include <math.h>
+#include <iterator>
+#include <list>
+#include <sstream>
+#include <string>
 
 using namespace std;
 
@@ -20,8 +26,6 @@
 	int per_trait_per_snp;
 	set<int> traits2write;
 	set<int> snps2write;
-	string create_filename(string, string);
-	string create_filename(string);
 	void write_datadims(ofstream&);
 	void write_snpnames(ofstream&);
 	void write_traitnames(ofstream&);



More information about the Genabel-commits mailing list