Answers.Body: <p>Why not use <code>tee</code>? Please see this <a href="https://stackoverflow.com/questions/418896/how-to-redirect-output-to-a-file-and-stdout">post</a>.</p>
  <p>You can write <code>mpileup</code> to file while also piping it to another process. For example, <code>samtools mpileup ... | tee file.mpileup | bcftools call ...</code></p>
  <p>the <code>bcftools</code> will run while generating the <code>file.mpileup</code>. After it's done, you can use <code>file.mpileup</code> for your <code>VarScan2</code>.</p>
  <p>You can test it with the following:</p>
  <pre class="lang-bash prettyprint-override"><code>touch helloworld.txt
  ls | tee file.txt | grep helloworld    # output helloworld.txt
  cat file.txt | grep helloworld         # output helloworld.txt
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-14T10:28:24.920Z
Answers.Text: Thanks @Law for the help. It turns out `cat file.mpileup | bcftools call ...` worked after all. It was a silly typo mistake from my side.
  But still, I cannot understand how to use `tee` here. In your example, you have `samtools mpileup ... | tee ... | bcftools call ...`. In my case the first part of that pipe needs to be a file instead of command.
Answers.UserDisplayName: PPrasai
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-14T10:49:55.887Z
Answers.Text: In your original post, you said `The problem is, BCFTools expects mpileup to be piped from another command and I cannot find an input parameter to specify a mpileup file that already exists (the one used with VarScan2)`. From what I understood is that `bcftools` expect only a piped input. You also said you didn't want to run the command twice of generating the `mpileup`, hence my answer. You can use `tee` to pipe `mpileup` to `bcftools` while also writing it to a file (aka to stdout and to file). Glad that it was only a typo then.
Answers.UserDisplayName: user324810
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-14T07:42:01.233Z
Answers.LastActivityDate: 2021-09-16T13:55:20.810Z
Answers.LastEditDate: 2021-09-16T13:55:20.810Z
Answers.UserDisplayName: user324810
Answers.Body: <p>Bcftools and samtools both follow the very common <a href="https://en.wikipedia.org/wiki/Filter_(software)" rel="nofollow noreferrer">Unix filter</a> pattern: they read from all input files specified (as non-option plain arguments), or if there are none they read from standard input.</p>
  <p><code>bcftools call</code> is no exception:</p>
  <pre><code>$ bcftools call
  
  About:   SNP/indel variant calling from VCF/BCF.
           To be used in conjunction with bcftools mpileup.
           [etc]
  Usage:   bcftools call [options] &lt;in.vcf.gz&gt;
  </code></pre>
  <p>So you can write either of the following equivalently:</p>
  <pre><code>cat file.mpileup | bcftools call [options]
  bcftools call [options] file.mpileup
  </code></pre>
  <p>This assumes that the file is VCF/BCF as produced by <code>bcftools mpileup</code>, and not actually textual “mpileup output” as suggested by the filename. If it is the latter that VarScan2 is expecting, you won't be able to share the input files between the two after all.</p>
  <p>See <a href="http://www.htslib.org/workflow/#variant-calling" rel="nofollow noreferrer">this workflow example</a>, which demonstrates <code>bcftools call</code> both with a pipe and a previously made input file.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-17T11:24:38.430Z
Answers.LastActivityDate: 2021-09-17T11:24:38.430Z
Answers.UserDisplayName: John Marshall
Body: <p>I need to call variants on a large number of reads using both <code>VarScan2</code> and <code>BCFTools</code>. Both of these variant calling tools use <code>mpileup</code> file as input to call the variants. <code>VarScan2</code> command is straightforward, as we can specify the <code>mpileup</code> file as a command parameter. The problem is, <code>BCFTools</code> expects <code>mpileup</code> to be piped from another command and I cannot find an input  parameter to specify a <code>mpileup</code> file that already exists (the one used with <code>VarScan2</code>). It seems horribly inefficient to run the same command twice instead of reusing the file obtained from previous step (especially because generating <code>mpileup</code> takes a substantial amount of time on my computer).</p>
  <p>Is there a way to reuse an existing <code>mpileup</code> file with <code>BCFTools</code>?</p>
  <p>I am using <code>Nextflow</code> to run my pre-processing pipeline, so could it be possible that I can pipe an input channel with <code>mpileup</code> into the <code>BCFTools</code>'s <code>call</code> command?</p>
  <p><s>I also tried doing
  <code>cat file.mpileup | bcftools call ...</code> but this does not seem to work.</s></p>
  <p>Edit: <code>cat file.mpileup | bcftools call ...</code> does work, which would be a solution to this question, however, answers offer other, even more elegant, solutions.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-16T13:58:54.247Z
