Tuesday, January 10, 2012

Extract single chromosome reads from BAM/SAM

Sometimes it is required to extract subset of reads for only one specific chromosome.
It's rather easy to accomplish this task with SAMtools.

First we create the index for a BAM file. It is required for random region positioning.

samtools index accepted_hits.bam

Then we extract the data for specific region, for example chromosome 20.

samtools view -h accepted_hits.bam chr20 > accepted_hits.20.sam

Friday, December 16, 2011

Small tricks for tab-delimeted files

Working on my current project includes a lot of manipulation with tab-delimited files (SAM,GFF, etc) Here are some nice tricks to remember.

Output only second field of a delimited file:
cat samout | cut -f 2

The same with awk:
awk '{print $2}'

Not related to tab-delimited files but still very useful :)

Compare two files based on their content:
cat file1 file2 | sort | uniq -u

Tuesday, November 8, 2011

Linux BASH tricks: recovering items

Very nice commands to know about

Run the last-command name: !!
Recover last entered item: Alt + "."
Search over history: Ctrl + R

Friday, June 25, 2010