# Combining VDSs with same samples

**URL:** <https://discuss.hail.is/t/combining-vdss-with-same-samples/2840>\
**Category:** Development\
**Created:** [September 19, 2022, 4:54pm UTC](https://discuss.hail.is/t/combining-vdss-with-same-samples/2840 "2022-09-19T16:54:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbgaither](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jbgaither](https://discuss.hail.is/u/jbgaither)\
**Post date:** [September 19, 2022, 4:54pm UTC](https://discuss.hail.is/t/combining-vdss-with-same-samples/2840/1 "2022-09-19T16:54:47Z")

</div>

I’ve built a collection of 22 VDSs, each containing variants from the same 100 samples, but covering a different chromosome:  
path/vds\_chr1  
…  
path/vds\_chr22.  
I want to merge these into a single VDS. However, when I try to run

```python
hl.vds.combiner.new_combiner(,...,vds_paths=[...])

```

the combiner thinks I’m loading 2200 samples, i.e. it doesn’t identify the identically-named samples in the different batches.  
Is there any way to merge multiple VDSes containing the same sample-set into a single VDS containing the same samples? This question was answered in 2017,[https://discuss.hail.is/t/join-vdss-with-same-samples/331](https://discuss.hail.is/t/join-vdss-with-same-samples/331), but the solution uses HailContexts, which don’t seem to be accessible in the current Hail version (version 0.2.99-57537fea08d4).

Any help you could offer would be greatly appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [September 19, 2022, 6:05pm UTC](https://discuss.hail.is/t/combining-vdss-with-same-samples/2840/2 "2022-09-19T18:05:54Z")

</div>

Here’s a way – we should add this onto the VDS module:

```python
vdses = [hl.vds.read_vds(path) for path in vds_paths)
def vds_union_rows(vdses):
    new_ref_mt = hl.MatrixTable.union_rows(*(vds.reference_data for vds in vdses))
    new_var_mt = hl.MatrixTable.union_rows(*(vds.variant_data for vds in vdses))
    return hl.vds.VariantDataset(new_ref_mt, new_var_mt)

```

---

<div class="post-metadata">

**Author:** ![danking](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/danking/32/43_2.png) [@danking](https://discuss.hail.is/u/danking)\
**Post date:** [October 5, 2022, 3:11am UTC](https://discuss.hail.is/t/combining-vdss-with-same-samples/2840/3 "2022-10-05T03:11:08Z")

</div>

I have a PR to add this to mainline, thanks for the tip @jbgaither ! [[query] add VDS.union\_rows by danking · Pull Request #12268 · hail-is/hail · GitHub](https://github.com/hail-is/hail/pull/12268)
