This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Keep just chromosomes in a .bam file

Dears all,

Hello. I have some merged bam files and now I want to keep only the reads related to the chromosomes, not MT and not the unlocated reads. I tried using the following command but still I saw MT and the unlocated ones in my file.

samtools view -b CF-F0-filtered.bam NC_031965.2 NC_031966.2 \
                 NC_031967.2 NC_031969.2 NC_031970.2 NC_031971.2 NC_031972.2 \
                 NC_031973.2 NC_031974.2 NC_031975.2 NC_031976.2 NC_031977.2 \
                 NC_031978.2 NC_031979.2 NC_031980.2 NC_031981.2 NC_031982.2 \
                 NC_031983.2 NC_031984.2 NC_031985.2 NC_031986.2 NC_031987.2 \
                 > CF-F0-ChrOnly.bam

Any help is appreciated in advance.

Regards,
Omid

genome next-gen assembly snp alignment

but still I saw MT and the unlocated ones in my file.

what is the output of

samtools view CF-F0-ChrOnly.bam |  |cut -f 3 | uniq | sort | uniq

The out put is just the Chromosomes! Here is the results:

samtools view CF-F0-ChrOnly.bam | cut -f 3 | uniq | sort | uniq

NC_031965.2
NC_031966.2
NC_031967.2
NC_031969.2
NC_031970.2
NC_031971.2
NC_031972.2
NC_031973.2
NC_031974.2
NC_031975.2
NC_031976.2
NC_031977.2
NC_031978.2
NC_031979.2
NC_031980.2
NC_031981.2
NC_031982.2
NC_031983.2
NC_031984.2
NC_031985.2
NC_031986.2
NC_031987.2

so, how can you say:

. I tried using the following command but still I saw MT and the unlocated ones in my file. ?

Yes it is weird to me. I said it based on my mpileup. Actually based on two sorted .bam files I generated the mpileup file and when I took its tail command I saw the MT there. Based on your command I checked the two .bam files and there is just Chromosomes but why in mpileup file I have both MT and the unlocated ones?! Maybe it is because of one option that I used in mpileup command. It is running now and will back soon.

Yes, it was because of the option that I used for mpileup generation.

Thank you very much for your great help.

Best regards,
Omid

0 answers

No answers yet.

Log in to answer this question.