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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 2 16:52:32 CEST 2013


Author: sharapovsodbo
Date: 2013-10-02 16:52:32 +0200 (Wed, 02 Oct 2013)
New Revision: 1336

Modified:
   pkg/OmicABEL/src/reshuffle/Parameters.cpp
   pkg/OmicABEL/src/reshuffle/Parameters.h
   pkg/OmicABEL/src/reshuffle/main.cpp
   pkg/OmicABEL/src/reshuffle/reshuffle.cpp
   pkg/OmicABEL/src/reshuffle/test.cpp
Log:
--ver 0.021
non-working temporary version
refactoring



Modified: pkg/OmicABEL/src/reshuffle/Parameters.cpp
===================================================================
--- pkg/OmicABEL/src/reshuffle/Parameters.cpp	2013-09-18 12:34:39 UTC (rev 1335)
+++ pkg/OmicABEL/src/reshuffle/Parameters.cpp	2013-10-02 14:52:32 UTC (rev 1336)
@@ -5,8 +5,7 @@
  *      Author: Sodbo
  */
 #include "Parameters.h"
-#include <stdlib.h>
-#include <string>
+
 using namespace std;
 
 string sep = "--"; // Set separator for cmdline
@@ -17,7 +16,6 @@
 	for (int i = 1; i < argc; i++) {
 		cmd_line += argv[i];
 	}
-	cout<<cmd_line<<endl;
 	cmd_line += sep; // Need for cmdline parsing
 	return cmd_line;
 }
@@ -38,23 +36,30 @@
 	cout<<"\tNames set ";
 	for (set<string>::iterator it= par.namesset.begin();it!=par.namesset.end();it++)
 		os <<*it<<" ";
-	os<<"\toutfile="<<par.outfile;
+	//os<<"\toutfile="<<par.outfile;
 	os<<endl;
 	return os;
 }
 
 //Overloading operator cout for class Parameters
 ostream &operator <<(ostream &os, Parameters par) {
-	os << "IOUT file is "<<par.iout_fname<<endl;
-	os << "OUT file is "<<par.out_fname<<endl;
-	os << par.datadims;
+	os << "OmicABEL iout_file is "<<par.iout_fname<<endl;
+	os << "OmicABEL out_file is "<<par.out_fname<<endl;
+	if (par.default_outfile){
+		os << "Using default out file name"<<endl;
+	}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 << par.dataslim;
+	os << "Write slim data : " << par.write_slim_data;
 	return os;
 }
 
@@ -63,7 +68,7 @@
 }
 
 //Constructor-Parser from command line
