Skip to content

Commit 50da439

Browse files
author
mikejiang
committed
allow subset during gs loading #15
1 parent 168cd50 commit 50da439

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: cytolib
22
Type: Package
33
Title: C++ infrastructure for representing and interacting with the gated cytometry
4-
Version: 1.9.5
4+
Version: 1.9.6
55
Date: 2017-08-07
66
Author: Mike Jiang
77
Maintainer: Mike Jiang <[email protected]>

inst/include/cytolib/GatingSet.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class GatingSet{
7777
* @param path
7878
* @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)
7979
*/
80-
GatingSet(string path, bool is_skip_data = false, bool readonly = true);
80+
GatingSet(string path, bool is_skip_data = false, bool readonly = true, vector<string> select_samples = {});
8181
/**
8282
* constructor from the legacy archives (de-serialization)
8383
* @param filename

src/GatingSet.cpp

+38-7
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ namespace cytolib
133133
* constructor from the archives (de-serialization)
134134
* @param path
135135
* @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)
136+
* @param select_sample_idx samples to load
136137
*/
137-
GatingSet::GatingSet(string path, bool is_skip_data, bool readonly)
138+
GatingSet::GatingSet(string path, bool is_skip_data, bool readonly, vector<string> select_samples)
138139
{
139140
fs::path pb_file;
140141
string errmsg = "Not a valid GatingSet archiving folder! " + path + "\n";
@@ -181,25 +182,55 @@ namespace cytolib
181182

182183
uid_ = pbGS.guid();
183184

185+
auto nSelect = select_samples.size();
186+
auto nTotal = pbGS.samplename_size();
187+
unordered_map<string,bool> sn_hash;
184188

189+
//prescan select and update hash
190+
if(nSelect>0)
191+
{
192+
for(int i = 0; i < nTotal; i++){
193+
string sn = pbGS.samplename(i);
194+
sn_hash[sn] = false;
195+
}
196+
for(unsigned i = 0; i < nSelect; i++)
197+
{
198+
auto sel = select_samples[i];
199+
auto it = sn_hash.find(sel);
200+
if(it == sn_hash.end())
201+
throw(domain_error("sample selection is out of boundary: " + sel));
202+
it->second = true;
203+
204+
}
205+
}
185206
//read gating hierarchy messages
186-
for(int i = 0; i < pbGS.samplename_size(); i++){
207+
for(int i = 0; i < nTotal; i++){
187208
string sn = pbGS.samplename(i);
188-
209+
// all_samples[i] =sn;
189210
//gh message is stored as the same order as sample name vector in gs
190211
pb::GatingHierarchy gh_pb;
191212
bool success = readDelimitedFrom(raw_input, gh_pb);
192213

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

197-
pb::CytoFrame fr = *gh_pb.mutable_frame();
198-
string h5_filename = (fs::path(path) / (sn + ".h5")).string();
199-
200-
add_GatingHierarchy(GatingHierarchyPtr(new GatingHierarchy(gh_pb, h5_filename, is_skip_data, readonly)), sn);
223+
add_GatingHierarchy(GatingHierarchyPtr(new GatingHierarchy(gh_pb, h5_filename, is_skip_data, readonly)), sn);
224+
}
201225
}
202226

227+
228+
//reorder view based on select
229+
if(nSelect>0)
230+
{
231+
uid_ = generate_uid();
232+
sample_names_ = select_samples;
233+
}
203234
}
204235

205236
}

0 commit comments

Comments
 (0)