# How to combine 2 VCF files in a Workflow...

**URL:** <https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595>\
**Category:** Uncategorized\
**Tags:** workflow, collections, variant-analysis, \_\_apply\_rules\_\_\
**Created:** [December 5, 2019, 12:20am UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595 "2019-12-05T00:20:31Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathew\_Moore](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mathew_moore/32/1118_2.png) [@Mathew\_Moore](https://help.galaxyproject.org/u/Mathew_Moore)\
**Post date:** [December 5, 2019, 12:20am UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/1 "2019-12-05T00:20:31Z")

</div>

Silly, simple question, but I can’t find a good solution.

I have 2 VCF files being produced in a workflow, and I’d like to combine these files as a single VCF. The bcf\_concat tool will do it, but how do I feed both files to the tool in a workflow?

Cheers,

Mat

---

<div class="post-metadata">

**Author:** ![jxtx](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/jxtx/32/47_2.png) [@jxtx](https://help.galaxyproject.org/u/jxtx)\
**Post date:** [December 5, 2019, 12:27am UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/2 "2019-12-05T00:27:02Z")

</div>

For a tool with a multiple data input, you should be able to drag multiple datasets onto the same input circle in the workflow editor. For example:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/galaxy/original/2X/a/ae25bb3f0853894f0265c2f5e53d88f23da8ecd2.png)

---

<div class="post-metadata">

**Author:** ![Mathew\_Moore](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mathew_moore/32/1118_2.png) [@Mathew\_Moore](https://help.galaxyproject.org/u/Mathew_Moore)\
**Post date:** [December 5, 2019, 1:24am UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/3 "2019-12-05T01:24:41Z")

</div>

Apologies, I should have been more specific. The inputs start out as a paired collection, the aligner combines into a single bam, and then I would like to run 2 variant callers and combine the output vcf  
Something like this…

 ![image](https://us1.discourse-cdn.com/flex020/uploads/galaxy/original/2X/7/78c6d132efdd292d803d92007278c4f1cf632e8d.png)

This doesn’t seem to work on a collection. What am I doing wrong 🙂 ?  
Cheers,  
Mat

---

<div class="post-metadata">

**Author:** ![jxtx](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/jxtx/32/47_2.png) [@jxtx](https://help.galaxyproject.org/u/jxtx)\
**Post date:** [December 5, 2019, 2:09am UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/4 "2019-12-05T02:09:45Z")

</div>

Looks like you don’t have two VCF files but two collections of VCF files (ribbons as inputs). Do you want to merge the collections element wise, creating a new collection of combined VCFs?

---

<div class="post-metadata">

**Author:** ![Mathew\_Moore](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mathew_moore/32/1118_2.png) [@Mathew\_Moore](https://help.galaxyproject.org/u/Mathew_Moore)\
**Post date:** [December 5, 2019, 3:03am UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/5 "2019-12-05T03:03:04Z")

</div>

yep 🙂

---

<div class="post-metadata">

**Author:** ![mvdbeek](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mvdbeek/32/110_2.png) [@mvdbeek](https://help.galaxyproject.org/u/mvdbeek)\
**Post date:** [December 5, 2019, 10:40am UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/6 "2019-12-05T10:40:14Z")

</div>

Ideally you could do with collections what @jxtx showed for regular datasets (two or more datasets going into an input that accepts multiple datasets). It does become ambiguous if you try to do this with collections (should the input collections be fully consumed and you get a single output dataset, or treated element-wise and you get a single output collection back). If element-wise, should we iterate over the top level collection or the lowest level collection ?)

There is one trick that should work now. You can use the `Zip Collection` tool, which will create a list of pairs from your two VCF collections. You can then use the `Apply Rule to Collection` tool where you can take this list of pairs collection as input, click `edit` in the tool form, and then click `Rules` -\> `Add / Modify Column Definitions`. Click on `Add Definition` -\> `List Identifier` and select column A, then click on `Assign another column` and select column B. Click on Apply, Save and run the tool. You’ll get a list of lists, where the inner list contains 2 elements, one for each variant caller. You can use this list in bcftools concat to get a single collection of combined VCFs.

Unfortunately the user interface in the workflow editor doesn’t let you do this at the moment, but you can extract this operation from the history. I’ve done this here: [https://usegalaxy.org/u/marius/w/workflow-constructed-from-history-test-1](https://usegalaxy.org/u/marius/w/workflow-constructed-from-history-test-1).  
Hope that helps!

---

<div class="post-metadata">

**Author:** ![innovate-invent](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/innovate-invent/32/734_2.png) [@innovate-invent](https://help.galaxyproject.org/u/innovate-invent)\
**Post date:** [December 5, 2019, 5:52pm UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/7 "2019-12-05T17:52:04Z")

</div>

I actually do this a bit differently than what @mvdbeek suggested.  
Use the Merge Collections tool to merge all of your collections into one big one, but set the  
‘How should conflicts (or potential conflicts) be handled?’ advanced option to ‘Append suffix to every element identifer’ and the default suffix ‘\_#’. Then send that into the Apply Rules tool with the following rule:

```auto
{
    "rules": [
        {
            "type": "add_column_metadata",
            "value": "identifier0"
        },
        {
            "type": "add_column_regex",
            "target_column": 0,
            "expression": "\\d+$"
        }
    ],
    "mapping": [
        {
            "type": "list_identifiers",
            "columns": [
                1,
                0
            ],
            "editing": false
        }
    ]
}

```

The benefit of this method is it works with any amount of input collections. You can then use the Relabel Collection tool to change the identifiers from numbers if need be.

---

<div class="post-metadata">

**Author:** ![Mathew\_Moore](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mathew_moore/32/1118_2.png) [@Mathew\_Moore](https://help.galaxyproject.org/u/Mathew_Moore)\
**Post date:** [December 5, 2019, 6:20pm UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/8 "2019-12-05T18:20:44Z")

</div>

Thanks Nolan, Marius, and James,  
I’m going to work on those multiple suggestions. I appreciate your time, you saved me many hours. We have finally got round to attempting to move an old hard-coded ngs-germline pipeline over to our galaxy instance.  
Thanks again,  
Mat

---

<div class="post-metadata">

**Author:** ![Suppinder\_Kaur](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/suppinder_kaur/32/1694_2.png) [@Suppinder\_Kaur](https://help.galaxyproject.org/u/Suppinder_Kaur)\
**Post date:** [July 26, 2020, 6:12pm UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/10 "2020-07-26T18:12:45Z")

</div>

Hello

I am trying to combine the different variants but its showing that it requires version 1.4 please suggest how to do that. I am stuck

---

<div class="post-metadata">

**Author:** ![almahmoud](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/almahmoud/32/1699_2.png) [@almahmoud](https://help.galaxyproject.org/u/almahmoud)\
**Post date:** [July 27, 2020, 6:18pm UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/11 "2020-07-27T18:18:01Z")

</div>

Hello,  
I tested the `bcftools concat` tool suggested by James on [usegalaxy.org](http://usegalaxy.org) with two VCF input files, with having set the desired output to `uncompressed VCF`, and it worked as expected.  
Please provide more information on where/how you’re getting the error so we can further assist you.

---

<div class="post-metadata">

**Author:** ![Suppinder\_Kaur](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/suppinder_kaur/32/1694_2.png) [@Suppinder\_Kaur](https://help.galaxyproject.org/u/Suppinder_Kaur)\
**Post date:** [July 28, 2020, 7:39pm UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/12 "2020-07-28T19:39:58Z")

</div>

Actually I have 10 mutants and I got single variant files for each mutant, because I have followed simple backcrossing so I want to add these variant files from each mutant and then subtract them to get the linkage and gene list. Earlier I used the "combine variants " and they worked perfectly but now this showing error and asked for version 1.4 and the one earlier I used was 0.0.4. If I use the one you mentioned bcftools concat what are the options I have to add and its giving me the vcf file. Please suggest

---

<div class="post-metadata">

**Author:** ![Suppinder\_Kaur](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/suppinder_kaur/32/1694_2.png) [@Suppinder\_Kaur](https://help.galaxyproject.org/u/Suppinder_Kaur)\
**Post date:** [August 1, 2020, 3:08am UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/13 "2020-08-01T03:08:42Z")

</div>

![error in combine variants](https://us1.discourse-cdn.com/flex020/uploads/galaxy/original/2X/0/089762dddc7a0ba147f7999a62a5f801a90d3d76.jpeg)

This is the error I am getting

---

<div class="post-metadata">

**Author:** ![jennaj](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/jennaj/32/27_2.png) [@jennaj](https://help.galaxyproject.org/u/jennaj)\
**Post date:** [April 7, 2026, 10:07pm UTC](https://help.galaxyproject.org/t/how-to-combine-2-vcf-files-in-a-workflow/2595/16 "2026-04-07T22:07:27Z")

</div>