-Parameter::Parameter(string cmdline, string paramname,string ofile) {
+Parameter::Parameter(string cmdline, string paramname, string ofile) {
 
 	name = paramname;
 	outfile=ofile;
@@ -136,19 +141,93 @@
 
 //	Constructor, which gets info about all parameters from cmdline
 Parameters::Parameters(int argc,char* argv[]) {
-	static string cmdline=get_cmd_line(argc,argv);
-	unsigned int seppos = cmdline.find(sep); // 	first separator's position
-	string filename = cmdline.substr(0, seppos);
-	cmdline.erase(0,seppos);//Erase file name
+
+	get_help = false;
+	get_info = false;
+	write_datadims = false;
+	write_slim_data = false;
+	default_outfile = true;
+
+	//get input file names and delete it from argv[]
+	string filename= argv[1];
+	if (filename.find("--")==0||filename.find("-h")==0)
+		get_help=true;
 	iout_fname = filename + ".iout";
 	out_fname = filename + ".out";
-	//h = Parameter(cmdline,"h","");
-	help = Parameter(cmdline,"help","");
-	info = Parameter(cmdline, "info","");
-	cmdline=info.delfromcmdline(cmdline);
-	datadims = Parameter(cmdline, "datadims","datadims.txt");
-	cmdline=datadims.delfromcmdline(cmdline);
-	snpnames = Parameter(cmdline, "snpnames","snpnames.txt");
+	argv[1] = " ";
+
+	const char* short_options = "hidn::m::t::s::e::c:l:o";
+
+	const struct option long_options[] = {
+			{"help",no_argument,NULL,'h'},
+			{"info",no_argument,NULL,'i'},
+			{"datadims",no_argument,NULL,'d'},
+			{"traitnames",optional_argument,NULL,'n'},
+			{"snpnames",optional_argument,NULL,'m'},
+			{"traits",optional_argument,NULL,'t'},
+			{"snps",optional_argument,NULL,'s'},
+			{"herit",optional_argument,NULL,'e'},
+			{"chi",required_argument,NULL,'c'},
+			{"dataslim",no_argument,NULL,'l'},
+			{"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){
+			switch (rez){
+			case 'h' :{
+				get_help=true;
+				break;
+			}
+			case 'i':{
+				get_info=true;
+				break;
+			}
+			case 'd':{
+				write_datadims=true;
+				break;
+			}
+			case 'n':{
+				write_datadims=true;
+				break;
+			}
+			case 'm':{
+				write_datadims=true;
+				break;
+			}
+			case 't':{
+				write_datadims=true;
+				break;
+			}
+			case 's':{
+				write_datadims=true;
+				break;
+			}
+			case 'e':{
+				write_datadims=true;
+				break;
+			}
+			case 'c':{
+				write_datadims=true;
+				break;
+			}
+			case 'l':{
+				write_slim_data=true;
+				break;
+			}
+			case 'o':{
+				default_outfile = false;
+				outfile=optarg;
+				break;
+			}
+			}
+
+		}
+	//
+	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);
@@ -159,17 +238,15 @@
 	heritabilities = Parameter(cmdline, "heritabilities","estimates.txt");
 	cmdline=heritabilities.delfromcmdline(cmdline);
 	chi = Parameter(cmdline, "chi","chi_data.txt");
-	cmdline=	chi.delfromcmdline(cmdline);
-	dataslim= Parameter(cmdline, "dataslim","slim_data.txt");
-	cmdline=	dataslim.delfromcmdline(cmdline);
-	test= Parameter(cmdline, "test","test.txt");
-	cmdline=test.delfromcmdline(cmdline);
-	defaultstate=datadims.use+snpnames.use+traitnames.use+traits.use+snps.use+heritabilities.use+chi.use+dataslim.use+test.use;
+	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);
-	}
+	}*/
+
 }
 
 void Parameter::setbynames(vector<string> names){

Modified: pkg/OmicABEL/src/reshuffle/Parameters.h
===================================================================
--- pkg/OmicABEL/src/reshuffle/Parameters.h	2013-09-18 12:34:39 UTC (rev 1335)
+++ pkg/OmicABEL/src/reshuffle/Parameters.h	2013-10-02 14:52:32 UTC (rev 1336)
@@ -12,14 +12,17 @@
 #include <string>
 #include <set>
 #include <vector>
+#include <getopt.h>
+#include <stdlib.h>
+
 using namespace std;
 
 class Parameter {
 
 public:
-	string name; 	//name of parametr
-	bool use; 	// Parameter use or not (Is paameter in command line?)
-	string value; 	// value of parametr,chars after "=" symbol
+	string name; 	//name of parameter
+	bool use; 	// Parameter use or not (Is parameter in command line?)
+	string value; 	// value of parameter,chars after "=" symbol
 	set<int> numbersset;
 	set<string> namesset;
 	string delfromcmdline(string);
@@ -33,20 +36,21 @@
 
 class Parameters {
 public:
-	string iout_fname; //iout_file_name
-	string out_fname;
-	//Parameter h; //Print help
-	Parameter help; //Print help
-	Parameter info; // Write info about progeamm's run
-	Parameter datadims;
+	string iout_fname; // OmicABEL iout_file_name
+	string out_fname; // OmicABEL out_file_name
+	string outfile; // out_file path
+	bool default_outfile; // use default out_file_name
+	bool get_help; //Print help
+	bool get_info; // Write info about programm's run
+	bool run_test;
+	bool write_datadims;
+	bool write_slim_data;
 	Parameter snpnames;
 	Parameter traitnames;
 	Parameter traits;
 	Parameter snps;
 	Parameter heritabilities;
 	Parameter chi;
-	Parameter dataslim;
-	Parameter test;
 	Parameters();
 	Parameters(int, char*[]);		//	Constructor from cmdline
 	static string get_cmd_line(int,char*[]);

Modified: pkg/OmicABEL/src/reshuffle/main.cpp
===================================================================
--- pkg/OmicABEL/src/reshuffle/main.cpp	2013-09-18 12:34:39 UTC (rev 1335)
+++ pkg/OmicABEL/src/reshuffle/main.cpp	2013-10-02 14:52:32 UTC (rev 1336)
@@ -13,33 +13,38 @@
 
 using namespace std;
 
+void print_help(){
+	cout <<endl;
+	cout << "	Available commands"<<endl<<endl;
+	cout << " --datadims | to get data's dimension"<<endl<<endl;
+	cout << " --snpnames=<indexes> | to get names of SNP by indexes"<<endl<<endl;
+	cout << " --traitnames=<indexes> | to get names of trait by indexes"<<endl<<endl;
+	cout << " --traits=<indexes OR/AND names OR/AND regexp> | to get data"<<endl;
+	cout << "   by trait's indexes OR/AND names OR/AND regexp"<<endl<<endl;
+	cout << " --snp=<indexes OR/AND names OR/AND focus> | to get data"<<endl;
+	cout << "   by SNP's indexes OR/AND names"<<endl<<endl;
+	cout << " --heritabilities=<indexes OR/AND names OR/AND regexp>"<<endl;
+	cout << "   to get estimates of trait's heritability, sigma, res_sigma and betas"<<endl<<endl;
+	cout << " --chi=<number> | to get data by snp's, which chi2>number"<<endl<<endl;
+	cout << " --dataslim | to get slim data [You should set --chi=<number>]"<<endl<<endl;
+	exit(1);
+}
+
 int main(int argc, char* argv[]) {
-	//cout<<"Start reshuffeling"<<endl;
+
+	if (argc==1){
+		print_help();
+	}
 	Parameters Params(argc, argv);
-	if((Params.help.use||(Params.iout_fname==".iout"&&Params.out_fname==".out"))&&(!Params.test.use)){
-		cout<<"Available commands"<<endl<<endl;
-		cout<<" --datadims | to get data's dimension"<<endl<<endl;
-		cout<<" --snpnames=<indexes> | to get names of SNP by indexes"<<endl<<endl;
-		cout<<" --traitnames=<indexes> | to get names of trait by indexes"<<endl<<endl;
-		cout<<" --traits=<indexes OR/AND names OR/AND regexp> | to get data"<<endl;
-		cout<<"   by trait's indexes OR/AND names OR/AND regexp"<<endl<<endl;
-		cout<<" --snp=<indexes OR/AND names OR/AND focus> | to get data"<<endl;
-		cout<<"   by SNP's indexes OR/AND names"<<endl<<endl;
-		cout<<" --heritabilities=<indexes OR/AND names OR/AND regexp>"<<endl;
-		cout<<"   to get estimates of trait's heritability, sigma, res_sigma and betas"<<endl<<endl;
-		cout<<" --chi=<number> | to get data by snp's, which chi2>number"<<endl<<endl;
-		cout<<" --dataslim | to get slim data [You should set --chi=<number>]"<<endl<<endl;
-		exit(1);
+	if(Params.get_info)
+		cout << Params;
+	if((Params.get_help||(Params.iout_fname==".iout"&&Params.out_fname==".out"))&&(!Params.run_test)){
+		print_help();
 	}
-
-	if(Params.info.use)
-		cout << Params;
+	cout<<"Start reshuffeling"<<endl;
 	iout_file iout_F(Params);
 	cout << "Finish iout_file read\t" << double(clock()) / CLOCKS_PER_SEC <<" sec" << endl;
-	if(Params.info.use){
-		cout<<iout_F.header;
-		cout<<iout_F.labels;
-	}
+
 	if(Params.traits.use)
 		Params.traits.setbynames(*(iout_F.labels.trait_names));
 	if(Params.snps.use)

Modified: pkg/OmicABEL/src/reshuffle/reshuffle.cpp
===================================================================
--- pkg/OmicABEL/src/reshuffle/reshuffle.cpp	2013-09-18 12:34:39 UTC (rev 1335)
+++ pkg/OmicABEL/src/reshuffle/reshuffle.cpp	2013-10-02 14:52:32 UTC (rev 1336)
@@ -299,17 +299,17 @@
 }
 
 void Reshuffle::run(){
-	if((*p_Parameters).datadims.use){
-		ofstream datadims((*p_Parameters).datadims.outfile.c_str());
+	if((*p_Parameters).write_datadims){
+		ofstream datadims((*p_Parameters).outfile.c_str());
 		write_datadims(datadims);
 	}
 	if((*p_Parameters).snpnames.use){
-		ofstream snpnames((*p_Parameters).snpnames.outfile.c_str());
+		ofstream snpnames((*p_Parameters).outfile.c_str());
 		write_snpnames(snpnames);
 	}
 
 	if((*p_Parameters).traitnames.use){
-		ofstream traitnames((*p_Parameters).traitnames.outfile.c_str());
+		ofstream traitnames((*p_Parameters).outfile.c_str());
 		write_traitnames(traitnames);
 	}
 
@@ -341,29 +341,29 @@
 	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).traits.outfile.c_str());
+			data.open((*p_Parameters).outfile.c_str());
 		}else
 			if((*p_Parameters).snps.outfile!="data.txt"){
-				data.open((*p_Parameters).snps.outfile.c_str());
+				data.open((*p_Parameters).outfile.c_str());
 			}else
 				data.open("data.txt");
 		write_data(out_file,data);
 	}
 
-	if((*p_Parameters).chi.use&&!(*p_Parameters).dataslim.use){
-		ofstream chi_data((*p_Parameters).chi.outfile.c_str());
+	if((*p_Parameters).chi.use&&!(*p_Parameters).write_slim_data){
+		ofstream chi_data((*p_Parameters).outfile.c_str());
 		write_data_chi(out_file,chi_data);
 
 	}
 
-	if((*p_Parameters).dataslim.use){
-		ofstream dataslim((*p_Parameters).dataslim.outfile.c_str());
+	if((*p_Parameters).write_slim_data){
+		ofstream dataslim((*p_Parameters).outfile.c_str());
 		write_slim_data(out_file,dataslim);
 
 	}
 
 	if((*p_Parameters).heritabilities.use){
-		ofstream herest((*p_Parameters).heritabilities.outfile.c_str());
+		ofstream herest((*p_Parameters).outfile.c_str());
 		write_herest(out_file,herest);
 	}
 }

Modified: pkg/OmicABEL/src/reshuffle/test.cpp
===================================================================
--- pkg/OmicABEL/src/reshuffle/test.cpp	2013-09-18 12:34:39 UTC (rev 1335)
+++ pkg/OmicABEL/src/reshuffle/test.cpp	2013-10-02 14:52:32 UTC (rev 1336)
@@ -18,7 +18,7 @@
 	check=Check;
 	Params_test->iout_fname="data_4test/4test.iout";
 	Params_test->out_fname="data_4test/4test.out";
-	if(name=="datadims")
+	/*if(name=="datadims")
 		Params_test->datadims = Parameter(cmd,"datadims","datadims.txt");
 	if(name=="traitnamesdef"||name=="traitnames")
 		Params_test->traitnames = Parameter(cmd,"traitnames","traitnames.txt");
@@ -44,11 +44,11 @@
 	if(name=="dataslim"){
 		Params_test->dataslim = Parameter(cmd,"dataslim","slim_data.txt");
 		Params_test->chi = Parameter(cmd,"chi","chi_data.txt");
-	}
+	}*/
 }
 
 void test::run(ofstream& test_txt){
-	test_txt.open ("test.txt", fstream::app);
+	test_txt.open ("testd.txt", fstream::app);
 	test_txt<<"START TEST "<<name<<"\t";
 	iout_file iout_F(*Params_test);
 	if(Params_test->traits.use)



More information about the Genabel-commits mailing list