In this tutorial I hope to introduce some of the concepts for using unix piping. Piping is a very useful feature to avoid creation of intermediate use once files.
Lets begin with a typical command to do paired end mapping with bwa:
#-t 4 is for using 4 threads/cores bwa aln -t 4 ./hg19.fasta ./s1_1.fastq > ./s1_1.sai bwa aln -t 4 ./hg19.fasta ./s1_2.fastq > ./s1_2.sai bwa sampe ./hg19.fasta ./s1_1.sai ./s1_2.sai ./s1_1.fastq ./s1_2.fastq > s1.sam
Supposed we wish to now convert to bam, sort, remove duplicates, and lastly create a bed file.
samtools view -Shu s1.sam > s1.bam samtools sort s1.bam s1_sorted samtools rmdup -s s1_sorted.bam s1_sorted_nodup.bam bamToBed -i s1_sorted_nodup.bam > s1_sorted_nodup.bed
This workflow above creates many files that are only used once (such as s1.bam) and we can use the linux pipe utility to reduce the number intermediate files created. The pipe function is the character | and what it does is take the output from one command and sets it as input for next command (assuming next command knows how to deal with this input).
For example, when you type in head myfile.txt the command ‘head’ will read first 10 lines of myfile.txt and output it (by default) into the display (stdout) so you will see the first 10 lines printed on your screen. However, if you were to do something like this:
head myfile.txt | wc -l
you will instead get 10 printed out on your screen. What the pipe command did was take the output of head command and used it as input for the wordcount (wc) command. wc -l command will count the number of lines passed in (which is 10 since head by default prints the first 10 lines). An equivalent command would be
head myfile.txt > myfile_top10_lines.txt wc -l myfile_top10_lines.txt
By using the pipe command we are able to eliminate the intermediate file that was generated.
Below would be an example of how pipe command can be used in samtools example
bwa aln -t 4 ./hg19.fasta ./s1_1.fastq > ./s1_1.sai bwa aln -t 4 ./hg19.fasta ./s1_2.fastq > ./s1_2.sai bwa sampe ./hg19.fasta ./s1_1.sai ./s1_2.sai ./s1_1.fastq ./s1_2.fastq | \ samtools view -Shu - | \ samtools sort - - | \ samtools rmdup -s - - | \ tee s1_sorted_nodup.bam | \ bamToBed > s1_sorted_nodup.bed
A couple of things I wanted to point out here:
- The \ symbol after the pipe symbol tells the terminal that I want to keep writing command on the next line, that way you can have multiline commands instead of super-long command on one line.
- The tee command takes the information being piped and creates a file while passing the data along the pipe, this command is useful if you want to save an intermediate file but still need to do additional processing.
- The – symbol in samtools it to tell the samtools program to take the input from pipe
- It is not recommended you run this command all at once like I showed above if you have a giant bam file because the sort will take forever. Running things in a pipe can be more space efficient since you are not storing intermediate files but can create issues/bottlenecks elsewhere. If there are problems, run the pieces without piping.
Other common uses of pipes that I have not shown above it to pipe output into snp calling, you can find some examples here: http://sourceforge.net/apps/mediawiki/samtools/index.php?title=SAM_FAQ
samtools merge - *.bam | tee merged.bam | samtools rmdup - - | tee rmdup.bam | samtools pileup - vcf ref.fa - | gzip > raw-var.txt.gz
Compressing files with gzip can save a lot of space, you can also view these files with the zless and zcat command.
In case you are wondering if there is a way to run bwa sampe without storing intermediate sai files the command below will do this:
bwa sampe ./hg19.fasta <(bwa aln -t 4 ./hg19.fasta ./s1_1.fastq) <(bwa aln -t 4 ./hg19.fasta ./s1_2.fastq > ./s1_2.sai) ./s1_1.fastq ./s1_2.fastq > s1.sam
Outstanding post, you have pointed out some wonderful points, I too believe this is a very excellent website.
It’s my honored that receive some positive feedback from aboard
I hope this website can grow up a good discussion field for the guys in bioinformatics!
Hi there! Someone in my Facebook group shared this website with us so I came to give it a look. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers! Excellent blog and fantastic style and design.
thanks for your message here!
Good write-up, I am normal visitor of one’s website, maintain up the nice operate, and It is going to be a regular visitor for a lengthy time. “Good nonsense is good sense in disguise.” by Josh Billings.
Thanks! I’m agree with u!
I am curious to find out what blog system you are working with? I’m having some small security problems with my latest site and I’d like to find something more safe. Do you have any recommendations?
Hey! I could have sworn I’ve been to this website before but after reading through some of the post I realized it’s new to me. Anyhow, I’m definitely glad I found it and I’ll be bookmarking and checking back frequently!
You got a very wonderful website, Gladiola I noticed it through Yahoo.
THANKS
Thanks, I’ve just been searching for info approximately this subject for a while and yours is the best I’ve discovered till now. But, what about the conclusion? Are you sure about the supply?
Appreciate it for this post, I am a big big fan of this site would like to go on updated.
Thanks u
Thanks for expressing your ideas. The one thing is that college students have a choice between federal government student loan as well as a private student loan where it really is easier to select student loan debt consolidation reduction than in the federal education loan.
I believe this web site has very wonderful indited articles posts.
Thanks !!!
Amaze, fantastic website style and design! The length of time will you be writing a blog for? You’ve made writing glimpse easy. The complete take a look to your site is without a doubt great, not to mention your content! Good post!
Yeah bookmaking this wasn’t a speculative conclusion outstanding post! .
If I had not personally seen it all I wouldn’t contain believed it is possible to people which have got this type of very good article content. Faith in god over the internet and personal blog sites, have been recovered!
Very good written information. It will be supportive to everyone who employess it, including yours truly :). Keep up the good work – looking forward to more posts.
Thanks !!!!
tremendous products inclusively, designer watches had your own logo creative target audience. How nicely buyers advise you for your mail for you to simply formulated last week before? Any and all special?
Yeah bookmaking this wasn’t a bad decision outstanding post! .
Thank u
Interesting blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple adjustements would really make my blog stand out. Please let me know where you got your theme. Cheers
Very nice post. I just stumbled upon your blog and wished to say that I’ve truly loved surfing around your blog posts. After all I’ll be subscribing in your rss feed and I’m hoping you write again very soon!
I gotta favorite this site it seems very beneficial very useful
Do you have a spam problem on this website; I also am a blogger, and I was wondering your situation; we have created some nice procedures and we are looking to trade solutions with others, be sure to shoot me an email if interested.
Pretty great post. I just stumbled upon your blog and wanted to mention that I’ve truly enjoyed browsing your blog posts. After all I’ll be subscribing to your rss feed and I hope you write again very soon!
Useful info. Lucky me I found your web site by accident, and I am shocked why this accident did not came about in advance! I bookmarked it.
Thank u !
Its excellent as your other posts : D, regards for putting up. “The squeaking wheel doesn’t always get the grease. Sometimes it gets replaced.” by Vic Gold.
Well I truly enjoyed reading it. This information offered by you is very helpful for accurate planning.
I wanted to thank you once again for that amazing web-site you have designed here. It can be full of ideas for those who are actually interested in this subject, particularly this very post. Your all amazingly sweet in addition to thoughtful of others plus reading the blog posts is a great delight in my experience. And what a generous present! Dan and I really have excitement making use of your recommendations in what we should instead do in a few weeks. Our checklist is a mile long which means that your tips might be put to beneficial use.
We are a gaggle of volunteers and opening a new scheme in our community. Your web site provided us with useful info to work on. You’ve performed a formidable activity and our whole group will be grateful to you.
Simply wanna remark on few general things, The website design is perfect, the subject material is real good : D.
My spouse and i still can not quite think I could become one of those studying the important guidelines found on this blog. My family and I are really thankful on your generosity and for presenting me the advantage to pursue my chosen profession path. Thanks for the important information I acquired from your website.
I like this web site its a master peace ! Glad I observed this on google. “The definition of a beautiful woman is one who loves me.” by Sloan Wilson.
Great work! That is the type of info that are meant to be shared around the net. Shame on Google for no longer positioning this post higher! Come on over and discuss with my web site . Thank you =)
Hey very nice blog!! Guy .. Beautiful .. Superb .. I’ll bookmark your website and take the feeds also…I am satisfied to find so many helpful information here within the submit, we want work out extra techniques in this regard, thanks for sharing.
Normally I don’t learn article on blogs, however I would like to say that this write-up very compelled me to check out and do it! Your writing style has been amazed me. Thank you, very nice article.
I’ll right away snatch your rss feed as I can’t to find your e-mail subscription link or newsletter service. Do you have any? Please permit me know in order that I may just subscribe. Thanks.
Simply wanna tell that this is very useful , Thanks for taking your time to write this.
You are my aspiration, I own few blogs and infrequently run out from brand :). “Yet do I fear thy nature It is too full o’ the milk of human kindness.” by William Shakespeare.
I will immediately grab your rss as I can’t to find your e-mail subscription hyperlink or newsletter service. Do you have any? Kindly allow me recognise so that I may just subscribe. Thanks.
Wow, fantastic blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your site is great, let alone the content!
I will immediately clutch your rss feed as I can not find your email subscription link or newsletter service. Do you’ve any? Please permit me understand so that I could subscribe. Thanks.
Thanks for your article. I would like to say that your health insurance brokerage service also works for the benefit of the actual coordinators of the group insurance cover. The health insurance agent is given a list of benefits sought by a person or a group coordinator. What any broker can is find individuals and also coordinators which best fit those needs. Then he reveals his advice and if the two of you agree, the actual broker formulates a legal contract between the two parties.
Thanks a lot for sharing this with all of us you really know what you are talking about! Bookmarked. Please also visit my web site =). We could have a link exchange arrangement between us!
We’re a bunch of volunteers and opening a new scheme in our community. Your website offered us with helpful information to work on. You’ve performed a formidable process and our entire group shall be thankful to you.
Regards for all your efforts that you have put in this. Very interesting info. “I’ve never known any trouble that an hour’s reading didn’t assuage.” by Charles De Secondat.
I am continuously searching online for ideas that can benefit me. Thank you!
I don’t unremarkably comment but I gotta state regards for the post on this amazing one : D.
Just a smiling visitant here to share the love (:, btw great style and design. “Everything should be made as simple as possible, but not one bit simpler.” by Albert Einstein.
Rattling superb info can be found on weblog.
Hello to every single one, it’s in fact a good for me to go to see this
site, it contains important Information.