Skip to content

Commit

Permalink
allow subset during gs loading #15
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejiang committed Dec 6, 2019
1 parent 168cd50 commit 50da439
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: cytolib
Type: Package
Title: C++ infrastructure for representing and interacting with the gated cytometry
Version: 1.9.5
Version: 1.9.6
Date: 2017-08-07
Author: Mike Jiang
Maintainer: Mike Jiang <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion inst/include/cytolib/GatingSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class GatingSet{
* @param path
* @param is_skip_data whether to skip loading cytoframe data from h5. It should typically remain as default unless for debug purpose (e.g. legacy pb archive)
*/
GatingSet(string path, bool is_skip_data = false, bool readonly = true);
GatingSet(string path, bool is_skip_data = false, bool readonly = true, vector<string> select_samples = {});
/**
* constructor from the legacy archives (de-serialization)
* @param filename
Expand Down
45 changes: 38 additions & 7 deletions src/GatingSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ namespace cytolib
* constructor from the archives (de-serialization)
* @param path
* @param is_skip_data whether to skip loading cytoframe data from h5. It should typically remain as default unless for debug purpose (e.g. legacy pb archive)
* @param select_sample_idx samples to load
*/
GatingSet::GatingSet(string path, bool is_skip_data, bool readonly)
GatingSet::GatingSet(string path, bool is_skip_data, bool readonly, vector<string> select_samples)
{
fs::path pb_file;
string errmsg = "Not a valid GatingSet archiving folder! " + path + "\n";
Expand Down Expand Up @@ -181,25 +182,55 @@ namespace cytolib

uid_ = pbGS.guid();

auto nSelect = select_samples.size();
auto nTotal = pbGS.samplename_size();
unordered_map<string,bool> sn_hash;

//prescan select and update hash
if(nSelect>0)
{
for(int i = 0; i < nTotal; i++){
string sn = pbGS.samplename(i);
sn_hash[sn] = false;
}
for(unsigned i = 0; i < nSelect; i++)
{
auto sel = select_samples[i];
auto it = sn_hash.find(sel);
if(it == sn_hash.end())
throw(domain_error("sample selection is out of boundary: " + sel));
it->second = true;

}
}
//read gating hierarchy messages
for(int i = 0; i < pbGS.samplename_size(); i++){
for(int i = 0; i < nTotal; i++){
string sn = pbGS.samplename(i);

// all_samples[i] =sn;
//gh message is stored as the same order as sample name vector in gs
pb::GatingHierarchy gh_pb;
bool success = readDelimitedFrom(raw_input, gh_pb);

if (!success) {
throw(domain_error("Failed to parse GatingHierarchy."));
}
//conditional add gh (thus avoid to load h5)
if(nSelect==0||sn_hash.find(sn)->second)
{
pb::CytoFrame fr = *gh_pb.mutable_frame();
string h5_filename = (fs::path(path) / (sn + ".h5")).string();

pb::CytoFrame fr = *gh_pb.mutable_frame();
string h5_filename = (fs::path(path) / (sn + ".h5")).string();

add_GatingHierarchy(GatingHierarchyPtr(new GatingHierarchy(gh_pb, h5_filename, is_skip_data, readonly)), sn);
add_GatingHierarchy(GatingHierarchyPtr(new GatingHierarchy(gh_pb, h5_filename, is_skip_data, readonly)), sn);
}
}


//reorder view based on select
if(nSelect>0)
{
uid_ = generate_uid();
sample_names_ = select_samples;
}
}

}
Expand Down

0 comments on commit 50da439

Please sign in to comment.