This is a test version of Biostars. For the public version, visit https://www.biostars.org.
match bin number with the coordinate for each chromosome

I couldn't really find a question similar to mine, or at least I didn't know what exactly to search for.

I have binned my chromosomes with a 1kb window,

chr1    0    1000
chr1    1000    2000
chr1    2000    3000
.
.
chr1    35000 36000
.
.
.
chrx 0    1000
chrx    1000    2000
.
chrx    20000    21000

after doing some statistical analyses, I have a list of bin numbers say, bin number 2364 till bin number 4576 and now I want to extract the coordinates for these bins, if I use awk 'NR==2364 { print $0 }' file.bed it is counting from line 1 till the end irrespective of the chromosomes, but I need a way to start counting from 1 for each chromosome name, how should I do that?

chromosome bins coordinates

2 answers

so the simplest answer would be

awk '$1=="chr1"' file.bed | awk 'NR==2364'

this way we can pick the desired bin for the desired chromosome separately, starting from 1 for each chromosome.

not tested:

 awk -F '\t' 'BEGIN{P="";N=0;} {if(P!=$1) {N=0;} N++;P=$1;if(N==2364) print;}'  in.bed

thanks, that works, but that picks up the same bin number for each chr, since I have different numbers for different chromosomes I came up with another solution

Log in to answer this question.