Hi!

I am trying to make smaller many BAM files (around 60 of them) of size ~200GB (due to disk space limitations) by removing base qualities and tags and other unwanted information. Doing copy number analysis, for me base qualities and tags and duplicates are somehow unwanted information. What I only care about is the mapping quality (MAPQ) since I filter low quality reads!

Currently, I am using [bamUtils squeeze][1] command. I don't know yet how good this tool is in making the bam file smaller! The *squeeze* sub command can replace QNAME with an integer, remove duplicates, and remove OQ tag (i.e. original base qualities) but not the QUAL field. However, for the QUAL field, the tool provides the binning option (to reduce the number of possible quality scores).

Previously, I used [cgat bam2bam method=strip-quality][2] which deletes only the QUAL field. This tool is slow (takes ~12 hours for a 160 GB BAM file) and didn't free much space. The modified BAM file was only 3GB smaller for a 160GB file.

I was wondering if deleting whatever comes after the SEQ (in a SAM/BAM file) will work (i.e QUAL and all other tags)? and if yes, what would be the fastest way to apply that? Or, if there is a tool available that I was not able to find?

Thanks in advance for sharing your ideas!

EDIT1: My question might have been misleading since I said "I only care about MAPQ". I also care about the FLAG and SEQ. Since later in the pipeline, I will call variants; but there only FLAG, MAPQ and SEQ are needed and not any thing else.

EDIT2: Now, I have the result from using [bamUtils squeeze][1] and to me the result is satisfactory. The BAM file is ~4-fold smaller when one:

1. removes the OQ tag,
2. removes the duplicates, and
3. bin the base quality scores

And it took less than 4 hours (3:51) to squeeze a 160GB file to 43.5GB.

 [1]: http://genome.sph.umich.edu/wiki/BamUtil:_squeeze
 [2]: https://www.cgat.org/downloads/public/cgat/documentation/scripts/bam2bam.html
I quickly wrote a tool: see https://github.com/lindenb/jvarkit/wiki/Biostar173114

I checked, it's compatible with samtools.

    $ java -jar dist/biostar173114.jar --formatout sam  my.bam  | samtools view -h | head -n 100
    
    @HD VN:1.5  GO:none SO:coordinate
    @SQ SN:1    LN:249250621
    @SQ SN:2    LN:243199373
    (...)
    @SQ SN:GL000192.1   LN:547496
    R0  0   1   822010  55  51M *   0   0   *   *
    R1  16  1   822010  55  51M *   0   0   *   *
    R2  0   1   829084  60  87M13S  *   0   0   *   *
    R3  0   1   829084  60  87M13S  *   0   0   *   *
    R4  0   1   829084  60  87M13S  *   0   0   *   *
    R5  16  1   829122  59  48M36D52M   *   0   0   *   *
    R6  16  1   829122  59  48M36D52M   *   0   0   *   *
    R7  16  1   829122  59  48M36D52M   *   0   0   *   *
    R8  0   1   848195  46  19S20M3S    *   0   0   *   *
    R9  16  1   848195  46  19S20M3S    *   0   0   *   *
    Ra  0   1   908830  60  47M *   0   0   *   *
    Rb  16  1   908830  60  47M *   0   0   *   *
    Rc  0   1   922930  60  100M    *   0   0   *   *
    Rd  0   1   922930  60  100M    *   0   0   *   *
    Re  0   1   922930  60  100M    *   0   0   *   *

and for better results, you should process your data in parallel.