Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #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


    • #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


      • #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


        • #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


          • #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


            • #7
              Thank you vivek.

              Comment


              • #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

                • seqadmin
                  Current Approaches to Protein Sequencing
                  by seqadmin


                  Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
                  04-04-2024, 04:25 PM
                • seqadmin
                  Strategies for Sequencing Challenging Samples
                  by seqadmin


                  Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
                  03-22-2024, 06:39 AM

                ad_right_rmr

                Collapse

                News

                Collapse

                Topics Statistics Last Post
                Started by seqadmin, 04-11-2024, 12:08 PM
                0 responses
                30 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 04-10-2024, 10:19 PM
                0 responses
                32 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 04-10-2024, 09:21 AM
                0 responses
                28 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 04-04-2024, 09:00 AM
                0 responses
                53 views
                0 likes
                Last Post seqadmin  
                Working...
                X