#include <consalgo.h>
Inheritance diagram for ConsAlgo:
Public Member Functions | |
ConsAlgo (TrapperDoc *pDoc_, std::set< db_recno_t > &recnoList, AlgoParam *param) | |
void | start () |
Definition at line 6 of file consalgo.h.
|
Definition at line 9 of file consalgo.h. 00009 : 00010 RWAlgo(pDoc_, recnoList, param) {}
|
|
Implements RWAlgo. Definition at line 17 of file consalgo.cc. References MAl_addon::get_max_col(), MAl_addon::get_min_col(), MAl_addon::get_most_freq_base_on_col(), MAl_addon::get_num_DNPs_on_col(), TrapperView::getDocument(), RWAlgo::getMAl(), RWAlgo::mal, Algo::my_param, TrapperDoc::title(), and ViewParam::view(). 00018 { 00019 if ( getMAl()->get_num_seq() == 0 ) { 00020 cerr<<"Nothing to be done here! "<<endl; 00021 return; 00022 } 00023 00024 ViewParam* param = dynamic_cast<ViewParam*>(my_param); 00025 assert(param); 00026 00027 QString title = param->view()->getDocument()->title(); 00028 00029 QString currdir = QDir::currentDirPath(); 00030 QString contig = title.section( '/', -2 ); 00031 00032 QString header = contig + ".cons.fasta"; 00033 QString default_file_name = currdir + '/' + header; 00034 00035 00036 // QString s = QFileDialog::getSaveFileName("/home", 00037 // "Images (*.png *.xpm *.jpg)", 00038 // this, 00039 // "save file dialog" 00040 // "Choose a filename to save under" ); 00041 QString filename = QFileDialog::getSaveFileName( default_file_name, 00042 0, 00043 0, 00044 "save contig file dialog" 00045 "Choose a filename to save under" ); 00046 00047 00048 if ( filename.isEmpty() ) return; 00049 00050 if ( QFile::exists( filename ) && 00051 QMessageBox::question( 00052 0, 00053 tr("Overwrite File? -- Trapper"), 00054 tr("A file called %1 already exists." 00055 "Do you want to overwrite it?") 00056 .arg( filename ), 00057 tr("&Yes"), tr("&No"), 00058 QString::null, 0, 1 ) ) { 00059 00060 return; 00061 } 00062 MAl_addon mal( getMAl() ); 00063 00064 int res = QMessageBox::question( 0, "Export consensus", "Consensus for whole group, or within an interval?", "Whole group", "Interval", "Cancel", 0, 2 ); 00065 00066 size_t min_ = mal.get_min_col(); 00067 size_t max_ = mal.get_max_col() - 1; 00068 00069 if( res == 2 ) { 00070 return; 00071 } 00072 else if ( res == 1 ) { 00073 bool ok; 00074 int low = QInputDialog::getInteger( 00075 "Export consensus", "Lower bound", min_, min_, max_, 1, 00076 &ok, 0 ); 00077 00078 if ( ok ) { 00079 // user entered something and pressed OK 00080 min_ = low; 00081 } else { 00082 // user pressed Cancel 00083 return; 00084 } 00085 int high = QInputDialog::getInteger( 00086 "Export consensus", "Upper bound", max_, min_, max_, 1, 00087 &ok, 0 ); 00088 00089 if ( ok ) { 00090 // user entered something and pressed OK 00091 max_ = high; 00092 } else { 00093 // user pressed Cancel 00094 return; 00095 } 00096 00097 } 00098 00099 00100 00101 00102 ofstream outFile(filename); 00103 ofstream outFileDNPs(filename + ".dnps"); 00104 // ofstream outFileDebug(filename + ".debug"); 00105 00106 outFile<<'>'<<header<<endl; 00107 int cnt(0); 00108 int abs_cnt(0); 00109 int numgap(0); 00110 for( int i = min_; i < max_ + 1; i++ ) { 00111 char base = mal.get_most_freq_base_on_col(i); 00112 if ( base == '*' || base == '-' ) { 00113 numgap++; 00114 continue; 00115 } 00116 if ( mal.get_num_DNPs_on_col(i) > 0 ) { 00117 outFileDNPs<<abs_cnt<<'\n'; 00118 } 00119 00120 cnt++; 00121 abs_cnt++; 00122 // outFileDebug<<abs_cnt<<'\t'<<numgap<<'\t'<<abs_cnt+numgap<<'\n'; 00123 outFile<<base; 00124 if ( cnt % 50 == 0 ) { 00125 outFile<<endl; 00126 } 00127 } 00128 00129 outFile.close(); 00130 cerr<<numgap<<" consensus gaps discarded"<<endl; 00131 00132 }
|