Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EcoRInya
    Member
    • Apr 2016
    • 11

    #1

    downsampling read pairs from a bam file

    Hi guys,

    I am trying to downsample a bam file with paired reads. Initially I was using samtools view -s, providing a fraction of reads I'd like to keep. But the caveat for this is that the output file will contain not only intact read pairs but also individual reads. It is bad for me because I am trying to use this downsampled bam file for analysis with packages that take as an input bed files (such as diffReps). In case when I have both paired and not paired reads in a bam file, there is no way I can convert it to bed 100% correctly.

    Do you have any suggestions on how I could downsample a bam file keeping read pairs intact? I really struggled to find a ready solution for this by googling.

    Many thanks in advance!
  • GenoMax
    Senior Member
    • Feb 2008
    • 7142

    #2
    Take a look at @Brian's post in this thread.

    Edit: Looking at @Brian's post again it seems as if the paired information would not be kept. If you have original fastq files available you should be able to retrieve the other read from a pair by using repair.sh.
    Last edited by GenoMax; 04-05-2016, 06:05 AM.

    Comment

    • fanli
      Senior Member
      • Jul 2014
      • 197

      #3
      seqtk does this and will keep read pairs intact if you pass the same random seed:


      Code:
      seqtk sample -s100 read1.fq 10000 > sub1.fq
      seqtk sample -s100 read2.fq 10000 > sub2.fq

      Comment

      • EcoRInya
        Member
        • Apr 2016
        • 11

        #4
        GenoMax, thank you for your reply!
        Do you know what happens with the total read count after this repair? I don't quite understand that. If I just complete all the read pairs, it will obviously affect total number of reads I am getting and screw downsampling.

        Comment

        • EcoRInya
          Member
          • Apr 2016
          • 11

          #5
          thank you, fanli!
          I am not sure that downsampling of a fastq file is a good idea. I use downsampling for normalisation and if I downsample initial fastq files I don't know how many reads I am getting back after the alignment is done which is not suitable for normalisation. However, I could convert bam with uniquely aligned reads after PCR duplicates removal to fastq and use seqtk. I am not sure that it is the most optimal solution though. But I will think about it.

          Comment

          • GenoMax
            Senior Member
            • Feb 2008
            • 7142

            #6
            "Repair.sh" (re-pair : a trick name) should only recover corresponding reads to the ones that are present in the downsampled file.

            I assume you are doing this from the BAM because you only want to sample reads that aligned (your BAM does not have unmapped reads?). If you don't care about the alignments then you could downsample the original fastq files by using reformat.sh or the seqtk method @fanli posted above.

            Comment

            • EcoRInya
              Member
              • Apr 2016
              • 11

              #7
              >"Repair.sh" (re-pair : a trick name) should only recover corresponding reads to the ones that are present in the downsampled file.

              But if I am doing it for several files, for different files ratio of the incomplete pairs will be random and different. It means that if I add a pair to the reads in the downsampled file I will potentially get different number of reads and scew downsampling (with subsequent normalisation).

              >I assume you are doing this from the BAM because you only want to sample reads that aligned (your BAM does not have unmapped reads?).

              Exactly!
              Last edited by EcoRInya; 04-05-2016, 07:30 AM.

              Comment

              • GenoMax
                Senior Member
                • Feb 2008
                • 7142

                #8
                Can you clarify what exactly are you trying to achive? Are these separate files/samples or same sample multiple files? Your BAM files don't have unmapped reads?

                Comment

                • EcoRInya
                  Member
                  • Apr 2016
                  • 11

                  #9
                  Sure! I am downsampling bam files that contain uniquely aligned reads with PCR duplicates removed. In total I have 6 bam files (2 conditions, 3 replicated each). For each file I have a normalisation coefficient which I want to use as a downsampling factor, bringing each bam file to a specific read count. I will be using the resulting downsampled bam files for different kinds of comparative analysis between groups. For instance, using diffReps package. It takes as an input bed files. For paired end reads these bed files should contain position of the centre of a fragment. In order, to create such a file all the reads in the bam file should be paired, which I have failed to achieve using standard samtools view -s.

                  Comment

                  Latest Articles

                  Collapse

                  • SEQadmin2
                    Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
                    by SEQadmin2



                    CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

                    Despite this, “CRISPR helped turn genome editing from a specialized technique into
                    ...
                    07-31-2026, 11:01 AM
                  • SEQadmin2
                    Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                    by SEQadmin2


                    Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                    The systematic characterization of the human proteome has
                    ...
                    07-20-2026, 11:48 AM
                  • SEQadmin2
                    Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                    by SEQadmin2



                    Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                    ...
                    07-09-2026, 11:10 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by SEQadmin2, 08-06-2026, 07:41 AM
                  0 responses
                  13 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 08-03-2026, 10:13 AM
                  0 responses
                  30 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-31-2026, 02:55 AM
                  0 responses
                  40 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-24-2026, 12:17 PM
                  0 responses
                  26 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...