Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WilliamsHJ1@cardiff.ac.uk
    Junior Member
    • Mar 2025
    • 4

    #1

    Remove unwanted contigs and update bam header

    Hi,
    I have some human genome data in bam format that I want to upload to some software (Congenica) to perform variant filtering.
    The problem I have is that presently the data has been mapped to a reference genome containing alternate contigs but the software does not accept them, it only accepts contigs from the standard chromosomes chr1-22, chrX, chrY and chrM.

    I therefore want to remove the alternate contigs and then update the header to only include the standard chromosomes. Sounds simple but nothing I have tried will actually give me a usable bam file to upload.

    I have started using a bam file where the header looks like:

    Click image for larger version

Name:	dataurl230738.png
Views:	283
Size:	235.9 KB
ID:	326478

    There are thousands of the alt contigs and then some lines with @RG and @PG data.

    I first used the following samtools command:

    samtools view -L bam_contigs_to_keep.bed -O BAM -o Foo_edit_1.bam Foo.bam

    where the bed file looks like:
    Click image for larger version

Name:	dataurl230743.png
Views:	302
Size:	72.6 KB
ID:	326476
    This has reduced the bam file size from ~12GB to ~9GB which I assume is a result of the alternate contigs being removed.
    However, the alternate contigs are still included in the header and so I’ve next used the following command to update the header:
    samtools reheader reordered_head_GRCh38.dict Foo_edit_1.bam > Foo_edit_2.bam
    the .dict file looks like this:
    Click image for larger version

Name:	dataurl230744.png
Views:	274
Size:	139.5 KB
ID:	326477

    This reduces the bam file size by just ~100KB which I’ve assumed is due to the alternate contigs being removed from the header.

    My problem is that when I run samtools flagstat the original bam and edit_1.bam have >1billion reads but edit_2.bam has ~600 and is truncated.

    I have also tried using the picard ReplaceSamHeader command, and this example from another forum:
    samtools view Foo.bam chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrX chrY chrM | samtools view -bo Foo_edit_2.bam -t corrected_bam_head.sam -

    Nothing has yet worked and given me a usable edited bam file.

    I would really appreciate any help or advice someone could give about this.

    Many thanks

    Hywel

    ​
  • katyperry
    Junior Member
    • May 2026
    • 4

    #2
    Very helpful explanation for handling BAM headers and unwanted contigs. Technical discussions like this feel satisfying to solve, almost like progressing through tricky levels in Golf Hit.

    Comment

    • incidental
      Junior Member
      • May 2026
      • 4

      #3
      Very helpful explanation for troubleshooting sequencing data and dealing with unexpected contigs. Technical problems like this are always satisfying to work through, almost like completing tricky levels in Hollow Knight

      Comment

      Latest Articles

      Collapse

      • 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
      • SEQadmin2
        New Genomics Technologies Take Aim at Long-Standing Limits
        by SEQadmin2


        Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

        We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
        ...
        09-28-2026, 10:25 AM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by SEQadmin2, 10-22-2026, 11:13 AM
      0 responses
      29 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 10-22-2026, 10:48 AM
      0 responses
      22 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 10-15-2026, 10:52 AM
      0 responses
      39 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 10-14-2026, 05:39 AM
      0 responses
      45 views
      0 reactions
      Last Post SEQadmin2  
      Working...