Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • Splitting a BAM based on # of reads?

    Hi All,

    I'm surprised I can't find anything on this topic, but I would like to take a BAM file of, say 100million reads, and split it into multiple files containing 1million reads each. Is there an easy way of doing that? (I thought BamTools, samtools, GATK, Picard, but none of them seem to be able to do this - these tools can only split based on RG, chromosomes, etc. - I wan't to do it based on number of reads).

    Thanks very much in advance.

  • #2
    Yes. Do a view with samtools and use the unix command "split" to split by number of lines and then pipe this output to a new file. You will get a set of output files that are in SAM format. Next run them back through samtools (view -b) and pipe them to a file with a BAM extension. Now you have BAM files split by # of reads.

    Comment


    • #3
      And reinsert the SAM header into each BAM file at the end if required using 'samtools reheader'

      Comment


      • #4
        Originally posted by maubp View Post
        And reinsert the SAM header into each BAM file at the end if required using 'samtools reheader'
        Yes, sorry for omitting this!

        Comment


        • #5
          Ah, yes - that's elegant. Thanks very much for the response - so easy nobody bothered making a script .

          Comment


          • #6
            Originally posted by maubp View Post
            And reinsert the SAM header into each BAM file at the end if required using 'samtools reheader'
            I had to do:
            samtools view -Sb -T reference.fasta out.sam > out.bam

            to each split, to get the header...

            I don't think that the "samtools reheader" would have worked as you describe it in this thread, as the splits themselves do not have any headers.

            Comment


            • #7
              Is there any way to split by number of reads, and not lines?

              Such that each read, even if it has 10 alignments, is contained in a single new BAM file, along with other reads?

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