Name of a Specific read
1
0
Entering edit mode
2.4 years ago
Sara • 0

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.1k views
ADD COMMENT
2
Entering edit mode
2.4 years ago

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
ADD COMMENT
1
Entering edit mode

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}' 
ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

$ 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
ADD REPLY
0
Entering edit mode

yes exactly!! Thank you so much!!

ADD REPLY

Login before adding your answer.

Traffic: 1558 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6