Is there a simple way to remove several bps at the end of each read in a BAM file?
Unconfigured Ad
Collapse
X
-
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):
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.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)
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 */
Latest Articles
Collapse
-
by SEQadmin2
When the Human Genome Project declared the human genome finished in 2003, portions of the sequence were still missing, including many of its most repetitive and structurally complex regions.1 Still, for the next two decades, researchers analyzed their sequencing data against the single linear reference that came out of this effort. Released in 2013 as GRCh38, that reference has powered countless discoveries, but it has gaps and cannot capture the genetic diversity of the world’s...-
Channel: Articles
Today, 07:04 AM -
-
by SEQadmin2
NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification,...-
Channel: Articles
10-30-2026, 06:46 AM -
ad_right_rmr
Collapse
News
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by SEQadmin2, Yesterday, 11:11 AM
|
0 responses
14 views
0 reactions
|
Last Post
by SEQadmin2
Yesterday, 11:11 AM
|
||
|
Started by SEQadmin2, 11-17-2026, 06:27 AM
|
0 responses
39 views
0 reactions
|
Last Post
by SEQadmin2
11-17-2026, 06:27 AM
|
||
|
Started by SEQadmin2, 11-12-2026, 07:59 AM
|
0 responses
55 views
0 reactions
|
Last Post
by SEQadmin2
11-12-2026, 07:59 AM
|
||
|
Started by SEQadmin2, 11-05-2026, 09:25 AM
|
0 responses
61 views
0 reactions
|
Last Post
by SEQadmin2
11-05-2026, 09:25 AM
|
Comment