BAMSORT(1)
πΈ BAMSORT(1) πΈ
okay bestie, welcome to bamsort from section 1 of the General Commands Manual π this one sorts BAM files by coordinate or by query name, and honestly? it's giving main character energy π
π¦ SYNOPSIS π¦
bamsort [options]
π DESCRIPTION π
okay so here's the tea β: bamsort reads a BAM, SAM or CRAM file, sorts it, and writes the sorted file back out in BAM, SAM or CRAM format β¨ and it can sort by literally so many things:
- coordinate β lexicographical by reference sequence id and position on reference sequence
- query name β possibly including the
HIaux tag, for ordering alignments featuring the same query name - hash value β computed for the query name or an aux tag value
now let's talk about what "lexicographical order" even means, because the way that word gets thrown around... π so lexicographical order means pairs (a,b) and (c,d) get ordered such that (a,b) < (c,d) if either a < c, or a = c and b < d. For coordinates this means the alignments are first grouped by reference sequence id (so like, all the alignments for one chromosome show up in one block π) and within the block for each reference sequence, the alignments get ordered by the start position on that sequence. periodt.
the order by query name decomposes the read names into parts containing numbers and parts containing no number π a read name A15_30_C50 will for instance be split into the components A, 15, _, 30, _C and 50. the comparison of read names is then performed lexicographically along this decomposition, where number fields are compared as numbers. as an example we have A15<B12 as A<B, and A9<A12 as A=A and 9<12 (where 9 and 12 are considered as numbers and not as the sequences of their digits π§ ).
the order by hash value computes a hash value (effectively a random number π²) for each read name and orders the alignments by this number in increasing order. alignments assigned the same hash value are ordered by query name.
the order by aux tag compares alignments by the value of a given aux field storing a string value. this string comparison follows the same order used for comparing query names stated above. alignments with the same aux value are sorted by coordinate order.
β οΈ if the memory buffer given is not sufficiently large to process the input file, then the program writes intermediate results to a temporary file. this file can be large and depending on the compression of the input file, larger than the input itself π³ so plan accordingly bestie.
the following key=value pairs can be given π
SO=<coordinate|queryname|hash|tag|tagonly|queryname_HI|queryname_lexicographic>β set the sort order. valid values are:coordinateβ sort alignments by coordinatequerynameβ sort alignments by query namehashβ sort alignments by (Murmur3) hash of query name. this effectively puts them in a random order π²tagβ sort alignments by string aux field. the tag of the aux fields needs to be provided using thesorttagkey. entries with identical tag are sorted by coordinate.tagonlyβ sort alignments by string aux field. the tag of the aux fields needs to be provided using thesorttagkey. entries with identical tag are left in the same order as they were in the input πqueryname_HIβ sort alignments by query name. alignments with identical query name are sorted by the value of theirHIaux field.queryname_lexicographicβ sort alignments by query name using a purely lexicographic comparison instead of the more sophisticated version described above.
level=<-1|0|1|9|11>β set compression level of the output BAM file. valid values are:-1β zlib/gzip default compression level0β uncompressed1β zlib/gzip level 1 (fast) compression9β zlib/gzip level 9 (best) compression
if libmaus has been compiled with support for igzip (see https://software.intel.com/en-us/articles/igzip-a-high-performance-deflate-compressor-with-optimizations-for-genomic-data) then an additional valid value is:
11β igzip compression π₯
verbose=<1>β valid values are:1β print progress report on standard error0β do not print progress report
blockmb=<1024>β set size of the internal memory sorting buffer in megabytes. the default buffer size is one gigabyte πtmpfile=<filename>β set the prefix for temporary file namesdisablevalidation=<0|1>β sets whether input validation is performed. valid values are:0β validation is enabled (default)1β validation is disabled
md5=<0|1>β md5 checksum creation for output file. this option can only be given ifoutputformat=bam. then valid values are:0β do not compute checksum. this is the default.1β compute checksum. if themd5filenamekey is set, then the checksum is written to the given file. ifmd5filenameis unset, then no checksum will be computed.
md5filenameβ file name for md5 checksum ifmd5=1.index=<0|1>β compute BAM index for output file. this option can only be given ifoutputformat=bam. then valid values are:0β do not compute BAM index. this is the default.1β compute BAM index. if theindexfilenamekey is set, then the BAM index is written to the given file. ifindexfilenameis unset, then no BAM index will be computed.
indexfilenameβ file name for output BAM index ifindex=1.inputformat=<bam>β input file format. all versions ofbamsortcome with support for the BAM input format. if the program in addition is linked to theio_libpackage, then the following options are valid:bamβ BAM (seehttp://samtools.sourceforge.net/SAM1.pdf)samβ SAM (seehttp://samtools.sourceforge.net/SAM1.pdf)cramβ CRAM (seehttp://www.ebi.ac.uk/ena/about/cram_toolkit)
outputformat=<bam>β output file format. all versions ofbamsortcome with support for the BAM output format. if the program in addition is linked to theio_libpackage, then the following options are valid:bamβ BAM (seehttp://samtools.sourceforge.net/SAM1.pdf)samβ SAM (seehttp://samtools.sourceforge.net/SAM1.pdf)cramβ CRAM (seehttp://www.ebi.ac.uk/ena/about/cram_toolkit). this format is not advisable for data sorted by query name π«
I=<[stdin]>β input filename, standard input if unset.O=<[stdout]>β output filename, standard output if unset.inputthreads=<[1]>β input helper threads, only valid forinputformat=bam.sortthreads=<[1]>β number of threads used for sorting.outputthreads=<[1]>β output helper threads, only valid foroutputformat=bam.reference=<[]>β reference FastA file forinputformat=cramandoutputformat=cram. an index file (.fai) is required πrange=<>β input range to be processed. this option is only valid if the input is a coordinate sorted and indexed BAM file.fixmates=<0|1>β fix mate information asbamfixmateinformationwould do. input is assumed to be collated by query name (no changes will be applied to mates which are not adjacent in the input stream). by default this option is disabled.calmdnm=<0|1>β calculate theMDandNMfields as a side effect. by default the fields are not calculated. calculation is only performed if sorting is performed by coordinate. ifcalmdnm=1, then the parametercalmdnmreferenceis required. the supported file formats can be found in the manual page forbammdnm.calmdnmreference=<[]>β name of reference sequence file ifcalmdnm=1.calmdnmrecompindetonly=<0|1>β computeMD/NMfields in the presence of indeterminate (N) bases only. this option is only relevant ifcalmdnm=1. by default the fields are computed for all mapped alignments ifcalmdnm=1.calmdnmwarnchange=<0|1>β warn ifMD/NMfield which was computed is differing from a previously existing field. by default no warnings are produced.adddupmarksupport=<0|1>β add information required for streaming duplicate marking in the aux fieldsMSandMC. input is assumed to be collated by query name. this option is ignored unlessfixmates=1. by default it is disabled.markduplicates=<[0]>β mark duplicate read pairs and reads. this option can only be used when a name collated file (all reads for a name are consecutive in the input) is sorted into coordinate order. in addition the input is required not to contain orphan reads (pair ends such that the other end of the pair is not contained in the file) π¨ settingmarkduplicates=1impliesadddupmarksupport=1. the temporarily added auxiliary fields are removed during output generation. themarkduplicatesoption is disabled by default.rmdup=<[0]>β remove the duplicates marked by themarkduplicatesoption. as this requiresmarkduplicates=1, the requirements stated formarkduplicatesalso apply forrmdup.tag=<tag>β name of auxiliary field storing tag information for duplicate marking in string form. read fragments or pairs with different tags will not be considered as duplicates, even if they would be according to their mapping coordinates. for pairs the tag field information of the first and second mate are concatenated to obtain the tag of the pair.nucltag=<tag>β this option works like thetagoption but is restricted to sequences of nucleotides (A,C,GorT) as tags. the length of each tag sequence is not allowed to exceed 15 bases. all tags are required to have the same length. each non nucleotide symbol is mapped toA. in contrast to thetagoption,nucltaguses less memory for processing and can be expected to be faster β‘M=<stderr>β name of the metrics file for duplicate marking (metrics are written to standard error if not set)streaming=<0|1>β do not open input file(s) multiple times if set to1. when given multiple input filesbamsortconcatenates the files on the fly and computes a merged header before starting the data processing. computing the header of the output file requires opening each input file. if each input file can only be opened once (as it may take the form of a pipe or socket connection), thenbamsortwill keep all the files open at the same time. otherwise the files will be opened only as needed to keep the number of open file descriptors lower.sorttag=β tag of aux field used for comparison whenSO=tag.hash=<crc32prod>β hash used for producingbamseqchksumtype header fields in sorted output.
βοΈ AUTHOR βοΈ
written by German Tischler π
π REPORTING BUGS π
report bugs to <germant@miltenyibiotec.de> π¬
Β©οΈ COPYRIGHT Β©οΈ
Copyright Β© 2009-2016 German Tischler, Β© 2011-2014 Genome Research Limited. License GPLv3+: GNU GPL version 3 <http://gnu.org/licenses/gpl.html>
this is free software: you are free to change and redistribute it. there is NO WARRANTY, to the extent permitted by law π
okay bestie that's the whole thing, you're officially a bamsort girlie now π
this page is from BIOBAMBAM, dated September 2017, and it's BAMSORT(1) β go forth and sort, no cap πβ¨π¦
π¦ where this page comes from
- debian bookworm: biobambam2 2.0.185+ds-1 Β· GPL-3.0-or-later
- debian trixie: biobambam2 2.0.185+ds-2 Β· GPL-3.0-or-later
- ubuntu noble: biobambam2 2.0.185+ds-1 Β· GPL-3.0-or-later
- ubuntu questing: biobambam2 2.0.185+ds-2
- ubuntu resolute: biobambam2 2.0.185+ds-2build1 Β· GPL-3.0-or-later
- ubuntu stonking: biobambam2 2.0.185+ds-2build1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms