Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • Remove several bps at the end of the reads

    Is there a simple way to remove several bps at the end of each read in a BAM file?

  • #2
    to really do it right one should also edit the alignment column but since that column which might specify different things at each alignment (continuous alignments, gapped, spliced etc) but if you just want to cut the reads and quality strings down (cutting from the right side and keeping left side) you could do this (all in one line):

    Code:
    myfile="some_file.bam";mylen=20;cat <(samtools view -H $myfile) <(samtools view $myfile | while read line; do cutRead=`echo "$line" | cut -f10 | cut -c1-$mylen`; cutQual=`echo "$line" | cut -f10 | cut -c1-$mylen`;  echo -e "$line" | awk -v cRead=$cutRead -v cQual=$cutQual 'BEGIN {FS="\t";OFS="\t"} {$10=cRead;$11=cQual;print $0}; done)
    just set myfile and mylen to your bam file and the length you want the reads to be post-trimming. the above will produce SAM output to stdout. samtools will not allow you to turn this back into a BAM file, however, since the alignment CIGAR column won't match the sequence lengths.

    of course i 100% do not recommend using the output of this for any downstream analysis using software the accepts SAM files because of the fact that the alignment column (CIGAR annotation) is not edited so as far as any tools are concerted the alignments will still be full length. note that editing that value would require more code to interpret the alignment and edit it based on the trimming.

    is there any chance you can trim the reads prior to alignment? that would be much less messy.
    /* Shawn Driscoll, Gene Expression Laboratory, Pfaff
    Salk Institute for Biological Studies, La Jolla, CA, USA */

    Comment


    • #3
      If you're stuck with .bam files then going along with what sdriscoll said you can convert the bam files to fastq files, trim, and then realign.

      Comment

      Latest Articles

      Collapse

      • seqadmin
        Latest Developments in Precision Medicine
        by seqadmin



        Technological advances have led to drastic improvements in the field of precision medicine, enabling more personalized approaches to treatment. This article explores four leading groups that are overcoming many of the challenges of genomic profiling and precision medicine through their innovative platforms and technologies.

        Somatic Genomics
        “We have such a tremendous amount of genetic diversity that exists within each of us, and not just between us as individuals,”...
        05-24-2024, 01:16 PM
      • seqadmin
        Recent Advances in Sequencing Analysis Tools
        by seqadmin


        The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
        05-06-2024, 07:48 AM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by seqadmin, 05-24-2024, 07:15 AM
      0 responses
      16 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 05-23-2024, 10:28 AM
      0 responses
      18 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 05-23-2024, 07:35 AM
      0 responses
      22 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 05-22-2024, 02:06 PM
      0 responses
      11 views
      0 likes
      Last Post seqadmin  
      Working...
      X