Skip to content

Commit 16ea529

Browse files
authored
Merge pull request #396 from AngieHinrichs/vcf_no_dup_samples
Error exit when VCF has duplicated samples
2 parents b4a5d10 + aecae4a commit 16ea529

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/matOptimize/import_vcf_fast.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ static void process(MAT::Tree& tree,infile_t& fd) {
384384
idx_map.push_back(-1);
385385
//exit(EXIT_FAILURE);
386386
} else {
387+
if (inserted_samples.count(fields[idx])) {
388+
fprintf(stderr, "ERROR: sample '%s' appears more than once in the VCF header\n", fields[idx].c_str());
389+
exit(EXIT_FAILURE);
390+
}
387391
auto res=inserted_samples.insert(fields[idx]);
388392
if (res.second) {
389393
idx_map.push_back(node->bfs_index);

src/usher-sampled/import_vcf.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ static void process(infile_t &fd, std::vector<Sample_Muts> &sample_mutations,
449449
for (size_t field_idx = 9; field_idx < fields.size(); field_idx++) {
450450
auto ins_result=vcf_samples.emplace(fields[field_idx],field_idx);
451451
if(!ins_result.second) {
452-
fprintf(stderr,"sample %s on both column %zu and %zu, taking first column\n",fields[field_idx].c_str(),ins_result.first->second,field_idx);
453-
continue;
452+
fprintf(stderr,"ERROR: sample '%s' is in both column %zu and %zu of VCF header\n",fields[field_idx].c_str(),ins_result.first->second,field_idx);
453+
exit(EXIT_FAILURE);
454454
}
455455
auto node=tree.get_node(fields[field_idx]);
456456
if (node != nullptr) {
@@ -652,4 +652,4 @@ void load_diff_for_usher(
652652

653653
line_count++;
654654
}
655-
}
655+
}

0 commit comments

Comments
 (0)