10 votes
Accepted

How to count reads in bam per bed interval with bedtools

The order of -a and -b switched at some point. You want: ...
Devon Ryan's user avatar
  • 19.6k
8 votes
Accepted

How to do `bedtools intersection` using pandas alone?

Your setup: ...
The Unfun Cat's user avatar
6 votes
Accepted

Merging bed records based on name

Although you don't mention it, I'm guessing you're using bedtools v2.26.0. Version 2.26.0 of groupBy has a bug in it, which you've encountered (it was fixed shortly after release, so you'll either ...
OrdiNeu's user avatar
  • 140
6 votes

Merging regions according to their identifier

If I understand correctly, you could create dummy chromosomes made by merging chromosome and identifier, merge with bedtools, split back chromosomes and identifiers. E.g. ...
dariober's user avatar
  • 699
5 votes
Accepted

How to create a .bed file from .fasta?

Here is a fun little python script I cooked up for the occasion. It will take a standard fasta file as a command-line argument and turn it into the proper bed format. Using your example fasta: ...
d_kennetz's user avatar
  • 631
5 votes

Parse out exon coordinates from bed file for each gene

There are multiple ways to go about it. On the command line you can make a 1 line BED file: chr1 11868 12227 And then ...
Devon Ryan's user avatar
  • 19.6k
5 votes
Accepted

bed file merge book-end features only if same name in column 4

...
Devon Ryan's user avatar
  • 19.6k
5 votes
Accepted

How to best detect the "peaks" in RNA-seq data that are not assigned to any gene?

Basically what you're discovering is that there are unannotated expressed features, so your task isn't really finding peaks, but rather finding novel expressed transcripts. For that, you can use ...
Devon Ryan's user avatar
  • 19.6k
5 votes
Accepted

bedtool intersect multiple bed files

If you want to find the intersection between ALL your bedfiles, you can try multiIntersectBed (available since bedtools 2.14.3). It should work like this : ...
Paul Endymion's user avatar
4 votes

Merging bed records based on name

You could do this with the CGAT toolkit: cgat bed2bed --method=merge --merge-by-name -I bed_with_gene_ids.bed Installing such ...
Ian Sudbery's user avatar
  • 3,321
4 votes

How to create a .bed file from .fasta?

I'm assuming the FASTA header contains all the information you want. You can easily generate a proper bed file with Biopython: ...
Chris_Rands's user avatar
  • 3,948
4 votes

How can I calculate coverage at single bases using a bam file?

Note: not yet tested, so there may be some additional fiddling with command line options needed The per-base depth can be obtained from samtools depth (-a includes zero-coverage positions): ...
gringer's user avatar
  • 13.9k
4 votes

How can I calculate coverage at single bases using a bam file?

git clone https://github.com/lh3/htsbox cd htsbox && make ./htsbox pileup -cCf ref.fa aln.bam | less -S This output a VCF containing positions covered by ...
user172818's user avatar
  • 6,525
4 votes

How to do `bedtools intersection` using pandas alone?

I don't think Pandas has this implemented functionality out-of-the-box. Even if it did, solutions not designed specifically for bioinformatics probably rarely handle intervals on different chromosomes ...
Daniel Standage's user avatar
4 votes

bedtools intersect on very large .bam file - -sorted confusion

It sounds like bedtools is behaving properly. The bam file is sorted by read name only if you used the -n option in samtools sort...
Lynn's user avatar
  • 71
4 votes

Get a certain gene sequence from bam/vcf and reference

The first approach that comes to mind is to cut the bam file and then convert the already cut bam to fasta: ...
terdon's user avatar
  • 9,881
3 votes

Merging regions according to their identifier

Here is a fairly simple (and hopefully readable) native Python solution. It assumes that the bed file is sorted prior to parsing: ...
Chris_Rands's user avatar
  • 3,948
3 votes
Accepted

How to split bedfile into non-overlapping regions and compute aggregation function on duplicate segments

To make disjoint intervals, you could use BEDOPS bedops --partition, piping to bedmap --mean to get the mean signal over ...
Alex Reynolds's user avatar
3 votes

How to create a .bed file from .fasta?

If your headers are always of the form >chrZ:a-b, where chrZ is a chromosome name, a is a ...
Alex Reynolds's user avatar
3 votes

How to create a .bed file from .fasta?

The UCSC format you linked to isn't a BED file, your method should never produce it. What you posted as your desired output is also not a BED file. Below is a BED file: ...
Devon Ryan's user avatar
  • 19.6k
3 votes
Accepted

Comparing two files with overlapping regions and get their associated information

You can use bedtools intersect and cut the results: ...
Devon Ryan's user avatar
  • 19.6k
3 votes
Accepted

Merging regions according to their identifier

The following python script will do what you want and should be relatively memory efficient. It processes a single chromosome at a time, so either sort the input or ensure that at least entries in a ...
Devon Ryan's user avatar
  • 19.6k
3 votes

Parse out exon coordinates from bed file for each gene

Via BEDOPS bedops -n and Unix I/O streams: $ echo -e "chr1\t11868\t12227" | bedops -n 1 exon.bed - > answer.bed Or, if you ...
Alex Reynolds's user avatar
3 votes

Using column 2 of one file to match with two columns of another file, and append

Pipe a modified form of the second file to BEDOPS bedmap and the first file, then pipe that result to cut out desired columns: ...
Alex Reynolds's user avatar
3 votes

Merging bed records based on name

You can do this easily with Hail. Hail primarily uses BED files to annotate genetic datasets (see the last annotate_variants_table example), but you can manipulate BED files using Hail's general ...
Cotton Seed's user avatar
3 votes

Unable to install bedtools on windows 10 ubuntu

My personal advice would be to avoid compiling tools like this if you can avoid it, especially where you are using a "barebones" setup like the one you get with WSL Ubunutu as you'll almost always run ...
Ian Sudbery's user avatar
  • 3,321
3 votes
Accepted

Extracting the number SNP in each range

There is like a thousand different ways how to achieve this. You could use a specialised software for this (like bedtools) or calculate it simply in R. R solution: You can make a function that ...
Kamil S Jaron's user avatar
3 votes
Accepted

bedtools feature out of bounds

There is no chromosome named chr10, but there is one named 10. The problem is that you're mixing chromosome name systems with a ...
Devon Ryan's user avatar
  • 19.6k
3 votes

How to do `bedtools intersection` using pandas alone?

As mentioned by OP, another option is to use pybedtools, which in my opinion is pretty convenient for people already familiar with BedTools. Let's even say df1's format is slightly different than df2: ...
Kapara newbie's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible