| Table of Contents |
|---|
Working with 3rd party program I/O
Recall the three standard Unix streams: they each have a number, a name and redirection syntax:
3rd party tool
...
file and
...
stream handling
Third party bioinformatics tools are often written to perform sub-command processing; that is, they have a top-level program that handles multiple sub-commands. Examples include the bwa NGS aligner and the samtools and bedtools tool suites.
...
| Tip | ||
|---|---|---|
| ||
Many tools write their main output to standard output by default, but have options to write it to a file instead. Similarly, tools often write processing status and diagnostics to standard error, and it is usually your responsibility to redirect this elsewhere (e.g. to a log file). Finally, tools may support taking their main input from standard input, but need a "placeholder" argument where you 'd would usually specify a file. That standard input placeholder is usually a single dash ( - ) but can also be a reserved word such as stdin. |
Now let's see how these concepts fit together when running 3rd party tools.
Exercise 2-3 bwa mem
Display the bwa mem sub-command usage using the more pager.
| Expand | ||
|---|---|---|
| ||
Just typing bwa mem | more doesn't use the more pager! That's because bwa writes its usage information to standard error, not to standard output. So you have to use the funky 2>&1 syntax before piping to more: bwa mem 2>&1 | more |
Where does the bwa mem sub-command write its output?
...
bwa mem also writes diagnostic progress as it runs, to standard error. This is typical for tools that may run for an extended period of time.
...
| title | Real example... |
|---|
...
| language | bash |
|---|
...
.
...
Show how you would invoke bwa mem to capture both its alignment output and its progress diagnostics. Use input from a my_fastq.fq file and ./refs/hg38 as the <idxbase>. (The resulting expression isn't expected to work!)
| Expand | ||
|---|---|---|
| ||
Redirecting the output to a file: Using the -o option: |
A real example:
| Code Block | ||
|---|---|---|
| ||
cd ~/gzips # Diagnostic progress is written to standard error, which is # mapped to the Terminal bwa mem /mnt/bioi/ref_genome/bwa/bwtsw/sacCer3/sacCer3.fa \ sm2.fq.gz > small.sam # Diagnostic progress on standard error is redirected to a log file bwa mem /mnt/bioi/ref_genome/bwa/bwtsw/sacCer3/sacCer3.fa \ sm2.fq.gz > small.sam 2>small.log cat small.log |
Exercise 2-4 cutadapt
The cutadapt adapter trimming command reads NGS sequences from a FASTQ file, and writes adapter-trimmed reads to a FASTQ file. Find its usage.
| Expand | ||
|---|---|---|
| ||
cutadapt # overview; tells you to run cutadapt --help for detailsdoesn't display help Note that it also points you to https://cutadapt.readthedocs.io/ for full documentation. |
Where does cutadapt write its output to from by default? How can that be changed?
| Expand | ||
|---|---|---|
| ||
Pipe the usage to less -I. The -I options does a Case Insensitive search. |
| Expand | ||
|---|---|---|
| ||
The cutadapt usage says that output can be written to a file using the -o option
The brackets around [-o output.fastq] suggest this is optional. Reading a bit further we see:
This suggests output can be specified in 2 ways:
|
...
| Expand | ||
|---|---|---|
| ||
The cutadapt usage suggests says that an input.fastq file is a required argument:
But again, Again reading a bit further we see:
This says that the input.fastq file can be provided in one of three compression formats. And the usage also suggests input can be specified in 2 ways:
|
...
| Expand | ||
|---|---|---|
| ||
The cutadapt usage doesn't say anything directly about diagnostics:
But again, reading in the Output: options section:
Careful reading of this suggests that:
| ||
| title | Real example...
Real examples:
| Code Block | ||
|---|---|---|
| ||
cd ~/gzips # No -o option, so output is written to standard output, redirected here # Summary report is written to standard error, which goes to the Terminal cutadapt -a AGATCGGAAGAGCACACGTCTGA small.fq > trimmed.fq # Same as above, but summary report is redirected to a log file cutadapt -a AGATCGGAAGAGCACACGTCTGA small.fq > trimmed.fq 2>trim.log cat trim.log # Use -o to specify the output file # Pipe the fastq data in, specifying "-" as the placeholder argument # Summary report will go to standard output; redirect to a log file cat small.fq | \ cutadapt -a AGATCGGAAGAGCACACGTCTGA -o trimmed.fq - 1>tr.log cat tr.log |