Extract bed file of uwanted chromosome names and positions from bam file
1
0
Entering edit mode
23 months ago
tien ▴ 10

Hello everyone,

Besides chr1->22, there are others name like chrM, KI270728.1,.... I want to create a bam file of these chromosome names (which is listed in common_chr.bed) by using samtools

samtools view -L common_chr.bed -U out_bam.bam in_bam.bam

I need to create common_chr.bed but not sure how to do this. Is there any way to create such bed file of distinct chromosome names and their positions from in_bam.bam that excludes chr1->22

Thanks for your help.

bed bam samtools • 661 views
ADD COMMENT
0
Entering edit mode
23 months ago

use the reference.fa.fai file create by samtools faidx

awk -F '\t' '($1 ~ /^(chr)?[0-9]+$/) {printf("%s\t0\t%s\n",$1,$2);}' reference.fa.fai > common.bed
ADD COMMENT
0
Entering edit mode

Thanks for your reply. I'm using output from cellranger and find no such fastq file for faidx. The two files that I have is bam and its bam index file. I try to use the above command with bam index file but it does not work. Do you know any other methods?

ADD REPLY
0
Entering edit mode

find the fasta reference file, index it with samtools faidx /path/to/ref.fasta

ADD REPLY

Login before adding your answer.

Traffic: 3431 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