![samtools threads samtools threads](https://itp1.itopfile.com/ImageServer/4fe4c0ae45823a1a/0/0/n40cez-z491329159531.jpg)
This README is generated using the create_readme.sh (stored in the eg folder) generated as per The examples in this README use the ERR188273_chrX.bam BAM file Latest information on SAMtools, please refer to the release High-throughput sequencing data, at some point you will probably have toĭeal with SAM/BAM files, so familiarise yourself with them! For the The SAM (Sequence Alignment/Map) format (BAM is just theīinary form of SAM) is currently the de facto standard for storing (bowtie2 -threads " $THREADS " -local -x " $tmpGenome " -q -1 " $tmp_fastq1 " -2 " $tmp_fastq2 " -met-file bowtie2_alignment-metrics.txt | tee stdout.log | samtools view " $THREADS " -Sb1 - | samtools sort -m 10G " $THREADS " - " $tmpOUTFILE " ) 3>&1 1>&2 2>&3 | tee stderr.SAMtools provides various (sub)tools for manipulating alignments in the # if you want to redirect both the stderr and the stdout to logs (warning: stdout.log will contain the SAM file, huge!)
![samtools threads samtools threads](https://www.basepairtech.com/wp-content/uploads/2016/08/mem-usage.png)
# redirect just the stderr to a log file, don't need to keep stdout from bowtie # THIS IS THE ONE WE WANT! FINAL COMMAND TO USE: (bowtie2 -threads " $THREADS " -local -x " $tmpGenome " -q -1 " $tmp_fastq1 " -2 " $tmp_fastq2 " -met-file bowtie2_alignment-metrics.txt | tee stdout.log ) 3>&1 1>&2 2>&3 | tee stderr.log 3> tee_tmp.txt # the '3' stream no longer exists after the pipe (bowtie2 -threads " $THREADS " -local -x " $tmpGenome " -q -1 " $tmp_fastq1 " -2 " $tmp_fastq2 " -met-file bowtie2_alignment-metrics.txt | tee stdout.log ) 3>&1 1>&2 2>&3 | tee stderr.log > tee_tmp.txt # you can see that the final tee's incoming stdout stream is the original stderr stream # the stdout stream, which now contains only the original stderr stream, gets copied into stderr.log with tee the new stdout stream now only contains original stderr # then the new stream '3' is getting redirected to stdout, stderr gets redirected to '3' which nows goes to stdout (for tee), and stdout gets sent to stderr # first bowtie stdout is getting copied to stdout.log with tee (bowtie2 -threads " $THREADS " -local -x " $tmpGenome " -q -1 " $tmp_fastq1 " -2 " $tmp_fastq2 " -met-file bowtie2_alignment-metrics.txt | tee stdout.log ) 3>&1 1>&2 2>&3 | tee stderr.log # redirect '3' to stdout, redirect stdout ('1') to stder ('2'), redirect stderr to '3'
![samtools threads samtools threads](https://www.biorxiv.org/content/biorxiv/early/2017/11/03/173716/F2.large.jpg)
# copy stdout AND stderr to stderr to separate log files (bowtie2 -threads " $THREADS " -local -x " $tmpGenome " -q -1 " $tmp_fastq1 " -2 " $tmp_fastq2 " -met-file bowtie2_alignment-metrics.txt | tee stdout.log ) # without stderr redirection stderr prints to consoleīowtie2 -threads " $THREADS " -local -x " $tmpGenome " -q -1 " $tmp_fastq1 " -2 " $tmp_fastq2 " -met-file bowtie2_alignment-metrics.txt | samtools view " $THREADS " -Sb1 - | samtools sort -m 10G " $THREADS " - " $tmpOUTFILE " (bowtie2 -threads " $THREADS " -local -x " $tmpGenome " -q -1 " $tmp_fastq1 " -2 " $tmp_fastq2 " -met-file bowtie2_alignment-metrics.txt) 2>stats.txt | samtools view " $THREADS " -Sb1 - | samtools sort -m 10G " $THREADS " - " $tmpOUTFILE " # this does not give console output though, which we want to keep # redirect bowtie stderr to text file while piping stdout (bowtie2 -threads " $THREADS " -local -x " $tmpGenome " -q -1 " $tmp_fastq1 " -2 " $tmp_fastq2 " -met-file bowtie2_alignment-metrics.txt) 2>stats.txt # redirect just the stderr from bowtie to a file bam file stderr is printed on screen and contains alignment stats from bowtie no stderr or stdout from samtoolsīowtie2 -threads " $THREADS " -local -x " $tmpGenome " -q -1 " $tmp_fastq1 " -2 " $tmp_fastq2 " -met-file bowtie2_alignment-stats.txt | samtools view " $THREADS " -Sb1 - | samtools sort -m 10G " $THREADS " - " $tmpOUTFILE " # standard bowtie2 alignment command, pipes output directly to samtools for sorting and conversion to. (bowtie2 -threads " $THREADS " -local -x " $tmpGenome " -q -1 " $tmp_fastq1 " -2 " $tmp_fastq2 " -met-file bowtie2_alignment-metrics.txt | samtools view " $THREADS " -Sb1 - | samtools sort -m 10G " $THREADS " - " $tmpOUTFILE " ) 3>&1 1>&2 2>&3 | tee stderr.log
![samtools threads samtools threads](https://hpc.nih.gov/training/gatk_tutorial/GATK_files/figure-html/bwaplot-1.png)
TmpOUTFILE= " $(basename " $tmp_fastq1 " ) " TmpGenome= "/local/data/iGenomes/Homo_sapiens/UCSC/hg19/Sequence/Bowtie2Index/genome " Tmp_outdir= " $HOME/projects/SmithLab_PARCLIP/test_bowtie2 " Tmp_fastq2= " $HOME/projects/SmithLab_PARCLIP/14Q-sample1_R2_mini.fastq " # SOLUTION: use `tee` along with some bash stream redirection to copy the stderr stream to a new file AND print it on the terminal # PROBLEM: want to preseve the terminal output from bowtie2, but also copy the stderr from bowtie into a separate file