Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • insert PG and CL tags into BAM header with BWA

    What do you recommend I use to insert full command line into the BAM header created with BWA. BWA already creates this:

    @PG ID:bwa PN:bwa VN:0.5.9-r16

    But I'd like to capture the whole process (aln and sampe) and insert them as CL tags.

    Tophat does it nicely like this for example:

    @PG ID:TopHat VN:1.2.0 CL:/packages/tophat-1.2.0/tophat -r 43 -p 8 -o /some/path/s_1_topHat -G /some/path/Homo_sapiens.NCBI36.54.noMT.gtf /some/path/human_b36_both_noM /some/path/s_1_1.fastq /some/path/s_1_3.fastq

  • #2
    One solution is a script in your language of choice (Perl, Python, etc) to edit the current header, combined with samtools reheader to update the BAM file.

    Comment


    • #3
      First way:

      samtools view -H file.bam > header.sam

      edit header.sam file

      samtools reheader header.sam file.bam > file_new_head.bam

      OR as a one liner, something like this:

      samtools view -h file.bam | perl -pe 's/^\@PG\told line$/@PG\tnew line/' | samtools view -Sb -o file_new_head.bam -

      Chris

      Comment


      • #4
        adding @PG @RG and more with BamUtil polishBam

        I disc-overed this great 'Umich' tooolbox after searching for quite some time (http://genome.sph.umich.edu/wiki/BamUtil:_polishBam)

        I first stored my full bwa command in a variable 'cmd' then looked for my bwa version using 'expr' and finally built the full @PG string taking care of keeping tabs (that was hard! ).

        The result was accepted by polishBam and creates a true @PG line.
        I guess similar approach will work for other header tags.

        Code:
        rgstring='@RG\tID:NA18507\tLB:lib-NA18507\tPU:unkn-0.0\tPL:ILLUMINA\tSM:GAIIx-chr21-BWA.mem'
        
        ... more parameters not replicated here (obvious)
        
        cmd="bwa mem -R \"${rgstring}\" \
        	-M \
        	-t ${nthr} \
        	${refgen} \
        	${fq1} ${fq2} > ${outfolder}/${bwape}.sam \
        	2>${outfolder}/${pfx}_bwa_mem.err"
         
        # execute the command
        eval ${cmd}
         
        #### add @PG group to results with **bamUtil**
        # important formatting issues here
        # $'\t' is adding a 'tab'
        # \' surrounding ${cmd} \' make sure the long text is not interpreted
        # finally, $pgstring should be quoted
        bwaver=$(expr "$(bwa 2>&1)" : '.*Version:\(.*\)Contact.*')
        pgstring=@PG$'\t'ID:BWA$'\t'VN:${bwaver}$'\t'CL:\'${cmd}\'
         
        bam polishBam --PG "${pgstring}" \
        	-i ${outfolder}/${bwape}.sam \
        	-o ${outfolder}/${bwape}pg.sam \
        	-l ${outfolder}/polishBam_${infile%%.bam}.log
        Hope this will help others!
        thanks to the BamUtil team for these great tools



        PS: the quick and dirty method consisting in adding the @PG line with the @RG (-R) option seems to work too.

        # substitute the following string in the upper command
        rgstring='@RG\tID:NA18507\tLB:lib-NA18507\tPU:unkn-0.0\tPL:ILLUMINA\tSM:GAIIx-chr21-BWA.mem\n@PG\tID:BWA\tVN:...'

        still, I would prefer an additional BWA parameter to do this and more about headers.
        http://www.bits.vib.be/index.php

        Comment

        Latest Articles

        Collapse

        • 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
        • seqadmin
          Techniques and Challenges in Conservation Genomics
          by seqadmin



          The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

          Avian Conservation
          Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
          03-08-2024, 10:41 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by seqadmin, Yesterday, 06:37 PM
        0 responses
        8 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, Yesterday, 06:07 PM
        0 responses
        8 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 03-22-2024, 10:03 AM
        0 responses
        49 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 03-21-2024, 07:32 AM
        0 responses
        67 views
        0 likes
        Last Post seqadmin  
        Working...
        X