This is a test version of Biostars. For the public version, visit https://www.biostars.org.
extract the aligned read names and their reference fasta sequence name

Its a silly question
How to extract list of read names and their corresponding aligned fasta sequence name as table from the reference provided based on alignment.bam file

rna-seq alignment

This is such an obscure thing to want to do that you'll very likely have to write something (using pysam) to do it.

Just in case your end goal is to find how many reads are aligned to each chromosome. You can just use:

samtools idxstats input.bam

Thank you, this gives me the number of the reads mapped to each chromosome, However I would like to know the name of the read corresponding to its mapped chromosome
for example from your given samtools indexstats
chr1 38193400 19672 0
I would like to know the name of the reads that mapped to the chromosome one

Thank you for your suggestion, However I get the following error. may be I did not understand correctly.
samtools view sorted_trimmed_corrected_merged.bam | cut -f1,3 Unless fasta identifier != "fasta sequence name"
cut: Unless: No such file or directory
cut: fasta: No such file or directory
cut: identifier: No such file or directory
cut: fasta sequence name: No such file or directory

What?! But. The last sentence was not part of the command. You just need to run the following:

samtools view alignment.bam | cut -f1,3

Thank you so much, I really apologies for this stupid blunder. This works perfectly well.

Great, I have moved my comment to an answer so you can mark it as accepted and as such mark this question as solved.

1 answer

Probably I don't understand the question, but what about this?

samtools view alignment.bam | cut -f1,3

Unless fasta identifier != "fasta sequence name"

Indeed, I may have missed the "name" part at the end (on my screen it's showing up on a separate line). I saw the title and thought that the sequence from the fasta file itself was what was needed.

Log in to answer this question.