I'm making a program in java for alignment visulaization. The input is a ref genome and a sam file with the alignment. I'm using RNAME field in the SAM file to see to which sequence does the alingment belong to. How to address when there is "" instead of a RNAME. In my SAM file for Ecoli alignemnt all RNAME fields are "" so I've added into my code that if there is only one sequence in the referente genome file the program takes the sequence name from the header as RNAME. I don't know if this aproach is correct and I don't know what to do when the referente genome file has more than one sequence. Any advice/explanation would be appreciated.
don't reinvent the wheel and use htsjdk. https://github.com/samtools/htsjdk/