This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to get the best overlap

Hi! I have many bed files like A.bed. And B.bed is converted from a gtf.

cat A.bed
chr7    158788004   158788417
chr7    158793650   158793726
chr7    158797942   158798076
chr7    158799050   158799072

bedtools intersect -a A.bed  -b B.bed -wa -wb
chr7    158788004   158788417   chr7    158788004   158788093   ENSG00000117868.15  exon    -
chr7    158788004   158788417   chr7    158788094   158788344   ENSG00000117868.15  intron  -
chr7    158788004   158788417   chr7    158788345   158788417   ENSG00000117868.15  exon    -
chr7    158793650   158793726   chr7    158793650   158793726   ENSG00000117868.15  exon    -
chr7    158793650   158793726   chr7    158793674   158793726   ENSG00000117868.15  exon    -
chr7    158797942   158798076   chr7    158797942   158798076   ENSG00000117868.15  exon    -
chr7    158799050   158799072   chr7    158799031   158799072   ENSG00000117868.15  exon    -

Now, I hope to get the result like this. For each feature in A.bed, only output the best overlap

chr7    158788004   158788417   chr7    158788004   158788093   ENSG00000117868.15  exon    -
chr7    158788004   158788417   chr7    158788094   158788344   ENSG00000117868.15  intron  -
chr7    158788004   158788417   chr7    158788345   158788417   ENSG00000117868.15  exon    -
chr7    158793650   158793726   chr7    158793650   158793726   ENSG00000117868.15  exon    -
chr7    158797942   158798076   chr7    158797942   158798076   ENSG00000117868.15  exon    -
chr7    158799050   158799072   chr7    158799031   158799072   ENSG00000117868.15  exon    -

Is there any good way? Thanks!

bedtools overlap

it would make it easier if you could write one more line explaining the expected outcome than me comparing 16 lines manually!

Yeah I'm not reading those tables. Maybe original poster could explain what a best overlap is? I've always been happy with bedtools overlap, maybe using some flags when I wanted certain behaviors, bedtools has a lot of options.

0 answers

No answers yet.

Log in to answer this question.