Skip to content

Commit

Permalink
FIX using .parent_path() instead of .remove_filename(). Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
qPCR4vir committed Aug 15, 2019
1 parent ae2c882 commit 8c291b3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 36 deletions.
6 changes: 3 additions & 3 deletions include/ThDySec/sec_mult.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CMultSec
CMultSec *_parentMS {nullptr}; ///< std::weak_ptr<CMultSec> _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)) { }
Expand Down Expand Up @@ -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<std::filesystem::path>().value));
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions include/ThDy_DNAHybrid.Nana/SeqExpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,21 @@ class SeqExpl : public CompoWidget
Node ReloadDir (Tree::item_proxy tn)
{
CMultSec *ms = tn.value<CMultSec*>();
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<CMultSec*>();
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)
{
Expand Down
37 changes: 24 additions & 13 deletions src/ThDySec/sec_mult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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);

Expand All @@ -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;

Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/ThDy_DNAHybrid.Nana/SeqExpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( ) )
Expand All @@ -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;
Expand Down Expand Up @@ -219,7 +219,7 @@ void SeqExpl::MakeResponive()
{
auto tn = _tree.selected();
CMultSec* ms = tn.value<CMultSec*>();
fs::path pt{ms->_Path};
fs::path pt{ms->_orig_file_path};
pt= fs::canonical(pt).make_preferred();

nana::filebox fb{ *this, true };
Expand All @@ -240,7 +240,7 @@ void SeqExpl::MakeResponive()
{
auto tn= _tree.selected();
CMultSec *ms = tn.value<CMultSec*>();
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;
Expand All @@ -253,7 +253,7 @@ void SeqExpl::MakeResponive()
{
auto tn= _tree.selected();
CMultSec *ms = tn.value<CMultSec*>();
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;
Expand Down
14 changes: 7 additions & 7 deletions src/ThDy_DNAHybrid.Nana/main.Nana.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
{
_DefLayout = R"(
< vertical gap=5 margin=[3,20,3,20]
<CR min=110 max=160 >
<all min=140 max=200 >
< min=10 max=30>
<close min=15 max=60>
< min=10 max=30>
> )";
<CR min=125 max=150 >
<all min=170 max=200 >
< min=1 max=180>
<close min=25 max=80>
< 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] > )");
}
Expand All @@ -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 ;
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/ThDy_programs/init_thdy_prog_param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8c291b3

Please sign in to comment.