This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Convert sam file with no header to fastq

I aligned to a genome using bowtie2 and saved unaligned reads to a sam file. That sam file has no header. I now want to align this 'unaligned' sam file to a genome but I cant convert to fastq using gatk SamToFastq as gatk needs a header. Any way I can get around this?

fastq sam gatk

1 answer

reformat.sh from BBMap suite should work.

reformat.sh in=your.sam out=reads.fq

reformat doesnt like the headerless sam either

Input is being processed as unpaired

java.lang.AssertionError: Missing field 1: GGCAGCACGGAGCCAGGCCAATGAGGGGACCCCACCTGGACGCCATCGCCACCCAGGGCCAGACCATGGGGCGGGCTGCAGGGTGTGGGCCAGGTGCTGGGAGGGGCAGGGGCAGGGGCAGAGGAGGAAGTGAGGTCCTGGCTCCAATCC at stream.SamLine.<init>(SamLine.java:491) at stream.SamReadInputStream.toReadList(SamReadInputStream.java:119) at stream.SamReadInputStream.fillBuffer(SamReadInputStream.java:90) at stream.SamReadInputStream.hasMore(SamReadInputStream.java:54) at stream.ConcurrentGenericReadInputStream$ReadThread.readLists(ConcurrentGenericReadInputStream.java:667) at stream.ConcurrentGenericReadInputStream$ReadThread.run(ConcurrentGenericReadInputStream.java:656)

The actual first line of the sam file is

@SRAnumber.n.n followed by base sequence as shown in the error above

@SRAnumber.n.n followed by base sequence as shown in the error above

Can you post actual 2-3 lines from the file. Sounds like it is not in SAM format.

If actually looks like fastq already here is first read

@SRR12348370.1.8123509
GGCAGCACGGAGCCAGGCCAATGAGGGGACCCCACCTGGACGCCATCGCCACCCAGGGCCAGACCATGGGGCGGGCTGCAGGGTGTGGGCCAGGTGCTGGGAGGGGCAGGGGCAGGGGCAGAGGAGGA
AGTGAGGTCCTGGCTCCAATCC
+
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
:FFFFFFFFFFFFFFFFFFFFF

Correct. So no conversion needed.

In any case, I think you could just add any dummy header to that SAM file to make something like samtools fastq work. Afaik the header has (in sam>fastq conversion) basically no meaning despite satisfying the sanity check that the tools run up front. (untested)

Log in to answer this question.