How about samtools view to select the region of interest, and then bamtools bedtobam to convert the BAM file to the BED format?
You can pipe the output of samtools view directly to bedtobam.
Header Leaderboard Ad
Collapse
How to transform BAM format to .TXT or .BED?
Collapse
Announcement
Collapse
No announcement yet.
X
-
Is there a way I could extract a range, say [chr3,a,b] to a BED format from a BAM file?
Leave a comment:
-
okay i understand,
and is there a way to calculate the length of splicing region ?
Leave a comment:
-
The read is spliced (note 7841N in the CIGAR string), so bamToBed is correct.
Leave a comment:
-
--Hi,
i have a strange result using BamToBed and awk command line:
samtools view -F 0x0004 464_J3_D1.bam | head -1
IP6FNQC01CAO42 0 gi|2281652|gb|AF004394.1| 18 40 5S304M7841N12M1D38M3S * 0 0 TTAACTCCCAGAAAAGACAAGATATCCTTGATCTGTGGGTCTACCACACGCAAGGCTACTTCCCTGATTGGCAGAACTACACACCAGGGCCAGGGATCAGATATCCACTGACCTTTGGATGGTGCTTCAAGCTAGTACCAGTGGAGCCAGAGAAGGTAGAAGAGGCCAATGAAGGAGAGAACAACAGCCTGTTACACCCTATGAGCCTGCATGGGATGGAGGACCCGGAGAAGGAAGTGTTAATGTGGCGGTTTGACAGCAGCCTAGCATTTCATCACATGGCCCGAGAGCTGCATCCGGAGCACTACAAGAACCAACAAGAAAGAATGAACAAGAATTATTAGAATTGGATAAATGGGACA 433146444?8.//153FFFFFFIIIIGGIIIIIII:::=IIIGGIIIIIIIIIIIIIIIIIIIHIIIIIIIIIIGIIIIIIIGGG888[email protected]@@@[email protected]>>AACCGDDDDDDDDE<<<>DCDFIIIIEDFFDDDDFDDFFDDDFFECC221;C>>>B?>888EGC>>>@CGGGC>>>BBBBB>>>::333<>;;;>>[email protected]@BB?==A???A?<<444;40..../588633579<<../0009<<<<<::=988:////25 MD:Z:17G17T8A45G46T9C2A14A14T21A6A5T3A6GA8GCA4AA10C41T13G4^A27A5G4 NH:i:1 HI:i:1 NM:i:26 SM:i:40 XQ:i:40 X2:i:0 XS:A:?
bamToBed give me this result:
gi|2281652|gb|AF004394.1| 17 8213 IP6FNQC01CAO42 40 +
and
awk '{OFS="\t"; if (and($2, 16)) print $3,$4,$4+length($10),$1,$5,"-"; else print $3,$4,$4+length($10),$1,$5,"+" }'
give me:
gi|2281652|gb|AF004394.1| 18 380 IP6FNQC01CAO42 40 +
in bamToBed result i have 8213, why ?
thank you --
Leave a comment:
-
bedtools bamtobed when large indels are present
I really like the bedtools bamtobed command, although there are some instances where reads skip very large indels and you don't want the bed file to include those indels. The only information you need is contained in columns 3 (chromosome), 4 (base pair start), and 6 (CIGAR) of the BAM file. Here is a simple awk script that should work (it really should be an option of bedtools bamtobed):
Code:samtools view in.bam | awk '{split ($6,a,"[MIDNSHP]"); bp=$4-1; n=0; for (i=1; i<=length(a); i++) { n+=1+length(a[i]); if (substr($6,n,1)=="M") print $3"\t"bp"\t"(bp+=a[i]); if (substr($6,n,1)=="D") bp+=a[i]; } }' > out.bed
Leave a comment:
-
Here is the sample code from Heng Li.
http://sourceforge.net/apps/mediawik...e=SAM_protocol
Protocol #4 describes his cut at bamToBed.
Aaron
Leave a comment:
-
Hi,
Originally posted by zhenshao View PostDear all,
I downloaded a file in .BAM format and want to transform it into .BED format. What can I do? Thanks a lot!
Zhen
Code:samtools view -F 0x0004 $filein | awk '{OFS="\t"; if (and($2, 16)) print $3,$4,$4+length($10),$1,$5,"-"; else print $3,$4,$4+length($10),$1,$5,"+" }
Leave a comment:
-
Hi,
I just finished a new version of BEDTools which has a C++ utility call bamToBed. This tool will convert BAM alignments to BED or BEDPE (see the BEDTools documentation) format. For example:
1. Convert BAM alignments to BED format.
Code:$ bamToBed -i reads.bam > reads.bed
Code:$ bamToBed -i reads.bam -ed > reads.bed
Code:$ bamToBed -i reads.bam -bedpe > reads.bedpe
You might also be interested in two other utilities in BEDTools that now support BAM input and output. Namely, intersectBed now accepts BAM files as input and will separately compare each alignment (each end separately if paired-end) to a BED file. One can create a new BAM file based on those alignments that do or do not overlap the BED features in question. Similarly, pairToBed does the same thing, but requires that the BAM file be paired. This tools is a bit more sophisticated in that one can require the "span" of the aligned pair to overlap, as well as either/both/neither/xor/notboth ends of the pair.
For example:
1. Retain only paired-end BAM alignments where neither end overlaps simple sequence repeats.
Code:$ pairToBed -abam reads.bam -b SSRs.bed -type neither > reads.noSSRs.bam
Code:$ pairToBed -abam reads.bam -b segdups.bed -type both > reads.SSRs.bam
Code:$ pairToBed -abam reads.bam -b segdups.bed -type notboth > reads.notbothSSRs.bam
The BAM support is built upon Derek Barnett's nice C++ BAM API called BAMTools (http://sourceforge.net/projects/bamtools/). I'd encourage you to take a look at the new BEDTools manual for more details if you are interested.
Best,
Aaron
Leave a comment:
-
How to transform BAM format to .TXT or .BED?
Dear all,
I downloaded a file in .BAM format and want to transform it into .BED format. What can I do? Thanks a lot!
ZhenTags: None
Latest Articles
Collapse
-
by seqadmin
Amplicon sequencing is a targeted approach that allows researchers to investigate specific regions of the genome. This technique is routinely used in applications such as variant identification, clinical research, and infectious disease surveillance. The amplicon sequencing process begins by designing primers that flank the regions of interest. The DNA sequences are then amplified through PCR (typically multiplex PCR) to produce amplicons complementary to the targets. RNA targets...-
Channel: Articles
Yesterday, 01:49 PM -
-
by seqadmin
Targeted sequencing is an effective way to sequence and analyze specific genomic regions of interest. This method enables researchers to focus their efforts on their desired targets, as opposed to other methods like whole genome sequencing that involve the sequencing of total DNA. Utilizing targeted sequencing is an attractive option for many researchers because it is often faster, more cost-effective, and only generates applicable data. While there are many approaches...-
Channel: Articles
03-10-2023, 05:31 AM -
-
by seqadmin
Using automation to prepare sequencing libraries isn’t a new concept, and most researchers are aware that there are numerous benefits to automating this process. However, many labs are still hesitant to switch to automation and often believe that it’s not suitable for their lab. To combat these concerns, we’ll cover some of the key advantages, review the most important considerations, and get real-world advice from automation experts to remove any lingering anxieties....-
Channel: Articles
02-21-2023, 02:14 PM -
ad_right_rmr
Collapse
News
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by seqadmin, 03-17-2023, 12:32 PM
|
0 responses
14 views
0 likes
|
Last Post
by seqadmin
03-17-2023, 12:32 PM
|
||
Started by seqadmin, 03-15-2023, 12:42 PM
|
0 responses
18 views
0 likes
|
Last Post
by seqadmin
03-15-2023, 12:42 PM
|
||
Started by seqadmin, 03-09-2023, 10:17 AM
|
0 responses
68 views
1 like
|
Last Post
by seqadmin
03-09-2023, 10:17 AM
|
||
Started by seqadmin, 03-03-2023, 12:03 PM
|
0 responses
64 views
0 likes
|
Last Post
by seqadmin
03-03-2023, 12:03 PM
|
Leave a comment: