Convert Bam file to Fastq
I used samtools to convert Bam paired files to Fastq, and I'd like to see if the conversion was successful. I attempted to check the read names with the following commands:
comm -1 -2 bam_read_names.txt (paste fastq1_read_ids.txt fastq2_read_ids.txt | sort) > common_read_names.txt
However, the common_read_names.txt file is empty.
How do you tackle this problem and ensure that the conversion is correct? Is there another way to check?
• 1,346 views
•
link
1 answer
I think your code is incorrect bash syntax. I think you want something like this:
sort bam_headers.txt > bam_haeders-sorted.txt # comm can only read one of the input file from STDIN so we need to sort the other file first
paste -d "\n" fq1_headers.txt fq2_headers.txt | sort | comm -1 -2 bam_headers-sorted.txt -
## paste using delimiter "\n" should create an interleaved file of both input files.
• 0 views
•
link
Log in to answer this question.
paste fastq1_read_ids.txt fastq2_read_ids.txt is a tabular file with two column. Is it the same for bam_read_names.txt ?
At first, I would trust samtools to do the right thing but of course it doesn't hurt to double check. But I think the crux is what is in fastq1|2_reads_ids.txt and bam read_read_names.txt and how did you get them? The first thing I would do always is look at the files and also the fastq files using head or less. Likely the files are properly sorted already, then you will immediately see what's wrong. If they are not properly sorted you have to do that too. Because for this command to work both files need to be sorted in the same way.
commalso has an option--check-orderthat might help you there.