From 8c291b3038f1f35fb0a29000c1db17d5878acccf Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Thu, 15 Aug 2019 14:00:03 +0200 Subject: [PATCH] FIX using .parent_path() instead of .remove_filename(). Code review --- include/ThDySec/sec_mult.h | 6 ++-- include/ThDy_DNAHybrid.Nana/SeqExpl.h | 8 ++--- src/ThDySec/sec_mult.cpp | 37 ++++++++++++++-------- src/ThDy_DNAHybrid.Nana/SeqExpl.cpp | 10 +++--- src/ThDy_DNAHybrid.Nana/main.Nana.cpp | 14 ++++---- src/ThDy_programs/init_thdy_prog_param.cpp | 8 ++--- 6 files changed, 47 insertions(+), 36 deletions(-) diff --git a/include/ThDySec/sec_mult.h b/include/ThDySec/sec_mult.h index 2baba80..109947c 100644 --- a/include/ThDySec/sec_mult.h +++ b/include/ThDySec/sec_mult.h @@ -52,7 +52,7 @@ class CMultSec CMultSec *_parentMS {nullptr}; ///< std::weak_ptr _parentMS ; CSec *_Consenso {nullptr}; bool _selected { true }; - std::string _Path ; ///< file path of the original sequence source + std::string _orig_file_path ; ///< file path of the original sequence source //explicit CMultSec (const std::string &Name ) : _name (trim_string(Name)) { } @@ -111,7 +111,7 @@ class CMultSec return path; } - /// Construct a filesystem path acording to the current tree, which can be different from the original path saved in member variable ._Path + /// Construct a filesystem path acording to the current tree, which can be different from the original path saved in member variable ._orig_file_path std::string path( ) { std::string sep(std::string(1, std::filesystem::path::preferred_separator));// ::slash().value)); @@ -238,7 +238,7 @@ class CMultSec /// (will try all child of base to set the base dir and export) /// To decide the name of the file it need the path of the base node that do not form part of the file name /// That is for example: "all_seq/Primers for Multiplex PCR/"... - bool Export_from ( CMultSec& base, bool only_selected) ; + bool Export_from ( CMultSec& tree_base, bool only_selected) ; /// Export local sequences to a new file in fasta format with filters applied diff --git a/include/ThDy_DNAHybrid.Nana/SeqExpl.h b/include/ThDy_DNAHybrid.Nana/SeqExpl.h index 2f11831..68a314a 100644 --- a/include/ThDy_DNAHybrid.Nana/SeqExpl.h +++ b/include/ThDy_DNAHybrid.Nana/SeqExpl.h @@ -162,21 +162,21 @@ class SeqExpl : public CompoWidget Node ReloadDir (Tree::item_proxy tn) { CMultSec *ms = tn.value(); - if (ms->_Path.empty()) + if (ms->_orig_file_path.empty()) { for (Tree::item_proxy& ntn : tn) ReloadDir(ntn); return tn; } - else return Refresh(Replace(tn, ms, ms->_Path,true)).expand(true).select(true);//true + else return Refresh(Replace(tn, ms, ms->_orig_file_path,true)).expand(true).select(true);//true } Node ReloadFile (Tree::item_proxy tn) { CMultSec *ms = tn.value(); - if (ms->_Path.empty()) + if (ms->_orig_file_path.empty()) return tn; else - return Refresh(Replace(tn, ms, ms->_Path,false)); + return Refresh(Replace(tn, ms, ms->_orig_file_path,false)); } void ShowLocals(bool showLocals) { diff --git a/src/ThDySec/sec_mult.cpp b/src/ThDySec/sec_mult.cpp index 865a2fe..0ae2944 100644 --- a/src/ThDySec/sec_mult.cpp +++ b/src/ThDySec/sec_mult.cpp @@ -46,21 +46,32 @@ fs::path unique_filename(fs::path name) } return name; } - -bool CMultSec::Export_from ( CMultSec& base, bool only_selected) +/// export all seq in this MSec in a file named as this tree-path. +bool CMultSec::Export_from ( CMultSec& tree_base, bool only_selected) { fs::path dir, file; - auto s= path(); + auto my_tree_path= path(); + std::cout << "my_tree_path: " + my_tree_path << "\n"; - for ( const auto& CurMSec : base.MSecL()) // recorre todos las msec + for ( const auto& CurMSec : tree_base.MSecL()) // recorre todos las msec to find what is my tree_base dir { - auto b= CurMSec->path(); - if ( b.empty() || s.find(b)) continue; // found OK only if s begin with p + auto major_sub_tree_path= CurMSec->path(); + std::cout << "major_sub_tree_path: " + major_sub_tree_path << "\n"; // like: 'All seq\Target seq\' + std::cout << "major_sub_tree_dir: " + CurMSec->_orig_file_path << "\n"; // like: '../ThDy/sequences/' + + // found OK only if my_tree_path begin with major_sub_tree_path + if ( major_sub_tree_path.empty() || my_tree_path.find(major_sub_tree_path)) + continue; - file = dir = s.replace(0, b.length()-1, CurMSec->_Path); - file.remove_filename().replace_extension("fasta"); - dir.remove_filename().remove_filename(); + // todo: find a robust solution for this hack: replace tree base with the original directory base. + file = dir = my_tree_path.replace(0, major_sub_tree_path.length()-1, CurMSec->_orig_file_path); + std::cout << "file: " + file.generic_string() << "\n"; + file = file.parent_path().replace_extension("export.fasta"); + std::cout << "file': " + file.generic_string() << "\n"; + dir = file.parent_path(); + std::cout << "dir': " + dir.generic_string() << "\n"; + //if (!fs::is_regular_file(dir)) fs::create_directories(dir); Export_as(unique_filename(file).string(), only_selected); return true; @@ -75,7 +86,7 @@ bool CMultSec::Export_local_seq ( CMultSec& base, bool only_selected) auto s= path(); auto b= base.path(); if ( s.find(b)) return false; // finded OK only if s beging with b - file = dir = s.replace(0, b.length(), base._Path); + file = dir = s.replace(0, b.length(), base._orig_file_path); file.replace_extension("fasta"); dir.remove_filename(); @@ -98,7 +109,7 @@ CMultSec::CMultSec ( const std::string &path , _MaxTgId (MaxTgId), _SecLenLim (SecLenLim), _NNPar (NNpar)/*, - _Path (file)*/ + _orig_file_path (file)*/ { fs::path itf(path); @@ -108,7 +119,7 @@ CMultSec::CMultSec ( const std::string &path , itf.remove_filename(); _name = itf.filename ().string(); // The new MSec take the name of the dir. - _Path = itf.string(); // and the _Path point to it. + _orig_file_path = itf.string(); // and the _orig_file_path point to it. fs::directory_iterator rdi{ itf }, end; @@ -126,7 +137,7 @@ CMultSec::CMultSec ( const std::string &path , if (itf.has_filename()) { _name = itf.filename ().string(); /// The new MSec take the name of the file. - _Path = itf.string(); /// and the _Path point directly to the file. + _orig_file_path = itf.string(); /// and the _Path point directly to the file. if (loadSec) AddFromFile(path); /// will throw if not a file return; diff --git a/src/ThDy_DNAHybrid.Nana/SeqExpl.cpp b/src/ThDy_DNAHybrid.Nana/SeqExpl.cpp index 3315067..ff353fd 100644 --- a/src/ThDy_DNAHybrid.Nana/SeqExpl.cpp +++ b/src/ThDy_DNAHybrid.Nana/SeqExpl.cpp @@ -104,7 +104,7 @@ void SeqExpl::AddMenuItems(nana::menu& menu) CMultSec *pms = ms->_parentMS; assert(ms); assert(pms); - fs::path pt{ms->_Path}; + fs::path pt{ms->_orig_file_path}; pt= fs::canonical(pt).make_preferred(); nana::filebox fb{ *this, true }; fb .add_filter ( SetupPage::FastaFiltre( ) ) @@ -131,7 +131,7 @@ void SeqExpl::AddMenuItems(nana::menu& menu) assert(ms); assert(pms); - fs::path pt{ms->_Path}; + fs::path pt{ms->_orig_file_path}; nana::folderbox fb{ *this, pt.parent_path() , "Replace/reload a group of sequences from a directory" }; auto p=fb.show(); if (p.empty()) return; @@ -219,7 +219,7 @@ void SeqExpl::MakeResponive() { auto tn = _tree.selected(); CMultSec* ms = tn.value(); - fs::path pt{ms->_Path}; + fs::path pt{ms->_orig_file_path}; pt= fs::canonical(pt).make_preferred(); nana::filebox fb{ *this, true }; @@ -240,7 +240,7 @@ void SeqExpl::MakeResponive() { auto tn= _tree.selected(); CMultSec *ms = tn.value(); - fs::path pt{ms->_Path}; + fs::path pt{ms->_orig_file_path}; nana::folderbox fb{ *this, pt, "Directory load: Add a tree of groups of sequences from a directory" }; auto path=fb(); if (path.empty()) return; @@ -253,7 +253,7 @@ void SeqExpl::MakeResponive() { auto tn= _tree.selected(); CMultSec *ms = tn.value(); - fs::path pt{ms->_Path}; + fs::path pt{ms->_orig_file_path}; nana::folderbox fb{ *this, pt, "Directory scan: Reproduce the structure of directory..." }; auto path=fb(); if (path.empty()) return; diff --git a/src/ThDy_DNAHybrid.Nana/main.Nana.cpp b/src/ThDy_DNAHybrid.Nana/main.Nana.cpp index 0dacb5d..f2f9ba8 100644 --- a/src/ThDy_DNAHybrid.Nana/main.Nana.cpp +++ b/src/ThDy_DNAHybrid.Nana/main.Nana.cpp @@ -68,12 +68,12 @@ { _DefLayout = R"( < vertical gap=5 margin=[3,20,3,20] - - - < min=10 max=30> - - < min=10 max=30> - > )"; + + + < min=1 max=180> + + < min=10 max=20> + > )"; c_r.div (R"(vert< CR vert vfit=290 height=60 gap=5 margin=[5,20,3,20] > )"); build.div (R"(vert< all vert gap=5 margin=[3,20,3,20] > )"); } @@ -83,7 +83,7 @@ _place["all"] << build ; _place["close"] << bclose ; - c_r ["CR" ] << copy_r << comments; + c_r ["CR" ] << copy_r << comments; build ["all"] << compiled << downloads << GUI_lib ; } }; diff --git a/src/ThDy_programs/init_thdy_prog_param.cpp b/src/ThDy_programs/init_thdy_prog_param.cpp index 8f24324..316f3a7 100644 --- a/src/ThDy_programs/init_thdy_prog_param.cpp +++ b/src/ThDy_programs/init_thdy_prog_param.cpp @@ -80,12 +80,12 @@ CMultSec* ThDyCommProgParam::AddSeqFromFile( CMultSec *parentGr, !onlyStructure); parentGr->AddMultiSec(sG); - std::string parent_path = fs::path(sG->_Path).remove_filename().string(); + std::string parent_path = fs::path(sG->_orig_file_path).remove_filename().string(); if (parentGr->_Local._NMSec == 1) - parentGr->_Path= parent_path ; - else if (parentGr->_Path != parent_path) - parentGr->_Path.clear(); + parentGr->_orig_file_path= parent_path ; + else if (parentGr->_orig_file_path != parent_path) + parentGr->_orig_file_path.clear(); return sG; }