Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • Subsampling bam files

    Hello,

    I need to extract reads from a bam file - for each genomic position, I need to extract a different number of reads.

    Eg.
    CHR START END #READS
    2 12345 12350 10
    2 14567 14568 7

    I have gone through samtools, and cannot see a way to sample a specified number of reads for each position. I have also ran into some elegant perl scripts that will do this by position and %, but not variable for each position.

    Can anyone help?
    Thanks in advance!

  • #2
    First of all sort and index your bam file.
    Then you can use a shell script like this:

    samtools view input.bam 2:12345-12350 | head 10

    The head command will get the desired number of reads.

    Comment


    • #3
      header works

      Thanks! For what I needed worked like a charm!

      The one problem with this command, is that it includes all heads -> you have to use head n+y
      This y is the number of lines before the actual reads (^@), and is specific to each bam file.
      It works great for a couple of files (my case), but will not work if you want to automate it for a larger number of files (unless you code that in as well).

      cheers

      Comment


      • #4
        It is strange. Samtools view show headers only, when you use -h parameter.
        Or you can use grep -v "^@" to remove header.

        You can use it in a bash scripts.

        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, 03-27-2024, 06:37 PM
        0 responses
        13 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 03-27-2024, 06:07 PM
        0 responses
        11 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 03-22-2024, 10:03 AM
        0 responses
        53 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 03-21-2024, 07:32 AM
        0 responses
        69 views
        0 likes
        Last Post seqadmin  
        Working...
        X