This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Issue with bed to bam conversion - sequence in bam headers

I have bam file that I must convert to bed file to filter specific reads. Now I need to convert output bed to bam file. I am using bedToBam. As an output I have bam file but when I visualize it I see that sequences are in headers. enter image description here

When I export it to txt. file I get:

TAATCACCAGCCTGACTGGCCGGGACAAAAACCAAGTGGAGGGCGAGATTCAGATCGTGTCAACTGCTGCCCAGACCTTCCTGGCAACGTGCATCAACGGGGTATGCTGGACTGTCTACCACGGGGCCGGAACGAGGACCATTGCGTCACCCAAGGGTCCTGTCATCCAGATGTATACCAACGTGGACCAAGACCTCGTGGGCTGGCCCGCTCCGCAGGGTTCCCGTTC pos=3329 len=229 ??????????????????????????????????????????????????????????????????????????????? ?????????????????????????????????????????????????????????????????????????????? ???????????????????????????????????????????????????????????????????????? TTGACGCCCTGCACCTGCGGTTCCTCGGACCTCTACCTGGTCACGAGGCACGCCGATGTCATCCCCGTGCGCCGGCGGGGTGATAGCAGGGGCAGCCTGCTTTCGCCCCGGCCCATTTCCTACTTGAAAGGCTCCTCGGGGGGTCCGCTGTTGTGCCCCGCGGGACACGCCGTGGGCATATTCAGGGCCGCGGTGTGCACC pos=3559 len=201 ??????????????????????????????????????????????????????????????????????????????? ?????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????

Is there any way to make this bed to bam conversion and get file with typical bam format ? Maybe there is an option fo filter headers containing sequences from my output bam and then using input bam, filter them in correct bam format?

bam bed

It looks like you deleted a prior question where you had shown how you did this conversion. Can you show us snippets of your BED, genome.size and resulting BAM file?

In any case it may be best to use the method that benformatics linked below in their answer.

1 answer

Bed files contain no extra metadata that would be relevant to a BAM file. By converting your BAM to bed you are losing all your mismatch, gap, and, sequence quality information. I somewhat can't imagine a scenario where you would be required to convert BAM files to bed files in order to do filtering. I would suggest you filter your BAM files directly.

You can subset BAM files by regions for instance: Extract Reads From A Bam File That Fall Within A Given Region

Log in to answer this question.