This is a test version of Biostars. For the public version, visit https://www.biostars.org.
retrieving rows from a bed file

Hello . my goal is to have this kind of bed file: Capture4

and be able to enter a chrom number and a range between chromeStart and chromeEnd, and to recieve all rows that match it. what is the best way to do it? Thanks

bed

2 answers

Some clean-up work is needed. Export your file from Excel as a tab-delimited file. Clean it of Microsoft line endings and make a headerless, sorted file via sort-bed:

$ tr -d '\r' elements.tsv | sort-bed - > elements.bed

Then via bedops:

$ CHROM=chr1
$ START=12345
$ END=23456
$ bedops -e 100% elements.bed <(echo -e "${CHROM}\t${START}\t${END}") > answer.bed

The file answer.bed will contain all elements within the specified bounds, on the specified chromosome. Adjust CHROM, START, and END as needed.

Reference:

  1. https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#element-of-e-element-of
  2. https://bedops.readthedocs.io/en/latest/content/reference/file-management/sorting/sort-bed.html
awk -F '\t' '($1=="chr1" && !( $2>10000  ||  $3 <= 100))' input.bed

or use bedtools intersect

Log in to answer this question.