Important: Sort by name, not position.
Hello everyone,
I would like to ask a question. I have BAM files for each hg19 chromosome, but I need to create a fastq.gz file, so I can realign the reads to hg38 again. The SRA for the dataset I am interested in doesn't exist, but only already aligned ones. I wanted to ask if anyone has done it before and how to create one pair of paired-end fastq.gz files out of 23 BAM files. Do I need to convert first to Fastq eahc BAM file separately and then combine corresponding fastq1 and fast2 for PE reads?
Thank you,
4 answers
You can merge all the bam files, sort them (samtools) and convert is to fastq (samtools or bedtools)
This answer is subject to caveat that I had noted in my answer. Otherwise there can be serious duplication of data.
If reads have been aligned to each chromosome separately then you may have the entire dataset in just one BAM file, assuming unaligned reads are included. Then you may need to convert just one file.
If unaligend reads are not included then you will need to do the conversion for each BAM file and then merge the reads. Make sure there are no duplicates. Passing the end result through repair.sh from BBMap suite will ensure that reads in R1/R2 files will be in sync.
how about this java software : https://github.com/ssadedin/bazam
The Subread aligner can take the BAM files directly as input, so there is no need to re-construct FASTQ files to re-align the reads.
Log in to answer this question.
This tutorial shows how to easily convert a BAM file into FASTA https://onestopdataanalysis.com/convert-bam-to-fasta/