From 68b2c14e890537264a66fc929b75e24873a4a258 Mon Sep 17 00:00:00 2001 From: Andrej Fischer Date: Tue, 22 Apr 2014 10:20:22 +0200 Subject: [PATCH] fixed output file bugs --- changelog.md | 5 +++++ src/EMu-prepare.cpp | 28 ++++++++++++++++++++-------- src/EMu.cpp | 4 ++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/changelog.md b/changelog.md index c748afd..9fa2f19 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # changelog for EMu and EMu-prepare +v1.5.2 / to come + +* bug fix in EMu-prepare: `--bin` now accepts `1e5` notation +* changed EMu-prepare localized output to `pre.sample.opp.chr23.per-1Mb.txt` etc. + v1.5.1 / 15.04.2014 * moved to MAJOR.MINOR.PATCH release numbering diff --git a/src/EMu-prepare.cpp b/src/EMu-prepare.cpp index 15aab3f..f862c19 100755 --- a/src/EMu-prepare.cpp +++ b/src/EMu-prepare.cpp @@ -54,6 +54,7 @@ struct cmdl_opts{ const char * pre; const char * suff; const char * chr_dir; + string bin_str; int bin_size, max_chr, no_chr, cnv_def; }; @@ -152,7 +153,7 @@ void get_opts( int argc, const char ** argv, cmdl_opts& opts){ } else if ( opt_switch.compare("--bin") == 0){ opt_idx++; - opts.bin_size = atoi( argv[opt_idx]); + opts.bin_size = int(atof( argv[opt_idx])); } else if ( opt_switch.compare("--default") == 0){ opt_idx++; @@ -172,7 +173,7 @@ void get_opts( int argc, const char ** argv, cmdl_opts& opts){ exit(1); } if (opts.cnv_file_name == NULL && opts.chr_dir == NULL){ - cout<<"ERROR: for mutational opportunity, you have to set --cnv [cnf_file] and --chr [dir]\n"; + cout<<"ERROR: for mutational opportunity, you have to set --cnv [cnv_file] and --chr [dir]\n"; exit(1); } if (opts.reg_file_name != NULL && opts.bin_size > 0 ){ @@ -180,6 +181,17 @@ void get_opts( int argc, const char ** argv, cmdl_opts& opts){ cout<<"OR whether to get data collapsed over specific regions (with --regions [reg_file])\n"; exit(1); } + if (opts.bin_size>0){ + char buff[128]; + sprintf( buff, "per-%ib", opts.bin_size); + opts.bin_str.assign(buff); + int bs = opts.bin_size; + if (bs == 1000) opts.bin_str = "per-1kb"; + if (bs == 10000) opts.bin_str = "per-10kb"; + if (bs == 100000) opts.bin_str = "per-100kb"; + if (bs == 1000000) opts.bin_str = "per-1Mb"; + if (bs == 10000000) opts.bin_str = "per-10Mb"; + } } @@ -258,13 +270,12 @@ void get_regions( vector * region_start, } - +//******************************************************************************************* // translate mutation information to the 96 tri-nucleotide channel format... void get_mut( cmdl_opts& opts, map& mut_idx, map& base_idx ){ - // int no_chn = 96; ifstream * chr_ifs = new ifstream [opts.max_chr]; int * start = new int [opts.max_chr]; @@ -432,10 +443,11 @@ void get_mut( cmdl_opts& opts, for (it = mut_per_bin.begin(); it != mut_per_bin.end(); ++it){ for (int chr=0; chrfirst); out_fn.append(".mut."); char chrbuff [32]; - sprintf( chrbuff, "chr%i.%i.dat", chr+1, opts.bin_size); + sprintf( chrbuff, "chr%i.%s.txt", chr+1, opts.bin_str.c_str()); out_fn.append(chrbuff); FILE * out_fp = fopen(out_fn.c_str(),"w"); for (int bin=0; bin<(int) (it->second)[chr]->size1; bin++){ @@ -460,7 +472,7 @@ void get_mut( cmdl_opts& opts, } - +//******************************************************************************************* // translate sequences to opportunity tracks, i.e. which mutational channels are open... void get_opp( map& base_idx, cmdl_opts& opts @@ -509,8 +521,8 @@ void get_opp( map& base_idx, cnv_mult.insert(pair*>(sample,mults)); if (opts.pre != NULL){ string ofn(opts.pre); + ofn.append("."); ofn.append(sample); - ofn.append(".opp."); sample_fn.insert(pair(sample,ofn)); } } @@ -729,7 +741,7 @@ void get_opp( map& base_idx, for ( int s=0; s< no_samples; s++){ string fn = sample_fn[samples[s]]; char chrbuff [32]; - sprintf( chrbuff, "chr%i.%i.dat", chr+1, opts.bin_size); + sprintf( chrbuff, ".opp.chr%i.%s.txt", chr+1, opts.bin_str.c_str()); fn.append(chrbuff); FILE * track_fp = fopen( fn.c_str(), "w"); // BINS: diff --git a/src/EMu.cpp b/src/EMu.cpp index 4ee05d2..c51a6d4 100755 --- a/src/EMu.cpp +++ b/src/EMu.cpp @@ -187,7 +187,7 @@ int main(int argc, const char * argv[]){ } } } - else{ + else{//flat opportunity... gsl_matrix_set_all( Opp, 1.0); } // *** SCENARIO 1 *** @@ -215,7 +215,7 @@ int main(int argc, const char * argv[]){ if ( opts.with_gwts == 1){ get_dims( opts.gwts_fn, &Npat, &Nsp); if ( (Nsa % Npat) != 0 ){ - printf("The number of samples (%i) is not a multiple of the number of patients (%i).\n",Nsa,Npat); + printf("The number of lines (%i) is not a multiple of the number of samples (%i).\n",Nsa,Npat); exit(1); } else{