Package: mergeBams
mergeBams==========version 0.14Merge sam/bam files with intelligent cell barcode preservation.  This has been tested on bam file and tsv output from the 10X Genomics Cellranger program.  The implementation of mergeBams was motivated by and primarily designed for working with Cellranger output.RequirementsPython > 3.5 (mergeBams uses the pysam package but will attempt to install if not already installed)Installation of pipxmoduleloadPython
python3-mpipinstall--userpipx
python3-mpipxensurepathTo read more about pipx, please visithttps://github.com/pipxproject/pipx.Installation of mergeBamsWith pipx installed, installation of mergeBams is trivial.pipxinstall--include-depsmergeBamsTest installation of mergeBamsYou should then be able to test installation by calling mergeBams.  After running the folllowing, you should see the help screen displayed.mergeBams-hHelpusage:mergeBams[-h]-iINPUTS[-lLABELS][-bBCS][-oOUT][--cell_tagCELL_TAG]mergesam/bamfileswithintelligentcellbarcodepreservation

optionalarguments:-h,--helpshowthishelpmessageandexit-iINPUTS,--inputsINPUTSsam/baminputfiles,comma-separated-lLABELS,--labelsLABELSstringsforprependingcellbarcode(i.e.samplename),comma-separated-bBCS,--bcsBCSbarcodesfiles,comma-separated-oOUT,--outOUToutdir--cell_tagCELL_TAGsetifcellbarcodetagshouldnotbeCBUsageThe following is an example of merging two bam files and two barcodes.tsv files that were derived from them.mergeBams-it1.bam,t2.bam\-lt1_,t2_\-bbarcodes1.tsv,barcodes2.tsv\-o/home/user/testExpected outputIn the above example mergeBams will take input bams t1.bam and t2.bam which have the following data...samtoolsviewt1.bam|head-n3-A00613:162:HKWCTDRXX:1:1228:5330:21151272112048091M*00GCAAGCTGAGCACTGGAGTGGAGTTTTCCTGTGGAGAGGAGCCATGCCTAGAGTGGGATGGGCCATTGTTCATCTTCTGGCCCCTGTTGTCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFNH:i:7HI:i:4AS:i:89nM:i:0RE:A:Ili:i:0BC:Z:GCTGTCCAQT:Z:FFFFFFFFCR:Z:ACACCAAAGGTTCCTACY:Z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:Z:FFFFFFFFCR:Z:TTTGTCATCGGTTCGGCY:Z:FFFFFFFFFFFFFFFFCB:Z:TTTGTCATCGGTTCGG-1UR:Z:GCACTGCGAGUY:Z:FF:FFFFF:FUB:Z:GCACTGCGAGRG:Z:B2_GEX:0:1:HKWCTDRXX:2These bam files will be concatenated but will prepend the cell barcode (CB tag) with the label supplied in the program call using the -l flag(samtoolsviewout.bam|head-n3-;samtoolsviewout.bam|tail-n3-)>topandbottom.txt
cattopandbottom.txtA00613:162:HKWCTDRXX:1:1228:5330:21151272112048091M*00GCAAGCTGAGCACTGGAGTGGAGTTTTCCTGTGGAGAGGAGCCATGCCTAGAGTGGGATGGGCCATTGTTCATCTTCTGGCCCCTGTTGTCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFNH:i:7HI:i:4AS:i:89nM:i:0RE:A:Ili:i:0BC:Z:GCTGTCCAQT:Z:FFFFFFFFCR:Z:ACACCAAAGGTTCCTACY:Z:FFFFFFFFFFFFFFFFUR:Z:ACCAGTCGGTUY:Z:FFFFFFFFFFUB:Z:ACCAGTCGGTRG:Z:B1_GEX:0:1:HKWCTDRXX:1CB:Z:t1_ACACCAAAGGTTCCTA-1
A00613:162:HKWCTDRXX:1:1166:7455:25708256116724042M92N49M*00GTGGGGGCGGTGGTGGTGCTGTTAGTACCCCATCTTGTAGGTCTTGAGAGGCTCGGCTACCTCAGTGTGGAAGGTGGGCAGTTCTGGAATGFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFNH:i:6HI:i:4AS:i:85nM:i:2RE:A:Ili:i:0BC:Z:TTGAGATCQT:Z:FFFFFFFFCR:Z:TTTATGCGTCGCCATGCY:Z:FFFFFFFFFFFFFFFFUR:Z:CTAGTTGCGCUY:Z:FFFFFFFFFF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FFFFFFFFFFFFFFFFFFFFFFFFFFF:FFFFFFFFFFFFFFF:F:F:FFFFFFFFFFFFFFFFFFFF:,F,:,NH:i:0HI:i:0AS:i:46nM:i:0uT:A:1xf:i:0li:i:0BC:Z:GCATCTCCQT:Z:FFFFFFFFCR:Z:TTTGTCATCCTGCAGGCY:Z:F:FFFFFFFF:FF:FFUR:Z:CTGCCTATCAUY:Z:FFFFFFFFFFUB:Z:CTGCCTATCARG:Z:B2_GEX:0:1:HKWCTDRXX:2CB:Z:t2_TTTGTCATCCTGCAGG-1
A00613:162:HKWCTDRXX:2:2234:20546:225144*00**00AAGCAGTGGTATCAACGCAGAGTACTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTAGTAAAAAACACCCCCGGTGGGGGGTGGGTAATTFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:FFFFFFFFFFFFFFFFFFFFFF,,:,F:,F,,:,,FF,::,,,FF,,,,::,,,,FNH:i:0HI:i:0AS:i:36nM:i:0uT:A:1xf:i:0li:i:0BC:Z:AACGTCAAQT:Z:FFFFFFFFCR:Z:TTTGTCATCGGTTCGGCY:Z:FFFFFFFFFFFFFFFFUR:Z:GCACTGCGAGUY:Z:FF:FFFFF:FUB:Z:GCACTGCGAGRG:Z:B2_GEX:0:1:HKWCTDRXX:2CB:Z:t2_TTTGTCATCGGTTCGG-1Similarly and if desired, mergeBams will concatenate and add labels to barcodes.tsv files (for compressed barcodes.tsv.gz see below for an explanation of how compression of barcodes files are handled).  For example, in the above case...head-n3barcodes1.tsvAAACCTGAGCCCGAAA-1
AAACCTGAGGTGCTTT-1
AAACCTGAGTACTTGC-1ANDtail-n3barcodes2.tsvTTTGTCATCATTCACT-1
TTTGTCATCCGTTGTC-1
TTTGTCATCCTGCAGG-1Will be joined and given labels.(head-n3outbcs.tsv;tail-n3outbcs.tsv)>topandbottombc.txt
cattopandbottombc.txtt1_AAACCTGAGCCCGAAA-1
t1_AAACCTGAGGTGCTTT-1
t1_AAACCTGAGTACTTGC-1
t2_TTTGTCATCATTCACT-1
t2_TTTGTCATCCGTTGTC-1
t2_TTTGTCATCCTGCAGG-1Note that this program is compression aware and will compress output of barcodes file to match input. I.e. the following will produce compressed barcode file as output.  All supplied barcodes files must either be all compressed or all uncompressed.mergeBams-it1.bam,t2.bam\-lt1_,t2_\-bbarcodes1.tsv.gz,barcodes2.tsv.gz\-o/home/user/testAcknowledgementsWritten by Scott Furlan with help from cfcooldood and rcguy