Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joseph
    Member
    • Feb 2008
    • 39

    #1

    subsetting a bam file with specific alingment length

    Hi
    I would like to extract a bam file with alignments length = 30.
    I tried a script that I found on BioStar:
    http://biostar.stackexchange.com/questions/12433/answer
    Code:
    samtools view -h in.bam | perl -lane '$l = 0; $F[5] =~ s/(\d+)[MX=DN]/$l+=$1/eg; print if $l = 30 or /^@/' | samtools view -bS - > out.bam
    but, the out.bam still has alignments with length other than 30.
    my in.bam was created by bowtie:
    Code:
    bowtie /indexes/dmelr5.42 -v 2 -k 5 --best --strata -S -t my.fastq | samtools view -uS -o my.bam -
    Please help
    Thanks
    Joseph



    http://biostar.stackexchange.com/questions/12433/answer
  • jbrwn
    Member
    • Mar 2011
    • 37

    #2
    rather than that perl, pipe it into this:
    Code:
    awk 'BEGIN{OFS=FS="\t"}/^@/{print}!/^@/{if(length($10)==30) print}'
    it'll print the header and any line where the sequence (column 10) is 30 characters.

    Comment

    • cedance
      Senior Member
      • Feb 2011
      • 108

      #3
      Both your links to biostar are broken. Are you sure its not at least 30?

      Comment

      • joseph
        Member
        • Feb 2008
        • 39

        #4
        Originally posted by jbrwn View Post
        rather than that perl, pipe it into this:
        Code:
        awk 'BEGIN{OFS=FS="\t"}/^@/{print}!/^@/{if(length($10)==30) print}'
        it'll print the header and any line where the sequence (column 10) is 30 characters.
        thanks. It worked.

        Comment

        • joseph
          Member
          • Feb 2008
          • 39

          #5
          Originally posted by cedance View Post
          Both your links to biostar are broken. Are you sure its not at least 30?
          I changed (print if $l < 60) to (print if $l = 30)
          here is the link again
          http://biostar.stackexchange.com/que...pecific-length

          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
          23 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-22-2026, 10:48 AM
          0 responses
          20 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-15-2026, 10:52 AM
          0 responses
          36 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-14-2026, 05:39 AM
          0 responses
          42 views
          0 reactions
          Last Post SEQadmin2  
          Working...