Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • francy
    Member
    • Jun 2011
    • 19

    Fastest way to find overlaps between multiple regions and a bed file

    Dear experts,

    I have a sorted large BED file (main.bed) and several regions defined in a file (regions.bed) which can be overlapping. I am trying to find a quick way to overlap the main BED file with the regions defined in regions.bed, and create a separate BED output file for each of these regions.

    I can do it using a loop with bash by looping through each line of main.bed and finding the regions that overlap regions.bed though an awk command, but it is extremely slow. I can also do it with intersectBed from bedtools but I am still using a loop to specify each region... Is there a better way to do this?

    Thank you!
    Francesca
    Last edited by francy; 09-20-2015, 05:18 PM.
  • dpryan
    Devon Ryan
    • Jul 2011
    • 3478

    #2
    Just directly intersect the two BED files rather than looping over anything. If you need the results in different files for each region then it'd be faster to pipe the output to awk and have it place things in different files as appropriate (yes, you can do redirection within awk...this is useful in such cases).

    Comment

    • francy
      Member
      • Jun 2011
      • 19

      #3
      Thank you dpryan, is there a way I can intersect bed files to get all the values in the main.bed that are included in the regions.bed (so in a way subsetting the main.bed -- including repeated entries in main.bed since there are overlapping regions-- and splitting these by the regions)? What I am looking for is not the overlap between the two bed files, but the subset of overlaps in main.bed that are included in each region defined by regions.bed. The output file for each region should contain many entries from main.bed, and entries in each output files could be duplicated with other output files since the regions can be overlapping... Is this possible to do?

      cat main.bed
      chr11 13302 13303 1
      chr11 13980 13981 1
      chr11 51476 51477 1

      cat regions.bed:
      chr11 13202 14981 2
      chr11 13980 51477 2

      And the output should be:
      cat res.region1
      chr11 13302 13303 1
      chr11 13980 13981 1

      cat res.region2
      chr11 13980 13981 1
      chr11 51476 51477 1
      Last edited by francy; 09-21-2015, 05:21 AM.

      Comment

      • dpryan
        Devon Ryan
        • Jul 2011
        • 3478

        #4
        Sure, but the output file names will probably need to be something like "chr11_10000_14000" and "chr11_13500_55000". You could use awk to do that. Have it generate the file name based on the regions.bed file entry and then only print the columns from main.bed to it (make sure to use ">>" rather than ">").

        Comment

        • francy
          Member
          • Jun 2011
          • 19

          #5
          Ok... but I don't know what to pipe, is there a software that will let me get all the values in the main.bed that are included in the regions.bed, including repeated entries, in a way that I could then easily pipe the resulting BED file and split by another column for example? Or is the only solution to get the subset of main.bed included in regions.bed using a loop for each of the lines in the regions.bed with intersectBed command for example? Thank you
          Last edited by francy; 09-21-2015, 05:52 AM.

          Comment

          • dpryan
            Devon Ryan
            • Jul 2011
            • 3478

            #6
            Pipe the output of bedtools intersect:

            Code:
            $ cat regions.bed 
            chr1	100	200
            chr1	250	300
            Code:
            $ cat main.bed 
            chr1	0	10
            chr1	1	100
            chr1	100	150
            chr1	110	150
            chr1	150	200
            chr1	150	200
            chr1	150	300
            Code:
            $ bedtools intersect -wao -a regions.bed -b main.bed 
            chr1	100	200	chr1	100	150	50
            chr1	100	200	chr1	110	150	40
            chr1	100	200	chr1	150	200	50
            chr1	100	200	chr1	150	200	50
            chr1	100	200	chr1	150	300	50
            chr1	250	300	chr1	150	300	50
            Note that entries with no overlap are also included and can easily be ignored. The last column is the number of overlapping bases, in case that's useful for filtering too. You can specify -sorted if both files are sorted and then things will run quicker.

            Comment

            • francy
              Member
              • Jun 2011
              • 19

              #7
              I see, thank you!
              Using your command line doesn't give me unmatched and this is perfect. Thanks!!!

              Comment

              Latest Articles

              Collapse

              • SEQadmin2
                Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                by SEQadmin2


                Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                The systematic characterization of the human proteome has
                ...
                07-20-2026, 11:48 AM
              • SEQadmin2
                Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                by SEQadmin2



                Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                ...
                07-09-2026, 11:10 AM
              • SEQadmin2
                Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                by SEQadmin2



                Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                07-08-2026, 05:17 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, 07-20-2026, 11:10 AM
              0 responses
              10 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-13-2026, 10:26 AM
              0 responses
              30 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-09-2026, 10:04 AM
              0 responses
              41 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-08-2026, 10:08 AM
              0 responses
              26 views
              0 reactions
              Last Post SEQadmin2  
              Working...