This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Name of a Specific read

Hello! I have a very simple question, I think, as I am only now learning and studying NGS. Supposing we have a bam file, how do I know the name of a specific read? For example, which is the name of read 313? Thank you very much!

samtools sequencing reads ngs read

1 answer

For example, which is the name of read 313?

do you mean the 313th read ?

$ samtools view in.bam | cut -f 1 | head -n 313 | tail -n 1

yes exactly!! Thank you so much!!

you can also try:

$ samtools view <in.bam> | awk  'NR==313 {print $1;exit}' 
$ samtools view <in.bam> | sed -n '313{s/\s.*//p;q}' 

what if I want to know the name of a fastq read? like 568th read

$ samtools view <in.bam> | awk 'NR== 568 {print $1;exit}'

  1. Install samtools on system and make sure that it is in user path and you are using bash shell
  2. save following script as read_name.sh
#! /usr/bin/env bash
samtools view $1 | awk -v line=$2 ' NR==line {printf "%s %d %s - %s\n", "read", line, "is",$1;exit}'
  1. Make the script executable. chmod +x read_name.sh
  2. Execute the script in bash shell

    ./read_name.sh <input.bam> <read_number>

For eg

$ read_name.sh s1454.bam 123

Log in to answer this question.