# Merge vcf or matrix tables

**URL:** <https://discuss.hail.is/t/merge-vcf-or-matrix-tables/1880>\
**Category:** Hail Query & hailctl\
**Created:** [January 7, 2021, 10:27am UTC](https://discuss.hail.is/t/merge-vcf-or-matrix-tables/1880 "2021-01-07T10:27:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wonu](https://avatars.discourse-cdn.com/v4/letter/w/f17d59/32.png) [@wonu](https://discuss.hail.is/u/wonu)\
**Post date:** [January 7, 2021, 10:27am UTC](https://discuss.hail.is/t/merge-vcf-or-matrix-tables/1880/1 "2021-01-07T10:27:28Z")

</div>

Hi, I was wondering if it’s possible to merge two vcf files (or resulting mts) with different samples but overlapping variants, such that any downstream QC takes into account information from the combined data set. I am working locally on a computer.

Thanks!  
Wonu

---

<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:** [January 7, 2021, 12:13pm UTC](https://discuss.hail.is/t/merge-vcf-or-matrix-tables/1880/2 "2021-01-07T12:13:31Z")

</div>

By “overlapping”, do you mean identical? If so, [`union_cols`](https://hail.is/docs/0.2/hail.MatrixTable.html#hail.MatrixTable.union_cols) will work out-of-the-box. The default row join type is an inner join, which will restrict to variants shared by both datasets.

---

<div class="post-metadata">

**Author:** ![wonu](https://avatars.discourse-cdn.com/v4/letter/w/f17d59/32.png) [@wonu](https://discuss.hail.is/u/wonu)\
**Post date:** [January 7, 2021, 2:45pm UTC](https://discuss.hail.is/t/merge-vcf-or-matrix-tables/1880/3 "2021-01-07T14:45:40Z")

</div>

ahh yes that’s exactly the case. thank you!

is there a solution for the alternative?

---

<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:** [January 7, 2021, 2:48pm UTC](https://discuss.hail.is/t/merge-vcf-or-matrix-tables/1880/4 "2021-01-07T14:48:33Z")

</div>

You can use `mt.union_cols(mt1, join_type='outer')` but the resulting matrix table will have missing entries that may require some special handling in downstream analysis.

---

<div class="post-metadata">

**Author:** ![wonu](https://avatars.discourse-cdn.com/v4/letter/w/f17d59/32.png) [@wonu](https://discuss.hail.is/u/wonu)\
**Post date:** [January 14, 2021, 2:21pm UTC](https://discuss.hail.is/t/merge-vcf-or-matrix-tables/1880/5 "2021-01-14T14:21:59Z")

</div>

thank you. would hail flag these scenarios as they occurred or would you have to preempt them and try to fix it beforehand?
