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
          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
        25 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-10-2024, 10:19 PM
        0 responses
        28 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-10-2024, 09:21 AM
        0 responses
        24 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-04-2024, 09:00 AM
        0 responses
        52 views
        0 likes
        Last Post seqadmin  
        Working...
        X