Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • Convert pileup to bed

    Hello,

    I'm currently using samtools mpileup like this:

    Code:
    samtools mpileup -l target_regions.bed file1.bam file2.bam file3.bam > mpileup-all
    The output format is pileup here's a short example:

    Code:
    chr1	6384820	N	0	*	*	1	G	E	0	*	*	0	*	*	0	*	*	1	G	A0	*	*
    chr1	6384821	N	0	*	*	1	G	H	0	*	*	0	*	*	0	*	*	1	G	H0	*	*
    chr1	6384822	N	0	*	*	1	C	I	0	*	*	0	*	*	0	*	*	1	C	G0	*	*
    chr1	6384825	N	0	*	*	1	C	I	0	*	*	0	*	*	0	*	*	1	C	G0	*	*
    chr1	6384826	N	0	*	*	1	C	I	0	*	*	0	*	*	0	*	*	1	C	G0	*	*
    chr1	6384827	N	0	*	*	1	C	I	0	*	*	0	*	*	0	*	*	1	C	G0	*	*
    chr1	6384828	N	0	*	*	1	C	I	0	*	*	0	*	*	0	*	*	1	C	G0	*	*
    Is there any way to convert his pileup format to bed. For this short example the desired output would be:

    Code:
    chr1	6384820	6384822
    chr1	6384825	6384828
    Thanks.

  • #2
    Perhaps a basic awk script would work:

    $ awk 'BEGIN{\
    first_start=$2;\
    old_start=first_start;\
    }\
    {\
    chr=$1;\
    current_start=$2;\
    if (current_start > (old_start + 1)) {\
    print chr"\t"first_start"\t"old_start;\
    first_start=current_start;\
    old_start=first_start;\
    }\
    else {\
    old_start=current_start;\
    }\
    }\
    END {\
    print chr"\t"first_start"\t"old_start;\
    }' pileup.txt

    Comment


    • #3
      A bed for your example would be

      Code:
      chr1	6384819	6384822
      chr1	6384824	6384828
      because bed is 0-based, right-open.

      You could use my intervalBed script from here in a little pipeline:

      Code:
      samtools mpileup ... \
      | cut -f1,2 \
      | intervalBed header=0 val_col=0 trackname="pileupIntervals" > pileup.bed
      The repository as well as the intervalBed script (written in awk) include more documentation.
      Last edited by dgscofield; 06-05-2013, 03:10 PM. Reason: correct typo in trackname label

      Comment


      • #4
        I think dgscofield is right — while BAM is 0-based, the output from SAM is still 1-based. Easy to screw up. Subtracting one from the start coordinate in my awk script should fix the indexing.

        Comment

        Latest Articles

        Collapse

        • seqadmin
          Recent Advances in Sequencing Analysis Tools
          by seqadmin


          The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
          Yesterday, 07:48 AM
        • seqadmin
          Essential Discoveries and Tools in Epitranscriptomics
          by seqadmin




          The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
          04-22-2024, 07:01 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by seqadmin, Yesterday, 07:17 AM
        0 responses
        12 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 05-02-2024, 08:06 AM
        0 responses
        19 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-30-2024, 12:17 PM
        0 responses
        20 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-29-2024, 10:49 AM
        0 responses
        29 views
        0 likes
        Last Post seqadmin  
        Working...
        X