Comments.Text: I am voting to close this since the OP [clarified](https://bioinformatics.stackexchange.com/questions/17701/how-do-i-call-variants-using-bcftools-without-piping-mpileup-file#comment24726_17702) that `cat file.mpileup | bcftools` does work, and there was a typo in the first attempt.
Comments.UserDisplayName: terdon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-17T13:17:11.713Z
Comments.Text: No close: There are misconceptions and nuances addressed in the answers that are of educational interest to other readers.
Comments.UserDisplayName: John Marshall
Tags: <variant-calling><nextflow><bcftools><mpileup>
Title: How do I call variants using BCFTools without piping mpileup file?
ThreadText: # How do I call variants using BCFTools without piping mpileup file?
  
  (Asked by: username_0 on 2021-09-14)
  
  I need to call variants on a large number of reads using both `VarScan2` and `BCFTools`. Both of these variant calling tools use `mpileup` file as input to call the variants. `VarScan2` command is straightforward, as we can specify the `mpileup` file as a command parameter. The problem is, `BCFTools` expects `mpileup` to be piped from another command and I cannot find an input parameter to specify a `mpileup` file that already exists (the one used with `VarScan2`). It seems horribly inefficient to run the same command twice instead of reusing the file obtained from previous step (especially because generating `mpileup` takes a substantial amount of time on my computer).
  
  Is there a way to reuse an existing `mpileup` file with `BCFTools`?
  
  I am using `Nextflow` to run my pre-processing pipeline, so could it be possible that I can pipe an input channel with `mpileup` into the `BCFTools`'s `call` command?
  
  ~~I also tried doing
  `cat file.mpileup | bcftools call ...` but this does not seem to work.~~
  
  Edit: `cat file.mpileup | bcftools call ...` does work, which would be a solution to this question, however, answers offer other, even more elegant, solutions.
  
  **Tags:** variant-calling, nextflow, bcftools, mpileup
  
  > **Comments:**
  > **username_1**: I am voting to close this since the OP [clarified](https://bioinformatics.stackexchange.com/questions/17701/how-do-i-call-variants-using-bcftools-without-piping-mpileup-file#comment24726_17702) that `cat file.mpileup | bcftools` does work, and there was a typo in the first attempt.  
  > **username_2**: No close: There are misconceptions and nuances addressed in the answers that are of educational interest to other readers.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2021-09-14. Score: 2
  
  Why not use `tee`? Please see this [post](https://stackoverflow.com/questions/418896/how-to-redirect-output-to-a-file-and-stdout).
  
  You can write `mpileup` to file while also piping it to another process. For example, `samtools mpileup ... | tee file.mpileup | bcftools call ...`
  
  the `bcftools` will run while generating the `file.mpileup`. After it's done, you can use `file.mpileup` for your `VarScan2`.
  
  You can test it with the following:
  
  ```bash
  touch helloworld.txt
  ls | tee file.txt | grep helloworld    # output helloworld.txt
  cat file.txt | grep helloworld         # output helloworld.txt
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks @Law for the help. It turns out `cat file.mpileup | bcftools call ...` worked after all. It was a silly typo mistake from my side. But still, I cannot understand how to use `tee` here. In your example, you have `samtools mpileup ... | tee ... | bcftools call ...`. In my case the first part of that pipe needs to be a file instead of command.  
  > **username_3**: In your original post, you said `The problem is, BCFTools expects mpileup to be piped from another command and I cannot find an input parameter to specify a mpileup file that already exists (the one used with VarScan2)`. From what I understood is that `bcftools` expect only a piped input. You also said you didn't want to run the command twice of generating the `mpileup`, hence my answer. You can use `tee` to pipe `mpileup` to `bcftools` while also writing it to a file (aka to stdout and to file). Glad that it was only a typo then.  
  
  ---
  
  ### Answer by username_2 on 2021-09-17. Score: 1
  
  Bcftools and samtools both follow the very common [Unix filter](https://en.wikipedia.org/wiki/Filter_(software)) pattern: they read from all input files specified (as non-option plain arguments), or if there are none they read from standard input.
  
  `bcftools call` is no exception:
  
  ```
  $ bcftools call
  
  About:   SNP/indel variant calling from VCF/BCF.
           To be used in conjunction with bcftools mpileup.
           [etc]
  Usage:   bcftools call [options] <in.vcf.gz>
  
  ```
  
  So you can write either of the following equivalently:
  
  ```
  cat file.mpileup | bcftools call [options]
  bcftools call [options] file.mpileup
  
  ```
  
  This assumes that the file is VCF/BCF as produced by `bcftools mpileup`, and not actually textual “mpileup output” as suggested by the filename. If it is the latter that VarScan2 is expecting, you won't be able to share the input files between the two after all.
  
  See [this workflow example](http://www.htslib.org/workflow/#variant-calling), which demonstrates `bcftools call` both with a pipe and a previously made input file.
  
  
  ---
  
  