9 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: ...
user avatar
  • 19.3k
7 votes
Accepted

How to do `bedtools intersection` using pandas alone?

Your setup: ...
user avatar
6 votes
Accepted

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

...
user avatar
  • 19.3k
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. ...
user avatar
  • 659
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: ...
user avatar
  • 601
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 ...
user avatar
  • 19.3k
5 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 ...
user avatar
  • 130
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 ...
user avatar
  • 19.3k
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 ...
user avatar
  • 3,201
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: ...
user avatar
  • 3,462
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): ...
user avatar
  • 11.5k
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 ...
user avatar
  • 5,645
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 ...
user avatar
4 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 : ...
user avatar
4 votes
Accepted

How to detect bedtools version used by pybedtools (in order to correctly preserve strand information when merging gtf records)

pybedtools assumes that bedtools is in your path and bedtools itself will return the version with bedtools --version. So: ...
user avatar
  • 19.3k
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: ...
user avatar
  • 3,462
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 ...
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 ...
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: ...
user avatar
  • 19.3k
3 votes
Accepted

Comparing two files with overlapping regions and get their associated information

You can use bedtools intersect and cut the results: ...
user avatar
  • 19.3k
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 ...
user avatar
  • 19.3k
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 ...
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: ...
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 ...
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 ...
user avatar
  • 3,201
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 ...
user avatar
  • 5,287
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 ...
user avatar
  • 19.3k
3 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...
user avatar
  • 61
3 votes
Accepted

Unexpected error using "stdin" in bedtools intersect as a piped command

With v2.27.1 (or any version I ever used) instead of stdin use - ...
user avatar
  • 2,706

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