Skip to content

Commit

Permalink
[Fix] BGEN sample check when sample selection was performed
Browse files Browse the repository at this point in the history
  • Loading branch information
choishingwan committed Jul 15, 2020
1 parent 65c25d0 commit e4b146e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion inc/commander.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#endif

const std::string version = "2.3.2";
const std::string date = "2020-06-23";
const std::string date = "2020-07-10";
class Commander
{
public:
Expand Down
45 changes: 27 additions & 18 deletions src/binarygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,26 +260,35 @@ void BinaryGen::check_sample_consistent(const genfile::bgen::Context& context,
size_t sample_idx = 0;
genfile::bgen::read_sample_identifier_block(
bgen_file, tmp_context, [this, &sample_idx](const std::string& id) {
std::string ref_id =
(m_ignore_fid ? "" : m_sample_id[sample_idx].FID + m_delim)
+ m_sample_id[sample_idx].IID;
if (ref_id != id && m_sample_id[sample_idx].IID != id)
auto&& find_id = m_sample_selection_list.find(id)
!= m_sample_selection_list.end();
bool inclusion = m_remove_sample ^ find_id;
if (inclusion)
{
throw std::runtime_error(
"Error: Sample mismatch "
"between bgen and phenotype file! Name in BGEN "
"file is "
":"
+ id + " and in phentoype file is: " + ref_id
+ ". Please note that PRSice require the bgen file "
"and "
"the .sample (or phenotype file if sample file is "
"not provided) to have sample in the same order. "
"(We "
"might be able to losen this requirement in future "
"when we have more time)");
std::string ref_id =
(m_ignore_fid ? ""
: m_sample_id[sample_idx].FID + m_delim)
+ m_sample_id[sample_idx].IID;
if (ref_id != id && m_sample_id[sample_idx].IID != id)
{
throw std::runtime_error(
"Error: Sample mismatch "
"between bgen and phenotype file! Name in BGEN "
"file is "
":"
+ id + " and in phentoype file is: " + ref_id
+ ". Please note that PRSice require the bgen file "
"and "
"the .sample (or phenotype file if sample file "
"is "
"not provided) to have sample in the same order. "
"(We "
"might be able to losen this requirement in "
"future "
"when we have more time)");
}
++sample_idx;
}
++sample_idx;
});
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/genotype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,6 @@ void Genotype::load_samples(bool verbose)
BITCT_TO_WORDCT(m_unfiltered_sample_ct);
m_exclude_from_std.resize(unfiltered_sample_ctl, 0);
if (verbose) m_reporter->report(message);
m_sample_selection_list.clear();
}

bool Genotype::perform_freqs_and_inter(const QCFiltering& filter_info,
Expand Down Expand Up @@ -1064,6 +1063,9 @@ void Genotype::load_snps(
message = "Error: No vairant remained!\n";
throw std::runtime_error(message);
}
// only remove selection list here, as we might need this for bgen file
// check
m_sample_selection_list.clear();
}


Expand Down

0 comments on commit e4b146e

Please sign in to comment.