Question: how to find a read by name in a bam file
0
gravatar for himanimalhotra89
2.9 years ago by
himanimalhotra890 wrote:

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 helpme to find this id from my original bam file. Thank you

sequencing tool next-gen • 4.1k views
ADD COMMENTlink modified 2.9 years ago by Samuel Brady310 • written 2.9 years ago by himanimalhotra890

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

ADD REPLYlink modified 2.9 years ago • written 2.9 years ago by genomax83k

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

ADD REPLYlink written 2.9 years ago by Istvan Albert ♦♦ 84k

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

ADD REPLYlink written 2.9 years ago by h.mon29k

Most likely @Pierre's software.

ADD REPLYlink written 2.9 years ago by genomax83k

not this one. But picard http://broadinstitute.github.io/picard/command-line-overview.html FilterSamReads with READ_LIST_FILE=read_names.txt

ADD REPLYlink written 2.9 years ago by Pierre Lindenbaum128k
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.

ADD REPLYlink modified 2.9 years ago • written 2.9 years ago by Samuel Brady310

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.

ADD REPLYlink modified 2.9 years ago • written 2.9 years ago by genomax83k

Thanks for the clarification.

ADD REPLYlink written 2.9 years ago by Samuel Brady310
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1405 users visited in the last hour