Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rama
    Member
    • Jan 2011
    • 20

    #1

    calculate total number of unique positions in target regions

    Hi there,

    I have a bed file containing target regions and I want to calculate the total number of bases covered by these regions(total length of target regions) and also the number of unique base positions covered(since some of the target regions are over lapping).

    thank you in advance for your kind help.
    Rama
  • vivek_
    PhD Student
    • Jul 2012
    • 164

    #2
    For unique bases:

    Code:
    cat <File.bed> | awk '{for(i=$1;i<$2;i++) print i}' | sort | uniq | wc -l
    For all bases:

    Code:
    cat <File.bed> | awk '{for(i=$1;i<$2;i++) print i}' | wc -l
    Last edited by vivek_; 01-14-2013, 02:24 PM. Reason: Bed is zero-based coordinates

    Comment

    • rama
      Member
      • Jan 2011
      • 20

      #3
      Hi Vivek,

      Thanks for your reply.

      I am not familiar with awk, I tried your commands but both gave 0 as result.
      here I have copied first few lines from my bed file.

      chr1 43814962 43815050 . MPL
      chr1 115256504 115256554 . NRAS
      chr1 115258717 115258765 . NRAS
      chr2 29432657 29432711 . ALK
      chr2 29443688 29443741 . ALK
      chr2 209113105 209113153 . IDH1

      don't know if I should change any of the arguments with the command.



      thanks again for you

      Comment

      • vivek_
        PhD Student
        • Jul 2012
        • 164

        #4
        Hi,

        Try these:

        For unique bases:

        Code:
        cat yourFile.bed | awk '{for(i=$2;i<$3;i++) print $1"\t"i}' | sort | uniq | wc -l
        For all bases:

        Code:
        cat yourFile.bed | awk '{for(i=$2;i<$3;i++) print $1"\t"i}' | wc -l

        Comment

        • rama
          Member
          • Jan 2011
          • 20

          #5
          Thank you Vivek, it worked like a charm.

          just one more request, how do I group by chromosome to see the number of bases per chromosome covered by the target regions.

          Comment

          • vivek_
            PhD Student
            • Jul 2012
            • 164

            #6
            This should work

            Code:
            cat yourFile.bed | awk '{for(i=$2;i<$3;i++) print $1"\t"i}' | sort | uniq | awk '{print $1}' | sort | uniq -c

            Comment

            • rama
              Member
              • Jan 2011
              • 20

              #7
              Thank you vivek.

              Comment

              • tedtoal
                Junior Member
                • Dec 2011
                • 3

                #8
                vivek_'s solution works, but it is very slow for large BED files. Here's a short Perl program to do it, along with bedtools:

                Code:
                    RGN_SIZE='
                        $chr = "";
                        $sum = 0;
                        $sumAll = 0;
                        $start = 0;
                        while ($ln = <STDIN>){
                            chomp $ln;
                            @A = split("\t", $ln);
                            if ($A[0] ne $chr){
                                if ($chr ne ""){
                                    print("$chr\t$sum\n");
                                    $sumAll += $sum;
                                }
                                $chr = $A[0];
                                $sum = 0;
                                $start = 0; # 0-based, next position after last one counted.
                            }
                            if ($A[1] > $start){ $start = $A[1]; }
                            if ($A[2] > $start){ $sum += $A[2] - $A[1]; $start = $A[2]; }
                        }
                        print("$chr\t$sum\n");
                        $sumAll += $sum;
                        print("Total: $sumAll\n");
                        '
                
                    bedtools sort -i <bedfile_name> | perl -e "$RGN_SIZE"
                Last edited by tedtoal; 01-12-2017, 05:04 PM.

                Comment

                Latest Articles

                Collapse

                • SEQadmin2
                  16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
                  by SEQadmin2




                  NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification, detection...
                  Today, 06:46 AM
                • SEQadmin2
                  Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
                  by SEQadmin2



                  Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

                  Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
                  ...
                  10-14-2026, 09:55 AM

                ad_right_rmr

                Collapse

                News

                Collapse

                Topics Statistics Last Post
                Started by SEQadmin2, 10-28-2026, 09:57 AM
                0 responses
                22 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-28-2026, 09:51 AM
                0 responses
                14 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-22-2026, 11:13 AM
                0 responses
                67 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-22-2026, 10:48 AM
                0 responses
                47 views
                0 reactions
                Last Post SEQadmin2  
                Working...