Hello, I have some SAM files which lack the header. In order to convert them to BAM I need first to add the header, but unfortunately I do not have any header file. Recently, Istvan Albert suggested (see here How to extract unaligned sequences from BAM files obtainend from BWA and here C: Obtaining the consensus sequence from a BAM file in FASTA) to use the Samtools's view option which the -h flag, but I get:
$ samtools view -S -h my_FILE.bam
[samopen] no @SQ lines in the header.
[sam_read1] missing header? Abort!
Maybe I am using the wrong syntax, I got the same error before (again, see here C: Obtaining the consensus sequence from a BAM file in FASTA). I tried also to use Picard Tools, but when I look at ReplaceSamHeader's manual I see that an input for the header is strictly required.
In brief, is it possible to generate a SAM header without any external header information?
I have the same suggestion. You can get a bam file online that used the same reference genome and extract the header from there. Of course, you need to change the sample, readgroup id information but if your present file is not that complicated then it should be easy to do. Also, as your primary purpose is to visualize the bam file it wont really matter even if your header doesnt have the exact library or read group information.
Thanks guys. The problem is that the genome is unpublished, so I would have to use similar genomes, so even if I succeeded the final output would be not so clean I guess. Summarising, if I understood well to generate a SAM header is unavoidable to grep information somewhere (this makes sense, it would be pointless to add a header to the file format if its information was somehow redundant). I choose this as the accepted answer, because it answers to my question and because it could help people with very similar issues.