This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to find a read by name in a bam file

hello

I am using cmpbam to compare bam files.For this I have to extract read names from original bamfile by using this command.

samtools view  file1.bam K01:2179-2179 |  cut -d '  ' -f 1  | sort | uniq > names.txt

Can someone help me that how I can find read id from my original bam file as k01:2179-2179 as shown in example.

Please help me to find this id from my original bam file.

Thank you

next-gen-sequencing

Is that command not putting read id's in file called names.txt?

I believe the OP is trying to find and extract reads by name from a BAM file

What is cmpbam? I can't find this tool.

samtools view file1.bam | grep -m 1 K01:2179-2179

This will output the line in the bam file with the "K01:2179-2179" read name in it, thus giving you the sequence of that read. (Is that what you're looking for?) Remove the -m 1 option if there is more than one read in the file expected to match the "K01:2179-2179" string. The -m 1 makes it stop after the first find.

This will output the line in the bam file with the "K01:2179-2179" read name in it

That is not the read name. It is the chromosome:start-stop interval for which the OP wants to retrieve the reads (or just names). We are speculating until OP chooses to respond to comments in this post.

Thanks for the clarification.

0 answers

No answers yet.

Log in to answer this question.