I have an aligned file in bam format. I want to get back the reads from the aligned file. Looking for any tool that can serve the purpose in a precise manner. Is it a tricky process? Looking for suggestions.
1) Use of Picard Tools: SamToFastq (http://picard.sourceforge.net/command-line-overview.shtml#SamToFastq). If you need a GUI, you always can use Galaxy (http://galaxyproject.org/).
2) Use of a pipe with samtools to get the sam, select the right columns (http://samtools.sourceforge.net/SAM1.pdf) and redirect into a file. In this case something like:
samtools view input.bam | cut -f1,10 | sed 's/^/>/' | sed 's/\t/\n/' > out.fasta
samtools view input.bam | cut -f1,10,11 | sed 's/^/>/' | sed 's/\t/\n/' | sed 's/\t/\n+\n/' > out.fastq
Please refer to the following thread on seqanswers which discusses the same. (http://seqanswers.com/forums/showthread.php?s=ff86dc537e51bb13492fecb01098c82b&t=12283)
In addition, it might be a good idea to explore the samtools mpileup option for extracting reads using a BED file, i.e. if you need to extract based on coordinates etc.